Message ID | 20220607070830.2654218-2-fei.w.wang@intel.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v1,1/4] lavc/hevc_refs: fix dpb logical for IRAP | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
On Tue, Jun 07, 2022 at 03:08:28PM +0800, Fei Wang wrote: > From: Xu Guangxin <guangxin.xu@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@intel.com> > Signed-off-by: Xu Guangxin <guangxin.xu@intel.com> > --- > libavcodec/hevc_refs.c | 13 ++++++++++++- > libavcodec/hevcdec.c | 4 ++-- > libavcodec/hevcdec.h | 3 +++ > 3 files changed, 17 insertions(+), 3 deletions(-) This causes segfaults Thread 9 "ffmpeg_g" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffcc5ad700 (LWP 14108)] 0x00005555564b88c0 in ff_emu_edge_vfix19_sse () (gdb) bt #0 0x00005555564b88c0 in ff_emu_edge_vfix19_sse () #1 0x00005555561c515c in emulated_edge_mc_avx2 () #2 0x0000555555d21bc8 in hls_prediction_unit.isra () #3 0x0000555555d2420b in hls_coding_quadtree () #4 0x0000555555d2338d in hls_coding_quadtree () #5 0x0000555555d25371 in hls_decode_entry () #6 0x0000555555bd77e5 in avcodec_default_execute () #7 0x0000555555d2a00f in hevc_decode_frame () #8 0x0000555555edc5a3 in frame_worker_thread () #9 0x00007ffff75fc6db in start_thread (arg=0x7fffcc5ad700) at pthread_create.c:463 #10 0x00007fffed17061f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 [...]
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of > Michael Niedermayer > Sent: Tuesday, June 7, 2022 8:07 PM > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH v1 2/4] lavc/hevcdec: do not let missing ref > frames invovled in dpb process > > On Tue, Jun 07, 2022 at 03:08:28PM +0800, Fei Wang wrote: > > From: Xu Guangxin <guangxin.xu@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@intel.com> > > Signed-off-by: Xu Guangxin <guangxin.xu@intel.com> > > --- > > libavcodec/hevc_refs.c | 13 ++++++++++++- > > libavcodec/hevcdec.c | 4 ++-- > > libavcodec/hevcdec.h | 3 +++ > > 3 files changed, 17 insertions(+), 3 deletions(-) > > This causes segfaults Thanks Michael, could you share your clip to me? I can't reproduce this with all my clips. Thanks Fei > > Thread 9 "ffmpeg_g" received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0x7fffcc5ad700 (LWP 14108)] > 0x00005555564b88c0 in ff_emu_edge_vfix19_sse () > (gdb) bt > #0 0x00005555564b88c0 in ff_emu_edge_vfix19_sse () > #1 0x00005555561c515c in emulated_edge_mc_avx2 () > #2 0x0000555555d21bc8 in hls_prediction_unit.isra () > #3 0x0000555555d2420b in hls_coding_quadtree () > #4 0x0000555555d2338d in hls_coding_quadtree () > #5 0x0000555555d25371 in hls_decode_entry () > #6 0x0000555555bd77e5 in avcodec_default_execute () > #7 0x0000555555d2a00f in hevc_decode_frame () > #8 0x0000555555edc5a3 in frame_worker_thread () > #9 0x00007ffff75fc6db in start_thread (arg=0x7fffcc5ad700) at > pthread_create.c:463 > #10 0x00007fffed17061f in clone () > at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > I do not agree with what you have to say, but I'll defend to the death your right > to say it. -- Voltaire
On Thu, Jun 09, 2022 at 05:34:47AM +0000, Wang, Fei W wrote: > > -----Original Message----- > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of > > Michael Niedermayer > > Sent: Tuesday, June 7, 2022 8:07 PM > > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> > > Subject: Re: [FFmpeg-devel] [PATCH v1 2/4] lavc/hevcdec: do not let missing ref > > frames invovled in dpb process > > > > On Tue, Jun 07, 2022 at 03:08:28PM +0800, Fei Wang wrote: > > > From: Xu Guangxin <guangxin.xu@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@intel.com> > > > Signed-off-by: Xu Guangxin <guangxin.xu@intel.com> > > > --- > > > libavcodec/hevc_refs.c | 13 ++++++++++++- > > > libavcodec/hevcdec.c | 4 ++-- > > > libavcodec/hevcdec.h | 3 +++ > > > 3 files changed, 17 insertions(+), 3 deletions(-) > > > > This causes segfaults > > Thanks Michael, could you share your clip to me? I can't reproduce this with all my clips. file sent by private mail thx [...]
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of > Michael Niedermayer > Sent: Thursday, June 9, 2022 10:05 PM > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> > Subject: Re: [FFmpeg-devel] [PATCH v1 2/4] lavc/hevcdec: do not let missing ref > frames invovled in dpb process > > On Thu, Jun 09, 2022 at 05:34:47AM +0000, Wang, Fei W wrote: > > > -----Original Message----- > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of > > > Michael Niedermayer > > > Sent: Tuesday, June 7, 2022 8:07 PM > > > To: FFmpeg development discussions and patches > > > <ffmpeg-devel@ffmpeg.org> > > > Subject: Re: [FFmpeg-devel] [PATCH v1 2/4] lavc/hevcdec: do not let > > > missing ref frames invovled in dpb process > > > > > > On Tue, Jun 07, 2022 at 03:08:28PM +0800, Fei Wang wrote: > > > > From: Xu Guangxin <guangxin.xu@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@intel.com> > > > > Signed-off-by: Xu Guangxin <guangxin.xu@intel.com> > > > > --- > > > > libavcodec/hevc_refs.c | 13 ++++++++++++- > > > > libavcodec/hevcdec.c | 4 ++-- > > > > libavcodec/hevcdec.h | 3 +++ > > > > 3 files changed, 17 insertions(+), 3 deletions(-) > > > > > > This causes segfaults > > > > Thanks Michael, could you share your clip to me? I can't reproduce this with all > my clips. > > file sent by private mail Fixed in V2. Thanks Fei > > thx > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > The smallest minority on earth is the individual. Those who deny individual rights > cannot claim to be defenders of minorities. - Ayn Rand
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index 3f8fe1ef18..3ea2fb6c0b 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -172,8 +172,19 @@ 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) { + unref_missing_refs(s); if (IS_IRAP(s) && s->no_rasl_output_flag == 1) { const static int mask = HEVC_FRAME_FLAG_BUMPING | HEVC_FRAME_FLAG_OUTPUT; for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { @@ -418,7 +429,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) 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; 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;