diff mbox series

[FFmpeg-devel] lavc/hevc_ps: fix process failed when SPS before VPS in hvcC

Message ID tencent_85D7773EAE21F4645415BD4794A772232E07@qq.com
State New
Headers show
Series [FFmpeg-devel] lavc/hevc_ps: fix process failed when SPS before VPS in hvcC | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

wangyaqiang Sept. 9, 2022, 1:09 p.m. UTC
From: Wang Yaqiang <wangyaqiang03@kuaishou.com>

In some videos, SPS will be stored before VPS in hvcC box,
parse SPS does not depend on VPS, so the video is expected to be processed normally.
Added "parsed_vps" parameter to indicate whether VPS have been parsed.
Only VPS have been parsed can be verified during SPS parsing.

Signed-off-by: Wang Yaqiang <wangyaqiang03@kuaishou.com>
---
 libavcodec/hevc_ps.c | 4 ++--
 libavcodec/hevc_ps.h | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

James Almer Sept. 9, 2022, 1:55 p.m. UTC | #1
On 9/9/2022 10:09 AM, 1035567130@qq.com wrote:
> From: Wang Yaqiang <wangyaqiang03@kuaishou.com>
> 
> In some videos, SPS will be stored before VPS in hvcC box,
> parse SPS does not depend on VPS, so the video is expected to be processed normally.
> Added "parsed_vps" parameter to indicate whether VPS have been parsed.
> Only VPS have been parsed can be verified during SPS parsing.
> 
> Signed-off-by: Wang Yaqiang <wangyaqiang03@kuaishou.com>
> ---
>   libavcodec/hevc_ps.c | 4 ++--
>   libavcodec/hevc_ps.h | 1 +
>   2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index f665d8053c..71835d0f36 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -464,7 +464,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>       if (!vps_buf)
>           return AVERROR(ENOMEM);
>       vps = (HEVCVPS*)vps_buf->data;
> -
> +    ps->parsed_vps = 1;

This would need to be reset in ff_hevc_ps_uninit().

>       av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n");
>   
>       nal_size = gb->buffer_end - gb->buffer;
> @@ -1272,7 +1272,7 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
>   
>       ret = ff_hevc_parse_sps(sps, gb, &sps_id,
>                               apply_defdispwin,
> -                            ps->vps_list, avctx);
> +                            ps->parsed_vps ? ps->vps_list : NULL, avctx);

If VPS is not required to parse SPS, wouldn't it be better to just 
change the check in ff_hevc_parse_sps() to turn the log message into a 
warning and then not error out?

>       if (ret < 0) {
>           av_buffer_unref(&sps_buf);
>           return ret;
> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
> index 2a1bbf6489..e6b694e7f3 100644
> --- a/libavcodec/hevc_ps.h
> +++ b/libavcodec/hevc_ps.h
> @@ -333,6 +333,7 @@ typedef struct HEVCParamSets {
>       const HEVCVPS *vps;
>       const HEVCSPS *sps;
>       const HEVCPPS *pps;
> +    int parsed_vps; // indicates VPS has been parsed
>   } HEVCParamSets;
>   
>   /**
wangyaqiang Sept. 9, 2022, 2:34 p.m. UTC | #2
> 2022年9月9日 下午9:55,James Almer <jamrial@gmail.com> 写道:
> 
> On 9/9/2022 10:09 AM, 1035567130@qq.com <mailto:1035567130@qq.com> wrote:
>> From: Wang Yaqiang <wangyaqiang03@kuaishou.com>
>> In some videos, SPS will be stored before VPS in hvcC box,
>> parse SPS does not depend on VPS, so the video is expected to be processed normally.
>> Added "parsed_vps" parameter to indicate whether VPS have been parsed.
>> Only VPS have been parsed can be verified during SPS parsing.
>> Signed-off-by: Wang Yaqiang <wangyaqiang03@kuaishou.com>
>> ---
>>  libavcodec/hevc_ps.c | 4 ++--
>>  libavcodec/hevc_ps.h | 1 +
>>  2 files changed, 3 insertions(+), 2 deletions(-)
>> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
>> index f665d8053c..71835d0f36 100644
>> --- a/libavcodec/hevc_ps.c
>> +++ b/libavcodec/hevc_ps.c
>> @@ -464,7 +464,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>>      if (!vps_buf)
>>          return AVERROR(ENOMEM);
>>      vps = (HEVCVPS*)vps_buf->data;
>> -
>> +    ps->parsed_vps = 1;
> 
> This would need to be reset in ff_hevc_ps_uninit().

Thanks,I will fix it in the next commit.

> 
>>      av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n");
>>        nal_size = gb->buffer_end - gb->buffer;
>> @@ -1272,7 +1272,7 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
>>        ret = ff_hevc_parse_sps(sps, gb, &sps_id,
>>                              apply_defdispwin,
>> -                            ps->vps_list, avctx);
>> +                            ps->parsed_vps ? ps->vps_list : NULL, avctx);
> 
> If VPS is not required to parse SPS, wouldn't it be better to just change the check in ff_hevc_parse_sps() to turn the log message into a warning and then not error out?

The SPS contains the vps_id,in the original logic,check the vps_id based on the vps_list param,so the original logic is preserved. i’m not sure which way is better.

> 
>>      if (ret < 0) {
>>          av_buffer_unref(&sps_buf);
>>          return ret;
>> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
>> index 2a1bbf6489..e6b694e7f3 100644
>> --- a/libavcodec/hevc_ps.h
>> +++ b/libavcodec/hevc_ps.h
>> @@ -333,6 +333,7 @@ typedef struct HEVCParamSets {
>>      const HEVCVPS *vps;
>>      const HEVCSPS *sps;
>>      const HEVCPPS *pps;
>> +    int parsed_vps; // indicates VPS has been parsed
>>  } HEVCParamSets;
>>    /**
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org <mailto:ffmpeg-devel-request@ffmpeg.org> with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index f665d8053c..71835d0f36 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -464,7 +464,7 @@  int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
     if (!vps_buf)
         return AVERROR(ENOMEM);
     vps = (HEVCVPS*)vps_buf->data;
-
+    ps->parsed_vps = 1;
     av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n");
 
     nal_size = gb->buffer_end - gb->buffer;
@@ -1272,7 +1272,7 @@  int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx,
 
     ret = ff_hevc_parse_sps(sps, gb, &sps_id,
                             apply_defdispwin,
-                            ps->vps_list, avctx);
+                            ps->parsed_vps ? ps->vps_list : NULL, avctx);
     if (ret < 0) {
         av_buffer_unref(&sps_buf);
         return ret;
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 2a1bbf6489..e6b694e7f3 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -333,6 +333,7 @@  typedef struct HEVCParamSets {
     const HEVCVPS *vps;
     const HEVCSPS *sps;
     const HEVCPPS *pps;
+    int parsed_vps; // indicates VPS has been parsed
 } HEVCParamSets;
 
 /**