1 /*
2 * Silicon Graphics Movie demuxer
3 * Copyright (c) 2012 Peter Ross
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 * Silicon Graphics Movie demuxer
25 */
26
31
34
38
39 int eof_count;
///< number of streams that have finished
41 int frame[2];
///< frame nb for current stream
42
46
47 #define AUDIO_FORMAT_SIGNED 401
48
50 {
54 return 0;
55 }
56
58 {
60 char *str;
61
62 if (size < 0 || size == INT_MAX)
64
66 if (!str)
69 if (n < size)
71 return str;
72 }
73
75 {
76 int v;
78 if (!s)
79 return 0;
80 v = strtol(s,
NULL, 10);
82 return v;
83 }
84
86 {
89 if (!s)
93 return v;
94 }
95
97 {
99 if (value)
101 }
102
104 {
105 if (channels <= 0) {
108 }
112 return 0;
113 }
114
115 /**
116 * Parse global variable
117 * @return < 0 if unknown
118 */
121 {
124 if (!strcmp(name, "__NUM_I_TRACKS")) {
126 } else if (!strcmp(name, "__NUM_A_TRACKS")) {
128 } else if (!strcmp(name, "COMMENT") || !strcmp(name, "TITLE")) {
130 } else if (!strcmp(name, "LOOP_MODE") || !strcmp(name, "NUM_LOOPS") ||
131 !strcmp(name, "OPTIMIZED")) {
133 } else
135
136 return 0;
137 }
138
139 /**
140 * Parse audio variable
141 * @return < 0 if unknown
142 */
145 {
148 if (!strcmp(name, "__DIR_COUNT")) {
150 } else if (!strcmp(name, "AUDIO_FORMAT")) {
152 } else if (!strcmp(name, "COMPRESSION")) {
154 } else if (!strcmp(name, "DEFAULT_VOL")) {
156 } else if (!strcmp(name, "NUM_CHANNELS")) {
158 } else if (!strcmp(name, "SAMPLE_RATE")) {
161 } else if (!strcmp(name, "SAMPLE_WIDTH")) {
163 } else
165
166 return 0;
167 }
168
169 /**
170 * Parse video variable
171 * @return < 0 if unknown
172 */
175 {
177 if (!strcmp(name, "__DIR_COUNT")) {
179 } else if (!strcmp(name, "COMPRESSION")) {
181 if (!str)
183 if (!strcmp(str, "1")) {
185 } else if (!strcmp(str, "2")) {
188 } else if (!strcmp(str, "3")) {
190 } else if (!strcmp(str, "10")) {
192 } else if (!strcmp(str, "MVC2")) {
194 } else {
196 }
198 } else if (!strcmp(name, "FPS")) {
202 } else if (!strcmp(name, "HEIGHT")) {
204 } else if (!strcmp(name, "PIXEL_ASPECT")) {
208 INT_MAX);
209 } else if (!strcmp(name, "WIDTH")) {
211 } else if (!strcmp(name, "ORIENTATION")) {
215 }
216 } else if (!strcmp(name, "Q_SPATIAL") || !strcmp(name, "Q_TEMPORAL")) {
218 } else if (!strcmp(name, "INTERLACING") || !strcmp(name, "PACKING")) {
220 } else
222
223 return 0;
224 }
225
229 {
231 int i;
232
237 for (i = 0; i <
count; i++) {
238 char name[17];
240
243
245 name[
sizeof(
name) - 1] = 0;
247 if (size < 0) {
250 }
251 if (
parse(avctx, st, name, size) < 0) {
254 }
255 }
256 return 0;
257 }
258
260 {
261 uint64_t timestamp = 0;
262 int i;
270 } else {
271 timestamp++;
272 }
273 }
274 }
275
277 {
282 int ret;
283
285
287 if (version == 2) {
288 uint64_t timestamp;
289 int v;
291
292 /* allocate audio track first to prevent unnecessary seeking
293 * (audio packet always precede video packet for a given frame) */
295 if (!ast)
297
299 if (!vst)
303 vst->avg_frame_rate =
av_inv_q(vst->time_base);
306 switch (v) {
307 case 1:
309 break;
310 case 2:
313 break;
314 default:
316 break;
317 }
318 vst->codecpar->codec_tag = 0;
322
329 }
333
337 } else {
339 }
340
345
346 timestamp = 0;
347 for (i = 0; i < vst->nb_frames; i++) {
357 }
358 }
else if (!version &&
avio_rb16(pb) == 3) {
360
362 return ret;
363
369 if (!ast)
373 return ret;
378 } else {
380 "Audio compression %i (format %i, sr %i)",
384 }
388 }
389 }
390
396 if (!vst)
400 return ret;
401 }
402
405
408 } else {
411 }
412
413 return 0;
414 }
415
417 {
423 int64_t ret;
424 uint64_t pos;
425
426 if (frame < st->nb_index_entries) {
429 if (index->
pos > pos)
431 else if (index->
pos < pos) {
435 if (ret < 0)
436 return ret;
437 }
439 if (ret < 0)
440 return ret;
441
445
448 } else {
452
453 // avoid returning 0 without a packet
455 }
456
460
461 return 0;
462 }
463
465 int64_t timestamp,
int flags)
466 {
470
473
476
478 if (frame < 0)
480
482 mv->
frame[i] = frame;
483 return 0;
484 }
485
494 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int mv_read_header(AVFormatContext *avctx)
static int parse_video_var(AVFormatContext *avctx, AVStream *st, const char *name, int size)
Parse video variable.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
static char * var_read_string(AVIOContext *pb, int size)
int stream_index
current stream index
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static AVRational var_read_float(AVIOContext *pb, int size)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define AV_CH_LAYOUT_STEREO
unsigned int avio_rb16(AVIOContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static int mv_read_packet(AVFormatContext *avctx, AVPacket *pkt)
static void var_read_metadata(AVFormatContext *avctx, const char *tag, int size)
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
unsigned int avio_rb32(AVIOContext *s)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
AVStream ** streams
A list of all streams in the file.
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
#define AVERROR_EOF
End of file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
uint64_t channel_layout
Audio only.
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
int eof_count
number of streams that have finished
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
static int mv_read_seek(AVFormatContext *avctx, int stream_index, int64_t timestamp, int flags)
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
enum AVMediaType codec_type
General type of the encoded data.
AVRational avg_frame_rate
Average framerate.
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
int flags
A combination of AV_PKT_FLAG values.
int extradata_size
Size of the extradata content in bytes.
static int read_table(AVFormatContext *avctx, AVStream *st, int(*parse)(AVFormatContext *avctx, AVStream *st, const char *name, int size))
static void read_index(AVIOContext *pb, AVStream *st)
int frame[2]
frame nb for current stream
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
audio channel layout utility functions
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
GLsizei GLboolean const GLfloat * value
#define AUDIO_FORMAT_SIGNED
static int parse_audio_var(AVFormatContext *avctx, AVStream *st, const char *name, int size)
Parse audio variable.
int acompression
compression level for audio stream
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
static const int8_t mv[256][2]
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
char * av_strdup(const char *s)
Duplicate a string.
AVIOContext * pb
I/O context.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Rational number (pair of numerator and denominator).
This structure contains the data a format has to probe a file.
AVInputFormat ff_mv_demuxer
static int var_read_int(AVIOContext *pb, int size)
static int parse_global_var(AVFormatContext *avctx, AVStream *st, const char *name, int size)
Parse global variable.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
int64_t duration
Decoding: duration of the stream, in stream time base.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int sample_rate
Audio only.
Utilties for rational number calculation.
int64_t nb_frames
number of frames in this stream if known or 0
#define MKBETAG(a, b, c, d)
void * priv_data
Format private data.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
static int mv_probe(AVProbeData *p)
static int set_channels(AVFormatContext *avctx, AVStream *st, int channels)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
simple arithmetic expression evaluator