Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * "Real" compatible demuxer. | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
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 | #include <inttypes.h> | ||
23 | |||
24 | #include "libavutil/avassert.h" | ||
25 | #include "libavutil/channel_layout.h" | ||
26 | #include "libavutil/internal.h" | ||
27 | #include "libavutil/intreadwrite.h" | ||
28 | #include "libavutil/dict.h" | ||
29 | #include "libavutil/mem.h" | ||
30 | #include "avformat.h" | ||
31 | #include "avio_internal.h" | ||
32 | #include "demux.h" | ||
33 | #include "internal.h" | ||
34 | #include "rmsipr.h" | ||
35 | #include "rm.h" | ||
36 | |||
37 | #define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for Cooker/ATRAC | ||
38 | #define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed | ||
39 | #define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8 | ||
40 | #define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro | ||
41 | #define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC | ||
42 | #define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC | ||
43 | |||
44 | struct RMStream { | ||
45 | AVPacket pkt; ///< place to store merged video frame / reordered audio data | ||
46 | int videobufsize; ///< current assembled frame size | ||
47 | int videobufpos; ///< position for the next slice in the video buffer | ||
48 | int curpic_num; ///< picture number of current frame | ||
49 | int cur_slice, slices; | ||
50 | int64_t pktpos; ///< first slice position in file | ||
51 | /// Audio descrambling matrix parameters | ||
52 | int64_t audiotimestamp; ///< Audio packet timestamp | ||
53 | int sub_packet_cnt; // Subpacket counter, used while reading | ||
54 | int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container | ||
55 | int audio_framesize; ///< Audio frame size from container | ||
56 | int sub_packet_lengths[16]; ///< Length of each subpacket | ||
57 | int32_t deint_id; ///< deinterleaver used in audio stream | ||
58 | }; | ||
59 | |||
60 | typedef struct RMDemuxContext { | ||
61 | int nb_packets; | ||
62 | int old_format; | ||
63 | int current_stream; | ||
64 | int remaining_len; | ||
65 | int audio_stream_num; ///< Stream number for audio packets | ||
66 | int audio_pkt_cnt; ///< Output packet counter | ||
67 | int data_end; | ||
68 | } RMDemuxContext; | ||
69 | |||
70 | 303 | static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len) | |
71 | { | ||
72 | 303 | int read = avio_get_str(pb, len, buf, buf_size); | |
73 | |||
74 |
2/2✓ Branch 0 taken 293 times.
✓ Branch 1 taken 10 times.
|
303 | if (read > 0) |
75 | 293 | avio_skip(pb, len - read); | |
76 | 303 | } | |
77 | |||
78 | 193 | static void get_str8(AVIOContext *pb, char *buf, int buf_size) | |
79 | { | ||
80 | 193 | get_strl(pb, buf, buf_size, avio_r8(pb)); | |
81 | 193 | } | |
82 | |||
83 | 30 | static int rm_read_extradata(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, unsigned size) | |
84 | { | ||
85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (size >= 1<<24) { |
86 | ✗ | av_log(s, AV_LOG_ERROR, "extradata size %u too large\n", size); | |
87 | ✗ | return -1; | |
88 | } | ||
89 | 30 | return ff_get_extradata(s, par, pb, size); | |
90 | } | ||
91 | |||
92 | 27 | static void rm_read_metadata(AVFormatContext *s, AVIOContext *pb, int wide) | |
93 | { | ||
94 | char buf[1024]; | ||
95 | int i; | ||
96 | |||
97 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 27 times.
|
135 | for (i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) { |
98 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 8 times.
|
108 | int len = wide ? avio_rb16(pb) : avio_r8(pb); |
99 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 75 times.
|
108 | if (len > 0) { |
100 | 33 | get_strl(pb, buf, sizeof(buf), len); | |
101 | 33 | av_dict_set(&s->metadata, ff_rm_metadata[i], buf, 0); | |
102 | } | ||
103 | } | ||
104 | 27 | } | |
105 | |||
106 | 45 | RMStream *ff_rm_alloc_rmstream (void) | |
107 | { | ||
108 | 45 | RMStream *rms = av_mallocz(sizeof(RMStream)); | |
109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (!rms) |
110 | ✗ | return NULL; | |
111 | 45 | rms->curpic_num = -1; | |
112 | 45 | return rms; | |
113 | } | ||
114 | |||
115 | 35 | void ff_rm_free_rmstream (RMStream *rms) | |
116 | { | ||
117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if (!rms) |
118 | ✗ | return; | |
119 | |||
120 | 35 | av_packet_unref(&rms->pkt); | |
121 | } | ||
122 | |||
123 | 14 | static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, | |
124 | AVStream *st, RMStream *ast, int read_all) | ||
125 | { | ||
126 | 14 | FFStream *const sti = ffstream(st); | |
127 | char buf[256]; | ||
128 | uint32_t version; | ||
129 | int ret; | ||
130 | |||
131 | /* ra type header */ | ||
132 | 14 | version = avio_rb16(pb); /* version */ | |
133 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
|
14 | if (version == 3) { |
134 | unsigned bytes_per_minute; | ||
135 | 2 | int header_size = avio_rb16(pb); | |
136 | 2 | int64_t startpos = avio_tell(pb); | |
137 | 2 | avio_skip(pb, 8); | |
138 | 2 | bytes_per_minute = avio_rb16(pb); | |
139 | 2 | avio_skip(pb, 4); | |
140 | 2 | rm_read_metadata(s, pb, 0); | |
141 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if ((startpos + header_size) >= avio_tell(pb) + 2) { |
142 | // fourcc (should always be "lpcJ") | ||
143 | 2 | avio_r8(pb); | |
144 | 2 | get_str8(pb, buf, sizeof(buf)); | |
145 | } | ||
146 | // Skip extra header crap (this should never happen) | ||
147 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if ((startpos + header_size) > avio_tell(pb)) |
148 | ✗ | avio_skip(pb, header_size + startpos - avio_tell(pb)); | |
149 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (bytes_per_minute) |
150 | 2 | st->codecpar->bit_rate = 8LL * bytes_per_minute / 60; | |
151 | 2 | st->codecpar->sample_rate = 8000; | |
152 | 2 | st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; | |
153 | 2 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
154 | 2 | st->codecpar->codec_id = AV_CODEC_ID_RA_144; | |
155 | 2 | ast->deint_id = DEINT_ID_INT0; | |
156 | } else { | ||
157 | int flavor, sub_packet_h, coded_framesize, sub_packet_size; | ||
158 | int codecdata_length; | ||
159 | unsigned bytes_per_minute; | ||
160 | /* old version (4) */ | ||
161 | 12 | avio_skip(pb, 2); /* unused */ | |
162 | 12 | avio_rb32(pb); /* .ra4 */ | |
163 | 12 | avio_rb32(pb); /* data size */ | |
164 | 12 | avio_rb16(pb); /* version2 */ | |
165 | 12 | avio_rb32(pb); /* header size */ | |
166 | 12 | flavor= avio_rb16(pb); /* add codec info / flavor */ | |
167 | 12 | coded_framesize = avio_rb32(pb); /* coded frame size */ | |
168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (coded_framesize < 0) |
169 | ✗ | return AVERROR_INVALIDDATA; | |
170 | 12 | ast->coded_framesize = coded_framesize; | |
171 | |||
172 | 12 | avio_rb32(pb); /* ??? */ | |
173 | 12 | bytes_per_minute = avio_rb32(pb); | |
174 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
|
12 | if (version == 4) { |
175 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (bytes_per_minute) |
176 | 7 | st->codecpar->bit_rate = 8LL * bytes_per_minute / 60; | |
177 | } | ||
178 | 12 | avio_rb32(pb); /* ??? */ | |
179 | 12 | ast->sub_packet_h = sub_packet_h = avio_rb16(pb); /* 1 */ | |
180 | 12 | st->codecpar->block_align= avio_rb16(pb); /* frame size */ | |
181 | 12 | ast->sub_packet_size = sub_packet_size = avio_rb16(pb); /* sub packet size */ | |
182 | 12 | avio_rb16(pb); /* ??? */ | |
183 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7 times.
|
12 | if (version == 5) { |
184 | 5 | avio_rb16(pb); avio_rb16(pb); avio_rb16(pb); | |
185 | } | ||
186 | 12 | st->codecpar->sample_rate = avio_rb16(pb); | |
187 | 12 | avio_rb32(pb); | |
188 | 12 | st->codecpar->ch_layout.nb_channels = avio_rb16(pb); | |
189 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7 times.
|
12 | if (version == 5) { |
190 | 5 | ast->deint_id = avio_rl32(pb); | |
191 | 5 | avio_read(pb, buf, 4); | |
192 | 5 | buf[4] = 0; | |
193 | } else { | ||
194 | 7 | AV_WL32(buf, 0); | |
195 | 7 | get_str8(pb, buf, sizeof(buf)); /* desc */ | |
196 | 7 | ast->deint_id = AV_RL32(buf); | |
197 | 7 | get_str8(pb, buf, sizeof(buf)); /* desc */ | |
198 | } | ||
199 | 12 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
200 | 12 | st->codecpar->codec_tag = AV_RL32(buf); | |
201 | 24 | st->codecpar->codec_id = ff_codec_get_id(ff_rm_codec_tags, | |
202 | 12 | st->codecpar->codec_tag); | |
203 | |||
204 |
5/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
12 | switch (st->codecpar->codec_id) { |
205 | 1 | case AV_CODEC_ID_AC3: | |
206 | 1 | sti->need_parsing = AVSTREAM_PARSE_FULL; | |
207 | 1 | break; | |
208 | 1 | case AV_CODEC_ID_RA_288: | |
209 | 1 | st->codecpar->extradata_size= 0; | |
210 | 1 | av_freep(&st->codecpar->extradata); | |
211 | 1 | ast->audio_framesize = st->codecpar->block_align; | |
212 | 1 | st->codecpar->block_align = coded_framesize; | |
213 | 1 | break; | |
214 | 5 | case AV_CODEC_ID_COOK: | |
215 | 5 | sti->need_parsing = AVSTREAM_PARSE_HEADERS; | |
216 | 9 | case AV_CODEC_ID_ATRAC3: | |
217 | case AV_CODEC_ID_SIPR: | ||
218 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (read_all) { |
219 | ✗ | codecdata_length = 0; | |
220 | } else { | ||
221 | 9 | avio_rb16(pb); avio_r8(pb); | |
222 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | if (version == 5) |
223 | 5 | avio_r8(pb); | |
224 | 9 | codecdata_length = avio_rb32(pb); | |
225 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if((unsigned)codecdata_length > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE){ |
226 | ✗ | av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); | |
227 | ✗ | return -1; | |
228 | } | ||
229 | } | ||
230 | |||
231 | 9 | ast->audio_framesize = st->codecpar->block_align; | |
232 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
9 | if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) { |
233 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (flavor > 3) { |
234 | ✗ | av_log(s, AV_LOG_ERROR, "bad SIPR file flavor %d\n", | |
235 | flavor); | ||
236 | ✗ | return -1; | |
237 | } | ||
238 | 4 | st->codecpar->block_align = ff_sipr_subpk_size[flavor]; | |
239 | 4 | sti->need_parsing = AVSTREAM_PARSE_FULL_RAW; | |
240 | } else { | ||
241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if(sub_packet_size <= 0){ |
242 | ✗ | av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n"); | |
243 | ✗ | return -1; | |
244 | } | ||
245 | 5 | st->codecpar->block_align = ast->sub_packet_size; | |
246 | } | ||
247 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if ((ret = rm_read_extradata(s, pb, st->codecpar, codecdata_length)) < 0) |
248 | ✗ | return ret; | |
249 | |||
250 | 9 | break; | |
251 | ✗ | case AV_CODEC_ID_AAC: | |
252 | ✗ | avio_rb16(pb); avio_r8(pb); | |
253 | ✗ | if (version == 5) | |
254 | ✗ | avio_r8(pb); | |
255 | ✗ | codecdata_length = avio_rb32(pb); | |
256 | ✗ | if((unsigned)codecdata_length > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE){ | |
257 | ✗ | av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); | |
258 | ✗ | return -1; | |
259 | } | ||
260 | ✗ | if (codecdata_length >= 1) { | |
261 | ✗ | avio_r8(pb); | |
262 | ✗ | if ((ret = rm_read_extradata(s, pb, st->codecpar, codecdata_length - 1)) < 0) | |
263 | ✗ | return ret; | |
264 | } | ||
265 | ✗ | break; | |
266 | } | ||
267 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | switch (ast->deint_id) { |
268 | 1 | case DEINT_ID_INT4: | |
269 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if (ast->coded_framesize > ast->audio_framesize || |
270 | 1 | sub_packet_h <= 1 || | |
271 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | ast->coded_framesize * (uint64_t)sub_packet_h > (2LL + (sub_packet_h & 1)) * ast->audio_framesize) |
272 | ✗ | return AVERROR_INVALIDDATA; | |
273 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (ast->coded_framesize * (uint64_t)sub_packet_h != 2LL*ast->audio_framesize) { |
274 | ✗ | avpriv_request_sample(s, "mismatching interleaver parameters"); | |
275 | ✗ | return AVERROR_INVALIDDATA; | |
276 | } | ||
277 | 1 | break; | |
278 | 5 | case DEINT_ID_GENR: | |
279 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (ast->sub_packet_size <= 0 || |
280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | ast->sub_packet_size > ast->audio_framesize) |
281 | ✗ | return AVERROR_INVALIDDATA; | |
282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (ast->audio_framesize % ast->sub_packet_size) |
283 | ✗ | return AVERROR_INVALIDDATA; | |
284 | 5 | break; | |
285 | 6 | case DEINT_ID_SIPR: | |
286 | case DEINT_ID_INT0: | ||
287 | case DEINT_ID_VBRS: | ||
288 | case DEINT_ID_VBRF: | ||
289 | 6 | break; | |
290 | ✗ | default: | |
291 | ✗ | av_log(s, AV_LOG_ERROR ,"Unknown interleaver %"PRIX32"\n", ast->deint_id); | |
292 | ✗ | return AVERROR_INVALIDDATA; | |
293 | } | ||
294 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
|
12 | if (ast->deint_id == DEINT_ID_INT4 || |
295 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 5 times.
|
11 | ast->deint_id == DEINT_ID_GENR || |
296 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | ast->deint_id == DEINT_ID_SIPR) { |
297 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (st->codecpar->block_align <= 0 || |
298 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | ast->audio_framesize * (uint64_t)sub_packet_h > (unsigned)INT_MAX || |
299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | ast->audio_framesize * sub_packet_h < st->codecpar->block_align) |
300 | ✗ | return AVERROR_INVALIDDATA; | |
301 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0) |
302 | ✗ | return AVERROR(ENOMEM); | |
303 | } | ||
304 | |||
305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (read_all) { |
306 | ✗ | avio_r8(pb); | |
307 | ✗ | avio_r8(pb); | |
308 | ✗ | avio_r8(pb); | |
309 | ✗ | rm_read_metadata(s, pb, 0); | |
310 | } | ||
311 | } | ||
312 | 14 | return 0; | |
313 | } | ||
314 | |||
315 | 44 | int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb, | |
316 | AVStream *st, RMStream *rst, | ||
317 | unsigned int codec_data_size, const uint8_t *mime) | ||
318 | { | ||
319 | unsigned int v; | ||
320 | int size; | ||
321 | int64_t codec_pos; | ||
322 | int ret; | ||
323 | |||
324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (codec_data_size > INT_MAX) |
325 | ✗ | return AVERROR_INVALIDDATA; | |
326 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (codec_data_size == 0) |
327 | ✗ | return 0; | |
328 | |||
329 | // Duplicate tags | ||
330 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | if ( st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN |
331 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | && st->codecpar->codec_type != AVMEDIA_TYPE_DATA) |
332 | ✗ | return AVERROR_INVALIDDATA; | |
333 | |||
334 | 44 | avpriv_set_pts_info(st, 64, 1, 1000); | |
335 | 44 | codec_pos = avio_tell(pb); | |
336 | 44 | v = avio_rb32(pb); | |
337 | |||
338 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 31 times.
|
44 | if (v == MKTAG(0xfd, 'a', 'r', '.')) { |
339 | /* ra type header */ | ||
340 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
|
13 | if (rm_read_audio_stream_info(s, pb, st, rst, 0)) |
341 | ✗ | return -1; | |
342 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 30 times.
|
31 | } else if (v == MKBETAG('L', 'S', 'D', ':')) { |
343 | 1 | avio_seek(pb, -4, SEEK_CUR); | |
344 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if ((ret = rm_read_extradata(s, pb, st->codecpar, codec_data_size)) < 0) |
345 | ✗ | return ret; | |
346 | |||
347 | 1 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
348 | 1 | st->codecpar->codec_tag = AV_RL32(st->codecpar->extradata); | |
349 | 1 | st->codecpar->codec_id = ff_codec_get_id(ff_rm_codec_tags, | |
350 | 1 | st->codecpar->codec_tag); | |
351 |
3/4✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 20 times.
|
40 | } else if(mime && !strcmp(mime, "logical-fileinfo")){ |
352 | int stream_count, rule_count, property_count, i; | ||
353 | 10 | ff_remove_stream(s, st); | |
354 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (avio_rb16(pb) != 0) { |
355 | ✗ | av_log(s, AV_LOG_WARNING, "Unsupported version\n"); | |
356 | ✗ | goto skip; | |
357 | } | ||
358 | 10 | stream_count = avio_rb16(pb); | |
359 | 10 | avio_skip(pb, 6*stream_count); | |
360 | 10 | rule_count = avio_rb16(pb); | |
361 | 10 | avio_skip(pb, 2*rule_count); | |
362 | 10 | property_count = avio_rb16(pb); | |
363 |
2/2✓ Branch 0 taken 89 times.
✓ Branch 1 taken 10 times.
|
99 | for(i=0; i<property_count; i++){ |
364 | uint8_t name[128], val[128]; | ||
365 | 89 | avio_rb32(pb); | |
366 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
|
89 | if (avio_rb16(pb) != 0) { |
367 | ✗ | av_log(s, AV_LOG_WARNING, "Unsupported Name value property version\n"); | |
368 | ✗ | goto skip; //FIXME skip just this one | |
369 | } | ||
370 | 89 | get_str8(pb, name, sizeof(name)); | |
371 |
2/2✓ Branch 1 taken 77 times.
✓ Branch 2 taken 12 times.
|
89 | switch(avio_rb32(pb)) { |
372 | 77 | case 2: get_strl(pb, val, sizeof(val), avio_rb16(pb)); | |
373 | 77 | av_dict_set(&s->metadata, name, val, 0); | |
374 | 77 | break; | |
375 | 12 | default: avio_skip(pb, avio_rb16(pb)); | |
376 | } | ||
377 | } | ||
378 | } else { | ||
379 | int fps; | ||
380 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
|
20 | if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) { |
381 | ✗ | fail1: | |
382 | ✗ | av_log(s, AV_LOG_WARNING, "Unsupported stream type %08x\n", v); | |
383 | ✗ | goto skip; | |
384 | } | ||
385 | 20 | st->codecpar->codec_tag = avio_rl32(pb); | |
386 | 40 | st->codecpar->codec_id = ff_codec_get_id(ff_rm_codec_tags, | |
387 | 20 | st->codecpar->codec_tag); | |
388 | 20 | av_log(s, AV_LOG_TRACE, "%"PRIX32" %X\n", | |
389 | 20 | st->codecpar->codec_tag, MKTAG('R', 'V', '2', '0')); | |
390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (st->codecpar->codec_id == AV_CODEC_ID_NONE) |
391 | ✗ | goto fail1; | |
392 | 20 | st->codecpar->width = avio_rb16(pb); | |
393 | 20 | st->codecpar->height = avio_rb16(pb); | |
394 | 20 | avio_skip(pb, 2); // looks like bits per sample | |
395 | 20 | avio_skip(pb, 4); // always zero? | |
396 | 20 | st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; | |
397 | 20 | ffstream(st)->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; | |
398 | 20 | fps = avio_rb32(pb); | |
399 | |||
400 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
|
20 | if ((ret = rm_read_extradata(s, pb, st->codecpar, codec_data_size - (avio_tell(pb) - codec_pos))) < 0) |
401 | ✗ | return ret; | |
402 | |||
403 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
|
20 | if (fps > 0) { |
404 | 19 | av_reduce(&st->avg_frame_rate.den, &st->avg_frame_rate.num, | |
405 | 0x10000, fps, (1 << 30) - 1); | ||
406 | #if FF_API_R_FRAME_RATE | ||
407 | 19 | st->r_frame_rate = st->avg_frame_rate; | |
408 | #endif | ||
409 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (s->error_recognition & AV_EF_EXPLODE) { |
410 | ✗ | av_log(s, AV_LOG_ERROR, "Invalid framerate\n"); | |
411 | ✗ | return AVERROR_INVALIDDATA; | |
412 | } | ||
413 | } | ||
414 | |||
415 | 1 | skip: | |
416 | /* skip codec info */ | ||
417 | 44 | size = avio_tell(pb) - codec_pos; | |
418 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | if (codec_data_size >= size) { |
419 | 44 | avio_skip(pb, codec_data_size - size); | |
420 | } else { | ||
421 | ✗ | av_log(s, AV_LOG_WARNING, "codec_data_size %u < size %d\n", codec_data_size, size); | |
422 | } | ||
423 | |||
424 | 44 | return 0; | |
425 | } | ||
426 | |||
427 | /** this function assumes that the demuxer has already seeked to the start | ||
428 | * of the INDX chunk, and will bail out if not. */ | ||
429 | 12 | static int rm_read_index(AVFormatContext *s) | |
430 | { | ||
431 | 12 | AVIOContext *pb = s->pb; | |
432 | unsigned int size, ver, n_pkts, str_id, next_off, n, pts; | ||
433 | uint64_t pos; | ||
434 | AVStream *st; | ||
435 | |||
436 | do { | ||
437 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 4 times.
|
14 | if (avio_rl32(pb) != MKTAG('I','N','D','X')) |
438 | 10 | return -1; | |
439 | 4 | size = avio_rb32(pb); | |
440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (size < 20) |
441 | ✗ | return -1; | |
442 | 4 | ver = avio_rb16(pb); | |
443 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4 | if (ver != 0 && ver != 2) |
444 | ✗ | return AVERROR_INVALIDDATA; | |
445 | 4 | n_pkts = avio_rb32(pb); | |
446 | 4 | str_id = avio_rb16(pb); | |
447 | 4 | next_off = avio_rb32(pb); | |
448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ver == 2) |
449 | ✗ | avio_skip(pb, 4); | |
450 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 | for (n = 0; n < s->nb_streams; n++) |
451 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if (s->streams[n]->id == str_id) { |
452 | 3 | st = s->streams[n]; | |
453 | 3 | break; | |
454 | } | ||
455 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (n == s->nb_streams) { |
456 | 1 | av_log(s, AV_LOG_ERROR, | |
457 | "Invalid stream index %d for index at pos %"PRId64"\n", | ||
458 | str_id, avio_tell(pb)); | ||
459 | 1 | goto skip; | |
460 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | } else if ((avio_size(pb) - avio_tell(pb)) / 14 < n_pkts) { |
461 | ✗ | av_log(s, AV_LOG_ERROR, | |
462 | "Nr. of packets in packet index for stream index %d " | ||
463 | "exceeds filesize (%"PRId64" at %"PRId64" = %"PRId64")\n", | ||
464 | str_id, avio_size(pb), avio_tell(pb), | ||
465 | ✗ | (avio_size(pb) - avio_tell(pb)) / 14); | |
466 | ✗ | goto skip; | |
467 | } | ||
468 | |||
469 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
|
21 | for (n = 0; n < n_pkts; n++) { |
470 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
18 | if (avio_feof(pb)) |
471 | ✗ | return AVERROR_INVALIDDATA; | |
472 | 18 | avio_skip(pb, 2); | |
473 | 18 | pts = avio_rb32(pb); | |
474 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | pos = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb); |
475 | 18 | avio_skip(pb, 4); /* packet no. */ | |
476 | |||
477 | 18 | av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME); | |
478 | } | ||
479 | |||
480 | 3 | skip: | |
481 |
3/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
4 | if (next_off && avio_tell(pb) < next_off && |
482 | ✗ | avio_seek(pb, next_off, SEEK_SET) < 0) { | |
483 | ✗ | av_log(s, AV_LOG_ERROR, | |
484 | "Non-linear index detected, not supported\n"); | ||
485 | ✗ | return -1; | |
486 | } | ||
487 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | } while (next_off); |
488 | |||
489 | 2 | return 0; | |
490 | } | ||
491 | |||
492 | 1 | static int rm_read_header_old(AVFormatContext *s) | |
493 | { | ||
494 | 1 | RMDemuxContext *rm = s->priv_data; | |
495 | AVStream *st; | ||
496 | |||
497 | 1 | rm->old_format = 1; | |
498 | 1 | st = avformat_new_stream(s, NULL); | |
499 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!st) |
500 | ✗ | return -1; | |
501 | 1 | st->priv_data = ff_rm_alloc_rmstream(); | |
502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!st->priv_data) |
503 | ✗ | return AVERROR(ENOMEM); | |
504 | 1 | return rm_read_audio_stream_info(s, s->pb, st, st->priv_data, 1); | |
505 | } | ||
506 | |||
507 | ✗ | static int rm_read_multi(AVFormatContext *s, AVIOContext *pb, | |
508 | AVStream *st, char *mime) | ||
509 | { | ||
510 | ✗ | int number_of_streams = avio_rb16(pb); | |
511 | int number_of_mdpr; | ||
512 | int i, ret; | ||
513 | unsigned size2; | ||
514 | ✗ | for (i = 0; i<number_of_streams; i++) | |
515 | ✗ | avio_rb16(pb); | |
516 | ✗ | number_of_mdpr = avio_rb16(pb); | |
517 | ✗ | if (number_of_mdpr != 1) { | |
518 | ✗ | avpriv_request_sample(s, "MLTI with multiple (%d) MDPR", number_of_mdpr); | |
519 | } | ||
520 | ✗ | for (i = 0; i < number_of_mdpr; i++) { | |
521 | AVStream *st2; | ||
522 | ✗ | if (i > 0) { | |
523 | ✗ | st2 = avformat_new_stream(s, NULL); | |
524 | ✗ | if (!st2) { | |
525 | ✗ | ret = AVERROR(ENOMEM); | |
526 | ✗ | return ret; | |
527 | } | ||
528 | ✗ | st2->id = st->id + (i<<16); | |
529 | ✗ | st2->codecpar->bit_rate = st->codecpar->bit_rate; | |
530 | ✗ | st2->start_time = st->start_time; | |
531 | ✗ | st2->duration = st->duration; | |
532 | ✗ | st2->codecpar->codec_type = AVMEDIA_TYPE_DATA; | |
533 | ✗ | st2->priv_data = ff_rm_alloc_rmstream(); | |
534 | ✗ | if (!st2->priv_data) | |
535 | ✗ | return AVERROR(ENOMEM); | |
536 | } else | ||
537 | ✗ | st2 = st; | |
538 | |||
539 | ✗ | size2 = avio_rb32(pb); | |
540 | ✗ | ret = ff_rm_read_mdpr_codecdata(s, s->pb, st2, st2->priv_data, | |
541 | size2, NULL); | ||
542 | ✗ | if (ret < 0) | |
543 | ✗ | return ret; | |
544 | } | ||
545 | ✗ | return 0; | |
546 | } | ||
547 | |||
548 | 26 | static int rm_read_header(AVFormatContext *s) | |
549 | { | ||
550 | 26 | RMDemuxContext *rm = s->priv_data; | |
551 | AVStream *st; | ||
552 | 26 | AVIOContext *pb = s->pb; | |
553 | unsigned int tag; | ||
554 | int tag_size; | ||
555 | int ver; | ||
556 | unsigned int start_time, duration; | ||
557 | 26 | unsigned int data_off = 0; | |
558 | 26 | uint64_t indx_off = 0; | |
559 | char buf[128], mime[128]; | ||
560 | 26 | int flags = 0; | |
561 | int ret; | ||
562 | unsigned size, v; | ||
563 | int64_t codec_pos; | ||
564 | |||
565 | 26 | tag = avio_rl32(pb); | |
566 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
|
26 | if (tag == MKTAG('.', 'r', 'a', 0xfd)) { |
567 | /* very old .ra format */ | ||
568 | 1 | return rm_read_header_old(s); | |
569 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
25 | } else if (tag != MKTAG('.', 'R', 'M', 'F') && tag != MKTAG('.', 'R', 'M', 'P')) { |
570 | ✗ | return AVERROR(EIO); | |
571 | } | ||
572 | |||
573 | 25 | tag_size = avio_rb32(pb); | |
574 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (tag_size < 0) |
575 | ✗ | return AVERROR_INVALIDDATA; | |
576 | 25 | avio_skip(pb, tag_size - 8); | |
577 | |||
578 | 94 | for(;;) { | |
579 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 119 times.
|
119 | if (avio_feof(pb)) |
580 | ✗ | return AVERROR_INVALIDDATA; | |
581 | 119 | tag = avio_rl32(pb); | |
582 | 119 | tag_size = avio_rb32(pb); | |
583 | 119 | ver = avio_rb16(pb); | |
584 | 119 | av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n", | |
585 | 119 | av_fourcc2str(tag), tag_size); | |
586 |
5/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 115 times.
|
119 | if ((tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) || |
587 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | (ver != 0 && ver != 2)) |
588 | ✗ | return AVERROR_INVALIDDATA; | |
589 |
4/5✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
|
119 | switch(tag) { |
590 | 25 | case MKTAG('P', 'R', 'O', 'P'): | |
591 | /* file header */ | ||
592 | 25 | avio_rb32(pb); /* max bit rate */ | |
593 | 25 | avio_rb32(pb); /* avg bit rate */ | |
594 | 25 | avio_rb32(pb); /* max packet size */ | |
595 | 25 | avio_rb32(pb); /* avg packet size */ | |
596 | 25 | avio_rb32(pb); /* nb packets */ | |
597 | 25 | duration = avio_rb32(pb); /* duration */ | |
598 | 25 | s->duration = av_rescale(duration, AV_TIME_BASE, 1000); | |
599 | 25 | avio_rb32(pb); /* preroll */ | |
600 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 2 times.
|
25 | indx_off = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb); /* index offset */ |
601 | 25 | data_off = avio_rb32(pb); /* data offset */ | |
602 | 25 | avio_rb16(pb); /* nb streams */ | |
603 | 25 | flags = avio_rb16(pb); /* flags */ | |
604 | 25 | break; | |
605 | 25 | case MKTAG('C', 'O', 'N', 'T'): | |
606 | 25 | rm_read_metadata(s, pb, 1); | |
607 | 25 | break; | |
608 | 44 | case MKTAG('M', 'D', 'P', 'R'): | |
609 | 44 | st = avformat_new_stream(s, NULL); | |
610 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (!st) |
611 | ✗ | return AVERROR(ENOMEM); | |
612 | 44 | st->id = avio_rb16(pb); | |
613 | 44 | avio_rb32(pb); /* max bit rate */ | |
614 | 44 | st->codecpar->bit_rate = avio_rb32(pb); /* bit rate */ | |
615 | 44 | avio_rb32(pb); /* max packet size */ | |
616 | 44 | avio_rb32(pb); /* avg packet size */ | |
617 | 44 | start_time = avio_rb32(pb); /* start time */ | |
618 | 44 | avio_rb32(pb); /* preroll */ | |
619 | 44 | duration = avio_rb32(pb); /* duration */ | |
620 | 44 | st->start_time = start_time; | |
621 | 44 | st->duration = duration; | |
622 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
|
44 | if(duration>0) |
623 | 33 | s->duration = AV_NOPTS_VALUE; | |
624 | 44 | get_str8(pb, buf, sizeof(buf)); /* desc */ | |
625 | 44 | get_str8(pb, mime, sizeof(mime)); /* mimetype */ | |
626 | 44 | st->codecpar->codec_type = AVMEDIA_TYPE_DATA; | |
627 | 44 | st->priv_data = ff_rm_alloc_rmstream(); | |
628 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (!st->priv_data) |
629 | ✗ | return AVERROR(ENOMEM); | |
630 | |||
631 | 44 | size = avio_rb32(pb); | |
632 | 44 | codec_pos = avio_tell(pb); | |
633 | |||
634 | 44 | ffio_ensure_seekback(pb, 4); | |
635 | 44 | v = avio_rb32(pb); | |
636 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (v == MKBETAG('M', 'L', 'T', 'I')) { |
637 | ✗ | ret = rm_read_multi(s, s->pb, st, mime); | |
638 | ✗ | if (ret < 0) | |
639 | ✗ | return ret; | |
640 | ✗ | avio_seek(pb, codec_pos + size, SEEK_SET); | |
641 | } else { | ||
642 | 44 | avio_skip(pb, -4); | |
643 | 44 | ret = ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data, | |
644 | size, mime); | ||
645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (ret < 0) |
646 | ✗ | return ret; | |
647 | } | ||
648 | |||
649 | 44 | break; | |
650 | 25 | case MKTAG('D', 'A', 'T', 'A'): | |
651 | 25 | goto header_end; | |
652 | ✗ | default: | |
653 | /* unknown tag: skip it */ | ||
654 | ✗ | avio_skip(pb, tag_size - 10); | |
655 | ✗ | break; | |
656 | } | ||
657 | } | ||
658 | 25 | header_end: | |
659 | 25 | rm->nb_packets = avio_rb32(pb); /* number of packets */ | |
660 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25 | if (!rm->nb_packets && (flags & 4)) |
661 | ✗ | rm->nb_packets = 3600 * 25; | |
662 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
|
25 | if (ver == 2) |
663 | 2 | avio_skip(pb, 12); | |
664 | 25 | avio_rb32(pb); /* next data header */ | |
665 | |||
666 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (!data_off) |
667 | ✗ | data_off = avio_tell(pb) - (ver == 0 ? 18 : 30); | |
668 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
25 | if (indx_off && (pb->seekable & AVIO_SEEKABLE_NORMAL) && |
669 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
24 | !(s->flags & AVFMT_FLAG_IGNIDX) && |
670 | 12 | avio_seek(pb, indx_off, SEEK_SET) >= 0) { | |
671 | 12 | rm_read_index(s); | |
672 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | avio_seek(pb, data_off + (ver == 0 ? 18 : 30), SEEK_SET); |
673 | } | ||
674 | |||
675 | 25 | return 0; | |
676 | } | ||
677 | |||
678 | 7544 | static int get_num(AVIOContext *pb, int *len) | |
679 | { | ||
680 | int n, n1; | ||
681 | |||
682 | 7544 | n = avio_rb16(pb); | |
683 | 7544 | (*len)-=2; | |
684 | 7544 | n &= 0x7FFF; | |
685 |
2/2✓ Branch 0 taken 6786 times.
✓ Branch 1 taken 758 times.
|
7544 | if (n >= 0x4000) { |
686 | 6786 | return n - 0x4000; | |
687 | } else { | ||
688 | 758 | n1 = avio_rb16(pb); | |
689 | 758 | (*len)-=2; | |
690 | 758 | return (n << 16) | n1; | |
691 | } | ||
692 | } | ||
693 | |||
694 | /* multiple of 20 bytes for ra144 (ugly) */ | ||
695 | #define RAW_PACKET_SIZE 1000 | ||
696 | |||
697 | 7301 | static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){ | |
698 | 7301 | RMDemuxContext *rm = s->priv_data; | |
699 | 7301 | AVIOContext *pb = s->pb; | |
700 | AVStream *st; | ||
701 | 7301 | uint32_t state=0xFFFFFFFF; | |
702 | |||
703 |
2/2✓ Branch 1 taken 1356568 times.
✓ Branch 2 taken 120 times.
|
1356688 | while(!avio_feof(pb)){ |
704 | int len, num, i; | ||
705 | int mlti_id; | ||
706 | 1356568 | *pos= avio_tell(pb) - 3; | |
707 |
2/2✓ Branch 0 taken 559 times.
✓ Branch 1 taken 1356009 times.
|
1356568 | if(rm->remaining_len > 0){ |
708 | 559 | num= rm->current_stream; | |
709 | 559 | mlti_id = 0; | |
710 | 559 | len= rm->remaining_len; | |
711 | 559 | *timestamp = AV_NOPTS_VALUE; | |
712 | 559 | *flags= 0; | |
713 | }else{ | ||
714 | 1356009 | state= (state<<8) + avio_r8(pb); | |
715 | |||
716 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1356005 times.
|
1356009 | if(state == MKBETAG('I', 'N', 'D', 'X')){ |
717 | int ver; | ||
718 | int n_pkts; | ||
719 | int64_t expected_len; | ||
720 | 4 | len = avio_rb32(pb); | |
721 | 4 | ver = avio_rb16(pb); | |
722 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4 | if (ver != 0 && ver != 2) |
723 | ✗ | return AVERROR_INVALIDDATA; | |
724 | 4 | n_pkts = avio_rb32(pb); | |
725 | |||
726 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (ver == 0) |
727 | 4 | expected_len = 20 + n_pkts * 14LL; | |
728 | ✗ | else if (ver == 2) | |
729 | ✗ | expected_len = 24 + n_pkts * 18LL; | |
730 | |||
731 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | if (len == 20 && expected_len <= INT_MAX) |
732 | /* some files don't add index entries to chunk size... */ | ||
733 | 2 | len = expected_len; | |
734 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | else if (len != expected_len) |
735 | ✗ | av_log(s, AV_LOG_WARNING, | |
736 | "Index size %d (%d pkts) is wrong, should be %"PRId64".\n", | ||
737 | len, n_pkts, expected_len); | ||
738 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if(len < 14) |
739 | ✗ | continue; | |
740 | 4 | len -= 14; // we already read part of the index header | |
741 | 4 | goto skip; | |
742 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1356005 times.
|
1356005 | } else if (state == MKBETAG('D','A','T','A')) { |
743 | ✗ | av_log(s, AV_LOG_WARNING, | |
744 | "DATA tag in middle of chunk, file may be broken.\n"); | ||
745 | } | ||
746 | |||
747 |
4/4✓ Branch 0 taken 7488 times.
✓ Branch 1 taken 1348517 times.
✓ Branch 2 taken 801 times.
✓ Branch 3 taken 6687 times.
|
1356005 | if(state > (unsigned)0xFFFF || state <= 12) |
748 | 1349318 | continue; | |
749 | 6687 | len=state - 12; | |
750 | 6687 | state= 0xFFFFFFFF; | |
751 | |||
752 | 6687 | num = avio_rb16(pb); | |
753 | 6687 | *timestamp = avio_rb32(pb); | |
754 | 6687 | mlti_id = (avio_r8(pb) >> 1) - 1; | |
755 | 6687 | mlti_id = FFMAX(mlti_id, 0) << 16; | |
756 | 6687 | *flags = avio_r8(pb); /* flags */ | |
757 | } | ||
758 |
2/2✓ Branch 0 taken 10257 times.
✓ Branch 1 taken 65 times.
|
10322 | for(i=0;i<s->nb_streams;i++) { |
759 | 10257 | st = s->streams[i]; | |
760 |
2/2✓ Branch 0 taken 7181 times.
✓ Branch 1 taken 3076 times.
|
10257 | if (mlti_id + num == st->id) |
761 | 7181 | break; | |
762 | } | ||
763 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 7181 times.
|
7246 | if (i == s->nb_streams) { |
764 | 65 | skip: | |
765 | /* skip packet if unknown number */ | ||
766 | 69 | avio_skip(pb, len); | |
767 | 69 | rm->remaining_len = 0; | |
768 | 69 | continue; | |
769 | } | ||
770 | 7181 | *stream_index= i; | |
771 | |||
772 | 7181 | return len; | |
773 | } | ||
774 | 120 | return -1; | |
775 | } | ||
776 | |||
777 | 3776 | static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, | |
778 | RMDemuxContext *rm, RMStream *vst, | ||
779 | AVPacket *pkt, int len, int *pseq, | ||
780 | int64_t *timestamp) | ||
781 | { | ||
782 | int hdr; | ||
783 | 3776 | int seq = 0, pic_num = 0, len2 = 0, pos = 0; //init to silence compiler warning | |
784 | int type; | ||
785 | int ret; | ||
786 | |||
787 | 3776 | hdr = avio_r8(pb); len--; | |
788 | 3776 | type = hdr >> 6; | |
789 | |||
790 |
2/2✓ Branch 0 taken 2536 times.
✓ Branch 1 taken 1240 times.
|
3776 | if(type != 3){ // not frame as a part of packet |
791 | 2536 | seq = avio_r8(pb); len--; | |
792 | } | ||
793 |
2/2✓ Branch 0 taken 3772 times.
✓ Branch 1 taken 4 times.
|
3776 | if(type != 1){ // not whole frame |
794 | 3772 | len2 = get_num(pb, &len); | |
795 | 3772 | pos = get_num(pb, &len); | |
796 | 3772 | pic_num = avio_r8(pb); len--; | |
797 | } | ||
798 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3776 times.
|
3776 | if(len<0) { |
799 | ✗ | av_log(s, AV_LOG_ERROR, "Insufficient data\n"); | |
800 | ✗ | return -1; | |
801 | } | ||
802 | 3776 | rm->remaining_len = len; | |
803 |
2/2✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 2532 times.
|
3776 | if(type&1){ // frame, not slice |
804 |
2/2✓ Branch 0 taken 1240 times.
✓ Branch 1 taken 4 times.
|
1244 | if(type == 3){ // frame as a part of packet |
805 | 1240 | len= len2; | |
806 | 1240 | *timestamp = pos; | |
807 | } | ||
808 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1243 times.
|
1244 | if(rm->remaining_len < len) { |
809 | 1 | av_log(s, AV_LOG_ERROR, "Insufficient remaining len\n"); | |
810 | 1 | return -1; | |
811 | } | ||
812 | 1243 | rm->remaining_len -= len; | |
813 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1243 times.
|
1243 | if ((ret = av_new_packet(pkt, len + 9)) < 0) |
814 | ✗ | return ret; | |
815 | 1243 | pkt->data[0] = 0; | |
816 | 1243 | AV_WL32(pkt->data + 1, 1); | |
817 | 1243 | AV_WL32(pkt->data + 5, 0); | |
818 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1241 times.
|
1243 | if ((ret = avio_read(pb, pkt->data + 9, len)) != len) { |
819 | 2 | av_packet_unref(pkt); | |
820 | 2 | av_log(s, AV_LOG_ERROR, "Failed to read %d bytes\n", len); | |
821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | return ret < 0 ? ret : AVERROR(EIO); |
822 | } | ||
823 | 1241 | return 0; | |
824 | } | ||
825 | //now we have to deal with single slice | ||
826 | |||
827 | 2532 | *pseq = seq; | |
828 |
4/4✓ Branch 0 taken 1502 times.
✓ Branch 1 taken 1030 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1501 times.
|
2532 | if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){ |
829 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1028 times.
|
1031 | if (len2 > ffio_limit(pb, len2)) { |
830 | 3 | av_log(s, AV_LOG_ERROR, "Impossibly sized packet\n"); | |
831 | 3 | return AVERROR_INVALIDDATA; | |
832 | } | ||
833 | 1028 | vst->slices = ((hdr & 0x3F) << 1) + 1; | |
834 | 1028 | vst->videobufsize = len2 + 8*vst->slices + 1; | |
835 | 1028 | av_packet_unref(&vst->pkt); //FIXME this should be output. | |
836 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1028 times.
|
1028 | if ((ret = av_new_packet(&vst->pkt, vst->videobufsize)) < 0) |
837 | ✗ | return ret; | |
838 | 1028 | vst->videobufpos = 8*vst->slices + 1; | |
839 | 1028 | vst->cur_slice = 0; | |
840 | 1028 | vst->curpic_num = pic_num; | |
841 | 1028 | vst->pktpos = avio_tell(pb); | |
842 | } | ||
843 |
2/2✓ Branch 0 taken 1017 times.
✓ Branch 1 taken 1512 times.
|
2529 | if(type == 2) |
844 | 1017 | len = FFMIN(len, pos); | |
845 | |||
846 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2529 times.
|
2529 | if(++vst->cur_slice > vst->slices) { |
847 | ✗ | av_log(s, AV_LOG_ERROR, "cur slice %d, too large\n", vst->cur_slice); | |
848 | ✗ | return 1; | |
849 | } | ||
850 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2529 times.
|
2529 | if(!vst->pkt.data) |
851 | ✗ | return AVERROR(ENOMEM); | |
852 | 2529 | AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1); | |
853 | 2529 | AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1); | |
854 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2529 times.
|
2529 | if(vst->videobufpos + len > vst->videobufsize) { |
855 | ✗ | av_log(s, AV_LOG_ERROR, "outside videobufsize\n"); | |
856 | ✗ | return 1; | |
857 | } | ||
858 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2529 times.
|
2529 | if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len) |
859 | ✗ | return AVERROR(EIO); | |
860 | 2529 | vst->videobufpos += len; | |
861 | 2529 | rm->remaining_len-= len; | |
862 | |||
863 |
4/4✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 1017 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1501 times.
|
2529 | if (type == 2 || vst->videobufpos == vst->videobufsize) { |
864 | 1028 | vst->pkt.data[0] = vst->cur_slice-1; | |
865 | 1028 | av_packet_move_ref(pkt, &vst->pkt); | |
866 |
2/2✓ Branch 0 taken 785 times.
✓ Branch 1 taken 243 times.
|
1028 | if(vst->slices != vst->cur_slice) //FIXME find out how to set slices correct from the begin |
867 | 785 | memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices, | |
868 | 785 | vst->videobufpos - 1 - 8*vst->slices); | |
869 | 1028 | av_shrink_packet(pkt, vst->videobufpos + 8*(vst->cur_slice - vst->slices)); | |
870 | 1028 | pkt->pts = AV_NOPTS_VALUE; | |
871 | 1028 | pkt->pos = vst->pktpos; | |
872 | 1028 | vst->slices = 0; | |
873 | 1028 | return 0; | |
874 | } | ||
875 | |||
876 | 1501 | return 1; | |
877 | } | ||
878 | |||
879 | static inline void | ||
880 | 956 | rm_ac3_swap_bytes (AVStream *st, AVPacket *pkt) | |
881 | { | ||
882 | uint8_t *ptr; | ||
883 | int j; | ||
884 | |||
885 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 946 times.
|
956 | if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { |
886 | 10 | ptr = pkt->data; | |
887 |
2/2✓ Branch 0 taken 1391 times.
✓ Branch 1 taken 10 times.
|
1401 | for (j=0;j<pkt->size;j+=2) { |
888 | 1391 | FFSWAP(int, ptr[0], ptr[1]); | |
889 | 1391 | ptr += 2; | |
890 | } | ||
891 | } | ||
892 | 956 | } | |
893 | |||
894 | 4196 | static int readfull(AVFormatContext *s, AVIOContext *pb, uint8_t *dst, int n) { | |
895 | 4196 | int ret = avio_read(pb, dst, n); | |
896 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 4189 times.
|
4196 | if (ret != n) { |
897 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (ret >= 0) memset(dst + ret, 0, n - ret); |
898 | 5 | else memset(dst , 0, n); | |
899 | 7 | av_log(s, AV_LOG_ERROR, "Failed to fully read block\n"); | |
900 | } | ||
901 | 4196 | return ret; | |
902 | } | ||
903 | |||
904 | int | ||
905 | 5928 | ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, | |
906 | AVStream *st, RMStream *ast, int len, AVPacket *pkt, | ||
907 | int *seq, int flags, int64_t timestamp) | ||
908 | { | ||
909 | 5928 | RMDemuxContext *rm = s->priv_data; | |
910 | int ret; | ||
911 | |||
912 |
2/2✓ Branch 0 taken 3776 times.
✓ Branch 1 taken 2152 times.
|
5928 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
913 | 3776 | rm->current_stream= st->id; | |
914 | 3776 | ret = rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, ×tamp); | |
915 |
2/2✓ Branch 0 taken 1507 times.
✓ Branch 1 taken 2269 times.
|
3776 | if(ret) |
916 | 1507 | return ret < 0 ? ret : -1; //got partial frame or error | |
917 |
1/2✓ Branch 0 taken 2152 times.
✗ Branch 1 not taken.
|
2152 | } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
918 |
2/2✓ Branch 0 taken 1900 times.
✓ Branch 1 taken 252 times.
|
2152 | if ((ast->deint_id == DEINT_ID_GENR) || |
919 |
2/2✓ Branch 0 taken 1485 times.
✓ Branch 1 taken 415 times.
|
1900 | (ast->deint_id == DEINT_ID_INT4) || |
920 |
2/2✓ Branch 0 taken 528 times.
✓ Branch 1 taken 957 times.
|
1485 | (ast->deint_id == DEINT_ID_SIPR)) { |
921 | int x; | ||
922 | 1195 | int sps = ast->sub_packet_size; | |
923 | 1195 | int cfs = ast->coded_framesize; | |
924 | 1195 | int h = ast->sub_packet_h; | |
925 | 1195 | int y = ast->sub_packet_cnt; | |
926 | 1195 | int w = ast->audio_framesize; | |
927 | |||
928 |
2/2✓ Branch 0 taken 141 times.
✓ Branch 1 taken 1054 times.
|
1195 | if (flags & 2) |
929 | 141 | y = ast->sub_packet_cnt = 0; | |
930 |
2/2✓ Branch 0 taken 141 times.
✓ Branch 1 taken 1054 times.
|
1195 | if (!y) |
931 | 141 | ast->audiotimestamp = timestamp; | |
932 | |||
933 |
3/4✓ Branch 0 taken 415 times.
✓ Branch 1 taken 252 times.
✓ Branch 2 taken 528 times.
✗ Branch 3 not taken.
|
1195 | switch (ast->deint_id) { |
934 | 415 | case DEINT_ID_INT4: | |
935 |
2/2✓ Branch 0 taken 2490 times.
✓ Branch 1 taken 415 times.
|
2905 | for (x = 0; x < h/2; x++) |
936 | 2490 | readfull(s, pb, ast->pkt.data+x*2*w+y*cfs, cfs); | |
937 | 415 | break; | |
938 | 252 | case DEINT_ID_GENR: | |
939 |
2/2✓ Branch 0 taken 1178 times.
✓ Branch 1 taken 252 times.
|
1430 | for (x = 0; x < w/sps; x++) |
940 | 1178 | readfull(s, pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); | |
941 | 252 | break; | |
942 | 528 | case DEINT_ID_SIPR: | |
943 | 528 | readfull(s, pb, ast->pkt.data + y * w, w); | |
944 | 528 | break; | |
945 | } | ||
946 | |||
947 |
2/2✓ Branch 0 taken 1060 times.
✓ Branch 1 taken 135 times.
|
1195 | if (++(ast->sub_packet_cnt) < h) |
948 | 1060 | return -1; | |
949 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 47 times.
|
135 | if (ast->deint_id == DEINT_ID_SIPR) |
950 | 88 | ff_rm_reorder_sipr_data(ast->pkt.data, h, w); | |
951 | |||
952 | 135 | ast->sub_packet_cnt = 0; | |
953 | 135 | rm->audio_stream_num = st->index; | |
954 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
|
135 | if (st->codecpar->block_align <= 0) { |
955 | ✗ | av_log(s, AV_LOG_ERROR, "Invalid block alignment %d\n", st->codecpar->block_align); | |
956 | ✗ | return AVERROR_INVALIDDATA; | |
957 | } | ||
958 | 135 | rm->audio_pkt_cnt = h * w / st->codecpar->block_align; | |
959 |
1/2✓ Branch 0 taken 957 times.
✗ Branch 1 not taken.
|
957 | } else if ((ast->deint_id == DEINT_ID_VBRF) || |
960 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 957 times.
|
957 | (ast->deint_id == DEINT_ID_VBRS)) { |
961 | int x; | ||
962 | ✗ | rm->audio_stream_num = st->index; | |
963 | ✗ | ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4; | |
964 | ✗ | if (ast->sub_packet_cnt) { | |
965 | ✗ | for (x = 0; x < ast->sub_packet_cnt; x++) | |
966 | ✗ | ast->sub_packet_lengths[x] = avio_rb16(pb); | |
967 | ✗ | rm->audio_pkt_cnt = ast->sub_packet_cnt; | |
968 | ✗ | ast->audiotimestamp = timestamp; | |
969 | } else | ||
970 | ✗ | return -1; | |
971 | } else { | ||
972 | 957 | ret = av_get_packet(pb, pkt, len); | |
973 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 956 times.
|
957 | if (ret < 0) |
974 | 1 | return ret; | |
975 | 956 | rm_ac3_swap_bytes(st, pkt); | |
976 | } | ||
977 | } else { | ||
978 | ✗ | ret = av_get_packet(pb, pkt, len); | |
979 | ✗ | if (ret < 0) | |
980 | ✗ | return ret; | |
981 | } | ||
982 | |||
983 | 3360 | pkt->stream_index = st->index; | |
984 | |||
985 | 3360 | pkt->pts = timestamp; | |
986 |
2/2✓ Branch 0 taken 689 times.
✓ Branch 1 taken 2671 times.
|
3360 | if (flags & 2) |
987 | 689 | pkt->flags |= AV_PKT_FLAG_KEY; | |
988 | |||
989 |
2/2✓ Branch 0 taken 1091 times.
✓ Branch 1 taken 2269 times.
|
3360 | return st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; |
990 | } | ||
991 | |||
992 | int | ||
993 | 9917 | ff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb, | |
994 | AVStream *st, RMStream *ast, AVPacket *pkt) | ||
995 | { | ||
996 | 9917 | RMDemuxContext *rm = s->priv_data; | |
997 | int ret; | ||
998 | |||
999 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9917 times.
|
9917 | av_assert0 (rm->audio_pkt_cnt > 0); |
1000 | |||
1001 |
1/2✓ Branch 0 taken 9917 times.
✗ Branch 1 not taken.
|
9917 | if (ast->deint_id == DEINT_ID_VBRF || |
1002 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9917 times.
|
9917 | ast->deint_id == DEINT_ID_VBRS) { |
1003 | ✗ | ret = av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]); | |
1004 | ✗ | if (ret < 0) | |
1005 | ✗ | return ret; | |
1006 | } else { | ||
1007 | 9917 | ret = av_new_packet(pkt, st->codecpar->block_align); | |
1008 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9917 times.
|
9917 | if (ret < 0) |
1009 | ✗ | return ret; | |
1010 | 9917 | memcpy(pkt->data, ast->pkt.data + st->codecpar->block_align * //FIXME avoid this | |
1011 | 9917 | (ast->sub_packet_h * ast->audio_framesize / st->codecpar->block_align - rm->audio_pkt_cnt), | |
1012 | 9917 | st->codecpar->block_align); | |
1013 | } | ||
1014 | 9917 | rm->audio_pkt_cnt--; | |
1015 |
2/2✓ Branch 0 taken 135 times.
✓ Branch 1 taken 9782 times.
|
9917 | if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) { |
1016 | 135 | ast->audiotimestamp = AV_NOPTS_VALUE; | |
1017 | 135 | pkt->flags = AV_PKT_FLAG_KEY; | |
1018 | } else | ||
1019 | 9782 | pkt->flags = 0; | |
1020 | 9917 | pkt->stream_index = st->index; | |
1021 | |||
1022 | 9917 | return rm->audio_pkt_cnt; | |
1023 | } | ||
1024 | |||
1025 | 11529 | static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) | |
1026 | { | ||
1027 | 11529 | RMDemuxContext *rm = s->priv_data; | |
1028 | 11529 | AVStream *st = NULL; // init to silence compiler warning | |
1029 | 11529 | int i, res, seq = 1; | |
1030 | int64_t timestamp, pos, len; | ||
1031 | int flags; | ||
1032 | |||
1033 | for (;;) { | ||
1034 |
2/2✓ Branch 0 taken 9917 times.
✓ Branch 1 taken 5950 times.
|
15867 | if (rm->audio_pkt_cnt) { |
1035 | // If there are queued audio packet return them first | ||
1036 | 9917 | st = s->streams[rm->audio_stream_num]; | |
1037 | 9917 | res = ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt); | |
1038 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9917 times.
|
9917 | if(res < 0) |
1039 | ✗ | return res; | |
1040 | 9917 | flags = 0; | |
1041 | } else { | ||
1042 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5947 times.
|
5950 | if (rm->old_format) { |
1043 | RMStream *ast; | ||
1044 | |||
1045 | 3 | st = s->streams[0]; | |
1046 | 3 | ast = st->priv_data; | |
1047 | 3 | timestamp = AV_NOPTS_VALUE; | |
1048 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | len = !ast->audio_framesize ? RAW_PACKET_SIZE : |
1049 | ✗ | ast->coded_framesize * (int64_t)ast->sub_packet_h / 2; | |
1050 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (len > INT_MAX) |
1051 | ✗ | return AVERROR_INVALIDDATA; | |
1052 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | flags = (seq++ == 1) ? 2 : 0; |
1053 | 3 | pos = avio_tell(s->pb); | |
1054 | } else { | ||
1055 | 5947 | len = rm_sync(s, ×tamp, &flags, &i, &pos); | |
1056 |
2/2✓ Branch 0 taken 5928 times.
✓ Branch 1 taken 19 times.
|
5947 | if (len > 0) |
1057 | 5928 | st = s->streams[i]; | |
1058 | } | ||
1059 | |||
1060 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 2 taken 5928 times.
|
5950 | if (avio_feof(s->pb)) |
1061 | 22 | return AVERROR_EOF; | |
1062 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5928 times.
|
5928 | if (len <= 0) |
1063 | ✗ | return AVERROR(EIO); | |
1064 | |||
1065 | 5928 | res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt, | |
1066 | &seq, flags, timestamp); | ||
1067 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 5922 times.
|
5928 | if (res < -1) |
1068 | 6 | return res; | |
1069 |
4/4✓ Branch 0 taken 966 times.
✓ Branch 1 taken 4956 times.
✓ Branch 2 taken 794 times.
✓ Branch 3 taken 172 times.
|
5922 | if((flags&2) && (seq&0x7F) == 1) |
1070 | 794 | av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); | |
1071 |
2/2✓ Branch 0 taken 2697 times.
✓ Branch 1 taken 3225 times.
|
5922 | if (res) |
1072 | 2697 | continue; | |
1073 | } | ||
1074 | |||
1075 |
4/4✓ Branch 0 taken 1641 times.
✓ Branch 1 taken 11501 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1619 times.
|
13142 | if( (st->discard >= AVDISCARD_NONKEY && !(flags&2)) |
1076 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 11501 times.
|
11523 | || st->discard >= AVDISCARD_ALL){ |
1077 | 1641 | av_packet_unref(pkt); | |
1078 | } else | ||
1079 | break; | ||
1080 | } | ||
1081 | |||
1082 | 11501 | return 0; | |
1083 | } | ||
1084 | |||
1085 | 26 | static int rm_read_close(AVFormatContext *s) | |
1086 | { | ||
1087 | int i; | ||
1088 | |||
1089 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 26 times.
|
61 | for (i=0;i<s->nb_streams;i++) |
1090 | 35 | ff_rm_free_rmstream(s->streams[i]->priv_data); | |
1091 | |||
1092 | 26 | return 0; | |
1093 | } | ||
1094 | |||
1095 | 7186 | static int rm_probe(const AVProbeData *p) | |
1096 | { | ||
1097 | /* check file header */ | ||
1098 |
4/4✓ Branch 0 taken 36 times.
✓ Branch 1 taken 7150 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 11 times.
|
7186 | if ((p->buf[0] == '.' && p->buf[1] == 'R' && |
1099 |
4/6✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
25 | p->buf[2] == 'M' && (p->buf[3] == 'F' || p->buf[3] == 'P') && |
1100 |
2/4✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
|
25 | p->buf[4] == 0 && p->buf[5] == 0) || |
1101 |
4/4✓ Branch 0 taken 11 times.
✓ Branch 1 taken 7150 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 10 times.
|
7161 | (p->buf[0] == '.' && p->buf[1] == 'r' && |
1102 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | p->buf[2] == 'a' && p->buf[3] == 0xfd)) |
1103 | 26 | return AVPROBE_SCORE_MAX; | |
1104 | else | ||
1105 | 7160 | return 0; | |
1106 | } | ||
1107 | |||
1108 | 248 | static int64_t rm_read_dts(AVFormatContext *s, int stream_index, | |
1109 | int64_t *ppos, int64_t pos_limit) | ||
1110 | { | ||
1111 | 248 | RMDemuxContext *rm = s->priv_data; | |
1112 | int64_t pos, dts; | ||
1113 | int stream_index2, flags, len, h; | ||
1114 | |||
1115 | 248 | pos = *ppos; | |
1116 | |||
1117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 248 times.
|
248 | if(rm->old_format) |
1118 | ✗ | return AV_NOPTS_VALUE; | |
1119 | |||
1120 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 248 times.
|
248 | if (avio_seek(s->pb, pos, SEEK_SET) < 0) |
1121 | ✗ | return AV_NOPTS_VALUE; | |
1122 | |||
1123 | 248 | rm->remaining_len=0; | |
1124 | 1106 | for(;;){ | |
1125 | 1354 | int seq=1; | |
1126 | AVStream *st; | ||
1127 | |||
1128 | 1354 | len = rm_sync(s, &dts, &flags, &stream_index2, &pos); | |
1129 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1253 times.
|
1354 | if(len<0) |
1130 | 101 | return AV_NOPTS_VALUE; | |
1131 | |||
1132 | 1253 | st = s->streams[stream_index2]; | |
1133 |
2/2✓ Branch 0 taken 1035 times.
✓ Branch 1 taken 218 times.
|
1253 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
1134 | 1035 | h= avio_r8(s->pb); len--; | |
1135 |
1/2✓ Branch 0 taken 1035 times.
✗ Branch 1 not taken.
|
1035 | if(!(h & 0x40)){ |
1136 | 1035 | seq = avio_r8(s->pb); len--; | |
1137 | } | ||
1138 | } | ||
1139 | |||
1140 |
3/4✓ Branch 0 taken 355 times.
✓ Branch 1 taken 898 times.
✓ Branch 2 taken 355 times.
✗ Branch 3 not taken.
|
1253 | if((flags&2) && (seq&0x7F) == 1){ |
1141 | 355 | av_log(s, AV_LOG_TRACE, "%d %d-%d %"PRId64" %d\n", | |
1142 | flags, stream_index2, stream_index, dts, seq); | ||
1143 | 355 | av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME); | |
1144 |
2/2✓ Branch 0 taken 147 times.
✓ Branch 1 taken 208 times.
|
355 | if(stream_index2 == stream_index) |
1145 | 147 | break; | |
1146 | } | ||
1147 | |||
1148 | 1106 | avio_skip(s->pb, len); | |
1149 | } | ||
1150 | 147 | *ppos = pos; | |
1151 | 147 | return dts; | |
1152 | } | ||
1153 | |||
1154 | 78 | static int rm_read_seek(AVFormatContext *s, int stream_index, | |
1155 | int64_t pts, int flags) | ||
1156 | { | ||
1157 | 78 | RMDemuxContext *rm = s->priv_data; | |
1158 | |||
1159 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 77 times.
|
78 | if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0) |
1160 | 1 | return -1; | |
1161 | 77 | rm->audio_pkt_cnt = 0; | |
1162 | 77 | return 0; | |
1163 | } | ||
1164 | |||
1165 | |||
1166 | const FFInputFormat ff_rm_demuxer = { | ||
1167 | .p.name = "rm", | ||
1168 | .p.long_name = NULL_IF_CONFIG_SMALL("RealMedia"), | ||
1169 | .priv_data_size = sizeof(RMDemuxContext), | ||
1170 | .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP, | ||
1171 | .read_probe = rm_probe, | ||
1172 | .read_header = rm_read_header, | ||
1173 | .read_packet = rm_read_packet, | ||
1174 | .read_close = rm_read_close, | ||
1175 | .read_timestamp = rm_read_dts, | ||
1176 | .read_seek = rm_read_seek, | ||
1177 | }; | ||
1178 | |||
1179 | const FFInputFormat ff_rdt_demuxer = { | ||
1180 | .p.name = "rdt", | ||
1181 | .p.long_name = NULL_IF_CONFIG_SMALL("RDT demuxer"), | ||
1182 | .p.flags = AVFMT_NOFILE, | ||
1183 | .priv_data_size = sizeof(RMDemuxContext), | ||
1184 | .read_close = rm_read_close, | ||
1185 | }; | ||
1186 | |||
1187 | 7186 | static int ivr_probe(const AVProbeData *p) | |
1188 | { | ||
1189 |
1/2✓ Branch 0 taken 7186 times.
✗ Branch 1 not taken.
|
7186 | if (memcmp(p->buf, ".R1M\x0\x1\x1", 7) && |
1190 |
1/2✓ Branch 0 taken 7186 times.
✗ Branch 1 not taken.
|
7186 | memcmp(p->buf, ".REC", 4)) |
1191 | 7186 | return 0; | |
1192 | |||
1193 | ✗ | return AVPROBE_SCORE_MAX; | |
1194 | } | ||
1195 | |||
1196 | ✗ | static int ivr_read_header(AVFormatContext *s) | |
1197 | { | ||
1198 | unsigned tag, type, len, tlen, value; | ||
1199 | ✗ | int i, j, n, count, nb_streams = 0, ret; | |
1200 | uint8_t key[256], val[256]; | ||
1201 | ✗ | AVIOContext *pb = s->pb; | |
1202 | AVStream *st; | ||
1203 | ✗ | int64_t pos, offset=0, temp; | |
1204 | |||
1205 | ✗ | pos = avio_tell(pb); | |
1206 | ✗ | tag = avio_rl32(pb); | |
1207 | ✗ | if (tag == MKTAG('.','R','1','M')) { | |
1208 | ✗ | if (avio_rb16(pb) != 1) | |
1209 | ✗ | return AVERROR_INVALIDDATA; | |
1210 | ✗ | if (avio_r8(pb) != 1) | |
1211 | ✗ | return AVERROR_INVALIDDATA; | |
1212 | ✗ | len = avio_rb32(pb); | |
1213 | ✗ | avio_skip(pb, len); | |
1214 | ✗ | avio_skip(pb, 5); | |
1215 | ✗ | temp = avio_rb64(pb); | |
1216 | ✗ | while (!avio_feof(pb) && temp) { | |
1217 | ✗ | offset = temp; | |
1218 | ✗ | temp = avio_rb64(pb); | |
1219 | } | ||
1220 | ✗ | if (offset <= 0) | |
1221 | ✗ | return AVERROR_INVALIDDATA; | |
1222 | ✗ | avio_skip(pb, offset - avio_tell(pb)); | |
1223 | ✗ | if (avio_r8(pb) != 1) | |
1224 | ✗ | return AVERROR_INVALIDDATA; | |
1225 | ✗ | len = avio_rb32(pb); | |
1226 | ✗ | avio_skip(pb, len); | |
1227 | ✗ | if (avio_r8(pb) != 2) | |
1228 | ✗ | return AVERROR_INVALIDDATA; | |
1229 | ✗ | avio_skip(pb, 16); | |
1230 | ✗ | pos = avio_tell(pb); | |
1231 | ✗ | tag = avio_rl32(pb); | |
1232 | } | ||
1233 | |||
1234 | ✗ | if (tag != MKTAG('.','R','E','C')) | |
1235 | ✗ | return AVERROR_INVALIDDATA; | |
1236 | |||
1237 | ✗ | if (avio_r8(pb) != 0) | |
1238 | ✗ | return AVERROR_INVALIDDATA; | |
1239 | ✗ | count = avio_rb32(pb); | |
1240 | ✗ | for (i = 0; i < count; i++) { | |
1241 | ✗ | if (avio_feof(pb)) | |
1242 | ✗ | return AVERROR_INVALIDDATA; | |
1243 | |||
1244 | ✗ | type = avio_r8(pb); | |
1245 | ✗ | tlen = avio_rb32(pb); | |
1246 | ✗ | avio_get_str(pb, tlen, key, sizeof(key)); | |
1247 | ✗ | len = avio_rb32(pb); | |
1248 | ✗ | if (type == 5) { | |
1249 | ✗ | avio_get_str(pb, len, val, sizeof(val)); | |
1250 | ✗ | av_log(s, AV_LOG_DEBUG, "%s = '%s'\n", key, val); | |
1251 | ✗ | } else if (type == 4) { | |
1252 | ✗ | av_log(s, AV_LOG_DEBUG, "%s = '0x", key); | |
1253 | ✗ | for (j = 0; j < len; j++) { | |
1254 | ✗ | if (avio_feof(pb)) | |
1255 | ✗ | return AVERROR_INVALIDDATA; | |
1256 | ✗ | av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb)); | |
1257 | } | ||
1258 | ✗ | av_log(s, AV_LOG_DEBUG, "'\n"); | |
1259 | ✗ | } else if (len == 4 && type == 3 && !strncmp(key, "StreamCount", tlen)) { | |
1260 | ✗ | nb_streams = value = avio_rb32(pb); | |
1261 | ✗ | } else if (len == 4 && type == 3) { | |
1262 | ✗ | value = avio_rb32(pb); | |
1263 | ✗ | av_log(s, AV_LOG_DEBUG, "%s = %d\n", key, value); | |
1264 | } else { | ||
1265 | ✗ | av_log(s, AV_LOG_DEBUG, "Skipping unsupported key: %s\n", key); | |
1266 | ✗ | avio_skip(pb, len); | |
1267 | } | ||
1268 | } | ||
1269 | |||
1270 | ✗ | for (n = 0; n < nb_streams; n++) { | |
1271 | ✗ | if (!(st = avformat_new_stream(s, NULL)) || | |
1272 | ✗ | !(st->priv_data = ff_rm_alloc_rmstream())) | |
1273 | ✗ | return AVERROR(ENOMEM); | |
1274 | |||
1275 | ✗ | if (avio_r8(pb) != 1) | |
1276 | ✗ | return AVERROR_INVALIDDATA; | |
1277 | |||
1278 | ✗ | count = avio_rb32(pb); | |
1279 | ✗ | for (i = 0; i < count; i++) { | |
1280 | ✗ | if (avio_feof(pb)) | |
1281 | ✗ | return AVERROR_INVALIDDATA; | |
1282 | |||
1283 | ✗ | type = avio_r8(pb); | |
1284 | ✗ | tlen = avio_rb32(pb); | |
1285 | ✗ | avio_get_str(pb, tlen, key, sizeof(key)); | |
1286 | ✗ | len = avio_rb32(pb); | |
1287 | ✗ | if (type == 5) { | |
1288 | ✗ | avio_get_str(pb, len, val, sizeof(val)); | |
1289 | ✗ | av_log(s, AV_LOG_DEBUG, "%s = '%s'\n", key, val); | |
1290 | ✗ | } else if (type == 4 && !strncmp(key, "OpaqueData", tlen)) { | |
1291 | ✗ | ret = ffio_ensure_seekback(pb, 4); | |
1292 | ✗ | if (ret < 0) | |
1293 | ✗ | return ret; | |
1294 | ✗ | if (avio_rb32(pb) == MKBETAG('M', 'L', 'T', 'I')) { | |
1295 | ✗ | ret = rm_read_multi(s, pb, st, NULL); | |
1296 | } else { | ||
1297 | ✗ | if (avio_feof(pb)) | |
1298 | ✗ | return AVERROR_INVALIDDATA; | |
1299 | ✗ | avio_seek(pb, -4, SEEK_CUR); | |
1300 | ✗ | ret = ff_rm_read_mdpr_codecdata(s, pb, st, st->priv_data, len, NULL); | |
1301 | } | ||
1302 | |||
1303 | ✗ | if (ret < 0) | |
1304 | ✗ | return ret; | |
1305 | ✗ | } else if (type == 4) { | |
1306 | int j; | ||
1307 | |||
1308 | ✗ | av_log(s, AV_LOG_DEBUG, "%s = '0x", key); | |
1309 | ✗ | for (j = 0; j < len; j++) { | |
1310 | ✗ | if (avio_feof(pb)) | |
1311 | ✗ | return AVERROR_INVALIDDATA; | |
1312 | ✗ | av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb)); | |
1313 | } | ||
1314 | ✗ | av_log(s, AV_LOG_DEBUG, "'\n"); | |
1315 | ✗ | } else if (len == 4 && type == 3 && !strncmp(key, "Duration", tlen)) { | |
1316 | ✗ | st->duration = avio_rb32(pb); | |
1317 | ✗ | } else if (len == 4 && type == 3) { | |
1318 | ✗ | value = avio_rb32(pb); | |
1319 | ✗ | av_log(s, AV_LOG_DEBUG, "%s = %d\n", key, value); | |
1320 | } else { | ||
1321 | ✗ | av_log(s, AV_LOG_DEBUG, "Skipping unsupported key: %s\n", key); | |
1322 | ✗ | avio_skip(pb, len); | |
1323 | } | ||
1324 | } | ||
1325 | } | ||
1326 | |||
1327 | ✗ | if (avio_r8(pb) != 6) | |
1328 | ✗ | return AVERROR_INVALIDDATA; | |
1329 | ✗ | avio_skip(pb, 12); | |
1330 | ✗ | avio_seek(pb, avio_rb64(pb) + pos, SEEK_SET); | |
1331 | ✗ | if (avio_r8(pb) != 8) | |
1332 | ✗ | return AVERROR_INVALIDDATA; | |
1333 | ✗ | avio_skip(pb, 8); | |
1334 | |||
1335 | ✗ | return 0; | |
1336 | } | ||
1337 | |||
1338 | ✗ | static int ivr_read_packet(AVFormatContext *s, AVPacket *pkt) | |
1339 | { | ||
1340 | ✗ | RMDemuxContext *rm = s->priv_data; | |
1341 | ✗ | int ret = AVERROR_EOF, opcode; | |
1342 | ✗ | AVIOContext *pb = s->pb; | |
1343 | unsigned size, index; | ||
1344 | int64_t pos, pts; | ||
1345 | |||
1346 | ✗ | if (avio_feof(pb) || rm->data_end) | |
1347 | ✗ | return AVERROR_EOF; | |
1348 | |||
1349 | ✗ | pos = avio_tell(pb); | |
1350 | |||
1351 | for (;;) { | ||
1352 | ✗ | if (rm->audio_pkt_cnt) { | |
1353 | // If there are queued audio packet return them first | ||
1354 | AVStream *st; | ||
1355 | |||
1356 | ✗ | st = s->streams[rm->audio_stream_num]; | |
1357 | ✗ | ret = ff_rm_retrieve_cache(s, pb, st, st->priv_data, pkt); | |
1358 | ✗ | if (ret < 0) { | |
1359 | ✗ | return ret; | |
1360 | } | ||
1361 | } else { | ||
1362 | ✗ | if (rm->remaining_len) { | |
1363 | ✗ | avio_skip(pb, rm->remaining_len); | |
1364 | ✗ | rm->remaining_len = 0; | |
1365 | } | ||
1366 | |||
1367 | ✗ | if (avio_feof(pb)) | |
1368 | ✗ | return AVERROR_EOF; | |
1369 | |||
1370 | ✗ | opcode = avio_r8(pb); | |
1371 | ✗ | if (opcode == 2) { | |
1372 | AVStream *st; | ||
1373 | ✗ | int seq = 1; | |
1374 | |||
1375 | ✗ | pts = avio_rb32(pb); | |
1376 | ✗ | index = avio_rb16(pb); | |
1377 | ✗ | if (index >= s->nb_streams) | |
1378 | ✗ | return AVERROR_INVALIDDATA; | |
1379 | |||
1380 | ✗ | avio_skip(pb, 4); | |
1381 | ✗ | size = avio_rb32(pb); | |
1382 | ✗ | avio_skip(pb, 4); | |
1383 | |||
1384 | ✗ | if (size < 1 || size > INT_MAX/4) { | |
1385 | ✗ | av_log(s, AV_LOG_ERROR, "size %u is invalid\n", size); | |
1386 | ✗ | return AVERROR_INVALIDDATA; | |
1387 | } | ||
1388 | |||
1389 | ✗ | st = s->streams[index]; | |
1390 | ✗ | ret = ff_rm_parse_packet(s, pb, st, st->priv_data, size, pkt, | |
1391 | &seq, 0, pts); | ||
1392 | ✗ | if (ret < -1) { | |
1393 | ✗ | return ret; | |
1394 | ✗ | } else if (ret) { | |
1395 | ✗ | continue; | |
1396 | } | ||
1397 | |||
1398 | ✗ | pkt->pos = pos; | |
1399 | ✗ | pkt->pts = pts; | |
1400 | ✗ | pkt->stream_index = index; | |
1401 | ✗ | } else if (opcode == 7) { | |
1402 | ✗ | pos = avio_rb64(pb); | |
1403 | ✗ | if (!pos) { | |
1404 | ✗ | rm->data_end = 1; | |
1405 | ✗ | return AVERROR_EOF; | |
1406 | } | ||
1407 | } else { | ||
1408 | ✗ | av_log(s, AV_LOG_ERROR, "Unsupported opcode=%d at %"PRIX64"\n", opcode, avio_tell(pb) - 1); | |
1409 | ✗ | return AVERROR(EIO); | |
1410 | } | ||
1411 | } | ||
1412 | |||
1413 | ✗ | break; | |
1414 | } | ||
1415 | |||
1416 | ✗ | return ret; | |
1417 | } | ||
1418 | |||
1419 | const FFInputFormat ff_ivr_demuxer = { | ||
1420 | .p.name = "ivr", | ||
1421 | .p.long_name = NULL_IF_CONFIG_SMALL("IVR (Internet Video Recording)"), | ||
1422 | .p.extensions = "ivr", | ||
1423 | .priv_data_size = sizeof(RMDemuxContext), | ||
1424 | .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP, | ||
1425 | .read_probe = ivr_probe, | ||
1426 | .read_header = ivr_read_header, | ||
1427 | .read_packet = ivr_read_packet, | ||
1428 | .read_close = rm_read_close, | ||
1429 | }; | ||
1430 |