Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: 1035567130@qq.com
To: ffmpeg-devel@ffmpeg.org
Cc: Wang Yaqiang <wangyaqiang03@kuaishou.com>
Subject: [FFmpeg-devel] [PATCH v3] lavc/hevc_ps: fix process failed when SPS before VPS in hvcC
Date: Wed, 26 Oct 2022 10:23:33 +0800
Message-ID: <tencent_BC2ACB8F384F754636AE8C7CD54333C96A08@qq.com> (raw)
In-Reply-To: <tencent_85D7773EAE21F4645415BD4794A772232E07@qq.com>

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_parser.c | 8 ++++++++
 libavcodec/hevc_ps.c     | 3 +--
 libavcodec/hevcdec.c     | 9 ++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c
index 59f9a0ff3e..be4aa55e51 100644
--- a/libavcodec/hevc_parser.c
+++ b/libavcodec/hevc_parser.c
@@ -85,8 +85,16 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
     }
     if (ps->sps != (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data) {
         ps->sps = (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data;
+        if (ps->sps->vps_id >= HEVC_MAX_VPS_COUNT || !ps->vps_list[ps->sps->vps_id]) {
+            av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", ps->sps->vps_id);
+            return AVERROR_INVALIDDATA;
+        }
         ps->vps = (HEVCVPS*)ps->vps_list[ps->sps->vps_id]->data;
     }
+    if (!ps->vps) {
+        av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n", ps->sps->vps_id);
+        return AVERROR_INVALIDDATA;
+    }
     ow  = &ps->sps->output_window;
 
     s->coded_width  = ps->sps->width;
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index f665d8053c..9abee8bd90 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -916,9 +916,8 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
     sps->vps_id = get_bits(gb, 4);
 
     if (vps_list && !vps_list[sps->vps_id]) {
-        av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
+        av_log(avctx, AV_LOG_WARNING, "VPS %d does not exist\n",
                sps->vps_id);
-        return AVERROR_INVALIDDATA;
     }
 
     sps->max_sub_layers = get_bits(gb, 3) + 1;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index fb44d8d3f2..03942a150d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -327,6 +327,10 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
 {
     AVCodecContext *avctx = s->avctx;
     const HEVCParamSets *ps = &s->ps;
+    if (!s->ps.vps_list[sps->vps_id]) {
+        av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
+        return;
+    }
     const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data;
     const HEVCWindow *ow = &sps->output_window;
     unsigned int num = 0, den = 0;
@@ -520,7 +524,10 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
     ret = pic_arrays_init(s, sps);
     if (ret < 0)
         goto fail;
-
+    if (!s->ps.vps_list[sps->vps_id]) {
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
+    }
     export_stream_params(s, sps);
 
     s->avctx->pix_fmt = pix_fmt;
-- 
2.33.0

_______________________________________________
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".

  parent reply	other threads:[~2022-10-26  2:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09 13:09 [FFmpeg-devel] [PATCH] " 1035567130
2022-09-09 13:55 ` James Almer
2022-09-09 14:34   ` wangyaqiang
2022-09-26  9:38 ` [FFmpeg-devel] [PATCH v2] " 1035567130
2022-09-26 20:21   ` Michael Niedermayer
2022-09-27 12:20     ` wangyaqiang
2022-10-14 10:13     ` wangyaqiang
2022-10-14 23:00       ` Michael Niedermayer
2022-10-25 14:29         ` wangyaqiang
2022-10-26  2:23 ` 1035567130 [this message]
2022-11-11  2:25   ` [FFmpeg-devel] [PATCH v3] " wangyaqiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_BC2ACB8F384F754636AE8C7CD54333C96A08@qq.com \
    --to=1035567130@qq.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=wangyaqiang03@kuaishou.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git