| @@ -162,6 +162,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc) · 161 unmodified lines |
| 162 | 162 | return AVERROR(ENOMEM); |
| 163 | 163 | |
| 164 | 164 | s->cur_frame = ref; |
| 165 | + l->cur_frame = ref; |
| 165 | 166 | s->collocated_ref = NULL; |
| 166 | 167 | |
| 167 | 168 | if (s->sh.pic_output_flag) |
| @@ -261,7 +262,9 @@ int ff_hevc_slice_rpl(HEVCContext *s) · 93 unmodified lines |
| 261 | 262 | return ret; |
| 262 | 263 | |
| 263 | 264 | if (!(s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs + |
| 264 | | − s->rps[LT_CURR].nb_refs) && !s->pps->pps_curr_pic_ref_enabled_flag) { |
| 265 | + s->rps[LT_CURR].nb_refs + |
| 266 | + s->rps[INTER_LAYER0].nb_refs + s->rps[INTER_LAYER1].nb_refs) && |
| 267 | + !s->pps->pps_curr_pic_ref_enabled_flag) { |
| 265 | 268 | av_log(s->avctx, AV_LOG_ERROR, "Zero refs in the frame RPS.\n"); |
| 266 | 269 | return AVERROR_INVALIDDATA; |
| 267 | 270 | } |
| @@ -271,11 +274,14 @@ int ff_hevc_slice_rpl(HEVCContext *s) · 3 unmodified lines |
| 271 | 274 | RefPicList *rpl = &s->cur_frame->refPicList[list_idx]; |
| 272 | 275 | |
| 273 | 276 | /* The order of the elements is |
| 274 | | − * ST_CURR_BEF - ST_CURR_AFT - LT_CURR for the L0 and |
| 275 | | − * ST_CURR_AFT - ST_CURR_BEF - LT_CURR for the L1 */ |
| 276 | | − int cand_lists[3] = { list_idx ? ST_CURR_AFT : ST_CURR_BEF, |
| 277 | | − list_idx ? ST_CURR_BEF : ST_CURR_AFT, |
| 278 | | − LT_CURR }; |
| 277 | + * ST_CURR_BEF - INTER_LAYER0 - ST_CURR_AFT - LT_CURR - INTER_LAYER1 for the L0 and |
| 278 | + * ST_CURR_AFT - INTER_LAYER1 - ST_CURR_BEF - LT_CURR - INTER_LAYER0 for the L1 */ |
| 279 | + int cand_lists[] = { list_idx ? ST_CURR_AFT : ST_CURR_BEF, |
| 280 | + list_idx ? INTER_LAYER1 : INTER_LAYER0, |
| 281 | + list_idx ? ST_CURR_BEF : ST_CURR_AFT, |
| 282 | + LT_CURR, |
| 283 | + list_idx ? INTER_LAYER0 : INTER_LAYER1 |
| 284 | + }; |
| 279 | 285 | |
| 280 | 286 | /* concatenate the candidate lists for the current frame */ |
| 281 | 287 | while (rpl_tmp.nb_refs < sh->nb_refs[list_idx]) { |
| @@ -284,7 +290,11 @@ int ff_hevc_slice_rpl(HEVCContext *s) · 2 unmodified lines |
| 284 | 290 | for (j = 0; j < rps->nb_refs && rpl_tmp.nb_refs < HEVC_MAX_REFS; j++) { |
| 285 | 291 | rpl_tmp.list[rpl_tmp.nb_refs] = rps->list[j]; |
| 286 | 292 | rpl_tmp.ref[rpl_tmp.nb_refs] = rps->ref[j]; |
| 287 | | − rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = i == 2; |
| 293 | + // multiview inter-layer refs are treated as long-term here, |
| 294 | + // cf. G.8.1.3 |
| 295 | + rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = cand_lists[i] == LT_CURR || |
| 296 | + cand_lists[i] == INTER_LAYER0 || |
| 297 | + cand_lists[i] == INTER_LAYER1; |
| 288 | 298 | rpl_tmp.nb_refs++; |
| 289 | 299 | } |
| 290 | 300 | } |
| @@ -423,11 +433,6 @@ int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l) · 132 unmodified lines |
| 423 | 433 | RefPicList *rps = s->rps; |
| 424 | 434 | int i, ret = 0; |
| 425 | 435 | |
| 426 | | − if (!short_rps) { |
| 427 | | − rps[0].nb_refs = rps[1].nb_refs = 0; |
| 428 | | − return 0; |
| 429 | | − } |
| 430 | | − |
| 431 | 436 | unref_missing_refs(l); |
| 432 | 437 | |
| 433 | 438 | /* clear the reference flags on all frames except the current one */ |
| @@ -443,6 +448,9 @@ int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l) · 9 unmodified lines |
| 443 | 448 | for (i = 0; i < NB_RPS_TYPE; i++) |
| 444 | 449 | rps[i].nb_refs = 0; |
| 445 | 450 | |
| 451 | + if (!short_rps) |
| 452 | + goto inter_layer; |
| 453 | + |
| 446 | 454 | /* add the short refs */ |
| 447 | 455 | for (i = 0; i < short_rps->num_delta_pocs; i++) { |
| 448 | 456 | int poc = s->poc + short_rps->delta_poc[i]; |
| @@ -472,6 +480,24 @@ int ff_hevc_frame_rps(HEVCContext *s, HEVCLayerContext *l) · 23 unmodified lines |
| 472 | 480 | goto fail; |
| 473 | 481 | } |
| 474 | 482 | |
| 483 | +inter_layer: |
| 484 | + /* add inter-layer refs */ |
| 485 | + if (s->sh.inter_layer_pred) { |
| 486 | + HEVCLayerContext *l0 = &s->layers[0]; |
| 487 | + |
| 488 | + av_assert0(l != l0); |
| 489 | + |
| 490 | + /* Given the assumption of at most two layers, refPicSet0Flag is |
| 491 | + * always 1, so only RefPicSetInterLayer0 can ever contain a frame. */ |
| 492 | + if (l0->cur_frame) { |
| 493 | + // inter-layer refs are treated as short-term here, cf. F.8.1.6 |
| 494 | + ret = add_candidate_ref(s, l0, &rps[INTER_LAYER0], l0->cur_frame->poc, |
| 495 | + HEVC_FRAME_FLAG_SHORT_REF, 1); |
| 496 | + if (ret < 0) |
| 497 | + goto fail; |
| 498 | + } |
| 499 | + } |
| 500 | + |
| 475 | 501 | fail: |
| 476 | 502 | /* release any frames that are now unused */ |
| 477 | 503 | for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) |
| @@ -480,7 +506,8 @@ fail: · 2 unmodified lines |
| 480 | 506 | return ret; |
| 481 | 507 | } |
| 482 | 508 | |
| 483 | | −int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps) |
| 509 | +int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps, |
| 510 | + unsigned layer_idx) |
| 484 | 511 | { |
| 485 | 512 | int ret = 0; |
| 486 | 513 | int i; |
| @@ -499,6 +526,11 @@ int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps) · 12 unmodified lines |
| 499 | 526 | ret += !!long_rps->used[i]; |
| 500 | 527 | } |
| 501 | 528 | |
| 529 | + if (sh->inter_layer_pred) { |
| 530 | + av_assert0(pps->sps->vps->num_direct_ref_layers[layer_idx] < 2); |
| 531 | + ret++; |
| 532 | + } |
| 533 | + |
| 502 | 534 | if (pps->pps_curr_pic_ref_enabled_flag) |
| 503 | 535 | ret++; |
| 504 | 536 | |