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 B3FC0449C8 for ; Fri, 31 May 2024 17:48:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E28F968D5D0; Fri, 31 May 2024 20:48:20 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE2DF689BA8 for ; Fri, 31 May 2024 20:48:14 +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=ldZS38+m; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id DDFAD4DE4 for ; Fri, 31 May 2024 19:48:13 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 7I8_a-p3LLtW for ; Fri, 31 May 2024 19:48:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1717177692; bh=D3+tqt54N2JRqsRua1CNHhDHsFZuQm+Hl+pATFq4gPY=; h=From:To:Subject:Date:From; b=ldZS38+mZUM7TTJ+efSkqLO6ER0IBIkwNt+S3hUeSim2hHkWXPFzDW8c6afJ3cWEH PGLllid2qKddkdDnlL0zN3HYCC6KJjlqivd82O/XUbKnrZhbcfl4rj/FWQ/M6uLogk T75f7yJg8uL+Tb5fnGBV7umWGObrqiiU/2gcNQkLe/s9ntDZNeP2Ps3kPA26ZuoD8Q BMkWr/1jECQLUJs/saDU+hxTQD/wfajq76lvPuYznfU9TEh3y0dnLmyyvQ4IkvLLLg NDE1e+KfDtasuFX7+mr2wtxjK/XX0r4YahFxdDDljLxf3eAWdGJc6V2PXxh3AvL4ui 4aeEhyEIi5dVA== 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 5CA6E4DD8 for ; Fri, 31 May 2024 19:48:12 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BBD043A0231 for ; Fri, 31 May 2024 19:48:06 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 31 May 2024 19:47:39 +0200 Message-ID: <20240531174804.17572-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/11] lavc/hevcdec: move handling of byte alignment at the end of slice header 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: Do it in hls_slice_header() rather than cabac_init_decoder() - the former is a more logical place as according the spec the byte alignment is a part of the slice header, not slice data. Avoids a second instance of alignment handling in vaapi_hevc. Also, check that alignment_bit_equal_to_one is, in fact, equal to one. --- libavcodec/hevc_cabac.c | 2 -- libavcodec/hevcdec.c | 7 +++++++ libavcodec/hevcdec.h | 1 + libavcodec/vaapi_hevc.c | 4 +--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c index 2e639a7e41..3f95c9ca05 100644 --- a/libavcodec/hevc_cabac.c +++ b/libavcodec/hevc_cabac.c @@ -430,8 +430,6 @@ static int cabac_reinit(HEVCLocalContext *lc) static int cabac_init_decoder(HEVCLocalContext *lc) { GetBitContext *gb = &lc->gb; - skip_bits(gb, 1); - align_get_bits(gb); return ff_init_cabac_decoder(&lc->cc, gb->buffer + get_bits_count(gb) / 8, (get_bits_left(gb) + 7) / 8); diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index ff9a418926..ad2cbd7ece 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -1005,6 +1005,13 @@ static int hls_slice_header(HEVCContext *s) skip_bits(gb, 8); // slice_header_extension_data_byte } + ret = get_bits1(gb); + if (!ret) { + av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n"); + return AVERROR_INVALIDDATA; + } + sh->data_offset = align_get_bits(gb) - gb->buffer; + // Inferred parameters sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta; if (sh->slice_qp > 51 || diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index 5aa3d40450..3824bf621b 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -277,6 +277,7 @@ typedef struct SliceHeader { int16_t chroma_offset_l1[16][2]; int slice_ctb_addr_rs; + unsigned data_offset; } SliceHeader; typedef struct CodingUnit { diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index 0f5dd50351..f0a0f295d9 100644 --- a/libavcodec/vaapi_hevc.c +++ b/libavcodec/vaapi_hevc.c @@ -485,9 +485,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx, .slice_data_size = size, .slice_data_offset = 0, .slice_data_flag = VA_SLICE_DATA_FLAG_ALL, - /* Add 1 to the bits count here to account for the byte_alignment bit, which - * always is at least one bit and not accounted for otherwise. */ - .slice_data_byte_offset = (get_bits_count(&h->HEVClc->gb) + 1 + 7) / 8, + .slice_data_byte_offset = sh->data_offset, .slice_segment_address = sh->slice_segment_addr, .slice_qp_delta = sh->slice_qp_delta, .slice_cb_qp_offset = sh->slice_cb_qp_offset, -- 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".