From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6D28F4B4BB for ; Fri, 7 Jun 2024 13:08:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3CD3268D83D; Fri, 7 Jun 2024 16:04:23 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6133A68D782 for ; Fri, 7 Jun 2024 16:03:51 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=KU1J2/MP; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 4A31E4D42 for ; Fri, 7 Jun 2024 15:03:51 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id WoixkzKdX8pq for ; Fri, 7 Jun 2024 15:03:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1717765422; bh=q4HK3pE1oAvBJizObCHv9wYRFMuyYvF3Po4iXjbtF40=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KU1J2/MPxvCCHvFoqCjwsnfU3JHcCERa5owhNAkXf+g2nEzulwixMk8iMt/bfzAAL O6OvuiGBthjFyekP5oSwvnrmhNkh7llbn28/HaBO8hl0UWqjIj8+BwIN/qvK9555EF 46Swrcn7yw+jhMN1CZi+fiWZVJaS8z+XHTmiRrVMLZxUVRYyNfc6b8s3zbFqjN8Agp pS2RBrRXYtx1Qm0jzuXH5wb3G+cQNtWvOo5Tt/EBJc9ofjcogL0iRKsCmZQwbWC8jj YuYI5U5YHCppyZ/iAymkPwnUhKAwT4g5IF1CGwY/kuvlv0EYnpf2m5iyzKsyBfTi3y HU8Ru+PGm1ppQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id B10894E0B for ; Fri, 7 Jun 2024 15:03:42 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0A7933A2729 for ; Fri, 07 Jun 2024 15:03:36 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jun 2024 15:01:32 +0200 Message-ID: <20240607130135.9088-36-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607130135.9088-1-anton@khirnov.net> References: <20240607130135.9088-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 36/39] lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavcodec/hevc/hevcdec.c | 97 +++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index b9aea45edb..7263b80a24 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3065,10 +3065,60 @@ static int hevc_frame_end(HEVCContext *s) return 0; } +static int decode_slice(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb) +{ + int ret; + + ret = hls_slice_header(&s->sh, s, gb); + if (ret < 0) + return ret; + + if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || + (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || + (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || + ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && + s->no_rasl_output_flag)) { + return 0; + } + + if (s->sh.first_slice_in_pic_flag) { + if (s->cur_frame) { + av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); + return AVERROR_INVALIDDATA; + } + + ret = hevc_frame_start(s); + if (ret < 0) + return ret; + } else if (!s->cur_frame) { + av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); + return AVERROR_INVALIDDATA; + } + + if (s->nal_unit_type != s->first_nal_type) { + av_log(s->avctx, AV_LOG_ERROR, + "Non-matching NAL types of the VCL NALUs: %d %d\n", + s->first_nal_type, s->nal_unit_type); + return AVERROR_INVALIDDATA; + } + + ret = decode_slice_data(s, nal, gb); + if (ret < 0) + return ret; + if (ret >= s->cur_frame->ctb_count) { + ret = hevc_frame_end(s); + if (ret < 0) + return ret; + s->is_decoded = 1; + } + + return 0; +} + static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) { GetBitContext gb = nal->gb; - int ctb_addr_ts, ret; + int ret; s->nal_unit_type = nal->type; s->temporal_id = nal->temporal_id; @@ -3124,52 +3174,9 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) case HEVC_NAL_RADL_R: case HEVC_NAL_RASL_N: case HEVC_NAL_RASL_R: - ret = hls_slice_header(&s->sh, s, &gb); + ret = decode_slice(s, nal, &gb); if (ret < 0) - return ret; - - if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) || - (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) || - (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || - ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && - s->no_rasl_output_flag)) { - break; - } - - if (s->sh.first_slice_in_pic_flag) { - if (s->cur_frame) { - av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n"); - ret = AVERROR_INVALIDDATA; - goto fail; - } - - ret = hevc_frame_start(s); - if (ret < 0) - return ret; - } else if (!s->cur_frame) { - av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); goto fail; - } - - if (s->nal_unit_type != s->first_nal_type) { - av_log(s->avctx, AV_LOG_ERROR, - "Non-matching NAL types of the VCL NALUs: %d %d\n", - s->first_nal_type, s->nal_unit_type); - return AVERROR_INVALIDDATA; - } - - ctb_addr_ts = decode_slice_data(s, nal, &gb); - if (ctb_addr_ts >= s->cur_frame->ctb_count) { - ret = hevc_frame_end(s); - if (ret < 0) - goto fail; - s->is_decoded = 1; - } - - if (ctb_addr_ts < 0) { - ret = ctb_addr_ts; - goto fail; - } break; case HEVC_NAL_EOS_NUT: case HEVC_NAL_EOB_NUT: -- 2.43.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".