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