diff mbox

[FFmpeg-devel,v2] avcodec/h264_parse: retry decoding SPS with complete NAL

Message ID 20190820022436.6773-1-junli1026@gmail.com
State Superseded
Headers show

Commit Message

Jun Li Aug. 20, 2019, 2:24 a.m. UTC
Fix #6591
The content has no rbsp_stop_one_bit for ending the SPS, that
causes the decoding SPS failure, results decoding frame failure as well.

The patch is just adding a retry with complete NALU, copied from the retry in decode_nal_unit()
---
 libavcodec/h264_parse.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Jun Li Aug. 21, 2019, 12:52 a.m. UTC | #1
On Mon, Aug 19, 2019 at 7:24 PM Jun Li <junli1026@gmail.com> wrote:

> Fix #6591
> The content has no rbsp_stop_one_bit for ending the SPS, that
> causes the decoding SPS failure, results decoding frame failure as well.
>
> The patch is just adding a retry with complete NALU, copied from the retry
> in decode_nal_unit()
> ---
>  libavcodec/h264_parse.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
> index ac31f54e07..ea7a958dd9 100644
> --- a/libavcodec/h264_parse.c
> +++ b/libavcodec/h264_parse.c
> @@ -376,8 +376,15 @@ static int decode_extradata_ps(const uint8_t *data,
> int size, H264ParamSets *ps,
>          switch (nal->type) {
>          case H264_NAL_SPS:
>              ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps,
> 0);
> -            if (ret < 0)
> -                goto fail;
> +            if (ret < 0) {
> +                GetBitContext tmp_gb = nal->gb;
> +                av_log(logctx, AV_LOG_DEBUG,
> +                   "SPS decoding failure, trying again with the complete
> NAL\n");
> +                init_get_bits8(&tmp_gb, nal->raw_data + 1, nal->raw_size
> - 1);
> +                if ((ret = ff_h264_decode_seq_parameter_set(&tmp_gb,
> logctx, ps, 0)) < 0 &&
> +                    (ret = ff_h264_decode_seq_parameter_set(&tmp_gb,
> logctx, ps, 1)) < 0)
> +                    goto fail;
> +            }
>              break;
>          case H264_NAL_PPS:
>              ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx,
> ps,
> --
> 2.17.1
>
>
Ping
Jun Li Aug. 22, 2019, 6:14 p.m. UTC | #2
On Tue, Aug 20, 2019 at 5:52 PM Jun Li <junli1026@gmail.com> wrote:

>
>
> On Mon, Aug 19, 2019 at 7:24 PM Jun Li <junli1026@gmail.com> wrote:
>
>> Fix #6591
>> The content has no rbsp_stop_one_bit for ending the SPS, that
>> causes the decoding SPS failure, results decoding frame failure as well.
>>
>> The patch is just adding a retry with complete NALU, copied from the
>> retry in decode_nal_unit()
>> ---
>>  libavcodec/h264_parse.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
>> index ac31f54e07..ea7a958dd9 100644
>> --- a/libavcodec/h264_parse.c
>> +++ b/libavcodec/h264_parse.c
>> @@ -376,8 +376,15 @@ static int decode_extradata_ps(const uint8_t *data,
>> int size, H264ParamSets *ps,
>>          switch (nal->type) {
>>          case H264_NAL_SPS:
>>              ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps,
>> 0);
>> -            if (ret < 0)
>> -                goto fail;
>> +            if (ret < 0) {
>> +                GetBitContext tmp_gb = nal->gb;
>> +                av_log(logctx, AV_LOG_DEBUG,
>> +                   "SPS decoding failure, trying again with the complete
>> NAL\n");
>> +                init_get_bits8(&tmp_gb, nal->raw_data + 1, nal->raw_size
>> - 1);
>> +                if ((ret = ff_h264_decode_seq_parameter_set(&tmp_gb,
>> logctx, ps, 0)) < 0 &&
>> +                    (ret = ff_h264_decode_seq_parameter_set(&tmp_gb,
>> logctx, ps, 1)) < 0)
>> +                    goto fail;
>> +            }
>>              break;
>>          case H264_NAL_PPS:
>>              ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx,
>> ps,
>> --
>> 2.17.1
>>
>>
> Ping
>

Ping :)
James Almer Aug. 22, 2019, 7 p.m. UTC | #3
On 8/19/2019 11:24 PM, Jun Li wrote:
> Fix #6591
> The content has no rbsp_stop_one_bit for ending the SPS, that
> causes the decoding SPS failure, results decoding frame failure as well.
> 
> The patch is just adding a retry with complete NALU, copied from the retry in decode_nal_unit()
> ---
>  libavcodec/h264_parse.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
> index ac31f54e07..ea7a958dd9 100644
> --- a/libavcodec/h264_parse.c
> +++ b/libavcodec/h264_parse.c
> @@ -376,8 +376,15 @@ static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets *ps,
>          switch (nal->type) {
>          case H264_NAL_SPS:
>              ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps, 0);
> -            if (ret < 0)
> -                goto fail;
> +            if (ret < 0) {
> +                GetBitContext tmp_gb = nal->gb;

nal->gb will already be changed here and will not be pointing to the
start of the SPS.

> +                av_log(logctx, AV_LOG_DEBUG,
> +                   "SPS decoding failure, trying again with the complete NAL\n");
> +                init_get_bits8(&tmp_gb, nal->raw_data + 1, nal->raw_size - 1);

And you're overwriting it here, so the above assignment was pointless.

> +                if ((ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps, 0)) < 0 &&
> +                    (ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps, 1)) < 0)

Similarly, tmp_gb will be not be pointing to the start of the SPS if the
second ff_h264_decode_seq_parameter_set() call (with truncation enabled)
is ever executed.

> +                    goto fail;
> +            }
>              break;
>          case H264_NAL_PPS:
>              ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx, ps,
>
Jun Li Aug. 22, 2019, 9:02 p.m. UTC | #4
On Thu, Aug 22, 2019 at 12:00 PM James Almer <jamrial@gmail.com> wrote:

> On 8/19/2019 11:24 PM, Jun Li wrote:
> > Fix #6591
> > The content has no rbsp_stop_one_bit for ending the SPS, that
> > causes the decoding SPS failure, results decoding frame failure as well.
> >
> > The patch is just adding a retry with complete NALU, copied from the
> retry in decode_nal_unit()
> > ---
> >  libavcodec/h264_parse.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
> > index ac31f54e07..ea7a958dd9 100644
> > --- a/libavcodec/h264_parse.c
> > +++ b/libavcodec/h264_parse.c
> > @@ -376,8 +376,15 @@ static int decode_extradata_ps(const uint8_t *data,
> int size, H264ParamSets *ps,
> >          switch (nal->type) {
> >          case H264_NAL_SPS:
> >              ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx,
> ps, 0);
> > -            if (ret < 0)
> > -                goto fail;
> > +            if (ret < 0) {
> > +                GetBitContext tmp_gb = nal->gb;
>
> nal->gb will already be changed here and will not be pointing to the
> start of the SPS.
>
> > +                av_log(logctx, AV_LOG_DEBUG,
> > +                   "SPS decoding failure, trying again with the
> complete NAL\n");
> > +                init_get_bits8(&tmp_gb, nal->raw_data + 1,
> nal->raw_size - 1);
>
> And you're overwriting it here, so the above assignment was pointless.
>
> > +                if ((ret = ff_h264_decode_seq_parameter_set(&tmp_gb,
> logctx, ps, 0)) < 0 &&
> > +                    (ret = ff_h264_decode_seq_parameter_set(&tmp_gb,
> logctx, ps, 1)) < 0)
>
> Similarly, tmp_gb will be not be pointing to the start of the SPS if the
> second ff_h264_decode_seq_parameter_set() call (with truncation enabled)
> is ever executed.
>
> > +                    goto fail;
> > +            }
> >              break;
> >          case H264_NAL_PPS:
> >              ret = ff_h264_decode_picture_parameter_set(&nal->gb,
> logctx, ps,
> >
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".


Thanks a lot James for pointing it out. Sorry about those obvious bugs.
I updated the version accordingly https://patchwork.ffmpeg.org/patch/14660/

-Jun
diff mbox

Patch

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index ac31f54e07..ea7a958dd9 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -376,8 +376,15 @@  static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets *ps,
         switch (nal->type) {
         case H264_NAL_SPS:
             ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps, 0);
-            if (ret < 0)
-                goto fail;
+            if (ret < 0) {
+                GetBitContext tmp_gb = nal->gb;
+                av_log(logctx, AV_LOG_DEBUG,
+                   "SPS decoding failure, trying again with the complete NAL\n");
+                init_get_bits8(&tmp_gb, nal->raw_data + 1, nal->raw_size - 1);
+                if ((ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps, 0)) < 0 &&
+                    (ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps, 1)) < 0)
+                    goto fail;
+            }
             break;
         case H264_NAL_PPS:
             ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx, ps,