1 /*
2 * Bethsoft VID format Demuxer
3 * Copyright (c) 2007 Nicholas Tung
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * @brief Bethesda Softworks VID (.vid) file demuxer
25 * @author Nicholas Tung [ntung (at. ntung com] (2007-03)
26 * @see http://wiki.multimedia.cx/index.php?title=Bethsoft_VID
27 * @see http://www.svatopluk.com/andux/docs/dfvid.html
28 */
29
35
36 #define BVID_PALETTE_SIZE 3 * 256
37
38 #define DEFAULT_SAMPLE_RATE 11111
39
41 {
46 /** delay value between frames, added to individual frame delay.
47 * custom units, which will be added to other custom units (~=16ms according
48 * to free, unofficial documentation) */
53
55
57
59 {
60 // little-endian VID tag, file starts with "VID0円"
62 return 0;
63
65 }
66
68 {
71
72 /* load main header. Contents:
73 * bytes: 'V' 'I' 'D'
74 * int16s: always_512, nframes, width, height, delay, always_14
75 */
82
83 // wait until the first packet to create each stream
88
89 return 0;
90 }
91
92 #define BUFFER_PADDING_SIZE 1000
95 {
97 int vidbuf_nbytes = 0;
98 int code;
99 int bytes_copied = 0;
101 unsigned int vidbuf_capacity;
104
107 if (!st)
112 "having no audio packet before the first "
113 "video packet");
114 }
120 }
123
125 if(!vidbuf_start)
127
128 // save the file position for the packet, include block type
130
131 vidbuf_start[vidbuf_nbytes++] = block_type;
132
133 // get the current packet duration
135
136 // set the y offset if it exists (decoder header data should be in data section)
138 if (
avio_read(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) {
140 goto fail;
141 }
142 vidbuf_nbytes += 2;
143 }
144
145 do{
147 if(!vidbuf_start)
149
151 vidbuf_start[vidbuf_nbytes++] = code;
152
153 if(code >= 0x80){ // rle sequence
155 vidbuf_start[vidbuf_nbytes++] =
avio_r8(pb);
156 } else if(code){ // plain sequence
157 if (
avio_read(pb, &vidbuf_start[vidbuf_nbytes], code) != code) {
159 goto fail;
160 }
161 vidbuf_nbytes += code;
162 }
163 bytes_copied += code & 0x7F;
164 if(bytes_copied == npixels){ // sometimes no stop character is given, need to keep track of bytes copied
165 // may contain a 0 byte even if read all pixels
168 break;
169 }
170 if (bytes_copied > npixels) {
172 goto fail;
173 }
174 } while(code);
175
176 // copy data into packet
178 goto fail;
179 memcpy(pkt->
data, vidbuf_start, vidbuf_nbytes);
181
187
188 /* if there is a new palette available, add it to packet side data */
192 if (pdata)
195 }
196
197 vid->
nframes--;
// used to check if all the frames were read
198 return 0;
199 fail:
202 }
203
206 {
209 unsigned char block_type;
210 int audio_length;
211 int ret_value;
212
215
217 switch(block_type){
222 }
229 }
231
234 // soundblaster DAC used for sample rate, as on specification page (link above)
239 if (!st)
251 }
253 if ((ret_value =
av_get_packet(pb, pkt, audio_length)) != audio_length) {
254 if (ret_value < 0)
255 return ret_value;
258 }
262 return 0;
263
267 return read_frame(vid, pb, pkt, block_type, s);
268
274 default:
275 av_log(s,
AV_LOG_ERROR,
"unknown block (character = %c, decimal = %d, hex = %x)!!!\n",
276 block_type, block_type, block_type);
278 }
279 }
280
282 {
285 return 0;
286 }
287
289 .
name =
"bethsoftvid",
296 };