FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/flvdec.c
Date: 2026-05-02 03:33:10
Exec Total Coverage
Lines: 810 1273 63.6%
Functions: 23 27 85.2%
Branches: 558 1035 53.9%

Line Branch Exec Source
1 /*
2 * FLV demuxer
3 * Copyright (c) 2003 The FFmpeg Project
4 *
5 * This demuxer will generate a 1 byte extradata for VP6F content.
6 * It is composed of:
7 * - upper 4 bits: difference between encoded width and visible width
8 * - lower 4 bits: difference between encoded height and visible height
9 *
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include "libavutil/attributes.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/channel_layout.h"
31 #include "libavutil/dict.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/intfloat.h"
36 #include "libavutil/intreadwrite.h"
37 #include "libavutil/mastering_display_metadata.h"
38 #include "avformat.h"
39 #include "demux.h"
40 #include "internal.h"
41 #include "flv.h"
42
43 #define VALIDATE_INDEX_TS_THRESH 2500
44
45 #define RESYNC_BUFFER_SIZE (1<<20)
46
47 #define MAX_DEPTH 16 ///< arbitrary limit to prevent unbounded recursion
48
49 typedef struct FLVMasteringMeta {
50 float r_x;
51 float r_y;
52 float g_x;
53 float g_y;
54 float b_x;
55 float b_y;
56 float white_x;
57 float white_y;
58 float max_luminance;
59 float min_luminance;
60 } FLVMasteringMeta;
61
62 typedef struct FLVMetaVideoColor {
63 enum AVColorSpace matrix_coefficients;
64 enum AVColorTransferCharacteristic trc;
65 enum AVColorPrimaries primaries;
66 uint16_t max_cll;
67 uint16_t max_fall;
68 FLVMasteringMeta mastering_meta;
69 } FLVMetaVideoColor;
70
71 enum FLVMetaColorInfoFlag {
72 FLV_COLOR_INFO_FLAG_NONE = 0,
73 FLV_COLOR_INFO_FLAG_GOT = 1,
74 FLV_COLOR_INFO_FLAG_PARSING = 2,
75 };
76
77 typedef struct FLVContext {
78 const AVClass *class; ///< Class for private options.
79 int trust_metadata; ///< configure streams according onMetaData
80 int trust_datasize; ///< trust data size of FLVTag
81 int dump_full_metadata; ///< Dump full metadata of the onMetadata
82 int wrong_dts; ///< wrong dts due to negative cts
83 uint8_t *new_extradata[FLV_STREAM_TYPE_NB];
84 int new_extradata_size[FLV_STREAM_TYPE_NB];
85 int last_sample_rate;
86 int last_channels;
87 struct {
88 int64_t dts;
89 int64_t pos;
90 } validate_index[2];
91 int validate_next;
92 int validate_count;
93 int searched_for_end;
94
95 uint8_t resync_buffer[2*RESYNC_BUFFER_SIZE];
96
97 int broken_sizes;
98 int64_t sum_flv_tag_size;
99
100 int last_keyframe_stream_index;
101 int keyframe_count;
102 int64_t video_bit_rate;
103 int64_t audio_bit_rate;
104 int64_t *keyframe_times;
105 int64_t *keyframe_filepositions;
106 AVRational framerate;
107 int64_t last_ts;
108 int64_t time_offset;
109 int64_t time_pos;
110
111 FLVMetaVideoColor meta_color_info;
112 enum FLVMetaColorInfoFlag meta_color_info_flag;
113
114 uint8_t **mt_extradata;
115 int *mt_extradata_sz;
116 int mt_extradata_cnt;
117 } FLVContext;
118
119 /* AMF date type */
120 typedef struct amf_date {
121 double milliseconds;
122 int16_t timezone;
123 } amf_date;
124
125 14960 static int probe(const AVProbeData *p, int live)
126 {
127 14960 const uint8_t *d = p->buf;
128 14960 unsigned offset = AV_RB32(d + 5);
129
130
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 14820 times.
14960 if (d[0] == 'F' &&
131
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 62 times.
140 d[1] == 'L' &&
132
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 d[2] == 'V' &&
133
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
78 d[3] < 5 && d[5] == 0 &&
134
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
78 offset + 100 < p->buf_size &&
135 offset > 8) {
136 78 int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
137
138
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 39 times.
78 if (live == is_live)
139 39 return AVPROBE_SCORE_MAX;
140 }
141 14921 return 0;
142 }
143
144 7480 static int flv_probe(const AVProbeData *p)
145 {
146 7480 return probe(p, 0);
147 }
148
149 7480 static int live_flv_probe(const AVProbeData *p)
150 {
151 7480 return probe(p, 1);
152 }
153
154 7480 static int kux_probe(const AVProbeData *p)
155 {
156 7480 const uint8_t *d = p->buf;
157
158
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7477 times.
7480 if (d[0] == 'K' &&
159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 d[1] == 'D' &&
160 d[2] == 'K' &&
161 d[3] == 0 &&
162 d[4] == 0) {
163 return AVPROBE_SCORE_EXTENSION + 1;
164 }
165 7480 return 0;
166 }
167
168 49 static void add_keyframes_index(AVFormatContext *s)
169 {
170 49 FLVContext *flv = s->priv_data;
171 49 AVStream *stream = NULL;
172 49 unsigned int i = 0;
173
174
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 46 times.
49 if (flv->last_keyframe_stream_index < 0) {
175 3 av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
176 3 return;
177 }
178
179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
180 46 stream = s->streams[flv->last_keyframe_stream_index];
181
182
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
46 if (ffstream(stream)->nb_index_entries == 0) {
183
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 46 times.
219 for (i = 0; i < flv->keyframe_count; i++) {
184 173 av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
185 173 flv->keyframe_filepositions[i], flv->keyframe_times[i]);
186 173 av_add_index_entry(stream, flv->keyframe_filepositions[i],
187 173 flv->keyframe_times[i], 0, 0, AVINDEX_KEYFRAME);
188 }
189 } else
190 av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
191
192
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 12 times.
46 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
193 34 av_freep(&flv->keyframe_times);
194 34 av_freep(&flv->keyframe_filepositions);
195 34 flv->keyframe_count = 0;
196 }
197 }
198
199 70 static AVStream *create_stream(AVFormatContext *s, int codec_type, int track_idx)
200 {
201 70 FFFormatContext *const si = ffformatcontext(s);
202 70 FLVContext *flv = s->priv_data;
203 70 AVStream *st = avformat_new_stream(s, NULL);
204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (!st)
205 return NULL;
206 70 st->codecpar->codec_type = codec_type;
207 70 st->id = track_idx;
208 70 avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
209
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 46 times.
70 if (track_idx)
210 24 return st;
211
212
3/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 40 times.
46 if (s->nb_streams>=3 ||( s->nb_streams==2
213
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
214
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
215
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
216
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
217 6 s->ctx_flags &= ~AVFMTCTX_NOHEADER;
218
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 34 times.
46 if (codec_type == AVMEDIA_TYPE_AUDIO) {
219 12 st->codecpar->bit_rate = flv->audio_bit_rate;
220 12 si->missing_streams &= ~FLV_HEADER_FLAG_HASAUDIO;
221 }
222
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 12 times.
46 if (codec_type == AVMEDIA_TYPE_VIDEO) {
223 34 st->codecpar->bit_rate = flv->video_bit_rate;
224 34 si->missing_streams &= ~FLV_HEADER_FLAG_HASVIDEO;
225 34 st->avg_frame_rate = flv->framerate;
226 }
227
228 46 flv->last_keyframe_stream_index = s->nb_streams - 1;
229 46 add_keyframes_index(s);
230 46 return st;
231 }
232
233 4905 static int flv_same_audio_codec(AVCodecParameters *apar, int flags, uint32_t codec_fourcc)
234 {
235
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 2313 times.
4905 int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
236 4905 int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
237 int codec_id;
238
239
5/8
✓ Branch 0 taken 1110 times.
✓ Branch 1 taken 465 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 165 times.
✓ Branch 4 taken 573 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2592 times.
✗ Branch 7 not taken.
4905 switch (codec_fourcc) {
240 1110 case MKBETAG('m', 'p', '4', 'a'):
241 1110 return apar->codec_id == AV_CODEC_ID_AAC;
242 465 case MKBETAG('O', 'p', 'u', 's'):
243 465 return apar->codec_id == AV_CODEC_ID_OPUS;
244 case MKBETAG('.', 'm', 'p', '3'):
245 return apar->codec_id == AV_CODEC_ID_MP3;
246 165 case MKBETAG('f', 'L', 'a', 'C'):
247 165 return apar->codec_id == AV_CODEC_ID_FLAC;
248 573 case MKBETAG('a', 'c', '-', '3'):
249 573 return apar->codec_id == AV_CODEC_ID_AC3;
250 case MKBETAG('e', 'c', '-', '3'):
251 return apar->codec_id == AV_CODEC_ID_EAC3;
252 2592 case 0:
253 // Not enhanced flv, continue as normal.
254 2592 break;
255 default:
256 // Unknown FOURCC
257 return 0;
258 }
259
260
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2592 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2592 if (!apar->codec_id && !apar->codec_tag)
261 return 1;
262
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2592 times.
2592 if (apar->bits_per_coded_sample != bits_per_coded_sample)
264 return 0;
265
266
3/10
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 613 times.
✓ Branch 3 taken 284 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1695 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
2592 switch (flv_codecid) {
267 // no distinction between S16 and S8 PCM codec flags
268 case FLV_CODECID_PCM:
269 codec_id = bits_per_coded_sample == 8
270 ? AV_CODEC_ID_PCM_U8
271 #if HAVE_BIGENDIAN
272 : AV_CODEC_ID_PCM_S16BE;
273 #else
274 : AV_CODEC_ID_PCM_S16LE;
275 #endif
276 return codec_id == apar->codec_id;
277 case FLV_CODECID_PCM_LE:
278 codec_id = bits_per_coded_sample == 8
279 ? AV_CODEC_ID_PCM_U8
280 : AV_CODEC_ID_PCM_S16LE;
281 return codec_id == apar->codec_id;
282 613 case FLV_CODECID_AAC:
283 613 return apar->codec_id == AV_CODEC_ID_AAC;
284 284 case FLV_CODECID_ADPCM:
285 284 return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
286 case FLV_CODECID_SPEEX:
287 return apar->codec_id == AV_CODEC_ID_SPEEX;
288 case FLV_CODECID_MP3:
289 return apar->codec_id == AV_CODEC_ID_MP3;
290 1695 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
291 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
292 case FLV_CODECID_NELLYMOSER:
293 1695 return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
294 case FLV_CODECID_PCM_MULAW:
295 return apar->sample_rate == 8000 &&
296 apar->codec_id == AV_CODEC_ID_PCM_MULAW;
297 case FLV_CODECID_PCM_ALAW:
298 return apar->sample_rate == 8000 &&
299 apar->codec_id == AV_CODEC_ID_PCM_ALAW;
300 default:
301 return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
302 }
303 }
304
305 2616 static int flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
306 AVCodecParameters *apar, int flv_codecid)
307 {
308 2616 FFStream *const astreami = ffstream(astream);
309 2616 AVCodecParameters *par = astream->codecpar;
310 2616 enum AVCodecID old_codec_id = astream->codecpar->codec_id;
311
312
8/18
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 618 times.
✓ Branch 3 taken 288 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 376 times.
✓ Branch 8 taken 1322 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
2616 switch (flv_codecid) {
313 // no distinction between S16 and S8 PCM codec flags
314 case FLV_CODECID_PCM:
315 apar->codec_id = apar->bits_per_coded_sample == 8
316 ? AV_CODEC_ID_PCM_U8
317 #if HAVE_BIGENDIAN
318 : AV_CODEC_ID_PCM_S16BE;
319 #else
320 : AV_CODEC_ID_PCM_S16LE;
321 #endif
322 break;
323 case FLV_CODECID_PCM_LE:
324 apar->codec_id = apar->bits_per_coded_sample == 8
325 ? AV_CODEC_ID_PCM_U8
326 : AV_CODEC_ID_PCM_S16LE;
327 break;
328 618 case FLV_CODECID_AAC:
329 618 apar->codec_id = AV_CODEC_ID_AAC;
330 618 break;
331 288 case FLV_CODECID_ADPCM:
332 288 apar->codec_id = AV_CODEC_ID_ADPCM_SWF;
333 288 break;
334 case FLV_CODECID_SPEEX:
335 apar->codec_id = AV_CODEC_ID_SPEEX;
336 apar->sample_rate = 16000;
337 break;
338 case FLV_CODECID_MP3:
339 apar->codec_id = AV_CODEC_ID_MP3;
340 ffstream(astream)->need_parsing = AVSTREAM_PARSE_FULL;
341 break;
342 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
343 // in case metadata does not otherwise declare samplerate
344 apar->sample_rate = 8000;
345 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
346 break;
347 376 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
348 376 apar->sample_rate = 16000;
349 376 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
350 376 break;
351 1322 case FLV_CODECID_NELLYMOSER:
352 1322 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
353 1322 break;
354 case FLV_CODECID_PCM_MULAW:
355 apar->sample_rate = 8000;
356 apar->codec_id = AV_CODEC_ID_PCM_MULAW;
357 break;
358 case FLV_CODECID_PCM_ALAW:
359 apar->sample_rate = 8000;
360 apar->codec_id = AV_CODEC_ID_PCM_ALAW;
361 break;
362 3 case MKBETAG('m', 'p', '4', 'a'):
363 3 apar->codec_id = AV_CODEC_ID_AAC;
364 3 break;
365 3 case MKBETAG('O', 'p', 'u', 's'):
366 3 apar->codec_id = AV_CODEC_ID_OPUS;
367 3 apar->sample_rate = 48000;
368 3 break;
369 case MKBETAG('.', 'm', 'p', '3'):
370 apar->codec_id = AV_CODEC_ID_MP3;
371 break;
372 3 case MKBETAG('f', 'L', 'a', 'C'):
373 3 apar->codec_id = AV_CODEC_ID_FLAC;
374 3 break;
375 3 case MKBETAG('a', 'c', '-', '3'):
376 3 apar->codec_id = AV_CODEC_ID_AC3;
377 3 break;
378 case MKBETAG('e', 'c', '-', '3'):
379 apar->codec_id = AV_CODEC_ID_EAC3;
380 break;
381 default:
382 avpriv_request_sample(s, "Audio codec (%x)",
383 flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
384 apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
385 }
386
387
3/4
✓ Branch 0 taken 2590 times.
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2590 times.
2616 if (!astreami->need_context_update && par->codec_id != old_codec_id) {
388 avpriv_request_sample(s, "Changing the codec id midstream");
389 return AVERROR_PATCHWELCOME;
390 }
391 2616 return 0;
392 }
393
394 3984 static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)
395 {
396
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3984 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3984 if (!vpar->codec_id && !vpar->codec_tag)
397 return 1;
398
399
9/11
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 552 times.
✓ Branch 2 taken 330 times.
✓ Branch 3 taken 229 times.
✓ Branch 4 taken 493 times.
✓ Branch 5 taken 271 times.
✓ Branch 6 taken 196 times.
✓ Branch 7 taken 173 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1723 times.
✗ Branch 10 not taken.
3984 switch (flv_codecid) {
400 17 case MKBETAG('v', 'v', 'c', '1'):
401 17 return vpar->codec_id == AV_CODEC_ID_VVC;
402 552 case FLV_CODECID_X_HEVC:
403 case MKBETAG('h', 'v', 'c', '1'):
404 552 return vpar->codec_id == AV_CODEC_ID_HEVC;
405 330 case MKBETAG('a', 'v', '0', '1'):
406 330 return vpar->codec_id == AV_CODEC_ID_AV1;
407 229 case MKBETAG('v', 'p', '0', '9'):
408 229 return vpar->codec_id == AV_CODEC_ID_VP9;
409 493 case FLV_CODECID_H263:
410 493 return vpar->codec_id == AV_CODEC_ID_FLV1;
411 271 case FLV_CODECID_SCREEN:
412 271 return vpar->codec_id == AV_CODEC_ID_FLASHSV;
413 196 case FLV_CODECID_SCREEN2:
414 196 return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
415 173 case FLV_CODECID_VP6:
416 173 return vpar->codec_id == AV_CODEC_ID_VP6F;
417 case FLV_CODECID_VP6A:
418 return vpar->codec_id == AV_CODEC_ID_VP6A;
419 1723 case FLV_CODECID_H264:
420 case MKBETAG('a', 'v', 'c', '1'):
421 1723 return vpar->codec_id == AV_CODEC_ID_H264;
422 default:
423 return vpar->codec_tag == flv_codecid;
424 }
425 }
426
427 2673 static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
428 uint32_t flv_codecid, int read)
429 {
430 2673 FFStream *const vstreami = ffstream(vstream);
431 2673 int ret = 0;
432 2673 AVCodecParameters *par = vstream->codecpar;
433 2673 enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
434
435
9/13
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 227 times.
✓ Branch 2 taken 176 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 503 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 276 times.
✓ Branch 7 taken 200 times.
✓ Branch 8 taken 174 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 977 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
2673 switch (flv_codecid) {
436 18 case MKBETAG('v', 'v', 'c', '1'):
437 18 par->codec_id = AV_CODEC_ID_VVC;
438 18 vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
439 18 break;
440 227 case FLV_CODECID_X_HEVC:
441 case MKBETAG('h', 'v', 'c', '1'):
442 227 par->codec_id = AV_CODEC_ID_HEVC;
443 227 vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
444 227 break;
445 176 case MKBETAG('a', 'v', '0', '1'):
446 176 par->codec_id = AV_CODEC_ID_AV1;
447 176 vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
448 176 break;
449 122 case MKBETAG('v', 'p', '0', '9'):
450 122 par->codec_id = AV_CODEC_ID_VP9;
451 122 vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
452 122 break;
453 503 case FLV_CODECID_H263:
454 503 par->codec_id = AV_CODEC_ID_FLV1;
455 503 break;
456 case FLV_CODECID_REALH263:
457 par->codec_id = AV_CODEC_ID_H263;
458 break; // Really mean it this time
459 276 case FLV_CODECID_SCREEN:
460 276 par->codec_id = AV_CODEC_ID_FLASHSV;
461 276 break;
462 200 case FLV_CODECID_SCREEN2:
463 200 par->codec_id = AV_CODEC_ID_FLASHSV2;
464 200 break;
465 174 case FLV_CODECID_VP6:
466 174 par->codec_id = AV_CODEC_ID_VP6F;
467 av_fallthrough;
468 174 case FLV_CODECID_VP6A:
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 174 times.
174 if (flv_codecid == FLV_CODECID_VP6A)
470 par->codec_id = AV_CODEC_ID_VP6A;
471
1/2
✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
174 if (read) {
472
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 173 times.
174 if (par->extradata_size != 1) {
473 1 ff_alloc_extradata(par, 1);
474 }
475
1/2
✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
174 if (par->extradata)
476 174 par->extradata[0] = avio_r8(s->pb);
477 else
478 avio_skip(s->pb, 1);
479 }
480 174 ret = 1; // 1 byte body size adjustment for flv_read_packet()
481 174 break;
482 977 case FLV_CODECID_H264:
483 case MKBETAG('a', 'v', 'c', '1'):
484 977 par->codec_id = AV_CODEC_ID_H264;
485 977 vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
486 977 break;
487 case FLV_CODECID_MPEG4:
488 par->codec_id = AV_CODEC_ID_MPEG4;
489 break;
490 default:
491 avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
492 par->codec_tag = flv_codecid;
493 }
494
495
3/4
✓ Branch 0 taken 2616 times.
✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2616 times.
2673 if (!vstreami->need_context_update && par->codec_id != old_codec_id) {
496 avpriv_request_sample(s, "Changing the codec id midstream");
497 return AVERROR_PATCHWELCOME;
498 }
499
500 2673 return ret;
501 }
502
503 593 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
504 {
505 int ret;
506 593 int length = avio_rb16(ioc);
507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 593 times.
593 if (length >= buffsize) {
508 avio_skip(ioc, length);
509 return AVERROR_INVALIDDATA;
510 }
511
512 593 ret = avio_read(ioc, buffer, length);
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 593 times.
593 if (ret < 0)
514 return ret;
515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 593 times.
593 if (ret < length)
516 return AVERROR_INVALIDDATA;
517
518 593 buffer[length] = '\0';
519
520 593 return length;
521 }
522
523 3 static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
524 {
525 3 FLVContext *flv = s->priv_data;
526 3 unsigned int timeslen = 0, fileposlen = 0, i;
527 char str_val[256];
528 3 int64_t *times = NULL;
529 3 int64_t *filepositions = NULL;
530 3 int ret = AVERROR(ENOSYS);
531 3 int64_t initial_pos = avio_tell(ioc);
532
533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (flv->keyframe_count > 0) {
534 av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
535 return 0;
536 }
537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 av_assert0(!flv->keyframe_times);
538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 av_assert0(!flv->keyframe_filepositions);
539
540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (s->flags & AVFMT_FLAG_IGNIDX)
541 return 0;
542
543
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
12 while (avio_tell(ioc) < max_pos - 2 &&
544 6 amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
545 int64_t **current_array;
546 unsigned int arraylen;
547 int factor;
548
549 // Expect array object in context
550
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
551 break;
552
553 6 arraylen = avio_rb32(ioc);
554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (arraylen>>28)
555 break;
556
557
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
558 3 current_array = &times;
559 3 timeslen = arraylen;
560 3 factor = 1000;
561
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
562
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 !filepositions) {
563 3 current_array = &filepositions;
564 3 fileposlen = arraylen;
565 3 factor = 1;
566 } else
567 // unexpected metatag inside keyframes, will not use such
568 // metadata for indexing
569 break;
570
571
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
572 ret = AVERROR(ENOMEM);
573 goto finish;
574 }
575
576
3/4
✓ Branch 0 taken 346 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 346 times.
✗ Branch 4 not taken.
352 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
577 double d;
578
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 346 times.
346 if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
579 goto invalid;
580 346 d = av_int2double(avio_rb64(ioc)) * factor;
581
3/6
✓ Branch 0 taken 346 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 346 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 346 times.
346 if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
582 goto invalid;
583
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 346 times.
346 if (avio_feof(ioc))
584 goto invalid;
585 346 current_array[0][i] = d;
586 }
587
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
6 if (times && filepositions) {
588 // All done, exiting at a position allowing amf_parse_object
589 // to finish parsing the object
590 3 ret = 0;
591 3 break;
592 }
593 }
594
595
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
3 if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
596
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for (i = 0; i < FFMIN(2,fileposlen); i++) {
597 6 flv->validate_index[i].pos = filepositions[i];
598 6 flv->validate_index[i].dts = times[i];
599 6 flv->validate_count = i + 1;
600 }
601 3 flv->keyframe_times = times;
602 3 flv->keyframe_filepositions = filepositions;
603 3 flv->keyframe_count = timeslen;
604 3 times = NULL;
605 3 filepositions = NULL;
606 } else {
607 invalid:
608 av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
609 }
610
611 3 finish:
612 3 av_freep(&times);
613 3 av_freep(&filepositions);
614 3 avio_seek(ioc, initial_pos, SEEK_SET);
615 3 return ret;
616 }
617
618 828 static int amf_parse_object(AVFormatContext *s, AVStream *astream,
619 AVStream *vstream, const char *key,
620 int64_t max_pos, int depth)
621 {
622 AVCodecParameters *apar, *vpar;
623 828 FLVContext *flv = s->priv_data;
624 AVIOContext *ioc;
625 AMFDataType amf_type;
626 char str_val[1024];
627 double num_val;
628 amf_date date;
629
630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 828 times.
828 if (depth > MAX_DEPTH)
631 return AVERROR_PATCHWELCOME;
632
633 828 num_val = 0;
634 828 ioc = s->pb;
635
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 828 times.
828 if (avio_feof(ioc))
636 return AVERROR_EOF;
637 828 amf_type = avio_r8(ioc);
638
639
7/9
✓ Branch 0 taken 688 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 37 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
828 switch (amf_type) {
640 688 case AMF_DATA_TYPE_NUMBER:
641 688 num_val = av_int2double(avio_rb64(ioc));
642 688 break;
643 27 case AMF_DATA_TYPE_BOOL:
644 27 num_val = avio_r8(ioc);
645 27 break;
646 28 case AMF_DATA_TYPE_STRING:
647
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
28 if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
648 av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
649 return -1;
650 }
651 28 break;
652 37 case AMF_DATA_TYPE_OBJECT:
653
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 if (key &&
654
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
655
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
37 !strcmp(KEYFRAMES_TAG, key) && depth == 1)
656
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (parse_keyframes_index(s, ioc, max_pos) < 0)
657 av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
658 else
659 3 add_keyframes_index(s);
660
3/4
✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
✓ Branch 4 taken 37 times.
182 while (avio_tell(ioc) < max_pos - 2 &&
661 91 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
662
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
54 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
663 depth + 1) < 0)
664 return -1; // if we couldn't skip, bomb out.
665
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
37 if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
666 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
667 return -1;
668 }
669 37 break;
670 case AMF_DATA_TYPE_NULL:
671 case AMF_DATA_TYPE_UNDEFINED:
672 case AMF_DATA_TYPE_UNSUPPORTED:
673 break; // these take up no additional space
674 40 case AMF_DATA_TYPE_MIXEDARRAY:
675 {
676 unsigned v;
677 40 avio_skip(ioc, 4); // skip 32-bit max array index
678
3/4
✓ Branch 1 taken 412 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 372 times.
✓ Branch 4 taken 40 times.
824 while (avio_tell(ioc) < max_pos - 2 &&
679 412 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
680 // this is the only case in which we would want a nested
681 // parse to not skip over the object
682
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
372 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
683 depth + 1) < 0)
684 return -1;
685 40 v = avio_r8(ioc);
686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (v != AMF_END_OF_OBJECT) {
687 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
688 return -1;
689 }
690 40 break;
691 }
692 7 case AMF_DATA_TYPE_ARRAY:
693 {
694 unsigned int arraylen, i;
695
696 7 arraylen = avio_rb32(ioc);
697
3/4
✓ Branch 0 taken 346 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 346 times.
✗ Branch 4 not taken.
353 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
698
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 346 times.
346 if (amf_parse_object(s, NULL, NULL, NULL, max_pos,
699 depth + 1) < 0)
700 return -1; // if we couldn't skip, bomb out.
701 }
702 7 break;
703 1 case AMF_DATA_TYPE_DATE:
704 // timestamp (double) and UTC offset (int16)
705 1 date.milliseconds = av_int2double(avio_rb64(ioc));
706 1 date.timezone = avio_rb16(ioc);
707 1 break;
708 default: // unsupported type, we couldn't skip
709 av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
710 return -1;
711 }
712
713
2/2
✓ Branch 0 taken 482 times.
✓ Branch 1 taken 346 times.
828 if (key) {
714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 482 times.
482 apar = astream ? astream->codecpar : NULL;
715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 482 times.
482 vpar = vstream ? vstream->codecpar : NULL;
716
717 // stream info doesn't live any deeper than the first object
718
2/2
✓ Branch 0 taken 390 times.
✓ Branch 1 taken 92 times.
482 if (depth == 1) {
719
4/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 312 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 51 times.
390 if (amf_type == AMF_DATA_TYPE_NUMBER ||
720 amf_type == AMF_DATA_TYPE_BOOL) {
721
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 299 times.
339 if (!strcmp(key, "duration"))
722 40 s->duration = num_val * AV_TIME_BASE;
723
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 265 times.
299 else if (!strcmp(key, "videodatarate") &&
724
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 0 <= (int)(num_val * 1024.0))
725 34 flv->video_bit_rate = num_val * 1024.0;
726
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 253 times.
265 else if (!strcmp(key, "audiodatarate") &&
727
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 0 <= (int)(num_val * 1024.0))
728 12 flv->audio_bit_rate = num_val * 1024.0;
729
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 221 times.
253 else if (!strcmp(key, "framerate")) {
730 32 flv->framerate = av_d2q(num_val, 1000);
731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (vstream)
732 vstream->avg_frame_rate = flv->framerate;
733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 221 times.
221 } else if (flv->trust_metadata) {
734 if (!strcmp(key, "videocodecid") && vpar) {
735 int ret = flv_set_video_codec(s, vstream, num_val, 0);
736 if (ret < 0)
737 return ret;
738 } else if (!strcmp(key, "audiocodecid") && apar) {
739 int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
740 int ret = flv_set_audio_codec(s, astream, apar, id);
741 if (ret < 0)
742 return ret;
743 } else if (!strcmp(key, "audiosamplerate") && apar) {
744 apar->sample_rate = num_val;
745 } else if (!strcmp(key, "audiosamplesize") && apar) {
746 apar->bits_per_coded_sample = num_val;
747 } else if (!strcmp(key, "stereo") && apar) {
748 av_channel_layout_default(&apar->ch_layout, num_val + 1);
749 } else if (!strcmp(key, "width") && vpar) {
750 vpar->width = num_val;
751 } else if (!strcmp(key, "height") && vpar) {
752 vpar->height = num_val;
753 } else if (!strcmp(key, "datastream")) {
754 AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE, 0);
755 if (!st)
756 return AVERROR(ENOMEM);
757 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
758 }
759 }
760 }
761
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 362 times.
390 if (amf_type == AMF_DATA_TYPE_STRING) {
762
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 24 times.
28 if (!strcmp(key, "encoder")) {
763 4 int version = -1;
764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
765 if (version > 0 && version <= 655)
766 flv->broken_sizes = 1;
767 }
768
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 23 times.
24 } else if (!strcmp(key, "metadatacreator")) {
769
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if ( !strcmp (str_val, "MEGA")
770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 || !strncmp(str_val, "FlixEngine", 10))
771 flv->broken_sizes = 1;
772 }
773 }
774 }
775
776
4/4
✓ Branch 0 taken 342 times.
✓ Branch 1 taken 140 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 312 times.
482 if (amf_type == AMF_DATA_TYPE_NUMBER && flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_PARSING) {
777 30 FLVMetaVideoColor *meta_video_color = &flv->meta_color_info;
778
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 26 times.
30 if (!strcmp(key, "colorPrimaries")) {
779 4 meta_video_color->primaries = num_val;
780
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22 times.
26 } else if (!strcmp(key, "transferCharacteristics")) {
781 4 meta_video_color->trc = num_val;
782
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12 times.
22 } else if (!strcmp(key, "matrixCoefficients")) {
783 10 meta_video_color->matrix_coefficients = num_val;
784
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 } else if (!strcmp(key, "maxFall")) {
785 1 meta_video_color->max_fall = num_val;
786
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 } else if (!strcmp(key, "maxCLL")) {
787 1 meta_video_color->max_cll = num_val;
788
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 } else if (!strcmp(key, "redX")) {
789 1 meta_video_color->mastering_meta.r_x = num_val;
790
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 } else if (!strcmp(key, "redY")) {
791 1 meta_video_color->mastering_meta.r_y = num_val;
792
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 } else if (!strcmp(key, "greenX")) {
793 1 meta_video_color->mastering_meta.g_x = num_val;
794
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 } else if (!strcmp(key, "greenY")) {
795 1 meta_video_color->mastering_meta.g_y = num_val;
796
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 } else if (!strcmp(key, "blueX")) {
797 1 meta_video_color->mastering_meta.b_x = num_val;
798
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 } else if (!strcmp(key, "blueY")) {
799 1 meta_video_color->mastering_meta.b_y = num_val;
800
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 } else if (!strcmp(key, "whitePointX")) {
801 1 meta_video_color->mastering_meta.white_x = num_val;
802
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 } else if (!strcmp(key, "whitePointY")) {
803 1 meta_video_color->mastering_meta.white_y = num_val;
804
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 } else if (!strcmp(key, "maxLuminance")) {
805 1 meta_video_color->mastering_meta.max_luminance = num_val;
806
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 } else if (!strcmp(key, "minLuminance")) {
807 1 meta_video_color->mastering_meta.min_luminance = num_val;
808 }
809 }
810
811
5/6
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 445 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
482 if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
812
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 ((!apar && !strcmp(key, "audiocodecid")) ||
813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 (!vpar && !strcmp(key, "videocodecid"))))
814 s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
815
816
2/2
✓ Branch 0 taken 442 times.
✓ Branch 1 taken 40 times.
482 if ((!strcmp(key, "duration") ||
817
2/2
✓ Branch 0 taken 403 times.
✓ Branch 1 taken 39 times.
442 !strcmp(key, "filesize") ||
818
2/2
✓ Branch 0 taken 369 times.
✓ Branch 1 taken 34 times.
403 !strcmp(key, "width") ||
819
2/2
✓ Branch 0 taken 335 times.
✓ Branch 1 taken 34 times.
369 !strcmp(key, "height") ||
820
2/2
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 34 times.
335 !strcmp(key, "videodatarate") ||
821
2/2
✓ Branch 0 taken 269 times.
✓ Branch 1 taken 32 times.
301 !strcmp(key, "framerate") ||
822
2/2
✓ Branch 0 taken 235 times.
✓ Branch 1 taken 34 times.
269 !strcmp(key, "videocodecid") ||
823
2/2
✓ Branch 0 taken 223 times.
✓ Branch 1 taken 12 times.
235 !strcmp(key, "audiodatarate") ||
824
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 11 times.
223 !strcmp(key, "audiosamplerate") ||
825
2/2
✓ Branch 0 taken 201 times.
✓ Branch 1 taken 11 times.
212 !strcmp(key, "audiosamplesize") ||
826
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 11 times.
201 !strcmp(key, "stereo") ||
827
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 12 times.
190 !strcmp(key, "audiocodecid") ||
828
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
✓ Branch 2 taken 304 times.
✗ Branch 3 not taken.
482 !strcmp(key, "datastream")) && !flv->dump_full_metadata)
829 304 return 0;
830
831 178 s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
832
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 162 times.
178 if (amf_type == AMF_DATA_TYPE_BOOL) {
833
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 av_strlcpy(str_val, num_val > 0 ? "true" : "false",
834 sizeof(str_val));
835 16 av_dict_set(&s->metadata, key, str_val, 0);
836
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 113 times.
162 } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
837 49 snprintf(str_val, sizeof(str_val), "%.f", num_val);
838 49 av_dict_set(&s->metadata, key, str_val, 0);
839
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 85 times.
113 } else if (amf_type == AMF_DATA_TYPE_STRING) {
840 28 av_dict_set(&s->metadata, key, str_val, 0);
841
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 84 times.
85 } else if ( amf_type == AMF_DATA_TYPE_DATE
842
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 && isfinite(date.milliseconds)
843
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 && date.milliseconds > INT64_MIN/1000
844
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 && date.milliseconds < INT64_MAX/1000
845 ) {
846 // timezone is ignored, since there is no easy way to offset the UTC
847 // timestamp into the specified timezone
848 1 ff_dict_set_timestamp(&s->metadata, key, 1000 * (int64_t)date.milliseconds);
849 }
850 }
851
852 524 return 0;
853 }
854
855 #define TYPE_ONTEXTDATA 1
856 #define TYPE_ONCAPTION 2
857 #define TYPE_ONCAPTIONINFO 3
858 #define TYPE_UNKNOWN 9
859
860 40 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
861 {
862 40 FLVContext *flv = s->priv_data;
863 AMFDataType type;
864 AVStream *stream, *astream, *vstream;
865 av_unused AVStream *dstream;
866 AVIOContext *ioc;
867 int i;
868 char buffer[32];
869
870 40 astream = NULL;
871 40 vstream = NULL;
872 40 dstream = NULL;
873 40 ioc = s->pb;
874
875 // first object needs to be "onMetaData" string
876 40 type = avio_r8(ioc);
877
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
80 if (type != AMF_DATA_TYPE_STRING ||
878 40 amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
879 return TYPE_UNKNOWN;
880
881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!strcmp(buffer, "onTextData"))
882 return TYPE_ONTEXTDATA;
883
884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!strcmp(buffer, "onCaption"))
885 return TYPE_ONCAPTION;
886
887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!strcmp(buffer, "onCaptionInfo"))
888 return TYPE_ONCAPTIONINFO;
889
890
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
40 if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint") && strcmp(buffer, "|RtmpSampleAccess")) {
891 av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
892 return TYPE_UNKNOWN;
893 }
894
895 // find the streams now so that amf_parse_object doesn't need to do
896 // the lookup every time it is called.
897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 for (i = 0; i < s->nb_streams; i++) {
898 stream = s->streams[i];
899 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
900 vstream = stream;
901 flv->last_keyframe_stream_index = i;
902 } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
903 astream = stream;
904 if (flv->last_keyframe_stream_index == -1)
905 flv->last_keyframe_stream_index = i;
906 } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
907 dstream = stream;
908 }
909
910 // parse the second object (we want a mixed array)
911
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
40 if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
912 return -1;
913
914 40 return 0;
915 }
916
917 40 static int flv_read_header(AVFormatContext *s)
918 {
919 40 FFFormatContext *const si = ffformatcontext(s);
920 int flags;
921 40 FLVContext *flv = s->priv_data;
922 int offset;
923 40 int pre_tag_size = 0;
924
925 /* Actual FLV data at 0xe40000 in KUX file */
926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if(!strcmp(s->iformat->name, "kux"))
927 avio_skip(s->pb, 0xe40000);
928
929 40 avio_skip(s->pb, 4);
930 40 flags = avio_r8(s->pb);
931
932 40 si->missing_streams = flags & (FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO);
933
934 40 s->ctx_flags |= AVFMTCTX_NOHEADER;
935
936 40 offset = avio_rb32(s->pb);
937 40 avio_seek(s->pb, offset, SEEK_SET);
938
939 /* Annex E. The FLV File Format
940 * E.3 TheFLVFileBody
941 * Field Type Comment
942 * PreviousTagSize0 UI32 Always 0
943 * */
944 40 pre_tag_size = avio_rb32(s->pb);
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (pre_tag_size) {
946 av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
947 }
948
949 40 s->start_time = 0;
950 40 flv->sum_flv_tag_size = 0;
951 40 flv->last_keyframe_stream_index = -1;
952
953 40 return 0;
954 }
955
956 40 static int flv_read_close(AVFormatContext *s)
957 {
958 int i;
959 40 FLVContext *flv = s->priv_data;
960
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 40 times.
200 for (i = 0; i < FLV_STREAM_TYPE_NB; i++)
961 160 av_freep(&flv->new_extradata[i]);
962
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 40 times.
43 for (i = 0; i < flv->mt_extradata_cnt; i++)
963 3 av_freep(&flv->mt_extradata[i]);
964 40 av_freep(&flv->mt_extradata);
965 40 av_freep(&flv->mt_extradata_sz);
966 40 av_freep(&flv->keyframe_times);
967 40 av_freep(&flv->keyframe_filepositions);
968 40 return 0;
969 }
970
971 40 static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
972 {
973 int ret;
974
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!size)
975 return 0;
976
977
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
40 if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
978 return ret;
979 40 ffstream(st)->need_context_update = 1;
980 40 return 0;
981 }
982
983 3 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
984 int size, int multitrack)
985 {
986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!size)
987 return 0;
988
989
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (!multitrack) {
990 2 av_free(flv->new_extradata[stream]);
991 2 flv->new_extradata[stream] = av_mallocz(size +
992 AV_INPUT_BUFFER_PADDING_SIZE);
993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!flv->new_extradata[stream])
994 return AVERROR(ENOMEM);
995 2 flv->new_extradata_size[stream] = size;
996 2 avio_read(pb, flv->new_extradata[stream], size);
997 } else {
998 1 int new_count = stream + 1;
999
1000
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (flv->mt_extradata_cnt < new_count) {
1001 1 void *tmp = av_realloc_array(flv->mt_extradata, new_count,
1002 sizeof(*flv->mt_extradata));
1003
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!tmp)
1004 return AVERROR(ENOMEM);
1005 1 flv->mt_extradata = tmp;
1006
1007 1 tmp = av_realloc_array(flv->mt_extradata_sz, new_count,
1008 sizeof(*flv->mt_extradata_sz));
1009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!tmp)
1010 return AVERROR(ENOMEM);
1011 1 flv->mt_extradata_sz = tmp;
1012
1013 // Set newly allocated pointers/sizes to 0
1014
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = flv->mt_extradata_cnt; i < new_count; i++) {
1015 3 flv->mt_extradata[i] = NULL;
1016 3 flv->mt_extradata_sz[i] = 0;
1017 }
1018 1 flv->mt_extradata_cnt = new_count;
1019 }
1020
1021 1 av_free(flv->mt_extradata[stream]);
1022 1 flv->mt_extradata[stream] = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
1023
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!flv->mt_extradata[stream])
1024 return AVERROR(ENOMEM);
1025 1 flv->mt_extradata_sz[stream] = size;
1026 1 avio_read(pb, flv->mt_extradata[stream], size);
1027 }
1028
1029 3 return 0;
1030 }
1031
1032 1 static void clear_index_entries(AVFormatContext *s, int64_t pos)
1033 {
1034 1 av_log(s, AV_LOG_WARNING,
1035 "Found invalid index entries, clearing the index.\n");
1036
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (unsigned i = 0; i < s->nb_streams; i++) {
1037 1 FFStream *const sti = ffstream(s->streams[i]);
1038 1 int out = 0;
1039 /* Remove all index entries that point to >= pos */
1040
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1 times.
133 for (int j = 0; j < sti->nb_index_entries; j++)
1041
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 131 times.
132 if (sti->index_entries[j].pos < pos)
1042 1 sti->index_entries[out++] = sti->index_entries[j];
1043 1 sti->nb_index_entries = out;
1044 }
1045 1 }
1046
1047 static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
1048 {
1049 int nb = -1, ret, parse_name = 1;
1050
1051 if (depth > MAX_DEPTH)
1052 return AVERROR_PATCHWELCOME;
1053
1054 if (avio_feof(pb))
1055 return AVERROR_EOF;
1056
1057 switch (type) {
1058 case AMF_DATA_TYPE_NUMBER:
1059 avio_skip(pb, 8);
1060 break;
1061 case AMF_DATA_TYPE_BOOL:
1062 avio_skip(pb, 1);
1063 break;
1064 case AMF_DATA_TYPE_STRING:
1065 avio_skip(pb, avio_rb16(pb));
1066 break;
1067 case AMF_DATA_TYPE_ARRAY:
1068 parse_name = 0;
1069 av_fallthrough;
1070 case AMF_DATA_TYPE_MIXEDARRAY:
1071 nb = avio_rb32(pb);
1072 if (nb < 0)
1073 return AVERROR_INVALIDDATA;
1074 av_fallthrough;
1075 case AMF_DATA_TYPE_OBJECT:
1076 while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
1077 if (parse_name) {
1078 int size = avio_rb16(pb);
1079 if (!size) {
1080 avio_skip(pb, 1);
1081 break;
1082 }
1083 avio_skip(pb, size);
1084 }
1085 if ((ret = amf_skip_tag(pb, avio_r8(pb), depth + 1)) < 0)
1086 return ret;
1087 }
1088 break;
1089 case AMF_DATA_TYPE_NULL:
1090 case AMF_DATA_TYPE_OBJECT_END:
1091 break;
1092 default:
1093 return AVERROR_INVALIDDATA;
1094 }
1095 return 0;
1096 }
1097
1098 static int flv_data_packet(AVFormatContext *s, AVPacket *pkt,
1099 int64_t dts, int64_t next)
1100 {
1101 AVIOContext *pb = s->pb;
1102 AVStream *st = NULL;
1103 char buf[20];
1104 int ret = AVERROR_INVALIDDATA;
1105 int i, length = -1;
1106 int array = 0;
1107
1108 switch (avio_r8(pb)) {
1109 case AMF_DATA_TYPE_ARRAY:
1110 array = 1;
1111 av_fallthrough;
1112 case AMF_DATA_TYPE_MIXEDARRAY:
1113 avio_seek(pb, 4, SEEK_CUR);
1114 av_fallthrough;
1115 case AMF_DATA_TYPE_OBJECT:
1116 break;
1117 default:
1118 goto skip;
1119 }
1120
1121 while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
1122 AMFDataType type = avio_r8(pb);
1123 if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
1124 length = avio_rb16(pb);
1125 ret = av_get_packet(pb, pkt, length);
1126 if (ret < 0)
1127 goto skip;
1128 else
1129 break;
1130 } else {
1131 if ((ret = amf_skip_tag(pb, type, 0)) < 0)
1132 goto skip;
1133 }
1134 }
1135
1136 if (length < 0) {
1137 ret = AVERROR_INVALIDDATA;
1138 goto skip;
1139 }
1140
1141 for (i = 0; i < s->nb_streams; i++) {
1142 st = s->streams[i];
1143 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1144 break;
1145 }
1146
1147 if (i == s->nb_streams) {
1148 st = create_stream(s, AVMEDIA_TYPE_SUBTITLE, 0);
1149 if (!st)
1150 return AVERROR(ENOMEM);
1151 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
1152 }
1153
1154 pkt->dts = dts;
1155 pkt->pts = dts;
1156 pkt->size = ret;
1157
1158 pkt->stream_index = st->index;
1159 pkt->flags |= AV_PKT_FLAG_KEY;
1160
1161 skip:
1162 avio_seek(s->pb, next + 4, SEEK_SET);
1163
1164 return ret;
1165 }
1166
1167 static int resync(AVFormatContext *s)
1168 {
1169 FLVContext *flv = s->priv_data;
1170 int64_t i;
1171 int64_t pos = avio_tell(s->pb);
1172
1173 for (i=0; !avio_feof(s->pb); i++) {
1174 int j = i & (RESYNC_BUFFER_SIZE-1);
1175 int j1 = j + RESYNC_BUFFER_SIZE;
1176 flv->resync_buffer[j ] =
1177 flv->resync_buffer[j1] = avio_r8(s->pb);
1178
1179 if (i >= 8 && pos) {
1180 uint8_t *d = flv->resync_buffer + j1 - 8;
1181 if (d[0] == 'F' &&
1182 d[1] == 'L' &&
1183 d[2] == 'V' &&
1184 d[3] < 5 && d[5] == 0) {
1185 av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
1186 flv->time_offset = flv->last_ts + 1;
1187 flv->time_pos = avio_tell(s->pb);
1188 }
1189 }
1190
1191 if (i > 22) {
1192 unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
1193 if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1194 unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
1195 unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
1196 if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1197 unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
1198 if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
1199 avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
1200 return 1;
1201 }
1202 }
1203 }
1204 }
1205 }
1206 return AVERROR_EOF;
1207 }
1208
1209 16 static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t next_pos)
1210 {
1211 int ret;
1212 16 FLVContext *flv = s->priv_data;
1213 AMFDataType type;
1214 AVIOContext *ioc;
1215 char buffer[32];
1216 16 ioc = s->pb;
1217
1218 // first object needs to be "colorInfo" string
1219 16 type = avio_r8(ioc);
1220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (type != AMF_DATA_TYPE_STRING) {
1221 av_log(s, AV_LOG_WARNING, "Ignore invalid colorInfo\n");
1222 return 0;
1223 }
1224
1225 16 ret = amf_get_string(ioc, buffer, sizeof(buffer));
1226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (ret < 0)
1227 return ret;
1228
1229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (strcmp(buffer, "colorInfo") != 0) {
1230 av_log(s, AV_LOG_WARNING, "Ignore invalid colorInfo type %s\n", buffer);
1231 return 0;
1232 }
1233
1234 16 flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_PARSING;
1235 16 ret = amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
1236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (ret < 0) {
1237 flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
1238 return ret;
1239 }
1240
1241 16 flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_GOT;
1242
1243 16 return 0;
1244 }
1245
1246 16 static int flv_update_video_color_info(AVFormatContext *s, AVStream *st)
1247 {
1248 16 FLVContext *flv = s->priv_data;
1249 16 const FLVMetaVideoColor* meta_video_color = &flv->meta_color_info;
1250 16 const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta;
1251
1252 int has_mastering_primaries, has_mastering_luminance;
1253 // Mastering primaries are CIE 1931 coords, and must be > 0.
1254 16 has_mastering_primaries =
1255
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 mastering_meta->r_x > 0 && mastering_meta->r_y > 0 &&
1256
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 mastering_meta->g_x > 0 && mastering_meta->g_y > 0 &&
1257
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 mastering_meta->b_x > 0 && mastering_meta->b_y > 0 &&
1258
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
17 mastering_meta->white_x > 0 && mastering_meta->white_y > 0;
1259
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
16 has_mastering_luminance = mastering_meta->max_luminance > 0 && mastering_meta->min_luminance > 0;
1260
1261
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (meta_video_color->matrix_coefficients != AVCOL_SPC_RESERVED)
1262 16 st->codecpar->color_space = meta_video_color->matrix_coefficients;
1263
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (meta_video_color->primaries != AVCOL_PRI_RESERVED &&
1264
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 meta_video_color->primaries != AVCOL_PRI_RESERVED0)
1265 4 st->codecpar->color_primaries = meta_video_color->primaries;
1266
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (meta_video_color->trc != AVCOL_TRC_RESERVED &&
1267
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 meta_video_color->trc != AVCOL_TRC_RESERVED0)
1268 4 st->codecpar->color_trc = meta_video_color->trc;
1269
1270
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
16 if (meta_video_color->max_cll && meta_video_color->max_fall) {
1271 1 size_t size = 0;
1272 1 AVContentLightMetadata *metadata = av_content_light_metadata_alloc(&size);
1273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!metadata)
1274 return AVERROR(ENOMEM);
1275
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!av_packet_side_data_add(&st->codecpar->coded_side_data, &st->codecpar->nb_coded_side_data,
1276 AV_PKT_DATA_CONTENT_LIGHT_LEVEL, metadata, size, 0)) {
1277 av_freep(&metadata);
1278 return AVERROR(ENOMEM);
1279 }
1280 1 metadata->MaxCLL = meta_video_color->max_cll;
1281 1 metadata->MaxFALL = meta_video_color->max_fall;
1282 }
1283
1284
3/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
16 if (has_mastering_primaries || has_mastering_luminance) {
1285 1 size_t size = 0;
1286 1 AVMasteringDisplayMetadata *metadata = av_mastering_display_metadata_alloc_size(&size);
1287 AVPacketSideData *sd;
1288
1289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!metadata)
1290 return AVERROR(ENOMEM);
1291
1292 1 sd = av_packet_side_data_add(&st->codecpar->coded_side_data,
1293 1 &st->codecpar->nb_coded_side_data,
1294 AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
1295 metadata, size, 0);
1296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!sd) {
1297 av_freep(&metadata);
1298 return AVERROR(ENOMEM);
1299 }
1300
1301 // hdrCll
1302
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (has_mastering_luminance) {
1303 1 metadata->max_luminance = av_d2q(mastering_meta->max_luminance, INT_MAX);
1304 1 metadata->min_luminance = av_d2q(mastering_meta->min_luminance, INT_MAX);
1305 1 metadata->has_luminance = 1;
1306 }
1307 // hdrMdcv
1308
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (has_mastering_primaries) {
1309 1 metadata->display_primaries[0][0] = av_d2q(mastering_meta->r_x, INT_MAX);
1310 1 metadata->display_primaries[0][1] = av_d2q(mastering_meta->r_y, INT_MAX);
1311 1 metadata->display_primaries[1][0] = av_d2q(mastering_meta->g_x, INT_MAX);
1312 1 metadata->display_primaries[1][1] = av_d2q(mastering_meta->g_y, INT_MAX);
1313 1 metadata->display_primaries[2][0] = av_d2q(mastering_meta->b_x, INT_MAX);
1314 1 metadata->display_primaries[2][1] = av_d2q(mastering_meta->b_y, INT_MAX);
1315 1 metadata->white_point[0] = av_d2q(mastering_meta->white_x, INT_MAX);
1316 1 metadata->white_point[1] = av_d2q(mastering_meta->white_y, INT_MAX);
1317 1 metadata->has_primaries = 1;
1318 }
1319 }
1320 16 return 0;
1321 }
1322
1323 static int flv_parse_mod_ex_data(AVFormatContext *s, int *pkt_type, int *size, int64_t *dts)
1324 {
1325 int ex_type, ret;
1326 uint8_t *ex_data;
1327
1328 int ex_size = (uint8_t)avio_r8(s->pb) + 1;
1329 *size -= 1;
1330
1331 if (ex_size == 256) {
1332 ex_size = (uint16_t)avio_rb16(s->pb) + 1;
1333 *size -= 2;
1334 }
1335
1336 if (ex_size >= *size) {
1337 av_log(s, AV_LOG_WARNING, "ModEx size larger than remaining data!\n");
1338 return AVERROR(EINVAL);
1339 }
1340
1341 ex_data = av_malloc(ex_size);
1342 if (!ex_data)
1343 return AVERROR(ENOMEM);
1344
1345 ret = avio_read(s->pb, ex_data, ex_size);
1346 if (ret < 0) {
1347 av_free(ex_data);
1348 return ret;
1349 }
1350 *size -= ex_size;
1351
1352 ex_type = (uint8_t)avio_r8(s->pb);
1353 *size -= 1;
1354
1355 *pkt_type = ex_type & 0x0f;
1356 ex_type &= 0xf0;
1357
1358 if (ex_type == PacketModExTypeTimestampOffsetNano) {
1359 uint32_t nano_offset;
1360
1361 if (ex_size != 3) {
1362 av_log(s, AV_LOG_WARNING, "Invalid ModEx size for Type TimestampOffsetNano!\n");
1363 nano_offset = 0;
1364 } else {
1365 nano_offset = (ex_data[0] << 16) | (ex_data[1] << 8) | ex_data[2];
1366 }
1367
1368 // this is not likely to ever add anything, but right now timestamps are with ms precision
1369 *dts += nano_offset / 1000000;
1370 } else {
1371 av_log(s, AV_LOG_INFO, "Unknown ModEx type: %d", ex_type);
1372 }
1373
1374 av_free(ex_data);
1375
1376 return 0;
1377 }
1378
1379 6362 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
1380 {
1381 6362 FLVContext *flv = s->priv_data;
1382 6362 int ret = AVERROR_BUG, i, size, flags;
1383 6362 int res = 0;
1384 enum FlvTagType type;
1385 6362 int stream_type = -1;
1386 int64_t next, pos, meta_pos;
1387 6362 int64_t dts, pts = AV_NOPTS_VALUE;
1388 6362 int av_uninit(channels);
1389 6362 int av_uninit(sample_rate);
1390 6362 AVStream *st = NULL;
1391 6362 int last = -1;
1392 int orig_size;
1393 6362 int enhanced_flv = 0;
1394 6362 int multitrack = 0;
1395 6362 int pkt_type = 0;
1396 6362 uint8_t track_idx = 0;
1397 6362 uint32_t codec_id = 0;
1398 6362 int multitrack_type = MultitrackTypeOneTrack;
1399
1400 6362 retry:
1401 /* pkt size is repeated at end. skip it */
1402 6362 pos = avio_tell(s->pb);
1403 6362 type = (avio_r8(s->pb) & 0x1F);
1404 6362 orig_size =
1405 6362 size = avio_rb24(s->pb);
1406 6362 flv->sum_flv_tag_size += size + 11LL;
1407 6362 dts = avio_rb24(s->pb);
1408 6362 dts |= (unsigned)avio_r8(s->pb) << 24;
1409 6362 av_log(s, AV_LOG_TRACE, "type:%d, size:%d, last:%d, dts:%"PRId64" pos:%"PRId64"\n", type, size, last, dts, avio_tell(s->pb));
1410
2/2
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 6284 times.
6362 if (avio_feof(s->pb))
1411 78 return AVERROR_EOF;
1412 6284 avio_skip(s->pb, 3); /* stream id, always 0 */
1413 6284 flags = 0;
1414
1415
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 6265 times.
6284 if (flv->validate_next < flv->validate_count) {
1416 19 int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1417
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 14 times.
19 if (pos == validate_pos) {
1418
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1419 VALIDATE_INDEX_TS_THRESH) {
1420 5 flv->validate_next++;
1421 } else {
1422 clear_index_entries(s, validate_pos);
1423 flv->validate_count = 0;
1424 }
1425
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 } else if (pos > validate_pos) {
1426 1 clear_index_entries(s, validate_pos);
1427 1 flv->validate_count = 0;
1428 }
1429 }
1430
1431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6284 times.
6284 if (size == 0) {
1432 ret = FFERROR_REDO;
1433 goto leave;
1434 }
1435
1436 6284 next = size + avio_tell(s->pb);
1437
1438
2/2
✓ Branch 0 taken 3267 times.
✓ Branch 1 taken 3017 times.
6284 if (type == FLV_TAG_TYPE_AUDIO) {
1439 3267 stream_type = FLV_STREAM_TYPE_AUDIO;
1440 3267 flags = avio_r8(s->pb);
1441 3267 size--;
1442
1443
2/2
✓ Branch 0 taken 663 times.
✓ Branch 1 taken 2604 times.
3267 if ((flags & FLV_AUDIO_CODECID_MASK) == FLV_CODECID_EX_HEADER) {
1444 663 enhanced_flv = 1;
1445 663 pkt_type = flags & ~FLV_AUDIO_CODECID_MASK;
1446
1447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 663 times.
663 while (pkt_type == PacketTypeModEx) {
1448 ret = flv_parse_mod_ex_data(s, &pkt_type, &size, &dts);
1449 if (ret < 0)
1450 goto leave;
1451 }
1452
1453
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 3 times.
663 if (pkt_type == AudioPacketTypeMultitrack) {
1454 660 uint8_t types = avio_r8(s->pb);
1455 660 multitrack_type = types & 0xF0;
1456 660 pkt_type = types & 0xF;
1457
1458 660 multitrack = 1;
1459 660 size--;
1460 }
1461
1462 663 codec_id = avio_rb32(s->pb);
1463 663 size -= 4;
1464
1465
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 3 times.
663 if (multitrack) {
1466 660 track_idx = avio_r8(s->pb);
1467 660 size--;
1468 }
1469 }
1470
2/2
✓ Branch 0 taken 2977 times.
✓ Branch 1 taken 40 times.
3017 } else if (type == FLV_TAG_TYPE_VIDEO) {
1471 2977 stream_type = FLV_STREAM_TYPE_VIDEO;
1472 2977 flags = avio_r8(s->pb);
1473 2977 codec_id = flags & FLV_VIDEO_CODECID_MASK;
1474 /*
1475 * Reference Enhancing FLV 2023-03-v1.0.0-B.8
1476 * https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
1477 * */
1478 2977 enhanced_flv = (flags >> 7) & 1;
1479
2/2
✓ Branch 0 taken 676 times.
✓ Branch 1 taken 2301 times.
2977 pkt_type = enhanced_flv ? codec_id : 0;
1480 2977 size--;
1481
1482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2977 times.
2977 while (pkt_type == PacketTypeModEx) {
1483 ret = flv_parse_mod_ex_data(s, &pkt_type, &size, &dts);
1484 if (ret < 0)
1485 goto leave;
1486 }
1487
1488
4/4
✓ Branch 0 taken 676 times.
✓ Branch 1 taken 2301 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 16 times.
2977 if (enhanced_flv && pkt_type != PacketTypeMetadata &&
1489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 660 times.
660 (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD)
1490 goto skip;
1491
1492
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 2527 times.
2977 if (pkt_type == PacketTypeMultitrack) {
1493 450 uint8_t types = avio_r8(s->pb);
1494 450 multitrack_type = types & 0xF0;
1495 450 pkt_type = types & 0xF;
1496
1497 450 multitrack = 1;
1498 450 size--;
1499 }
1500
1501
2/2
✓ Branch 0 taken 676 times.
✓ Branch 1 taken 2301 times.
2977 if (enhanced_flv) {
1502 676 codec_id = avio_rb32(s->pb);
1503 676 size -= 4;
1504 }
1505
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 2527 times.
2977 if (multitrack) {
1506 450 track_idx = avio_r8(s->pb);
1507 450 size--;
1508 }
1509
1510
4/4
✓ Branch 0 taken 676 times.
✓ Branch 1 taken 2301 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 660 times.
2977 if (enhanced_flv && (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD) {
1511
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (pkt_type == PacketTypeMetadata) {
1512 16 ret = flv_parse_video_color_info(s, st, next);
1513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (ret < 0)
1514 goto leave;
1515 }
1516 16 goto skip;
1517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2961 times.
2961 } else if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD) {
1518 goto skip;
1519 }
1520
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 } else if (type == FLV_TAG_TYPE_META) {
1521 40 stream_type=FLV_STREAM_TYPE_SUBTITLE;
1522
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (size > 13 + 1 + 4) { // Header-type metadata stuff
1523 int type;
1524 40 meta_pos = avio_tell(s->pb);
1525 40 type = flv_read_metabody(s, next);
1526
2/6
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
40 if (type == 0 && dts == 0 || type < 0) {
1527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
40 if (type < 0 && flv->validate_count &&
1528 flv->validate_index[0].pos > next &&
1529 flv->validate_index[0].pos - 4 < next) {
1530 av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1531 next = flv->validate_index[0].pos - 4;
1532 }
1533 40 goto skip;
1534 } else if (type == TYPE_ONTEXTDATA) {
1535 avpriv_request_sample(s, "OnTextData packet");
1536 return flv_data_packet(s, pkt, dts, next);
1537 } else if (type == TYPE_ONCAPTION) {
1538 return flv_data_packet(s, pkt, dts, next);
1539 } else if (type == TYPE_UNKNOWN) {
1540 stream_type = FLV_STREAM_TYPE_DATA;
1541 }
1542 avio_seek(s->pb, meta_pos, SEEK_SET);
1543 }
1544 } else {
1545 av_log(s, AV_LOG_DEBUG,
1546 "Skipping flv packet: type %d, size %d, flags %d.\n",
1547 type, size, flags);
1548 56 skip:
1549
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
56 if (avio_seek(s->pb, next, SEEK_SET) != next) {
1550 // This can happen if flv_read_metabody above read past
1551 // next, on a non-seekable input, and the preceding data has
1552 // been flushed out from the IO buffer.
1553 av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1554 return AVERROR_INVALIDDATA;
1555 }
1556 56 ret = FFERROR_REDO;
1557 56 goto leave;
1558 }
1559
1560 /* skip empty data packets */
1561
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6224 times.
6228 if (!size) {
1562 4 ret = FFERROR_REDO;
1563 4 goto leave;
1564 }
1565
1566 for (;;) {
1567 6224 int track_size = size;
1568
1569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6224 times.
6224 if (multitrack_type != MultitrackTypeOneTrack) {
1570 track_size = avio_rb24(s->pb);
1571 size -= 3;
1572 }
1573
1574 /* now find stream */
1575
2/2
✓ Branch 0 taken 13986 times.
✓ Branch 1 taken 70 times.
14056 for (i = 0; i < s->nb_streams; i++) {
1576 13986 st = s->streams[i];
1577
2/2
✓ Branch 0 taken 8803 times.
✓ Branch 1 taken 5183 times.
13986 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1578
2/2
✓ Branch 0 taken 4905 times.
✓ Branch 1 taken 3898 times.
8803 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1579
3/4
✓ Branch 0 taken 4905 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 3461 times.
✓ Branch 4 taken 1444 times.
4905 (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags, codec_id)) &&
1580
2/2
✓ Branch 0 taken 3239 times.
✓ Branch 1 taken 222 times.
3461 st->id == track_idx)
1581 3239 break;
1582
1/2
✓ Branch 0 taken 5183 times.
✗ Branch 1 not taken.
5183 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1583
2/2
✓ Branch 0 taken 4049 times.
✓ Branch 1 taken 1134 times.
5183 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1584
4/4
✓ Branch 0 taken 3984 times.
✓ Branch 1 taken 65 times.
✓ Branch 3 taken 2967 times.
✓ Branch 4 taken 1017 times.
4049 (s->video_codec_id || flv_same_video_codec(st->codecpar, codec_id)) &&
1585
2/2
✓ Branch 0 taken 2915 times.
✓ Branch 1 taken 117 times.
3032 st->id == track_idx)
1586 2915 break;
1587 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1588 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1589 break;
1590 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1591 if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1592 break;
1593 }
1594 }
1595
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 6154 times.
6224 if (i == s->nb_streams) {
1596 static const enum AVMediaType stream_types[] = {AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_SUBTITLE, AVMEDIA_TYPE_DATA};
1597 70 st = create_stream(s, stream_types[stream_type], track_idx);
1598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (!st)
1599 return AVERROR(ENOMEM);
1600 }
1601 6224 av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1602
1603
1/2
✓ Branch 0 taken 6224 times.
✗ Branch 1 not taken.
6224 if (flv->time_pos <= pos) {
1604 6224 dts += flv->time_offset;
1605 }
1606
1607
1/2
✓ Branch 0 taken 6224 times.
✗ Branch 1 not taken.
6224 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1608
4/4
✓ Branch 0 taken 4741 times.
✓ Branch 1 taken 1483 times.
✓ Branch 2 taken 2316 times.
✓ Branch 3 taken 2425 times.
6224 ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
1609 stream_type == FLV_STREAM_TYPE_AUDIO))
1610 3799 av_add_index_entry(st, pos, dts, track_size, 0, AVINDEX_KEYFRAME);
1611
1612
5/6
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 5936 times.
✓ Branch 2 taken 278 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 278 times.
6224 if ((st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || stream_type == FLV_STREAM_TYPE_AUDIO)) ||
1613
3/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5936 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5946 (st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && stream_type == FLV_STREAM_TYPE_VIDEO)) ||
1614
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5936 times.
5946 st->discard >= AVDISCARD_ALL) {
1615 288 avio_seek(s->pb, next, SEEK_SET);
1616 288 ret = FFERROR_REDO;
1617 288 goto leave;
1618 }
1619
1620 // if not streamed and no duration from metadata then seek to end to find
1621 // the duration from the timestamps
1622
1/2
✓ Branch 0 taken 5936 times.
✗ Branch 1 not taken.
5936 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1623
2/4
✓ Branch 0 taken 5936 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5936 times.
5936 (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1624 !flv->searched_for_end) {
1625 int final_size;
1626 const int64_t pos = avio_tell(s->pb);
1627 // Read the last 4 bytes of the file, this should be the size of the
1628 // previous FLV tag. Use the timestamp of its payload as duration.
1629 int64_t fsize = avio_size(s->pb);
1630 retry_duration:
1631 avio_seek(s->pb, fsize - 4, SEEK_SET);
1632 final_size = avio_rb32(s->pb);
1633 if (final_size > 0 && final_size < fsize) {
1634 // Seek to the start of the last FLV tag at position (fsize - 4 - final_size)
1635 // but skip the byte indicating the type.
1636 avio_seek(s->pb, fsize - 3 - final_size, SEEK_SET);
1637 if (final_size == avio_rb24(s->pb) + 11) {
1638 uint32_t ts = avio_rb24(s->pb);
1639 ts |= (unsigned)avio_r8(s->pb) << 24;
1640 if (ts)
1641 s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1642 else if (fsize >= 8 && fsize - 8 >= final_size) {
1643 fsize -= final_size+4;
1644 goto retry_duration;
1645 }
1646 }
1647 }
1648
1649 avio_seek(s->pb, pos, SEEK_SET);
1650 flv->searched_for_end = 1;
1651 }
1652
1653
4/4
✓ Branch 0 taken 3263 times.
✓ Branch 1 taken 2673 times.
✓ Branch 2 taken 2604 times.
✓ Branch 3 taken 659 times.
8540 if (stream_type == FLV_STREAM_TYPE_AUDIO && !enhanced_flv) {
1654 int bits_per_coded_sample;
1655
2/2
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 1698 times.
2604 channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
1656 2604 sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1657 FLV_AUDIO_SAMPLERATE_OFFSET) >> 3;
1658
1/2
✓ Branch 0 taken 2604 times.
✗ Branch 1 not taken.
2604 bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1659
2/2
✓ Branch 1 taken 2592 times.
✓ Branch 2 taken 12 times.
2604 if (!av_channel_layout_check(&st->codecpar->ch_layout) ||
1660
1/2
✓ Branch 0 taken 2592 times.
✗ Branch 1 not taken.
2592 !st->codecpar->sample_rate ||
1661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2592 times.
2592 !st->codecpar->bits_per_coded_sample) {
1662 12 av_channel_layout_uninit(&st->codecpar->ch_layout);
1663 12 av_channel_layout_default(&st->codecpar->ch_layout, channels);
1664 12 st->codecpar->sample_rate = sample_rate;
1665 12 st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1666 }
1667
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2592 times.
2604 if (!st->codecpar->codec_id) {
1668 12 ret = flv_set_audio_codec(s, st, st->codecpar,
1669 flags & FLV_AUDIO_CODECID_MASK);
1670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (ret < 0)
1671 goto leave;
1672 12 flv->last_sample_rate =
1673 12 sample_rate = st->codecpar->sample_rate;
1674 12 flv->last_channels =
1675 12 channels = st->codecpar->ch_layout.nb_channels;
1676 } else {
1677 2592 AVCodecParameters *par = avcodec_parameters_alloc();
1678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2592 times.
2592 if (!par) {
1679 ret = AVERROR(ENOMEM);
1680 goto leave;
1681 }
1682 2592 par->sample_rate = sample_rate;
1683 2592 par->bits_per_coded_sample = bits_per_coded_sample;
1684 2592 ret = flv_set_audio_codec(s, st, par, flags & FLV_AUDIO_CODECID_MASK);
1685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2592 times.
2592 if (ret < 0)
1686 goto leave;
1687 2592 sample_rate = par->sample_rate;
1688 2592 avcodec_parameters_free(&par);
1689 }
1690
2/2
✓ Branch 0 taken 659 times.
✓ Branch 1 taken 2673 times.
3332 } else if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1691
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 647 times.
659 if (!st->codecpar->codec_id) {
1692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 ret = flv_set_audio_codec(s, st, st->codecpar,
1693 codec_id ? codec_id : (flags & FLV_AUDIO_CODECID_MASK));
1694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (ret < 0)
1695 goto leave;
1696 }
1697
1698 // These are not signalled in the flags anymore
1699 659 channels = 0;
1700 659 sample_rate = 0;
1701
1702
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 643 times.
659 if (pkt_type == AudioPacketTypeMultichannelConfig) {
1703 16 int channel_order = avio_r8(s->pb);
1704 16 channels = avio_r8(s->pb);
1705 16 size -= 2;
1706 16 track_size -= 2;
1707
1708 16 av_channel_layout_uninit(&st->codecpar->ch_layout);
1709
1710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (channel_order == AudioChannelOrderCustom) {
1711 ret = av_channel_layout_custom_init(&st->codecpar->ch_layout, channels);
1712 if (ret < 0)
1713 return ret;
1714
1715 for (i = 0; i < channels; i++) {
1716 uint8_t id = avio_r8(s->pb);
1717 size--;
1718 track_size--;
1719
1720 if (id < 18)
1721 st->codecpar->ch_layout.u.map[i].id = id;
1722 else if (id >= 18 && id <= 23)
1723 st->codecpar->ch_layout.u.map[i].id = id - 18 + AV_CHAN_LOW_FREQUENCY_2;
1724 else if (id == 0xFE)
1725 st->codecpar->ch_layout.u.map[i].id = AV_CHAN_UNUSED;
1726 else
1727 st->codecpar->ch_layout.u.map[i].id = AV_CHAN_UNKNOWN;
1728 }
1729
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
16 } else if (channel_order == AudioChannelOrderNative) {
1730 13 uint64_t mask = avio_rb32(s->pb);
1731 13 size -= 4;
1732 13 track_size -= 4;
1733
1734 // The first 18 entries in the mask match ours, but the remaining 6 entries start at AV_CHAN_LOW_FREQUENCY_2
1735 13 mask = (mask & 0x3FFFF) | ((mask & 0xFC0000) << (AV_CHAN_LOW_FREQUENCY_2 - 18));
1736 13 ret = av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
1737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (ret < 0)
1738 return ret;
1739 } else {
1740 3 av_channel_layout_default(&st->codecpar->ch_layout, channels);
1741 }
1742
1743 16 av_log(s, AV_LOG_DEBUG, "Set channel data from MultiChannel info.\n");
1744
1745 16 goto next_track;
1746 }
1747
1/2
✓ Branch 0 taken 2673 times.
✗ Branch 1 not taken.
2673 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1748 2673 int sret = flv_set_video_codec(s, st, codec_id, 1);
1749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2673 times.
2673 if (sret < 0)
1750 return sret;
1751 2673 size -= sret;
1752 2673 track_size -= sret;
1753 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1754 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
1755 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1756 st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1757 }
1758
1759
2/2
✓ Branch 0 taken 5083 times.
✓ Branch 1 taken 837 times.
5920 if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1760
2/2
✓ Branch 0 taken 4852 times.
✓ Branch 1 taken 231 times.
5083 st->codecpar->codec_id == AV_CODEC_ID_OPUS ||
1761
2/2
✓ Branch 0 taken 4800 times.
✓ Branch 1 taken 52 times.
4852 st->codecpar->codec_id == AV_CODEC_ID_FLAC ||
1762
2/2
✓ Branch 0 taken 3823 times.
✓ Branch 1 taken 977 times.
4800 st->codecpar->codec_id == AV_CODEC_ID_H264 ||
1763
1/2
✓ Branch 0 taken 3823 times.
✗ Branch 1 not taken.
3823 st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
1764
2/2
✓ Branch 0 taken 3596 times.
✓ Branch 1 taken 227 times.
3823 st->codecpar->codec_id == AV_CODEC_ID_HEVC ||
1765
2/2
✓ Branch 0 taken 3578 times.
✓ Branch 1 taken 18 times.
3596 st->codecpar->codec_id == AV_CODEC_ID_VVC ||
1766
2/2
✓ Branch 0 taken 3402 times.
✓ Branch 1 taken 176 times.
3578 st->codecpar->codec_id == AV_CODEC_ID_AV1 ||
1767
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 3280 times.
3402 st->codecpar->codec_id == AV_CODEC_ID_VP9) {
1768 2640 int type = 0;
1769
2/2
✓ Branch 0 taken 1162 times.
✓ Branch 1 taken 1478 times.
2640 if (enhanced_flv) {
1770 1162 type = pkt_type;
1771 } else {
1772 1478 type = avio_r8(s->pb);
1773 1478 size--;
1774 1478 track_size--;
1775 }
1776
1777
2/4
✓ Branch 0 taken 2640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2640 times.
2640 if (size < 0 || track_size < 0) {
1778 ret = AVERROR_INVALIDDATA;
1779 goto leave;
1780 }
1781
1782
4/4
✓ Branch 0 taken 1162 times.
✓ Branch 1 taken 1478 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 502 times.
2640 if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO &&
1783
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 644 times.
660 flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_GOT) {
1784 16 flv_update_video_color_info(s, st); // update av packet side data
1785 16 flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
1786 }
1787
1788
1/2
✓ Branch 0 taken 2640 times.
✗ Branch 1 not taken.
2640 if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
1789
2/2
✓ Branch 0 taken 1663 times.
✓ Branch 1 taken 977 times.
2640 ((st->codecpar->codec_id == AV_CODEC_ID_H264 ||
1790
2/2
✓ Branch 0 taken 1645 times.
✓ Branch 1 taken 18 times.
1663 st->codecpar->codec_id == AV_CODEC_ID_VVC ||
1791
4/4
✓ Branch 0 taken 227 times.
✓ Branch 1 taken 1418 times.
✓ Branch 2 taken 362 times.
✓ Branch 3 taken 860 times.
2640 st->codecpar->codec_id == AV_CODEC_ID_HEVC) &&
1792
2/2
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 85 times.
362 (!enhanced_flv || type == PacketTypeCodedFrames))) {
1793
2/4
✓ Branch 0 taken 1137 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1137 times.
1137 if (size < 3 || track_size < 3) {
1794 ret = AVERROR_INVALIDDATA;
1795 goto leave;
1796 }
1797 // sign extension
1798 1137 int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1799 1137 pts = av_sat_add64(dts, cts);
1800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1137 times.
1137 if (cts < 0) { // dts might be wrong
1801 if (!flv->wrong_dts)
1802 av_log(s, AV_LOG_WARNING,
1803 "Negative cts, previous timestamps might be wrong.\n");
1804 flv->wrong_dts = 1;
1805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1137 times.
1137 } else if (FFABS(dts - pts) > 1000*60*15) {
1806 av_log(s, AV_LOG_WARNING,
1807 "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1808 dts = pts = AV_NOPTS_VALUE;
1809 }
1810 1137 size -= 3;
1811 1137 track_size -= 3;
1812 }
1813
6/6
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 2597 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
2640 if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1814
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 st->codecpar->codec_id == AV_CODEC_ID_OPUS || st->codecpar->codec_id == AV_CODEC_ID_FLAC ||
1815
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC ||
1816 st->codecpar->codec_id == AV_CODEC_ID_VVC ||
1817 st->codecpar->codec_id == AV_CODEC_ID_AV1 || st->codecpar->codec_id == AV_CODEC_ID_VP9)) {
1818 AVDictionaryEntry *t;
1819
1820
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 40 times.
43 if (st->codecpar->extradata) {
1821
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 if ((ret = flv_queue_extradata(flv, s->pb, multitrack ? track_idx : stream_type, track_size, multitrack)) < 0)
1822 return ret;
1823 3 ret = FFERROR_REDO;
1824 3 goto leave;
1825 }
1826
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
40 if ((ret = flv_get_extradata(s, st, track_size)) < 0)
1827 return ret;
1828
1829 /* Workaround for buggy Omnia A/XE encoder */
1830 40 t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1831
5/6
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
40 if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1832 st->codecpar->extradata_size = 2;
1833
1834 40 ret = FFERROR_REDO;
1835 40 goto leave;
1836 }
1837 }
1838
1839 /* skip empty or broken data packets */
1840
3/4
✓ Branch 0 taken 5867 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5867 times.
5877 if (size <= 0 || track_size < 0) {
1841 10 ret = FFERROR_REDO;
1842 10 goto leave;
1843 }
1844
1845 /* skip empty data track */
1846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5867 times.
5867 if (!track_size)
1847 goto next_track;
1848
1849 5867 ret = av_get_packet(s->pb, pkt, track_size);
1850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5867 times.
5867 if (ret < 0)
1851 return ret;
1852
1853 5867 track_size -= ret;
1854 5867 size -= ret;
1855
1856 5867 pkt->dts = dts;
1857
2/2
✓ Branch 0 taken 4748 times.
✓ Branch 1 taken 1119 times.
5867 pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1858 5867 pkt->stream_index = st->index;
1859 5867 pkt->pos = pos;
1860
4/4
✓ Branch 0 taken 4796 times.
✓ Branch 1 taken 1071 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4794 times.
5867 if (!multitrack && flv->new_extradata[stream_type]) {
1861 2 ret = av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
1862 flv->new_extradata[stream_type],
1863 2 flv->new_extradata_size[stream_type]);
1864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0)
1865 return ret;
1866
1867 2 flv->new_extradata[stream_type] = NULL;
1868 2 flv->new_extradata_size[stream_type] = 0;
1869
2/2
✓ Branch 0 taken 1071 times.
✓ Branch 1 taken 4794 times.
5865 } else if (multitrack &&
1870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1071 times.
1071 flv->mt_extradata_cnt > track_idx &&
1871 flv->mt_extradata[track_idx]) {
1872 ret = av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
1873 flv->mt_extradata[track_idx],
1874 flv->mt_extradata_sz[track_idx]);
1875 if (ret < 0)
1876 return ret;
1877
1878 flv->mt_extradata[track_idx] = NULL;
1879 flv->mt_extradata_sz[track_idx] = 0;
1880 }
1881
4/4
✓ Branch 0 taken 3231 times.
✓ Branch 1 taken 2636 times.
✓ Branch 2 taken 2598 times.
✓ Branch 3 taken 633 times.
5867 if (stream_type == FLV_STREAM_TYPE_AUDIO && !enhanced_flv &&
1882
1/2
✓ Branch 0 taken 2598 times.
✗ Branch 1 not taken.
2598 (sample_rate != flv->last_sample_rate ||
1883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2598 times.
2598 channels != flv->last_channels)) {
1884 flv->last_sample_rate = sample_rate;
1885 flv->last_channels = channels;
1886 ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
1887 }
1888
1889
2/2
✓ Branch 0 taken 2636 times.
✓ Branch 1 taken 3231 times.
5867 if (stream_type == FLV_STREAM_TYPE_AUDIO ||
1890
3/4
✓ Branch 0 taken 2147 times.
✓ Branch 1 taken 489 times.
✓ Branch 2 taken 2147 times.
✗ Branch 3 not taken.
2636 (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
1891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2147 times.
2147 stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1892 stream_type == FLV_STREAM_TYPE_DATA)
1893 3720 pkt->flags |= AV_PKT_FLAG_KEY;
1894
1895 5867 ret = ff_buffer_packet(s, pkt);
1896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5867 times.
5867 if (ret < 0)
1897 return ret;
1898 5867 res = FFERROR_REDO;
1899
1900 5883 next_track:
1901
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5882 times.
5883 if (track_size) {
1902 1 av_log(s, AV_LOG_WARNING, "Track size mismatch: %d!\n", track_size);
1903
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!avio_feof(s->pb)) {
1904 if (track_size > 0) {
1905 avio_skip(s->pb, track_size);
1906 size -= track_size;
1907 } else {
1908 /* We have somehow read more than the track had to offer, leave and re-sync */
1909 ret = FFERROR_REDO;
1910 goto leave;
1911 }
1912 }
1913 }
1914
1915
2/2
✓ Branch 0 taken 5882 times.
✓ Branch 1 taken 1 times.
5883 if (!size)
1916 5882 break;
1917
1918
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (multitrack_type == MultitrackTypeOneTrack) {
1919 1 av_log(s, AV_LOG_ERROR, "Attempted to read next track in single-track mode.\n");
1920 1 ret = FFERROR_REDO;
1921 1 goto leave;
1922 }
1923
1924 if (multitrack_type == MultitrackTypeManyTracksManyCodecs) {
1925 codec_id = avio_rb32(s->pb);
1926 size -= 4;
1927 }
1928
1929 track_idx = avio_r8(s->pb);
1930 size--;
1931
1932 if (avio_feof(s->pb)) {
1933 av_log(s, AV_LOG_WARNING, "Premature EOF\n");
1934 /* return REDO so that any potentially queued up packages can be drained first */
1935 return FFERROR_REDO;
1936 }
1937 }
1938
1939 5882 ret = 0;
1940 6284 leave:
1941 6284 last = avio_rb32(s->pb);
1942
1/2
✓ Branch 0 taken 6284 times.
✗ Branch 1 not taken.
6284 if (!flv->trust_datasize) {
1943
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6283 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
6285 if (last != orig_size + 11 && last != orig_size + 10 &&
1944
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1 !avio_feof(s->pb) &&
1945 (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1946 !flv->broken_sizes) {
1947 av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %"PRId64"\n", last, orig_size + 11, flv->sum_flv_tag_size);
1948 avio_seek(s->pb, pos + 1, SEEK_SET);
1949 ret = resync(s);
1950 av_packet_unref(pkt);
1951 if (ret >= 0) {
1952 goto retry;
1953 }
1954 }
1955 }
1956
1957
2/2
✓ Branch 0 taken 5882 times.
✓ Branch 1 taken 402 times.
6284 if (ret >= 0)
1958 5882 flv->last_ts = pkt->dts;
1959
1960
2/2
✓ Branch 0 taken 402 times.
✓ Branch 1 taken 5882 times.
6284 return ret ? ret : res;
1961 }
1962
1963 289 static int flv_read_seek(AVFormatContext *s, int stream_index,
1964 int64_t ts, int flags)
1965 {
1966 289 FLVContext *flv = s->priv_data;
1967 289 flv->validate_count = 0;
1968 289 return avio_seek_time(s->pb, stream_index, ts, flags);
1969 }
1970
1971 #define OFFSET(x) offsetof(FLVContext, x)
1972 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1973 static const AVOption options[] = {
1974 { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1975 { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1976 { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1977 { NULL }
1978 };
1979
1980 static const AVClass flv_kux_class = {
1981 .class_name = "(live) flv/kux demuxer",
1982 .item_name = av_default_item_name,
1983 .option = options,
1984 .version = LIBAVUTIL_VERSION_INT,
1985 };
1986
1987 const FFInputFormat ff_flv_demuxer = {
1988 .p.name = "flv",
1989 .p.long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1990 .p.extensions = "flv",
1991 .p.priv_class = &flv_kux_class,
1992 .priv_data_size = sizeof(FLVContext),
1993 .read_probe = flv_probe,
1994 .read_header = flv_read_header,
1995 .read_packet = flv_read_packet,
1996 .read_seek = flv_read_seek,
1997 .read_close = flv_read_close,
1998 };
1999
2000 const FFInputFormat ff_live_flv_demuxer = {
2001 .p.name = "live_flv",
2002 .p.long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
2003 .p.extensions = "flv",
2004 .p.priv_class = &flv_kux_class,
2005 .p.flags = AVFMT_TS_DISCONT,
2006 .priv_data_size = sizeof(FLVContext),
2007 .read_probe = live_flv_probe,
2008 .read_header = flv_read_header,
2009 .read_packet = flv_read_packet,
2010 .read_seek = flv_read_seek,
2011 .read_close = flv_read_close,
2012 };
2013
2014 const FFInputFormat ff_kux_demuxer = {
2015 .p.name = "kux",
2016 .p.long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
2017 .p.extensions = "kux",
2018 .p.priv_class = &flv_kux_class,
2019 .priv_data_size = sizeof(FLVContext),
2020 .read_probe = kux_probe,
2021 .read_header = flv_read_header,
2022 .read_packet = flv_read_packet,
2023 .read_seek = flv_read_seek,
2024 .read_close = flv_read_close,
2025 };
2026