Showing the changes to libavformat (1 of 1 file). Show all
Unified · Split
| @@ -10301,6 +10301,56 @@ static AVStream *mov_find_reference_track(AVFormatContext *s, AVStream *st, · 10300 unmodified lines | ||
| 10301 | 10301 | return NULL; |
| 10302 | 10302 | } |
| 10303 | 10303 | |
| 10304 | +static int mov_parse_lcevc_streams(AVFormatContext *s) | |
| 10305 | +{ | |
| 10306 | + int err; | |
| 10307 | + | |
| 10308 | + for (int i = 0; i < s->nb_streams; i++) { | |
| 10309 | + AVStreamGroup *stg; | |
| 10310 | + AVStream *st = s->streams[i]; | |
| 10311 | + AVStream *st_base; | |
| 10312 | + MOVStreamContext *sc = st->priv_data; | |
| 10313 | + int j = 0; | |
| 10314 | + | |
| 10315 | + /* Find an enhancement stream. */ | |
| 10316 | + if (st->codecpar->codec_id != AV_CODEC_ID_LCEVC || | |
| 10317 | + !(sc->tref_flags & MOV_TREF_FLAG_ENHANCEMENT)) | |
| 10318 | + continue; | |
| 10319 | + | |
| 10320 | + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; | |
| 10321 | + | |
| 10322 | + stg = avformat_stream_group_create(s, AV_STREAM_GROUP_PARAMS_LCEVC, NULL); | |
| 10323 | + if (!stg) | |
| 10324 | + return AVERROR(ENOMEM); | |
| 10325 | + | |
| 10326 | + stg->id = st->id; | |
| 10327 | + stg->params.lcevc->width = st->codecpar->width; | |
| 10328 | + stg->params.lcevc->height = st->codecpar->height; | |
| 10329 | + st->codecpar->width = 0; | |
| 10330 | + st->codecpar->height = 0; | |
| 10331 | + | |
| 10332 | + while (st_base = mov_find_reference_track(s, st, j)) { | |
| 10333 | + err = avformat_stream_group_add_stream(stg, st_base); | |
| 10334 | + if (err < 0) | |
| 10335 | + return err; | |
| 10336 | + | |
| 10337 | + j = st_base->index + 1; | |
| 10338 | + } | |
| 10339 | + if (!j) { | |
| 10340 | + av_log(s, AV_LOG_ERROR, "Failed to find base stream for enhancement stream\n"); | |
| 10341 | + return AVERROR_INVALIDDATA; | |
| 10342 | + } | |
| 10343 | + | |
| 10344 | + err = avformat_stream_group_add_stream(stg, st); | |
| 10345 | + if (err < 0) | |
| 10346 | + return err; | |
| 10347 | + | |
| 10348 | + stg->params.lcevc->lcevc_index = stg->nb_streams - 1; | |
| 10349 | + } | |
| 10350 | + | |
| 10351 | + return 0; | |
| 10352 | +} | |
| 10353 | + | |
| 10304 | 10354 | static int mov_read_header(AVFormatContext *s) |
| 10305 | 10355 | { |
| 10306 | 10356 | MOVContext *mov = s->priv_data; |
| @@ -10387,48 +10437,9 @@ static int mov_read_header(AVFormatContext *s) · 80 unmodified lines | ||
| 10387 | 10437 | export_orphan_timecode(s); |
| 10388 | 10438 | |
| 10389 | 10439 | /* Create LCEVC stream groups. */ |
| 10390 | − for (i = 0; i < s->nb_streams; i++) { | |
| 10391 | − AVStreamGroup *stg; | |
| 10392 | − AVStream *st = s->streams[i]; | |
| 10393 | − AVStream *st_base; | |
| 10394 | − MOVStreamContext *sc = st->priv_data; | |
| 10395 | − | |
| 10396 | − /* Find an enhancement stream. */ | |
| 10397 | − if (st->codecpar->codec_id != AV_CODEC_ID_LCEVC || | |
| 10398 | − !(sc->tref_flags & MOV_TREF_FLAG_ENHANCEMENT)) | |
| 10399 | − continue; | |
| 10400 | − | |
| 10401 | − st->codecpar->codec_type = AVMEDIA_TYPE_DATA; | |
| 10402 | − | |
| 10403 | − stg = avformat_stream_group_create(s, AV_STREAM_GROUP_PARAMS_LCEVC, NULL); | |
| 10404 | − if (!stg) | |
| 10405 | − return AVERROR(ENOMEM); | |
| 10406 | − | |
| 10407 | − stg->id = st->id; | |
| 10408 | − stg->params.lcevc->width = st->codecpar->width; | |
| 10409 | − stg->params.lcevc->height = st->codecpar->height; | |
| 10410 | − st->codecpar->width = 0; | |
| 10411 | − st->codecpar->height = 0; | |
| 10412 | − | |
| 10413 | − j = 0; | |
| 10414 | − while (st_base = mov_find_reference_track(s, st, j)) { | |
| 10415 | − err = avformat_stream_group_add_stream(stg, st_base); | |
| 10416 | − if (err < 0) | |
| 10417 | − return err; | |
| 10418 | − | |
| 10419 | − j = st_base->index + 1; | |
| 10420 | − } | |
| 10421 | − if (!j) { | |
| 10422 | − av_log(s, AV_LOG_ERROR, "Failed to find base stream for enhancement stream\n"); | |
| 10423 | − return AVERROR_INVALIDDATA; | |
| 10424 | − } | |
| 10425 | − | |
| 10426 | − err = avformat_stream_group_add_stream(stg, st); | |
| 10427 | − if (err < 0) | |
| 10428 | − return err; | |
| 10429 | − | |
| 10430 | − stg->params.lcevc->lcevc_index = stg->nb_streams - 1; | |
| 10431 | − } | |
| 10440 | + err = mov_parse_lcevc_streams(s); | |
| 10441 | + if (err < 0) | |
| 10442 | + return err; | |
| 10432 | 10443 | |
| 10433 | 10444 | for (i = 0; i < s->nb_streams; i++) { |
| 10434 | 10445 | AVStream *st = s->streams[i]; |