Mercurial > libavformat.hg
annotate idroq.c @ 1894:1cbd1d658165 libavformat
fix demuxing of broken MVI_3011.avi
author | michael |
---|---|
date | Sat, 10 Mar 2007 19:30:59 +0000 |
parents | a782462e2497 |
children | 1a3c9056982a |
rev | line source |
---|---|
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1 /* |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
2 * Id RoQ (.roq) File Demuxer |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
3 * Copyright (c) 2003 The ffmpeg Project |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
16 * |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
20 */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
21 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
22 /** |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
23 * @file idroq.c |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
24 * Id RoQ format file demuxer |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
25 * by Mike Melanson (melanson@pcisys.net) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
26 * for more information on the .roq file format, visit: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
27 * http://www.csse.monash.edu.au/~timf/ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
28 */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
29 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
30 #include "avformat.h" |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
31 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
32 #define RoQ_MAGIC_NUMBER 0x1084 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
33 #define RoQ_CHUNK_PREAMBLE_SIZE 8 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
34 #define RoQ_AUDIO_SAMPLE_RATE 22050 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
35 #define RoQ_CHUNKS_TO_SCAN 30 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
36 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
37 #define RoQ_INFO 0x1001 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
38 #define RoQ_QUAD_CODEBOOK 0x1002 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
39 #define RoQ_QUAD_VQ 0x1011 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
40 #define RoQ_SOUND_MONO 0x1020 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
41 #define RoQ_SOUND_STEREO 0x1021 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
42 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
43 typedef struct RoqDemuxContext { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
44 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
45 int width; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
46 int height; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
47 int audio_channels; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
48 int framerate; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
49 int frame_pts_inc; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
50 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
51 int video_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
52 int audio_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
53 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
54 int64_t video_pts; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
55 unsigned int audio_frame_count; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
56 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
57 } RoqDemuxContext; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
58 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
59 static int roq_probe(AVProbeData *p) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
60 { |
254
bca5abd97e43
clean up 4xm demuxer; make valgrind just a little happier
tmmm
parents:
211
diff
changeset
|
61 if (p->buf_size < 6) |
bca5abd97e43
clean up 4xm demuxer; make valgrind just a little happier
tmmm
parents:
211
diff
changeset
|
62 return 0; |
bca5abd97e43
clean up 4xm demuxer; make valgrind just a little happier
tmmm
parents:
211
diff
changeset
|
63 |
1673 | 64 if ((AV_RL16(&p->buf[0]) != RoQ_MAGIC_NUMBER) || |
65 (AV_RL32(&p->buf[2]) != 0xFFFFFFFF)) | |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
66 return 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
67 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
68 return AVPROBE_SCORE_MAX; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
69 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
70 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
71 static int roq_read_header(AVFormatContext *s, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
72 AVFormatParameters *ap) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
73 { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
74 RoqDemuxContext *roq = s->priv_data; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
75 ByteIOContext *pb = &s->pb; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
76 AVStream *st; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
77 unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
78 int i; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
79 unsigned int chunk_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
80 unsigned int chunk_type; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
81 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
82 /* get the main header */ |
885 | 83 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
84 RoQ_CHUNK_PREAMBLE_SIZE) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
85 return AVERROR_IO; |
1673 | 86 roq->framerate = AV_RL16(&preamble[6]); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
87 roq->frame_pts_inc = 90000 / roq->framerate; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
88 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
89 /* init private context parameters */ |
885 | 90 roq->width = roq->height = roq->audio_channels = roq->video_pts = |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
91 roq->audio_frame_count = 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
92 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
93 /* scan the first n chunks searching for A/V parameters */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
94 for (i = 0; i < RoQ_CHUNKS_TO_SCAN; i++) { |
885 | 95 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
96 RoQ_CHUNK_PREAMBLE_SIZE) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
97 return AVERROR_IO; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
98 |
1673 | 99 chunk_type = AV_RL16(&preamble[0]); |
100 chunk_size = AV_RL32(&preamble[2]); | |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
101 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
102 switch (chunk_type) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
103 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
104 case RoQ_INFO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
105 /* fetch the width and height; reuse the preamble bytes */ |
885 | 106 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
107 RoQ_CHUNK_PREAMBLE_SIZE) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
108 return AVERROR_IO; |
1673 | 109 roq->width = AV_RL16(&preamble[0]); |
110 roq->height = AV_RL16(&preamble[2]); | |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
111 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
112 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
113 case RoQ_QUAD_CODEBOOK: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
114 case RoQ_QUAD_VQ: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
115 /* ignore during this scan */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
116 url_fseek(pb, chunk_size, SEEK_CUR); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
117 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
118 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
119 case RoQ_SOUND_MONO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
120 roq->audio_channels = 1; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
121 url_fseek(pb, chunk_size, SEEK_CUR); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
122 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
123 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
124 case RoQ_SOUND_STEREO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
125 roq->audio_channels = 2; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
126 url_fseek(pb, chunk_size, SEEK_CUR); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
127 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
128 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
129 default: |
1673 | 130 av_log(s, AV_LOG_ERROR, " unknown RoQ chunk type (%04X)\n", AV_RL16(&preamble[0])); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
131 return AVERROR_INVALIDDATA; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
132 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
133 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
134 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
135 /* if all necessary parameters have been gathered, exit early */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
136 if ((roq->width && roq->height) && roq->audio_channels) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
137 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
138 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
139 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
140 /* seek back to the first chunk */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
141 url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_SET); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
142 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
143 /* initialize the decoders */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
144 st = av_new_stream(s, 0); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
145 if (!st) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
146 return AVERROR_NOMEM; |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
386
diff
changeset
|
147 /* set the pts reference (1 pts = 1/90000) */ |
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
386
diff
changeset
|
148 av_set_pts_info(st, 33, 1, 90000); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
149 roq->video_stream_index = st->index; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
150 st->codec->codec_type = CODEC_TYPE_VIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
151 st->codec->codec_id = CODEC_ID_ROQ; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
152 st->codec->codec_tag = 0; /* no fourcc */ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
153 st->codec->width = roq->width; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
154 st->codec->height = roq->height; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
155 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
156 if (roq->audio_channels) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
157 st = av_new_stream(s, 0); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
158 if (!st) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
159 return AVERROR_NOMEM; |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
386
diff
changeset
|
160 av_set_pts_info(st, 33, 1, 90000); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
161 roq->audio_stream_index = st->index; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
162 st->codec->codec_type = CODEC_TYPE_AUDIO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
163 st->codec->codec_id = CODEC_ID_ROQ_DPCM; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
164 st->codec->codec_tag = 0; /* no tag */ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
165 st->codec->channels = roq->audio_channels; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
166 st->codec->sample_rate = RoQ_AUDIO_SAMPLE_RATE; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
167 st->codec->bits_per_sample = 16; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
168 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
169 st->codec->bits_per_sample; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
170 st->codec->block_align = st->codec->channels * st->codec->bits_per_sample; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
171 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
172 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
173 return 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
174 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
175 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
176 static int roq_read_packet(AVFormatContext *s, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
177 AVPacket *pkt) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
178 { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
179 RoqDemuxContext *roq = s->priv_data; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
180 ByteIOContext *pb = &s->pb; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
181 int ret = 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
182 unsigned int chunk_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
183 unsigned int chunk_type; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
184 unsigned int codebook_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
185 unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
186 int packet_read = 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
187 offset_t codebook_offset; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
188 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
189 while (!packet_read) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
190 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
191 if (url_feof(&s->pb)) |
482 | 192 return AVERROR_IO; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
193 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
194 /* get the next chunk preamble */ |
885 | 195 if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) != |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
196 RoQ_CHUNK_PREAMBLE_SIZE) |
482 | 197 return AVERROR_IO; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
198 |
1673 | 199 chunk_type = AV_RL16(&preamble[0]); |
200 chunk_size = AV_RL32(&preamble[2]); | |
643 | 201 if(chunk_size > INT_MAX) |
202 return AVERROR_INVALIDDATA; | |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
203 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
204 switch (chunk_type) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
205 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
206 case RoQ_INFO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
207 /* don't care about this chunk anymore */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
208 url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
209 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
210 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
211 case RoQ_QUAD_CODEBOOK: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
212 /* packet needs to contain both this codebook and next VQ chunk */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
213 codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
214 codebook_size = chunk_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
215 url_fseek(pb, codebook_size, SEEK_CUR); |
885 | 216 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
217 RoQ_CHUNK_PREAMBLE_SIZE) |
482 | 218 return AVERROR_IO; |
1673 | 219 chunk_size = AV_RL32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 + |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
220 codebook_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
221 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
222 /* rewind */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
223 url_fseek(pb, codebook_offset, SEEK_SET); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
224 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
225 /* load up the packet */ |
775 | 226 ret= av_get_packet(pb, pkt, chunk_size); |
227 if (ret != chunk_size) | |
482 | 228 return AVERROR_IO; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
229 pkt->stream_index = roq->video_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
230 pkt->pts = roq->video_pts; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
231 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
232 roq->video_pts += roq->frame_pts_inc; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
233 packet_read = 1; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
234 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
235 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
236 case RoQ_SOUND_MONO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
237 case RoQ_SOUND_STEREO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
238 case RoQ_QUAD_VQ: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
239 /* load up the packet */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
240 if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE)) |
482 | 241 return AVERROR_IO; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
242 /* copy over preamble */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
243 memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
244 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
245 if (chunk_type == RoQ_QUAD_VQ) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
246 pkt->stream_index = roq->video_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
247 pkt->pts = roq->video_pts; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
248 roq->video_pts += roq->frame_pts_inc; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
249 } else { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
250 pkt->stream_index = roq->audio_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
251 pkt->pts = roq->audio_frame_count; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
252 pkt->pts *= 90000; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
253 pkt->pts /= RoQ_AUDIO_SAMPLE_RATE; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
254 roq->audio_frame_count += (chunk_size / roq->audio_channels); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
255 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
256 |
775 | 257 pkt->pos= url_ftell(pb); |
257
3b33a366e13b
send the chunk preamble bytes to the respective decoders; Id RoQ demuxer
tmmm
parents:
254
diff
changeset
|
258 ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, |
3b33a366e13b
send the chunk preamble bytes to the respective decoders; Id RoQ demuxer
tmmm
parents:
254
diff
changeset
|
259 chunk_size); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
260 if (ret != chunk_size) |
482 | 261 ret = AVERROR_IO; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
262 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
263 packet_read = 1; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
264 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
265 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
266 default: |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
257
diff
changeset
|
267 av_log(s, AV_LOG_ERROR, " unknown RoQ chunk (%04X)\n", chunk_type); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
268 return AVERROR_INVALIDDATA; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
269 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
270 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
271 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
272 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
273 return ret; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
274 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
275 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
276 static int roq_read_close(AVFormatContext *s) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
277 { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
278 // RoqDemuxContext *roq = (RoqDemuxContext *)s->priv_data; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
279 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
280 return 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
281 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
282 |
1169 | 283 AVInputFormat roq_demuxer = { |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
284 "RoQ", |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
285 "Id RoQ format", |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
286 sizeof(RoqDemuxContext), |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
287 roq_probe, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
288 roq_read_header, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
289 roq_read_packet, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
290 roq_read_close, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
291 }; |