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
66
68 }
69
71 {
74
75 /* load main header. Contents:
76 * bytes: 'V' 'I' 'D'
77 * int16s: always_512, nframes, width, height, delay, always_14
78 */
85
86 // wait until the first packet to create each stream
91
92 return 0;
93 }
94
95 #define BUFFER_PADDING_SIZE 1000
98 {
100 int vidbuf_nbytes = 0;
101 int code;
102 int bytes_copied = 0;
104 unsigned int vidbuf_capacity;
105 int ret = 0;
107
110 if (!st)
115 "having no audio packet before the first "
116 "video packet");
117 }
123 }
126
128 if(!vidbuf_start)
130
131 // save the file position for the packet, include block type
133
134 vidbuf_start[vidbuf_nbytes++] = block_type;
135
136 // get the current packet duration
138
139 // set the y offset if it exists (decoder header data should be in data section)
141 if (
avio_read(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) {
144 }
145 vidbuf_nbytes += 2;
146 }
147
148 do{
150 if(!vidbuf_start)
152
154 vidbuf_start[vidbuf_nbytes++] = code;
155
156 if(code >= 0x80){ // rle sequence
158 vidbuf_start[vidbuf_nbytes++] =
avio_r8(pb);
159 } else if(code){ // plain sequence
160 if (
avio_read(pb, &vidbuf_start[vidbuf_nbytes], code) != code) {
163 }
164 vidbuf_nbytes += code;
165 }
166 bytes_copied += code & 0x7F;
167 if(bytes_copied == npixels){ // sometimes no stop character is given, need to keep track of bytes copied
168 // may contain a 0 byte even if read all pixels
171 break;
172 }
173 if (bytes_copied > npixels) {
176 }
177 } while(code);
178
179 // copy data into packet
182 memcpy(pkt->
data, vidbuf_start, vidbuf_nbytes);
183
189
190 /* if there is a new palette available, add it to packet side data */
194 if (!pdata) {
198 }
200
202 }
203
204 vid->
nframes--;
// used to check if all the frames were read
207 return ret;
208 }
209
212 {
215 unsigned char block_type;
216 int audio_length;
217 int ret_value;
218
221
223 switch(block_type){
228 }
235 }
237
240 // soundblaster DAC used for sample rate, as on specification page (link above)
245 if (!st)
257 }
259 if ((ret_value =
av_get_packet(pb, pkt, audio_length)) != audio_length) {
260 if (ret_value < 0)
261 return ret_value;
264 }
268 return 0;
269
273 return read_frame(vid, pb, pkt, block_type, s);
274
280 default:
281 av_log(s,
AV_LOG_ERROR,
"unknown block (character = %c, decimal = %d, hex = %x)!!!\n",
282 block_type, block_type, block_type);
284 }
285 }
286
288 {
291 return 0;
292 }
293
295 .
name =
"bethsoftvid",
302 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int bethsoft_global_delay
delay value between frames, added to individual frame delay.
static int vid_read_header(AVFormatContext *s)
static int vid_probe(AVProbeData *p)
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
int64_t pos
byte position in stream, -1 if unknown
int index
stream index in AVFormatContext
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int ctx_flags
Flags signalling stream properties.
int sample_rate
audio sample rate
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define BVID_PALETTE_SIZE
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define DEFAULT_SAMPLE_RATE
int video_index
video stream index
int flags
A combination of AV_PKT_FLAG values.
uint64_t channel_layout
Audio channel layout.
#define BUFFER_PADDING_SIZE
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
AVInputFormat ff_bethsoftvid_demuxer
audio channel layout utility functions
int width
picture width / height.
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int vid_read_close(AVFormatContext *s)
enum AVMediaType codec_type
int sample_rate
samples per second
AVIOContext * pb
I/O context.
int audio_index
audio stream index
This structure contains the data a format has to probe a file.
static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt, uint8_t block_type, AVFormatContext *s)
unsigned int avio_rl16(AVIOContext *s)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
int channels
number of audio channels
void * priv_data
Format private data.
static int vid_read_packet(AVFormatContext *s, AVPacket *pkt)
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.