From patchwork Thu Jan 9 01:04:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 17267 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 50ABF44AF3A for ; Thu, 9 Jan 2020 03:04:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2C497689FE3; Thu, 9 Jan 2020 03:04:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F14AC687FF0 for ; Thu, 9 Jan 2020 03:04:40 +0200 (EET) Received: by mail-pl1-f181.google.com with SMTP id s21so1825563plr.7 for ; Wed, 08 Jan 2020 17:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=xdRwGhPqj6iu8eY6caha0ysZIR1pO4s9fzJm3Z81sas=; b=M6dNBz+g1HZkZKZOb6aicNU+YTL/U4Oz4zzPXfFQJvthGODdRUO+Pg7bXYtgVAM8VN lAHiA+E/jogAWMoY3s0qRDLbIBti+hoZfPMhi9/gzanjd0ExOBAC/oIPKs7TkPCty3eR OU1xPuiQ7UxSEkHkLEB8MTxT18tGpM1fHlbeve0hDSk2XEc6+NiOcbjV4ePyHw1X34rb JTtEdNvE/S+kwOeOsXvcJJj22RVowrL6pfhXlWZS3SErvi60cV1EDMFCTj40ISerQDj/ tmKT8l8D+wQ6+649f9BPpCpySeYT7Vgta4zbECbB9IxaCYJglIlRHARPgr3NJSKkovob 2EUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xdRwGhPqj6iu8eY6caha0ysZIR1pO4s9fzJm3Z81sas=; b=Y3drwVP99AULtKGrbYX3k2MC8L0s2u8RH24bgpD+dJUT/n6R53j3aen0pnLIgKxU6L 8lv3ZUTT6LmfINzPnHskq7GO4Kglaqm6hZhmm0q5Xb1LMeKce1S3MiORvazvoISUAKuh lnaJeH+rCwlWliYG6M5f+1rmMtsVA489PN8wDVzOLqtYG+7H7dOSgbYjKtSZgpCmuRBw VJm0/wPNt99QPsAXywJlEWh/g3/NkAJZG8HzPfGfpSACJDBzKQqOUIQRG8bbeIFFwCQS b8ZJJInGxOON2lKUs851qO6S4MtLHoC4OfAPkruOOHQJ4lX0v0omggJlOuVmS/9w8Im6 34tg== X-Gm-Message-State: APjAAAWsLyqdqbLwsIMiog6txQK5yFuz8WlLIDbnH6ovroRw+wcrcO6y 76H9qTM8yRsZfWdWAswVUAlwgdhM X-Google-Smtp-Source: APXvYqxAFgRf80QsKATFHFXzUawlnZD+FBkLmWpiipYgBW0RjlTIpEuYDmbHtW3kXViEJLeKATFhMw== X-Received: by 2002:a17:90a:8a8f:: with SMTP id x15mr1932504pjn.87.1578531879126; Wed, 08 Jan 2020 17:04:39 -0800 (PST) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id p5sm4889939pgs.28.2020.01.08.17.04.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jan 2020 17:04:38 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jan 2020 09:04:33 +0800 Message-Id: <20200109010433.20951-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 Subject: [FFmpeg-devel] [PATCH v1] avcodec/utils: replace avctx->internal with avci for better readability X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/utils.c | 63 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index fd5565a..ab48754 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -551,6 +551,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code int codec_init_ok = 0; AVDictionary *tmp = NULL; const AVPixFmtDescriptor *pixdesc; + AVCodecInternal *avci; if (avcodec_is_open(avctx)) return 0; @@ -575,55 +576,56 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ff_lock_avcodec(avctx, codec); - avctx->internal = av_mallocz(sizeof(*avctx->internal)); - if (!avctx->internal) { + avci = av_mallocz(sizeof(*avci)); + if (!avci) { ret = AVERROR(ENOMEM); goto end; } + avctx->internal = avci; - avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool)); - if (!avctx->internal->pool) { + avci->pool = av_mallocz(sizeof(*avci->pool)); + if (!avci->pool) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->to_free = av_frame_alloc(); - if (!avctx->internal->to_free) { + avci->to_free = av_frame_alloc(); + if (!avci->to_free) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->compat_decode_frame = av_frame_alloc(); - if (!avctx->internal->compat_decode_frame) { + avci->compat_decode_frame = av_frame_alloc(); + if (!avci->compat_decode_frame) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->buffer_frame = av_frame_alloc(); - if (!avctx->internal->buffer_frame) { + avci->buffer_frame = av_frame_alloc(); + if (!avci->buffer_frame) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->buffer_pkt = av_packet_alloc(); - if (!avctx->internal->buffer_pkt) { + avci->buffer_pkt = av_packet_alloc(); + if (!avci->buffer_pkt) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->ds.in_pkt = av_packet_alloc(); - if (!avctx->internal->ds.in_pkt) { + avci->ds.in_pkt = av_packet_alloc(); + if (!avci->ds.in_pkt) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->last_pkt_props = av_packet_alloc(); - if (!avctx->internal->last_pkt_props) { + avci->last_pkt_props = av_packet_alloc(); + if (!avci->last_pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } - avctx->internal->skip_samples_multiplier = 1; + avci->skip_samples_multiplier = 1; if (codec->priv_data_size > 0) { if (!avctx->priv_data) { @@ -755,7 +757,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code } if (HAVE_THREADS - && !(avctx->internal->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) { + && !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) { ret = ff_thread_init(avctx); if (ret < 0) { goto free_and_end; @@ -947,7 +949,7 @@ FF_ENABLE_DEPRECATION_WARNINGS "gray decoding requested but not enabled at configuration time\n"); if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME) - || avctx->internal->frame_thread_encoder)) { + || avci->frame_thread_encoder)) { ret = avctx->codec->init(avctx); if (ret < 0) { goto free_and_end; @@ -1045,7 +1047,7 @@ free_and_end: (avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))) avctx->codec->close(avctx); - if (HAVE_THREADS && avctx->internal->thread_ctx) + if (HAVE_THREADS && avci->thread_ctx) ff_thread_free(avctx); if (codec->priv_class && codec->priv_data_size) @@ -1061,19 +1063,20 @@ FF_ENABLE_DEPRECATION_WARNINGS av_dict_free(&tmp); av_freep(&avctx->priv_data); av_freep(&avctx->subtitle_header); - if (avctx->internal) { - av_frame_free(&avctx->internal->to_free); - av_frame_free(&avctx->internal->compat_decode_frame); - av_frame_free(&avctx->internal->buffer_frame); - av_packet_free(&avctx->internal->buffer_pkt); - av_packet_free(&avctx->internal->last_pkt_props); - - av_packet_free(&avctx->internal->ds.in_pkt); + if (avci) { + av_frame_free(&avci->to_free); + av_frame_free(&avci->compat_decode_frame); + av_frame_free(&avci->buffer_frame); + av_packet_free(&avci->buffer_pkt); + av_packet_free(&avci->last_pkt_props); + + av_packet_free(&avci->ds.in_pkt); ff_decode_bsfs_uninit(avctx); - av_freep(&avctx->internal->pool); + av_freep(&avci->pool); } - av_freep(&avctx->internal); + av_freep(&avci); + avctx->internal = NULL; avctx->codec = NULL; goto end; }