diff mbox

[FFmpeg-devel] avcodec/h264_parse: no need check ref list1 for P slices.

Message ID 1548920216-28339-1-git-send-email-decai.lin@intel.com
State Accepted
Commit 9d800d39d557965d63eb671a6de50d0c6ef6d4ab
Headers show

Commit Message

Decai Lin Jan. 31, 2019, 7:36 a.m. UTC
This is robust for some corner case there is incorrect list1 count
in pps header, but it's a P slice and can be decoded well.

Signed-off-by: Decai Lin <decai.lin@intel.com>
---
 libavcodec/h264_parse.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Michael Niedermayer Jan. 31, 2019, 5:11 p.m. UTC | #1
On Thu, Jan 31, 2019 at 03:36:56PM +0800, Decai Lin wrote:
> This is robust for some corner case there is incorrect list1 count
> in pps header, but it's a P slice and can be decoded well.

please provide a sample h264 video that needs this

thanks

[...]
Decai Lin Feb. 1, 2019, 5:28 a.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> Michael Niedermayer
> Sent: 2019年2月1日 1:12
> To: FFmpeg development discussions and patches
> <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_parse: no need check ref
> list1 for P slices.
> 
> On Thu, Jan 31, 2019 at 03:36:56PM +0800, Decai Lin wrote:
> > This is robust for some corner case there is incorrect list1 count in
> > pps header, but it's a P slice and can be decoded well.
> 
> please provide a sample h264 video that needs this
> 

Attached the test clip for this patch.

Thanks
mypopy@gmail.com Feb. 1, 2019, 7:13 a.m. UTC | #3
On Fri, Feb 1, 2019 at 1:28 PM Lin, Decai <decai.lin@intel.com> wrote:
>
>
>
> > -----Original Message-----
> > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> > Michael Niedermayer
> > Sent: 2019年2月1日 1:12
> > To: FFmpeg development discussions and patches
> > <ffmpeg-devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_parse: no need check ref
> > list1 for P slices.
> >
> > On Thu, Jan 31, 2019 at 03:36:56PM +0800, Decai Lin wrote:
> > > This is robust for some corner case there is incorrect list1 count in
> > > pps header, but it's a P slice and can be decoded well.
> >
> > please provide a sample h264 video that needs this
> >
>
> Attached the test clip for this patch.
>

I think the better way is to add a new fate test case with the test
clip for h264dec, isn't it?
Decai Lin Feb. 1, 2019, 8:38 a.m. UTC | #4
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of

> mypopy@gmail.com

> Sent: 2019年2月1日 15:14

> To: FFmpeg development discussions and patches

> <ffmpeg-devel@ffmpeg.org>

> Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_parse: no need check ref

> list1 for P slices.

> 

> On Fri, Feb 1, 2019 at 1:28 PM Lin, Decai <decai.lin@intel.com> wrote:

> >

> >

> >

> > > -----Original Message-----

> > > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On

> > > Behalf Of Michael Niedermayer

> > > Sent: 2019年2月1日 1:12

> > > To: FFmpeg development discussions and patches

> > > <ffmpeg-devel@ffmpeg.org>

> > > Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_parse: no need

> > > check ref

> > > list1 for P slices.

> > >

> > > On Thu, Jan 31, 2019 at 03:36:56PM +0800, Decai Lin wrote:

> > > > This is robust for some corner case there is incorrect list1 count

> > > > in pps header, but it's a P slice and can be decoded well.

> > >

> > > please provide a sample h264 video that needs this

> > >

> >

> > Attached the test clip for this patch.

> >

> 

> I think the better way is to add a new fate test case with the test clip for

> h264dec, isn't it?


Yes, I can file another patch for the related fate test case.

Thanks
Michael Niedermayer Feb. 8, 2019, 12:21 a.m. UTC | #5
On Fri, Feb 01, 2019 at 08:38:12AM +0000, Lin, Decai wrote:
> 
> 
> > -----Original Message-----
> > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> > mypopy@gmail.com
> > Sent: 2019年2月1日 15:14
> > To: FFmpeg development discussions and patches
> > <ffmpeg-devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_parse: no need check ref
> > list1 for P slices.
> > 
> > On Fri, Feb 1, 2019 at 1:28 PM Lin, Decai <decai.lin@intel.com> wrote:
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On
> > > > Behalf Of Michael Niedermayer
> > > > Sent: 2019年2月1日 1:12
> > > > To: FFmpeg development discussions and patches
> > > > <ffmpeg-devel@ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] [PATCH] avcodec/h264_parse: no need
> > > > check ref
> > > > list1 for P slices.
> > > >
> > > > On Thu, Jan 31, 2019 at 03:36:56PM +0800, Decai Lin wrote:
> > > > > This is robust for some corner case there is incorrect list1 count
> > > > > in pps header, but it's a P slice and can be decoded well.
> > > >
> > > > please provide a sample h264 video that needs this
> > > >
> > >
> > > Attached the test clip for this patch.
> > >
> > 
> > I think the better way is to add a new fate test case with the test clip for
> > h264dec, isn't it?
> 
> Yes, I can file another patch for the related fate test case.

fate tests covering previously uncovered cases is always a good idea

thx


[...]
Michael Niedermayer Feb. 8, 2019, 10:49 a.m. UTC | #6
On Thu, Jan 31, 2019 at 03:36:56PM +0800, Decai Lin wrote:
> This is robust for some corner case there is incorrect list1 count
> in pps header, but it's a P slice and can be decoded well.
> 
> Signed-off-by: Decai Lin <decai.lin@intel.com>
> ---
>  libavcodec/h264_parse.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)

will apply with a minor change clearing the contraditionary value

thanks

[...]
diff mbox

Patch

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 290ab68..a42cc29 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -242,7 +242,12 @@  int ff_h264_parse_ref_count(int *plist_count, int ref_count[2],
                 ref_count[1] = 1;
         }
 
-        if (ref_count[0] - 1 > max[0] || ref_count[1] - 1 > max[1]) {
+        if (slice_type_nos == AV_PICTURE_TYPE_B)
+            list_count = 2;
+        else
+            list_count = 1;
+
+        if (ref_count[0] - 1 > max[0] || (list_count == 2 && (ref_count[1] - 1 > max[1]))) {
             av_log(logctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n",
                    ref_count[0] - 1, max[0], ref_count[1] - 1, max[1]);
             ref_count[0] = ref_count[1] = 0;
@@ -250,10 +255,6 @@  int ff_h264_parse_ref_count(int *plist_count, int ref_count[2],
             goto fail;
         }
 
-        if (slice_type_nos == AV_PICTURE_TYPE_B)
-            list_count = 2;
-        else
-            list_count = 1;
     } else {
         list_count   = 0;
         ref_count[0] = ref_count[1] = 0;