[FFmpeg-devel,v2] avcodec/h264_parse: decode sps before pps

Submitted by Jun Li on Oct. 8, 2019, 3:33 a.m.

Details

Message ID 20191008033315.29946-1-junli1026@gmail.com
State New
Headers show

Commit Message

Jun Li Oct. 8, 2019, 3:33 a.m.
Fix ticket #6422
The content put pps before sps, which is not a common case. The change
put decoding sps before pps, just for compability.

Signed-off-by: Jun Li <junli1026@gmail.com>
---
 libavcodec/h264_parse.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Jun Li Oct. 10, 2019, 3:43 a.m.
On Mon, Oct 7, 2019 at 8:33 PM Jun Li <junli1026@gmail.com> wrote:

> Fix ticket #6422
> The content put pps before sps, which is not a common case. The change
> put decoding sps before pps, just for compability.
>
> Signed-off-by: Jun Li <junli1026@gmail.com>
> ---
>  libavcodec/h264_parse.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
> index 352ffea948..eeda5a76e5 100644
> --- a/libavcodec/h264_parse.c
> +++ b/libavcodec/h264_parse.c
> @@ -373,35 +373,36 @@ static int decode_extradata_ps(const uint8_t *data,
> int size, H264ParamSets *ps,
>          goto fail;
>      }
>
> +    /* decode sps before pps, just in case some bitstream put pps before
> sps. */
>      for (i = 0; i < pkt.nb_nals; i++) {
>          H2645NAL *nal = &pkt.nals[i];
> -        switch (nal->type) {
> -        case H264_NAL_SPS: {
> +        if (nal->type == H264_NAL_SPS) {
>              GetBitContext tmp_gb = nal->gb;
>              ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps,
> 0);
>              if (ret >= 0)
> -                break;
> +                continue;
>              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);
>              ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps,
> 0);
>              if (ret >= 0)
> -                break;
> +                continue;
>              ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps,
> 1);
>              if (ret < 0)
>                  goto fail;
> -            break;
>          }
> -        case H264_NAL_PPS:
> +    }
> +
> +    for (i = 0; i < pkt.nb_nals; i++) {
> +        H2645NAL *nal = &pkt.nals[i];
> +        if (nal->type == H264_NAL_PPS) {
>              ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx,
> ps,
>                                                         nal->size_bits);
>              if (ret < 0)
>                  goto fail;
> -            break;
> -        default:
> +        } else if (nal->type != H264_NAL_SPS) {
>              av_log(logctx, AV_LOG_VERBOSE, "Ignoring NAL type %d in
> extradata\n",
>                     nal->type);
> -            break;
>          }
>      }
>
> --
> 2.17.1
>
>
Ping

Patch hide | download patch | download mbox

diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 352ffea948..eeda5a76e5 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -373,35 +373,36 @@  static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets *ps,
         goto fail;
     }
 
+    /* decode sps before pps, just in case some bitstream put pps before sps. */
     for (i = 0; i < pkt.nb_nals; i++) {
         H2645NAL *nal = &pkt.nals[i];
-        switch (nal->type) {
-        case H264_NAL_SPS: {
+        if (nal->type == H264_NAL_SPS) {
             GetBitContext tmp_gb = nal->gb;
             ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps, 0);
             if (ret >= 0)
-                break;
+                continue;
             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);
             ret = ff_h264_decode_seq_parameter_set(&tmp_gb, logctx, ps, 0);
             if (ret >= 0)
-                break;
+                continue;
             ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps, 1);
             if (ret < 0)
                 goto fail;
-            break;
         }
-        case H264_NAL_PPS:
+    }
+
+    for (i = 0; i < pkt.nb_nals; i++) {
+        H2645NAL *nal = &pkt.nals[i];
+        if (nal->type == H264_NAL_PPS) {
             ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx, ps,
                                                        nal->size_bits);
             if (ret < 0)
                 goto fail;
-            break;
-        default:
+        } else if (nal->type != H264_NAL_SPS) {
             av_log(logctx, AV_LOG_VERBOSE, "Ignoring NAL type %d in extradata\n",
                    nal->type);
-            break;
         }
     }