[FFmpeg-devel] [PATCH v2 2/4] lavc/hevcdec: do not let missing ref frames invovled in dpb process

Wang, Fei W fei.w.wang at intel.com
Fri Jul 15 08:08:58 EEST 2022


On Thu, 2022-07-14 at 03:56 +0000, Xiang, Haihao wrote:
> On Tue, 2022-06-14 at 09:23 +0800, Fei Wang wrote:
> > From: Xu Guangxin <guangxin.xu at intel.com>
> > 
> > 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 at intel.com>
> > Signed-off-by: Xu Guangxin <guangxin.xu at intel.com>
> > ---
> >  libavcodec/hevc_refs.c | 14 +++++++++++++-
> >  libavcodec/hevcdec.c   |  4 ++--
> >  libavcodec/hevcdec.h   |  3 +++
> >  3 files changed, 18 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> > index 3f8fe1ef18..89053fd1a2 100644
> > --- a/libavcodec/hevc_refs.c
> > +++ b/libavcodec/hevc_refs.c
> > @@ -172,6 +172,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_DECODE_SEQUENCE_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) {
> > @@ -418,7 +428,7 @@ static HEVCFrame
> > *generate_missing_ref(HEVCContext *s, int
> > poc)
> >      }
> >  
> >      frame->poc      = poc;
> > -    frame->sequence = s->seq_decode;
> > +    frame->sequence = HEVC_DECODE_SEQUENCE_INVALID;
> >      frame->flags    = 0;
> >  
> >      if (s->threads_type == FF_THREAD_FRAME)
> > @@ -462,6 +472,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];
> > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
> > index f782ea6394..99785aa5d1 100644
> > --- a/libavcodec/hevcdec.c
> > +++ b/libavcodec/hevcdec.c
> > @@ -569,7 +569,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_DECODE_SEQUENCE_MASK;
> >          s->max_ra     = INT_MAX;
> >          if (IS_IDR(s))
> >              ff_hevc_clear_refs(s);
> > @@ -614,7 +614,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_DECODE_SEQUENCE_MASK;
> 
> I see 0xff is used in other places, could you replace it with
> HEVC_DECODE_SEQUENCE_MASK too ?

Fixed in V3. Thanks

Fei

> 
> Thanks
> Haihao
> 
> 
> >          s->max_ra     = INT_MAX;
> >      }
> >  
> > diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
> > index de861b88b3..9c8bcefb48 100644
> > --- a/libavcodec/hevcdec.h
> > +++ b/libavcodec/hevcdec.h
> > @@ -390,6 +390,9 @@ typedef struct DBParams {
> >  #define HEVC_FRAME_FLAG_LONG_REF  (1 << 2)
> >  #define HEVC_FRAME_FLAG_BUMPING   (1 << 3)
> >  
> > +#define HEVC_DECODE_SEQUENCE_MASK 0xff
> > +#define HEVC_DECODE_SEQUENCE_INVALID (HEVC_DECODE_SEQUENCE_MASK +
> > 1)
> > +
> >  typedef struct HEVCFrame {
> >      AVFrame *frame;
> >      AVFrame *frame_grain;


More information about the ffmpeg-devel mailing list