You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
lavc/hevcdec: do not let missing ref frames invovled in dpb process
We will generate a new frame for a missed reference. The frame can only be used for reference. We assign an invalid decode sequence to it, so it will not be involved in any dpb process. Tested-by: Fei Wang <fei.w.wang@intel.com> Signed-off-by: Fei Wang <fei.w.wang@intel.com> Signed-off-by: Xu Guangxin <guangxin.xu@intel.com>
This commit is contained in:
committed by
Haihao Xiang
parent
6c12fe0dda
commit
99501b5015
@@ -173,6 +173,16 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void unref_missing_refs(HEVCContext *s)
|
||||
{
|
||||
for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
|
||||
HEVCFrame *frame = &s->DPB[i];
|
||||
if (frame->sequence == HEVC_SEQUENCE_COUNTER_INVALID) {
|
||||
ff_hevc_unref_frame(s, frame, ~0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
|
||||
{
|
||||
if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
|
||||
@@ -233,7 +243,7 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
|
||||
}
|
||||
|
||||
if (s->seq_output != s->seq_decode)
|
||||
s->seq_output = (s->seq_output + 1) & 0xff;
|
||||
s->seq_output = (s->seq_output + 1) & HEVC_SEQUENCE_COUNTER_MASK;
|
||||
else
|
||||
break;
|
||||
} while (1);
|
||||
@@ -419,7 +429,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
|
||||
}
|
||||
|
||||
frame->poc = poc;
|
||||
frame->sequence = s->seq_decode;
|
||||
frame->sequence = HEVC_SEQUENCE_COUNTER_INVALID;
|
||||
frame->flags = 0;
|
||||
|
||||
if (s->threads_type == FF_THREAD_FRAME)
|
||||
@@ -463,6 +473,8 @@ int ff_hevc_frame_rps(HEVCContext *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unref_missing_refs(s);
|
||||
|
||||
/* clear the reference flags on all frames except the current one */
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
|
||||
HEVCFrame *frame = &s->DPB[i];
|
||||
|
@@ -570,7 +570,7 @@ static int hls_slice_header(HEVCContext *s)
|
||||
}
|
||||
|
||||
if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
|
||||
s->seq_decode = (s->seq_decode + 1) & 0xff;
|
||||
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
|
||||
s->max_ra = INT_MAX;
|
||||
if (IS_IDR(s))
|
||||
ff_hevc_clear_refs(s);
|
||||
@@ -615,7 +615,7 @@ static int hls_slice_header(HEVCContext *s)
|
||||
return pix_fmt;
|
||||
s->avctx->pix_fmt = pix_fmt;
|
||||
|
||||
s->seq_decode = (s->seq_decode + 1) & 0xff;
|
||||
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
|
||||
s->max_ra = INT_MAX;
|
||||
}
|
||||
|
||||
@@ -3254,7 +3254,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
|
||||
break;
|
||||
case HEVC_NAL_EOS_NUT:
|
||||
case HEVC_NAL_EOB_NUT:
|
||||
s->seq_decode = (s->seq_decode + 1) & 0xff;
|
||||
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
|
||||
s->max_ra = INT_MAX;
|
||||
break;
|
||||
case HEVC_NAL_AUD:
|
||||
@@ -3718,7 +3718,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
|
||||
s->threads_type = s0->threads_type;
|
||||
|
||||
if (s0->eos) {
|
||||
s->seq_decode = (s->seq_decode + 1) & 0xff;
|
||||
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
|
||||
s->max_ra = INT_MAX;
|
||||
}
|
||||
|
||||
|
@@ -395,6 +395,9 @@ typedef struct DBParams {
|
||||
#define HEVC_FRAME_FLAG_LONG_REF (1 << 2)
|
||||
#define HEVC_FRAME_FLAG_BUMPING (1 << 3)
|
||||
|
||||
#define HEVC_SEQUENCE_COUNTER_MASK 0xff
|
||||
#define HEVC_SEQUENCE_COUNTER_INVALID (HEVC_SEQUENCE_COUNTER_MASK + 1)
|
||||
|
||||
typedef struct HEVCFrame {
|
||||
AVFrame *frame;
|
||||
AVFrame *frame_grain;
|
||||
|
Reference in New Issue
Block a user