Mercurial > libavformat.hg
annotate idroq.c @ 5018:2d29b49bae3e libavformat
cosmetics: Prettyprint one more line to have columns line up.
author | diego |
---|---|
date | Thu, 11 Jun 2009 20:45:35 +0000 |
parents | 492dd0722ee1 |
children | 536e5527c1e0 |
rev | line source |
---|---|
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1 /* |
3428
b0936b8a0337
cosmetics: s/Id/id/ in libavformat where Id refers to id Software.
diego
parents:
3424
diff
changeset
|
2 * id RoQ (.roq) File Demuxer |
211
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 /** |
4331
49c1d3b27727
Use full internal pathname in doxygen @file directives.
diego
parents:
4201
diff
changeset
|
23 * @file libavformat/idroq.c |
3428
b0936b8a0337
cosmetics: s/Id/id/ in libavformat where Id refers to id Software.
diego
parents:
3424
diff
changeset
|
24 * id RoQ format file demuxer |
211
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 |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
3973
diff
changeset
|
30 #include "libavutil/intreadwrite.h" |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
31 #include "avformat.h" |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
32 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
33 #define RoQ_MAGIC_NUMBER 0x1084 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
34 #define RoQ_CHUNK_PREAMBLE_SIZE 8 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
35 #define RoQ_AUDIO_SAMPLE_RATE 22050 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
36 #define RoQ_CHUNKS_TO_SCAN 30 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
37 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
38 #define RoQ_INFO 0x1001 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
39 #define RoQ_QUAD_CODEBOOK 0x1002 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
40 #define RoQ_QUAD_VQ 0x1011 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
41 #define RoQ_SOUND_MONO 0x1020 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
42 #define RoQ_SOUND_STEREO 0x1021 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
43 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
44 typedef struct RoqDemuxContext { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
45 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
46 int width; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
47 int height; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
48 int audio_channels; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
49 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
50 int video_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
51 int audio_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
52 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
53 int64_t video_pts; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
54 unsigned int audio_frame_count; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
55 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
56 } RoqDemuxContext; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
57 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
58 static int roq_probe(AVProbeData *p) |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
59 { |
1673 | 60 if ((AV_RL16(&p->buf[0]) != RoQ_MAGIC_NUMBER) || |
61 (AV_RL32(&p->buf[2]) != 0xFFFFFFFF)) | |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
62 return 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
63 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
64 return AVPROBE_SCORE_MAX; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
65 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
66 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
67 static int roq_read_header(AVFormatContext *s, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
68 AVFormatParameters *ap) |
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 RoqDemuxContext *roq = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
71 ByteIOContext *pb = s->pb; |
4705
492dd0722ee1
Simplify RoQ demuxer pts calculation by using a appropriate time bases.
reimar
parents:
4704
diff
changeset
|
72 int framerate; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
73 AVStream *st; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
74 unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
75 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
76 /* get the main header */ |
885 | 77 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
|
78 RoQ_CHUNK_PREAMBLE_SIZE) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
79 return AVERROR(EIO); |
4705
492dd0722ee1
Simplify RoQ demuxer pts calculation by using a appropriate time bases.
reimar
parents:
4704
diff
changeset
|
80 framerate = AV_RL16(&preamble[6]); |
211
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 /* init private context parameters */ |
885 | 83 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
|
84 roq->audio_frame_count = 0; |
4704
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
85 roq->audio_stream_index = -1; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
86 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
87 st = av_new_stream(s, 0); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
88 if (!st) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
89 return AVERROR(ENOMEM); |
4705
492dd0722ee1
Simplify RoQ demuxer pts calculation by using a appropriate time bases.
reimar
parents:
4704
diff
changeset
|
90 av_set_pts_info(st, 63, 1, framerate); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 st->codec->codec_tag = 0; /* no fourcc */ |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
95 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
96 return 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
97 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
98 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
99 static int roq_read_packet(AVFormatContext *s, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
100 AVPacket *pkt) |
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 RoqDemuxContext *roq = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
103 ByteIOContext *pb = s->pb; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
104 int ret = 0; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
105 unsigned int chunk_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
106 unsigned int chunk_type; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
107 unsigned int codebook_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
108 unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
109 int packet_read = 0; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3908
diff
changeset
|
110 int64_t codebook_offset; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
111 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
112 while (!packet_read) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
113 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
114 if (url_feof(s->pb)) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
115 return AVERROR(EIO); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
116 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
117 /* get the next chunk preamble */ |
885 | 118 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
|
119 RoQ_CHUNK_PREAMBLE_SIZE) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
120 return AVERROR(EIO); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
121 |
1673 | 122 chunk_type = AV_RL16(&preamble[0]); |
123 chunk_size = AV_RL32(&preamble[2]); | |
643 | 124 if(chunk_size > INT_MAX) |
125 return AVERROR_INVALIDDATA; | |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
126 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
127 switch (chunk_type) { |
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 case RoQ_INFO: |
4704
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
130 if (!roq->width || !roq->height) { |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
131 AVStream *st = s->streams[roq->video_stream_index]; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
132 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
133 return AVERROR(EIO); |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
134 st->codec->width = roq->width = AV_RL16(preamble); |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
135 st->codec->height = roq->height = AV_RL16(preamble + 2); |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
136 break; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
137 } |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
138 /* don't care about this chunk anymore */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
139 url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
140 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
141 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
142 case RoQ_QUAD_CODEBOOK: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
143 /* 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
|
144 codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
145 codebook_size = chunk_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
146 url_fseek(pb, codebook_size, SEEK_CUR); |
885 | 147 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
|
148 RoQ_CHUNK_PREAMBLE_SIZE) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
149 return AVERROR(EIO); |
1673 | 150 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
|
151 codebook_size; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
152 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
153 /* rewind */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
154 url_fseek(pb, codebook_offset, SEEK_SET); |
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 /* load up the packet */ |
775 | 157 ret= av_get_packet(pb, pkt, chunk_size); |
158 if (ret != chunk_size) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
159 return AVERROR(EIO); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
160 pkt->stream_index = roq->video_stream_index; |
4705
492dd0722ee1
Simplify RoQ demuxer pts calculation by using a appropriate time bases.
reimar
parents:
4704
diff
changeset
|
161 pkt->pts = roq->video_pts++; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
162 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
163 packet_read = 1; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
164 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
165 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
166 case RoQ_SOUND_MONO: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
167 case RoQ_SOUND_STEREO: |
4704
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
168 if (roq->audio_stream_index == -1) { |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
169 AVStream *st = av_new_stream(s, 1); |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
170 if (!st) |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
171 return AVERROR(ENOMEM); |
4705
492dd0722ee1
Simplify RoQ demuxer pts calculation by using a appropriate time bases.
reimar
parents:
4704
diff
changeset
|
172 av_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); |
4704
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
173 roq->audio_stream_index = st->index; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
174 st->codec->codec_type = CODEC_TYPE_AUDIO; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
175 st->codec->codec_id = CODEC_ID_ROQ_DPCM; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
176 st->codec->codec_tag = 0; /* no tag */ |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
177 st->codec->channels = roq->audio_channels = chunk_type == RoQ_SOUND_STEREO ? 2 : 1; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
178 st->codec->sample_rate = RoQ_AUDIO_SAMPLE_RATE; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
179 st->codec->bits_per_coded_sample = 16; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
180 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
181 st->codec->bits_per_coded_sample; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
182 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; |
2b641c55e83e
Set video width/height and create audio stream in read_packet instead of
reimar
parents:
4331
diff
changeset
|
183 } |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
184 case RoQ_QUAD_VQ: |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
185 /* load up the packet */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
186 if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE)) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
187 return AVERROR(EIO); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
188 /* copy over preamble */ |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
189 memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE); |
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 (chunk_type == RoQ_QUAD_VQ) { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
192 pkt->stream_index = roq->video_stream_index; |
4705
492dd0722ee1
Simplify RoQ demuxer pts calculation by using a appropriate time bases.
reimar
parents:
4704
diff
changeset
|
193 pkt->pts = roq->video_pts++; |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
194 } else { |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
195 pkt->stream_index = roq->audio_stream_index; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
196 pkt->pts = roq->audio_frame_count; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
197 roq->audio_frame_count += (chunk_size / roq->audio_channels); |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
198 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
199 |
775 | 200 pkt->pos= url_ftell(pb); |
257
3b33a366e13b
send the chunk preamble bytes to the respective decoders; Id RoQ demuxer
tmmm
parents:
254
diff
changeset
|
201 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
|
202 chunk_size); |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
203 if (ret != chunk_size) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
204 ret = AVERROR(EIO); |
211
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 packet_read = 1; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
207 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
208 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
209 default: |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
257
diff
changeset
|
210 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
|
211 return AVERROR_INVALIDDATA; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
212 break; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
213 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
214 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
215 |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
216 return ret; |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
217 } |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
218 |
1169 | 219 AVInputFormat roq_demuxer = { |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
220 "RoQ", |
3428
b0936b8a0337
cosmetics: s/Id/id/ in libavformat where Id refers to id Software.
diego
parents:
3424
diff
changeset
|
221 NULL_IF_CONFIG_SMALL("id RoQ format"), |
211
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
222 sizeof(RoqDemuxContext), |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
223 roq_probe, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
224 roq_read_header, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
225 roq_read_packet, |
349d63d52e7e
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
226 }; |