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 093974A833 for ; Wed, 10 Apr 2024 13:32:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 224E368D0C5; Wed, 10 Apr 2024 16:31:37 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60BEA68CEE6 for ; Wed, 10 Apr 2024 16:31:27 +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=fRbYs34V; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 2B4824D6E for ; Wed, 10 Apr 2024 15:31:26 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id urJuahZlDkS3 for ; Wed, 10 Apr 2024 15:31:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1712755884; bh=yD3xfZVzLgylUzG8gzFzdKJhWCsYUQ8tc8CCzHBUosQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fRbYs34VWZqPr9uakoNveOyTO0GrdhvylqoS1md7w2CP7e91Ak0PX/LwiiZig+DXv BWUx7O0sgQjMqTzKejKoB2JVqivY0hQeruE5ZI/MMxT2W8PKSqQ1Osd0qOMYob4CmF 7LlrJqvlOp7GdxlLJ2nLyg9ZNc81EZggPX/3+zTtdEjxwr5B5sFxNB7NvcvJslqY3u UN4RXbz+4vpJnG8oBecDlSmRILdNkA1YCY6MssxCrF1duw8g4+Biu9g0jOiyU5g8UL 3O2xY3/ciLCr8+R6ZrbpuSy6Bars3q27NPGdUWonQLFj1m/LtDQrHKnfzOI0x1yzPw o/wNjh0dY4MeA== 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 B1B654D72 for ; Wed, 10 Apr 2024 15:31:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9B92D3A03BC for ; Wed, 10 Apr 2024 15:31:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Apr 2024 15:31:11 +0200 Message-ID: <20240410133118.28144-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410133118.28144-1-anton@khirnov.net> References: <20240410133118.28144-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/10] lavc/hevcdec: allocate local_ctx as array of structs rather than pointers 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: It is more efficient and easier to manage. --- libavcodec/hevcdec.c | 57 +++++++++++++++++++++++++------------------- libavcodec/hevcdec.h | 2 +- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 55f72af972..47226ef0ab 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2598,7 +2598,7 @@ static int hls_slice_data(HEVCContext *s) static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist, int job, int self_id) { - HEVCLocalContext *lc = ((HEVCLocalContext**)hevc_lclist)[self_id]; + HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id]; const HEVCContext *const s = lc->parent; int ctb_size = 1 << s->ps.sps->log2_ctb_size; int more_data = 1; @@ -2682,7 +2682,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) { const uint8_t *data = nal->data; int length = nal->size; - HEVCLocalContext *lc = s->HEVClc; + HEVCLocalContext *lc; int *ret; int64_t offset; int64_t startheader, cmpt = 0; @@ -2696,19 +2696,31 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) return AVERROR_INVALIDDATA; } - for (i = 1; i < s->threads_number; i++) { - if (i < s->nb_local_ctx) - continue; - s->local_ctx[i] = av_mallocz(sizeof(HEVCLocalContext)); - if (!s->local_ctx[i]) - return AVERROR(ENOMEM); - s->nb_local_ctx++; + if (s->threads_number > s->nb_local_ctx) { + HEVCLocalContext *tmp = av_malloc_array(s->threads_number, sizeof(*s->local_ctx)); - s->local_ctx[i]->logctx = s->avctx; - s->local_ctx[i]->parent = s; - s->local_ctx[i]->common_cabac_state = &s->cabac; + if (!tmp) + return AVERROR(ENOMEM); + + memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx); + av_free(s->local_ctx); + s->local_ctx = tmp; + s->HEVClc = &s->local_ctx[0]; + + for (unsigned i = s->nb_local_ctx; i < s->threads_number; i++) { + tmp = &s->local_ctx[i]; + + memset(tmp, 0, sizeof(*tmp)); + + tmp->logctx = s->avctx; + tmp->parent = s; + tmp->common_cabac_state = &s->cabac; + } + + s->nb_local_ctx = s->threads_number; } + lc = &s->local_ctx[0]; offset = (lc->gb.index >> 3); for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) { @@ -2744,8 +2756,8 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) s->data = data; for (i = 1; i < s->threads_number; i++) { - s->local_ctx[i]->first_qp_group = 1; - s->local_ctx[i]->qp_y = s->HEVClc->qp_y; + s->local_ctx[i].first_qp_group = 1; + s->local_ctx[i].qp_y = s->HEVClc->qp_y; } atomic_store(&s->wpp_err, 0); @@ -3476,12 +3488,6 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) av_freep(&s->sh.offset); av_freep(&s->sh.size); - if (s->local_ctx) { - for (i = 1; i < s->nb_local_ctx; i++) { - av_freep(&s->local_ctx[i]); - } - } - av_freep(&s->HEVClc); av_freep(&s->local_ctx); ff_h2645_packet_uninit(&s->pkt); @@ -3498,15 +3504,16 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) s->avctx = avctx; - s->HEVClc = av_mallocz(sizeof(HEVCLocalContext)); - s->local_ctx = av_mallocz(sizeof(HEVCLocalContext*) * s->threads_number); - if (!s->HEVClc || !s->local_ctx) + s->local_ctx = av_mallocz(sizeof(*s->local_ctx)); + if (!s->local_ctx) return AVERROR(ENOMEM); + s->nb_local_ctx = 1; + + s->HEVClc = &s->local_ctx[0]; + s->HEVClc->parent = s; s->HEVClc->logctx = avctx; s->HEVClc->common_cabac_state = &s->cabac; - s->local_ctx[0] = s->HEVClc; - s->nb_local_ctx = 1; s->output_frame = av_frame_alloc(); if (!s->output_frame) diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index a881eb9981..5a4ed270e8 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -441,7 +441,7 @@ typedef struct HEVCContext { const AVClass *c; // needed by private avoptions AVCodecContext *avctx; - HEVCLocalContext **local_ctx; + HEVCLocalContext *local_ctx; unsigned nb_local_ctx; HEVCLocalContext *HEVClc; -- 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".