diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index 7870a72fd6..73aa6d8caf 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -358,24 +358,26 @@ int ff_hevc_slice_rpl(HEVCContext *s) return 0; } -static HEVCFrame *find_ref_idx(HEVCContext *s, int poc) +static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb) { int i; - int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1; - for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - HEVCFrame *ref = &s->DPB[i]; - if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) { - if ((ref->poc & LtMask) == poc) - return ref; + if (use_msb) { + for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { + HEVCFrame *ref = &s->DPB[i]; + if (ref->frame->buf[0] && (ref->sequence == s->seq_decode)) { + if (ref->poc == poc) + return ref; + } } - } - - for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - HEVCFrame *ref = &s->DPB[i]; - if (ref->frame->buf[0] && ref->sequence == s->seq_decode) { - if (ref->poc == poc || (ref->poc & LtMask) == poc) - return ref; + } else { + int LtMask = (1 << s->ps.sps->log2_max_poc_lsb) - 1; + for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { + HEVCFrame *ref = &s->DPB[i]; + if (ref->frame->buf[0] && ref->sequence == s->seq_decode) { + if ((ref->poc & LtMask) == poc) + return ref; + } } } @@ -427,9 +429,9 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) /* add a reference with the given poc to the list and mark it as used in DPB */ static int add_candidate_ref(HEVCContext *s, RefPicList *list, - int poc, int ref_flag) + int poc, int ref_flag, uint8_t use_msb) { - HEVCFrame *ref = find_ref_idx(s, poc); + HEVCFrame *ref = find_ref_idx(s, poc, use_msb); if (ref == s->ref || list->nb_refs >= HEVC_MAX_REFS) return AVERROR_INVALIDDATA; @@ -485,7 +487,7 @@ int ff_hevc_frame_rps(HEVCContext *s) else list = ST_CURR_AFT; - ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF); + ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1); if (ret < 0) goto fail; } @@ -495,7 +497,7 @@ int ff_hevc_frame_rps(HEVCContext *s) int poc = long_rps->poc[i]; int list = long_rps->used[i] ? LT_CURR : LT_FOLL; - ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF); + ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i]); if (ret < 0) goto fail; }