From patchwork Thu May 28 13:57:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19930 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 58AC644A156 for ; Thu, 28 May 2020 16:57:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 44E3868AE7C; Thu, 28 May 2020 16:57:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B55E468AD77 for ; Thu, 28 May 2020 16:57:42 +0300 (EEST) Received: by mail-pj1-f65.google.com with SMTP id nu7so3225555pjb.0 for ; Thu, 28 May 2020 06:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hqxuxn/McTtfHRHmkD6MlEw5188imd3Pbmr4gu0rysY=; b=t0I6961NtSYtxZApUkc+8TZ+D0qVXFD0N0R2DXjXiKFFXCdRIrbEU4gzjZhKgQ5o/w 0iJcLu4GStIBWR5syF+t+2TyY9dkm00knLZ98F7JIlajXAt45exstlvXBH/NFON2V92F 8v6B8VS+MlZl22VLdRZiXUdMwATVdf00dYjSsMlqhjcwkcsYp2b4FPW0ilVSs9onJQ87 WDjbejkl99imd8sPnT3BrtzYpKeQUrHuF17p81M/Ss9I0/SDlFAmBUC2LvD8c8FIsYeH Lz/x2YlaxaEwG3VzFcH+uTFqp9LGglDVlEUl36eKtsVgU+/pvI53Kkq+hyF9q/fDQCZP Prpw== 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:in-reply-to :references; bh=hqxuxn/McTtfHRHmkD6MlEw5188imd3Pbmr4gu0rysY=; b=sLWmRCwFvO4c5P3vfFGKv1A/u+v9/CRH9h4dweJssH0Q+Axi32tx5LTitGlw2DyE2O W1Yd1boNfDAjKZerI8QB9hTBvcnTykZrR25GLyfVHqx7DR1IDA+1qUYQY7WLG5iWHnyS TcGqqXszPrplfnXNxYClYoPWJYtcQFUctKRKOhC1A3wQYO7pamuLiFdalQ2XEYduyR1v SOrYxgUDpb+a2yp8PT9iUYxHjXf7bF51zmbgssD8EPGtZvp3R1ADFl+FeZ+ovhwGXSlH +Iy1v+pd5Zobc/LxvF5d8tGID30L40Aqb8ReVerqf+i/+fganQIlGj10o5LYN3cxMbsj hVig== X-Gm-Message-State: AOAM5323Xo7uzadVTehFrb0ryXLibi+6nPqNucIMYkVJuBIjp+cBXnuj oTruhqmnkl+1aL1Bi6jywswCiiKZ X-Google-Smtp-Source: ABdhPJxfr1NWzSFhJ5AJs7u5DGRjD0Grc3BdWfpcOBX2u1oQ8qbRSxJKzsn/jR5XYCdbmx8iwDmgwg== X-Received: by 2002:a17:902:525:: with SMTP id 34mr3550950plf.289.1590674260838; Thu, 28 May 2020 06:57:40 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:40 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:26 +0800 Message-Id: <1590674250-32571-3-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1590674250-32571-1-git-send-email-lance.lmwang@gmail.com> References: <1590674250-32571-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/7] avcodec/h264dec: replace FF_ALLOCZ{_ARRAY}_OR_GOTO with av_mallocz_array() 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 remove the fail goto label and return AVERROR(ENOMEM) directly Signed-off-by: Limin Wang --- libavcodec/h264dec.c | 60 +++++++++++++++------------------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index b03e6ed..974d324 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -185,38 +185,24 @@ int ff_h264_alloc_tables(H264Context *h) const int slice_tsize = big_mb_num + h->mb_stride; int x, y; - FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->intra4x4_pred_mode, - row_mb_num, 8 * sizeof(uint8_t), fail) + if (!(h->intra4x4_pred_mode = av_mallocz_array(row_mb_num * 8, sizeof(uint8_t))) || + !(h->non_zero_count = av_mallocz_array(big_mb_num * 48, sizeof(uint8_t))) || + !(h->slice_table_base = av_mallocz_array(slice_tsize, sizeof(*h->slice_table_base))) || + !(h->cbp_table = av_mallocz_array(big_mb_num, sizeof(uint16_t))) || + !(h->chroma_pred_mode_table = av_mallocz_array(big_mb_num, sizeof(uint8_t))) || + !(h->mvd_table[0] = av_mallocz_array(row_mb_num * 8, sizeof(uint8_t))) || + !(h->mvd_table[1] = av_mallocz_array(row_mb_num * 8, sizeof(uint8_t))) || + !(h->direct_table = av_mallocz_array(big_mb_num * 4, sizeof(uint8_t))) || + !(h->list_counts = av_mallocz_array(big_mb_num, sizeof(uint8_t))) || + !(h->mb2b_xy = av_mallocz_array(big_mb_num, sizeof(uint32_t))) || + !(h->mb2br_xy = av_mallocz_array(big_mb_num, sizeof(uint32_t)))) + return AVERROR(ENOMEM); h->slice_ctx[0].intra4x4_pred_mode = h->intra4x4_pred_mode; - - FF_ALLOCZ_OR_GOTO(h->avctx, h->non_zero_count, - big_mb_num * 48 * sizeof(uint8_t), fail) - FF_ALLOCZ_OR_GOTO(h->avctx, h->slice_table_base, - slice_tsize * sizeof(*h->slice_table_base), fail) - FF_ALLOCZ_OR_GOTO(h->avctx, h->cbp_table, - big_mb_num * sizeof(uint16_t), fail) - FF_ALLOCZ_OR_GOTO(h->avctx, h->chroma_pred_mode_table, - big_mb_num * sizeof(uint8_t), fail) - FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->mvd_table[0], - row_mb_num, 16 * sizeof(uint8_t), fail); - FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->mvd_table[1], - row_mb_num, 16 * sizeof(uint8_t), fail); h->slice_ctx[0].mvd_table[0] = h->mvd_table[0]; h->slice_ctx[0].mvd_table[1] = h->mvd_table[1]; - - FF_ALLOCZ_OR_GOTO(h->avctx, h->direct_table, - 4 * big_mb_num * sizeof(uint8_t), fail); - FF_ALLOCZ_OR_GOTO(h->avctx, h->list_counts, - big_mb_num * sizeof(uint8_t), fail) - memset(h->slice_table_base, -1, slice_tsize * sizeof(*h->slice_table_base)); h->slice_table = h->slice_table_base + h->mb_stride * 2 + 1; - - FF_ALLOCZ_OR_GOTO(h->avctx, h->mb2b_xy, - big_mb_num * sizeof(uint32_t), fail); - FF_ALLOCZ_OR_GOTO(h->avctx, h->mb2br_xy, - big_mb_num * sizeof(uint32_t), fail); for (y = 0; y < h->mb_height; y++) for (x = 0; x < h->mb_width; x++) { const int mb_xy = x + y * h->mb_stride; @@ -227,9 +213,6 @@ int ff_h264_alloc_tables(H264Context *h) } return 0; - -fail: - return AVERROR(ENOMEM); } /** @@ -269,8 +252,11 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) er->b8_stride = h->mb_width * 2 + 1; // error resilience code looks cleaner with this - FF_ALLOCZ_OR_GOTO(h->avctx, er->mb_index2xy, - (h->mb_num + 1) * sizeof(int), fail); + if (!(er->mb_index2xy = av_mallocz_array(h->mb_num + 1, sizeof(int))) || + !(er->error_status_table = av_mallocz_array(mb_array_size, sizeof(uint8_t))) || + !(er->er_temp_buffer = av_mallocz_array(h->mb_height * h->mb_stride + 1, sizeof(int))) || + !(sl->dc_val_base = av_mallocz_array(yc_size, sizeof(int16_t)))) + return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us for (y = 0; y < h->mb_height; y++) for (x = 0; x < h->mb_width; x++) @@ -278,15 +264,6 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) er->mb_index2xy[h->mb_height * h->mb_width] = (h->mb_height - 1) * h->mb_stride + h->mb_width; - - FF_ALLOCZ_OR_GOTO(h->avctx, er->error_status_table, - mb_array_size * sizeof(uint8_t), fail); - - FF_ALLOC_OR_GOTO(h->avctx, er->er_temp_buffer, - h->mb_height * h->mb_stride * (4*sizeof(int) + 1), fail); - - FF_ALLOCZ_OR_GOTO(h->avctx, sl->dc_val_base, - yc_size * sizeof(int16_t), fail); er->dc_val[0] = sl->dc_val_base + h->mb_width * 2 + 2; er->dc_val[1] = sl->dc_val_base + y_size + h->mb_stride + 1; er->dc_val[2] = er->dc_val[1] + c_size; @@ -295,9 +272,6 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) } return 0; - -fail: - return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us } static int h264_init_context(AVCodecContext *avctx, H264Context *h)