From patchwork Thu May 28 13:57:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19928 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 7C4D944A156 for ; Thu, 28 May 2020 16:57:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 518A568ADE6; Thu, 28 May 2020 16:57:46 +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 1B84368AC9B for ; Thu, 28 May 2020 16:57:40 +0300 (EEST) Received: by mail-pj1-f65.google.com with SMTP id nu7so3225499pjb.0 for ; Thu, 28 May 2020 06:57:39 -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; bh=8Mr6vOLTG3q+hgcX5S2G1aP2dZiBs0y+HNd8J636eRs=; b=glWM9arELqh5O46xdtpNjQQE0ROTLDA3NK5fR3Esn5JFR4dwgrpeluAo/LFS2h7fal b8WlqONiH6gyCYHpV5JL8sRiL9LM1H0aYDcsu9KBfKf5DGOE5aAA7IiXP+ec1pvofqNE RO7M4U+DVLkDaIz/dUYQuLS9PzwkwM/Ql2dhkmeKJY8u9JuCbO/pdTvP8SNZdjNVFZzi vfrta7PTTgr7tRnkM5s6yxjE6UJx+ZNmEWLj+EEBCt5KsvlQwFbuuJc0s8jy5kj1iPlh UviRnPSrQCtt395Br52x4s1n1aLDzODBHTujyB3jFLQYHuzLvpgZjKn8mjSdNyM4zJth kR0Q== 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=8Mr6vOLTG3q+hgcX5S2G1aP2dZiBs0y+HNd8J636eRs=; b=QeUv+72DJ9axJNiBmEssOXtScH+bo2l4R4y2GS9SQcpsVRskqixG+hbBCo2FnbvqLl F3pVF+hVooK4P2OEHwoQz8Uh2qriq3KcVGSjZK5r3Y3PApbgIHqt+5nUvXGJl90vmms6 GktsKLDhaVyiQumHVhbLC7C6Ps1gcyW9tJRITCt0hT/Ms3MCfNOfJiwrnd5iHeYBsBAG gsqYZIrrdfC6DViCn8R4RMBYCuDidoXITH/5wsCFNcS35/Tj7qEVIPGwwHdhds58lMW/ WbxdyJfL1VsJBTdwd9/fjV60N2p9t6QmS8zLERuwXQRXt1oq0rpVzDkjluJBVjVRRXj/ qyfw== X-Gm-Message-State: AOAM531Mi2Il050oysOHbwHBPt7u9UQvtkmPBZm9qwv4ISa5dySEuDS4 HgPfBEpUbZcdyBeJEu7NaCYwkjvm X-Google-Smtp-Source: ABdhPJymic+He1OQEVOFtmNiD2RBARi2CSl+hOVHleOF+ns3al/w4MyEMjp9EvH0I6x7YPPzKDJgdg== X-Received: by 2002:a17:90b:19d5:: with SMTP id nm21mr3986387pjb.212.1590674257586; Thu, 28 May 2020 06:57:37 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:36 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:24 +0800 Message-Id: <1590674250-32571-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH 1/7] avcodec/h264dec: cosmetics 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/h264dec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index e463fde..7c7a63c 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -253,8 +253,7 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) if (sl != h->slice_ctx) { memset(er, 0, sizeof(*er)); - } else - if (CONFIG_ERROR_RESILIENCE) { + } else if (CONFIG_ERROR_RESILIENCE) { /* init ER */ er->avctx = h->avctx; From patchwork Thu May 28 13:57:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19929 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 7822544A156 for ; Thu, 28 May 2020 16:57:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 629D868AE2D; Thu, 28 May 2020 16:57:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2787B68AD24 for ; Thu, 28 May 2020 16:57:41 +0300 (EEST) Received: by mail-pj1-f68.google.com with SMTP id a45so720734pje.1 for ; Thu, 28 May 2020 06:57:41 -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=+zSOW68MrqU0qm2HSHBQQ//cMeSZydTOvPLCLrKl6Eo=; b=t96E2xiOYe5ZfHzmP8gHIblnAZZqI5o35BFJ0UiQ6fOsRd/o31J3JlSwTkbjwGJE04 lHETAtAcQIF974aUH8CTU0fMX/fk/6oO+1yj8aHwXHNZiCSxK/AqMp+nY80ac0kY2d4p Xv3mJcZHlnr3T/wqjq9CH/hhAju1pVZmeuvcYT6sl2Q3AjGyrw2vmBdESivNoEhIQ7f7 7ByHXbjDXQUlWBaoV6j8aSH/AvP0IhJVzQgruD2AIQprtV2lN46DIjSGwsANLWNlB86n hsXu5nHnNDkraB66ucsD1O6CGIHJXLTIe4cjpNx56ixkq+xWyjT5XOT55/BSokpQyWyt N6AQ== 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=+zSOW68MrqU0qm2HSHBQQ//cMeSZydTOvPLCLrKl6Eo=; b=eNlQjUa+8lj6tiWyyzEAwqd3HA7n3uEEJfiG2yL7GHRVHWX2mnPWgrfnTzwy6Ieo4j V0ckZ4XJIrCVHg3ibuvqCOxRRCTJCqFy8zM3NGn6YLMeaIgehNTtzL052GMb7Waw4Y9g ETFEgBxuPzzG6RDHThao37OIb2RFCCU4N+z25nkRzom8i9EhzHbLzqNDq6XSTnoNRKSY EMclbOF7DHBmx9X2MAPRaphcMpF3EealurQ+fYk8oxjNk9IC0LTDgVBLgm6hFso/L9PL BuuAxrPvZ4oYO2Odh5BVZKP1d/Tv22gSz4DCJ76zYlFrskrUY5NIaQxi+y9r+kbmbJ7X tGiw== X-Gm-Message-State: AOAM531EExGSSpCMvXurZR/px+Pl+v80POXTcCwtzaXeiGZP4RY6TVVi hbsYHFl1jM2no/ZHhHUtFI8zUiH4 X-Google-Smtp-Source: ABdhPJzlfBe18aFnsE5+mxziyhRDbVI+Uv55bysIaTQvDxA6Wwed1r8AcKuw8tq4RvafdL/xwj91AA== X-Received: by 2002:a17:90b:88d:: with SMTP id bj13mr3677197pjb.133.1590674259242; Thu, 28 May 2020 06:57:39 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:38 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:25 +0800 Message-Id: <1590674250-32571-2-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 2/7] avcodec/h264dec: store count of slice_table_base with local variable 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/h264dec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 7c7a63c..b03e6ed 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -182,6 +182,7 @@ int ff_h264_alloc_tables(H264Context *h) { const int big_mb_num = h->mb_stride * (h->mb_height + 1); const int row_mb_num = 2*h->mb_stride*FFMAX(h->nb_slice_ctx, 1); + const int slice_tsize = big_mb_num + h->mb_stride; int x, y; FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->intra4x4_pred_mode, @@ -191,7 +192,7 @@ int ff_h264_alloc_tables(H264Context *h) 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, - (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base), fail) + 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, @@ -209,7 +210,7 @@ int ff_h264_alloc_tables(H264Context *h) big_mb_num * sizeof(uint8_t), fail) memset(h->slice_table_base, -1, - (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base)); + 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, 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) From patchwork Thu May 28 13:57:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19931 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 1846944A156 for ; Thu, 28 May 2020 16:57:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0514D68AEB7; Thu, 28 May 2020 16:57:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7126868AD85 for ; Thu, 28 May 2020 16:57:44 +0300 (EEST) Received: by mail-pj1-f66.google.com with SMTP id ci23so3134074pjb.5 for ; Thu, 28 May 2020 06:57:44 -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=Ay+lK7B+JQJq68Ut5XxHUzdu3hzvybNz8lHfe3Vsxhg=; b=RCW426FLctwYFSklycyrKEnQI1biHtVgnpWSGx8o8EHwdOlWN8EXL+COo4TfP1kNJD YE94ce4L8AlVY+cLU27mQ4unrhf0TEf2q/L73NJ8ilxECuArXRyKRAZsmCunXoLM1VFU l7CbQwBp0kHJ2dX5XV49zXk8dp7Q6a5WbPiEfJXvgv8rAcn4UPFwmY3uxAcm1hjxKpm7 SC5i+g134AawIDumqhJcybZe4hxZ0GTFAXXmh2iB2ThLvpB5XeXGafarPxKiYmAMhZ0k bCkA/76jaM9gMiuGR0I7kIqJUYknNOd/Fh/5Vrsn9Iq75rtq5tRV0hgN5ELia56kqrWc vZdA== 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=Ay+lK7B+JQJq68Ut5XxHUzdu3hzvybNz8lHfe3Vsxhg=; b=k+v2l8gx8DVEQHxO+4BTJxtLXPtW7iiUaiHqYfK3NFln7ainAMAWJr19ogw7YLs+lW 4l4XgQ5n36XGEZ+3LrO/TgHcrrEaFLtU6F4c3Bt4GSFGxb5jWeypAvdjIHRXfzhw1NQC e6iixrqSlPfYlz4Pm1ps5fQ+qTf0xsnClOZdJiupn5HVfLYfsFEGSyiyGBX3D4VbyQSB E6Z6BsTZ7141ThRRtPbnfqB4vq9Y5NI2zf44dFTMgfIgdX2/O4DMcLHS85XbXR39Wtb8 7RldezOpfB0nrBXAZlrDpbvDV6OrFqq5G9P7C9A0F8EgH0EjyhNQaTpY8X8wunQ+j/nj acsg== X-Gm-Message-State: AOAM533L2i/QvbHZR1dAxZCPmiha2DhzD8gEe4gSgXiAFC+4G50bcj/w YH9e7bOSjabld7VXBmPdv4QYFZHb X-Google-Smtp-Source: ABdhPJw6cC2eCTBd2dOlfW8DmUNJ70wXdqFtIGefJnKFTe5H5ujE5f6q7NtneXd0AJHtrh3Q7S5j8A== X-Received: by 2002:a17:90a:d17:: with SMTP id t23mr4040391pja.77.1590674262471; Thu, 28 May 2020 06:57:42 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:41 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:27 +0800 Message-Id: <1590674250-32571-4-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 4/7] avcodec/h264dec: prefer to use variable instead of type for sizeof 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/h264dec.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 974d324..d5b3df3 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -185,17 +185,17 @@ int ff_h264_alloc_tables(H264Context *h) const int slice_tsize = big_mb_num + h->mb_stride; int x, y; - 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))) || + if (!(h->intra4x4_pred_mode = av_mallocz_array(row_mb_num * 8, sizeof(*h->intra4x4_pred_mode))) || + !(h->non_zero_count = av_mallocz_array(big_mb_num * 48, sizeof(*h->non_zero_count))) || !(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)))) + !(h->cbp_table = av_mallocz_array(big_mb_num, sizeof(*h->cbp_table))) || + !(h->chroma_pred_mode_table = av_mallocz_array(big_mb_num, sizeof(*h->chroma_pred_mode_table))) || + !(h->mvd_table[0] = av_mallocz_array(row_mb_num * 8, sizeof(*h->mvd_table[0]))) || + !(h->mvd_table[1] = av_mallocz_array(row_mb_num * 8, sizeof(*h->mvd_table[1]))) || + !(h->direct_table = av_mallocz_array(big_mb_num * 4, sizeof(*h->direct_table))) || + !(h->list_counts = av_mallocz_array(big_mb_num, sizeof(*h->list_counts))) || + !(h->mb2b_xy = av_mallocz_array(big_mb_num, sizeof(*h->mb2b_xy))) || + !(h->mb2br_xy = av_mallocz_array(big_mb_num, sizeof(*h->mb2br_xy)))) return AVERROR(ENOMEM); h->slice_ctx[0].intra4x4_pred_mode = h->intra4x4_pred_mode; h->slice_ctx[0].mvd_table[0] = h->mvd_table[0]; @@ -252,10 +252,10 @@ 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 - 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)))) + if (!(er->mb_index2xy = av_mallocz_array(h->mb_num + 1, sizeof(*er->mb_index2xy))) || + !(er->error_status_table = av_mallocz_array(mb_array_size, sizeof(*er->error_status_table))) || + !(er->er_temp_buffer = av_mallocz_array(h->mb_height * h->mb_stride + 1, sizeof(*er->er_temp_buffer))) || + !(sl->dc_val_base = av_mallocz_array(yc_size, sizeof(*sl->dc_val_base)))) return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us for (y = 0; y < h->mb_height; y++) From patchwork Thu May 28 13:57:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19932 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 D2B2644A156 for ; Thu, 28 May 2020 16:57:53 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B6B1068AE45; Thu, 28 May 2020 16:57:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92D5968AEA8 for ; Thu, 28 May 2020 16:57:46 +0300 (EEST) Received: by mail-pg1-f196.google.com with SMTP id p21so13497607pgm.13 for ; Thu, 28 May 2020 06:57:46 -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=+QKH0Tuc7O7m/7WWIvf88PBum6ydtQxO3/4AqfOZrfg=; b=CauWNuVMS1n2aqVNo+5dJSOt54z7cYVhrCQhRZLhRMbsnR/wLKR/05/k6jjQyPS8hr PSVpplbbMXrxYXTh7Dkg7cXup7s4L9X+JewcxLK5UzDaXhGfDwkTBUzaRlQwmtqYESJh YFgv7osrJLHNfvSpuvGxb2t8it2jFMp6egdCyne00bYt1Y3LPxwmexMqqVnWGpncu9eM l0z5JNmFQyXZanjpqmwEkZAvqkwfZg+xfdZK9IKqQFli7V6nrJiPIvQwnK8ezgdA67Dv B2kPzTDKW1mAoxiMieHt0RvcmRGTce6/TU9CjHKMmXmwUscF+tgZF4Cxp/lLIN1FAMeH M8kQ== 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=+QKH0Tuc7O7m/7WWIvf88PBum6ydtQxO3/4AqfOZrfg=; b=rT9LfJy9EX6L7ZJeetyWoJaDNOKKQX0n1hi0gxAMEsCMZWOtTc5y5eatDCY0VXrjRl pAIWJEKTn4P6Gio3Kid21lsc0iwZAYKTBCRzR7sKqzuqGdwkk7GnfnDNkzazekFavL1v Gk9jnzHNWrkYKK7GB1VHQX98guGOJrNkWEKhH0Gvq4Ff7X8pRmsxtSgicX0HDX+Q1hDN yxQ7KLFx9K4N7gg3VXs/5V3vdWjsXhVju+R+lEna4PedOTzuX5MUZLKPtTy/621YsgSw Ym2x9eYVAXS4/5H5p5Diyvr2ndCTufclnlBmlqt9GCDDQLnFgl6IPEQzcdISmfTx644O zKMA== X-Gm-Message-State: AOAM530lqETi0qqHg/m/5BrrSqpa4x/N2sk9B0IWTs7dx4llyR3FDXIJ cJ6SPQuOcDkhKrrL0AU4L3ObFqp7 X-Google-Smtp-Source: ABdhPJz7ivP9A93IrwDckG0Rc7mTvmZ/dkzbUJR+cjbqMmFM/cn42o0FItHrf9qEmiyvN6o/P4RUXg== X-Received: by 2002:a62:1957:: with SMTP id 84mr1563926pfz.54.1590674264129; Thu, 28 May 2020 06:57:44 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:43 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:28 +0800 Message-Id: <1590674250-32571-5-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 5/7] avcodec/h264dec: define and use FF_ALLOCZ_TYPED_ARRAY helper macro 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 The macro will help to short the long lines and avoid split them. Signed-off-by: Limin Wang --- libavcodec/h264dec.c | 30 +++++++++++++++--------------- libavutil/internal.h | 2 ++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index d5b3df3..b797c79 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -185,17 +185,17 @@ int ff_h264_alloc_tables(H264Context *h) const int slice_tsize = big_mb_num + h->mb_stride; int x, y; - if (!(h->intra4x4_pred_mode = av_mallocz_array(row_mb_num * 8, sizeof(*h->intra4x4_pred_mode))) || - !(h->non_zero_count = av_mallocz_array(big_mb_num * 48, sizeof(*h->non_zero_count))) || - !(h->slice_table_base = av_mallocz_array(slice_tsize, sizeof(*h->slice_table_base))) || - !(h->cbp_table = av_mallocz_array(big_mb_num, sizeof(*h->cbp_table))) || - !(h->chroma_pred_mode_table = av_mallocz_array(big_mb_num, sizeof(*h->chroma_pred_mode_table))) || - !(h->mvd_table[0] = av_mallocz_array(row_mb_num * 8, sizeof(*h->mvd_table[0]))) || - !(h->mvd_table[1] = av_mallocz_array(row_mb_num * 8, sizeof(*h->mvd_table[1]))) || - !(h->direct_table = av_mallocz_array(big_mb_num * 4, sizeof(*h->direct_table))) || - !(h->list_counts = av_mallocz_array(big_mb_num, sizeof(*h->list_counts))) || - !(h->mb2b_xy = av_mallocz_array(big_mb_num, sizeof(*h->mb2b_xy))) || - !(h->mb2br_xy = av_mallocz_array(big_mb_num, sizeof(*h->mb2br_xy)))) + if (!FF_ALLOCZ_TYPED_ARRAY(h->intra4x4_pred_mode, row_mb_num * 8) || + !FF_ALLOCZ_TYPED_ARRAY(h->non_zero_count, big_mb_num * 48) || + !FF_ALLOCZ_TYPED_ARRAY(h->slice_table_base, slice_tsize) || + !FF_ALLOCZ_TYPED_ARRAY(h->cbp_table, big_mb_num) || + !FF_ALLOCZ_TYPED_ARRAY(h->chroma_pred_mode_table,big_mb_num) || + !FF_ALLOCZ_TYPED_ARRAY(h->mvd_table[0], row_mb_num * 8) || + !FF_ALLOCZ_TYPED_ARRAY(h->mvd_table[1], row_mb_num * 8) || + !FF_ALLOCZ_TYPED_ARRAY(h->direct_table, big_mb_num * 4) || + !FF_ALLOCZ_TYPED_ARRAY(h->list_counts, big_mb_num) || + !FF_ALLOCZ_TYPED_ARRAY(h->mb2b_xy, big_mb_num) || + !FF_ALLOCZ_TYPED_ARRAY(h->mb2br_xy, big_mb_num)) return AVERROR(ENOMEM); h->slice_ctx[0].intra4x4_pred_mode = h->intra4x4_pred_mode; h->slice_ctx[0].mvd_table[0] = h->mvd_table[0]; @@ -252,10 +252,10 @@ 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 - if (!(er->mb_index2xy = av_mallocz_array(h->mb_num + 1, sizeof(*er->mb_index2xy))) || - !(er->error_status_table = av_mallocz_array(mb_array_size, sizeof(*er->error_status_table))) || - !(er->er_temp_buffer = av_mallocz_array(h->mb_height * h->mb_stride + 1, sizeof(*er->er_temp_buffer))) || - !(sl->dc_val_base = av_mallocz_array(yc_size, sizeof(*sl->dc_val_base)))) + if (!FF_ALLOCZ_TYPED_ARRAY(er->mb_index2xy, h->mb_num + 1) || + !FF_ALLOCZ_TYPED_ARRAY(er->error_status_table, mb_array_size) || + !FF_ALLOCZ_TYPED_ARRAY(er->er_temp_buffer, h->mb_height * h->mb_stride + 1) || + !FF_ALLOCZ_TYPED_ARRAY(sl->dc_val_base, yc_size)) return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us for (y = 0; y < h->mb_height; y++) diff --git a/libavutil/internal.h b/libavutil/internal.h index 4acbcf5..9c4499e 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -137,6 +137,8 @@ # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,)) #endif +#define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_mallocz_array(nelem, sizeof(*p))) + #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\ {\ p = av_malloc(size);\ From patchwork Thu May 28 13:57:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19933 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 94F6144A156 for ; Thu, 28 May 2020 16:57:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 82DD568AF0D; Thu, 28 May 2020 16:57:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 162DF68AD9D for ; Thu, 28 May 2020 16:57:48 +0300 (EEST) Received: by mail-pf1-f170.google.com with SMTP id y18so13556209pfl.9 for ; Thu, 28 May 2020 06:57:47 -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=ynet0j1Tc87idiyqkVyqFFioOZYuS37yQO2TTNeFpEw=; b=pOao02UoKBJ9D+QGSdAdvAdLlUy8uUXmbbD4gDIofi049Y5IxNCgpXvJE5rXOzfyz8 w1otUjlku5c2jTAxzSNkkC9rJ6+V2QOqcJae4nSm94/GH30bBxghn9fZbRn9EJJx/mmU C+Irt7tZ/8X6quR7X4JYFyfCWgbUCZZWtPsOsv9MYaSm2qsxaIhXDM44z20VT15vZhK+ ESmQXocCI0ZQO+8pMDsD4gGoJFs32J/8E3J18nuTiTL/DMZr5IUjJ04Ram1pbQdX+Ym/ Ag+a+2k3M4RaVh/0pH7X5OnTt9AHgnuPkciYiXaP0jTQ42+bX1QN5R3XsDzm9RPZxofC 9KpQ== 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=ynet0j1Tc87idiyqkVyqFFioOZYuS37yQO2TTNeFpEw=; b=IdRMEZFtcKgyzMSfo7rVmRUgYQ9nNhPUuCqSkHbv+tRjMmRRUwWM99TbUC9S0XFhR3 sQKX0EV7Rz0gVwtUJEcV6v7U5U6s0IdQlg3yZMBGNGdUdtee3aBqlhdyNNsANVnM/SUM zS98uaWyDDcFtJ4Ui8IPhRDdtzRJMc0vYql4xOmXXMJQfDfdnP5ZTE3caoKJcaqYDwiD 7oNZJZs6bpNn3JWNpZxVfpn52EbgMvD+Bc6+YCxV7mzmUviFCMJZzGwLmDKwIpqifY/X ADdKRFtCfZtVKHc5uBdr0LweCj2AHzZ8vu9UYa2gRwEVe54h8yrG+uuL212TkzttspVp M6oQ== X-Gm-Message-State: AOAM5321pZVNlDbkKhXHwExK4Co3p7dKEdp8DoYxFJLM30PlkEbC/xF6 tZs3cOpat4JRPhtv49VT8uO0kwcV X-Google-Smtp-Source: ABdhPJw1fzi/8Yuk1l7kcrlib/F3EqISkbLJw3x0m3utATfUpxvvKIB4RHGzb5Eda2LtnpRV693nHA== X-Received: by 2002:a63:a363:: with SMTP id v35mr2852912pgn.95.1590674265816; Thu, 28 May 2020 06:57:45 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:45 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:29 +0800 Message-Id: <1590674250-32571-6-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 6/7] avcodec/adpcmenc: remove FF_ALLOC_OR_GOTO macros for gotos will be removed 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/adpcmenc.c | 25 +++++++++++++------------ libavutil/internal.h | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index d5fbc0b..bcb6783 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -89,14 +89,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) if (avctx->trellis) { int frontier = 1 << avctx->trellis; int max_paths = frontier * FREEZE_INTERVAL; - FF_ALLOC_OR_GOTO(avctx, s->paths, - max_paths * sizeof(*s->paths), error); - FF_ALLOC_OR_GOTO(avctx, s->node_buf, - 2 * frontier * sizeof(*s->node_buf), error); - FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, - 2 * frontier * sizeof(*s->nodep_buf), error); - FF_ALLOC_OR_GOTO(avctx, s->trellis_hash, - 65536 * sizeof(*s->trellis_hash), error); + if (!FF_ALLOC_TYPED_ARRAY(s->paths, max_paths) || + !FF_ALLOC_TYPED_ARRAY(s->node_buf, 2 * frontier) || + !FF_ALLOC_TYPED_ARRAY(s->nodep_buf, 2 * frontier) || + !FF_ALLOC_TYPED_ARRAY(s->trellis_hash, 65536)) + return AVERROR(ENOMEM); } avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id); @@ -523,7 +520,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* stereo: 4 bytes (8 samples) for left, 4 bytes for right */ if (avctx->trellis > 0) { - FF_ALLOC_ARRAY_OR_GOTO(avctx, buf, avctx->channels, blocks * 8, error); + if (!FF_ALLOC_TYPED_ARRAY(buf, avctx->channels * blocks * 8)) + return AVERROR(ENOMEM); for (ch = 0; ch < avctx->channels; ch++) { adpcm_compress_trellis(avctx, &samples_p[ch][1], buf + ch * blocks * 8, &c->status[ch], @@ -618,7 +616,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } if (avctx->trellis > 0) { - FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error); + if (!(buf = av_malloc(2 * n))) + return AVERROR(ENOMEM); adpcm_compress_trellis(avctx, samples + avctx->channels, buf, &c->status[0], n, avctx->channels); if (avctx->channels == 2) @@ -666,7 +665,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (avctx->trellis > 0) { n = avctx->block_align - 7 * avctx->channels; - FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error); + if (!(buf = av_malloc(2 * n))) + return AVERROR(ENOMEM); if (avctx->channels == 1) { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, avctx->channels); @@ -693,7 +693,8 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, case AV_CODEC_ID_ADPCM_YAMAHA: n = frame->nb_samples / 2; if (avctx->trellis > 0) { - FF_ALLOC_OR_GOTO(avctx, buf, 2 * n * 2, error); + if (!(buf = av_malloc(2 * n * 2))) + return AVERROR(ENOMEM); n *= 2; if (avctx->channels == 1) { adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n, diff --git a/libavutil/internal.h b/libavutil/internal.h index 9c4499e..485bc3c 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -137,6 +137,7 @@ # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,)) #endif +#define FF_ALLOC_TYPED_ARRAY(p, nelem) (p = av_malloc_array(nelem, sizeof(*p))) #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_mallocz_array(nelem, sizeof(*p))) #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\ From patchwork Thu May 28 13:57:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19934 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 457BF44A156 for ; Thu, 28 May 2020 16:57:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2BEF568AEBC; Thu, 28 May 2020 16:57:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39A1B68AF04 for ; Thu, 28 May 2020 16:57:49 +0300 (EEST) Received: by mail-pg1-f196.google.com with SMTP id w20so8479885pga.6 for ; Thu, 28 May 2020 06:57:49 -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=wkKKFaNOO5ZiI1YFSNGkxWC5j6DSs8zlYoaL/8VeJWQ=; b=lheLN1r79wrVLxqIQJc7xORNCXvdLXmFtQ6nbry4+wcvPq6ugW5c5IvwFnQqjujRyx IQSEISnHICmi/KOfezrJkXZv65KY330RCezBG/kmbuNRn0Rb14Rwb4WkPlX0CkTcNfYf hhN+7UW9oJBgrihhRCum1ZnWSW1SBmMHNkQcsWz2Imr0ZuMk1j6YvMWZ8G8YDoxZ/0vO KVv+ZY0GphDfRYEhM7Vyuv0GJntJXNBUVb5CuprquuaHO6vMgMhmqCMZ45P2PvslkIYL e/f8RUrmulhmLgShi/mWY0+C++0Dk1C9Ymu2H2n5IdVzgDpAbIIdwWUQ95Py30qDWjE5 2kbw== 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=wkKKFaNOO5ZiI1YFSNGkxWC5j6DSs8zlYoaL/8VeJWQ=; b=gBsFDH1IaTwp80m2+bh8Me+p+KpwJ/VR8PaOma3j4HD1Kr68klgkRkL8/v6ACzBpnZ S/Wyl+/XG11tn409/bxrC6uGTNKOzk/VUOUZoJcZmcZ5aTNFOmdwOJ7M+tThEPp6c1eg FBhPLZV/2eoJ6mvrK0lsrY2uA6odX+cmTvbVInxncknTswWreiCCLisWh6cEq9vnzWwx NqyamFnpuRoXoqOL3/6gmP2ykizRgme1oYuNLawcJJyfPYCnjkRG+aBVeDwxiEHZLbBr Dodu+pMD1TP+wu1XILJobyQEugDZeJc47lDSAkm4o6CoPhlNRhMPWWavv3iWRMPmJhnB i6lw== X-Gm-Message-State: AOAM532vFb39xxoV5S4PqhRTydbGzZchAkLMP5xwuQ2gVj6w4NgYFW9k RhE34Abc1h2cI9CwXIgcaX/5sK8x X-Google-Smtp-Source: ABdhPJyKh4TsqLoaSlkHAJp/nfABazk3sOUjjZBDgo3T4/A/72BhHqmNTeLiOQKlcxyhYBykLxk6Mw== X-Received: by 2002:a63:7f5d:: with SMTP id p29mr3000040pgn.337.1590674267398; Thu, 28 May 2020 06:57:47 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id x11sm1412118pfm.196.2020.05.28.06.57.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 06:57:46 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 May 2020 21:57:30 +0800 Message-Id: <1590674250-32571-7-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 7/7] avcodec/adpcmenc: remove gotos and error label 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/adpcmenc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index bcb6783..52f0f67 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -65,7 +65,6 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) ADPCMEncodeContext *s = avctx->priv_data; uint8_t *extradata; int i; - int ret = AVERROR(ENOMEM); if (avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n"); @@ -120,7 +119,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->bits_per_coded_sample = 4; avctx->block_align = BLKSIZE; if (!(avctx->extradata = av_malloc(32 + AV_INPUT_BUFFER_PADDING_SIZE))) - goto error; + return AVERROR(ENOMEM); avctx->extradata_size = 32; extradata = avctx->extradata; bytestream_put_le16(&extradata, avctx->frame_size); @@ -140,8 +139,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->sample_rate != 44100) { av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, " "22050 or 44100\n"); - ret = AVERROR(EINVAL); - goto error; + return AVERROR(EINVAL); } avctx->frame_size = 512 * (avctx->sample_rate / 11025); break; @@ -150,13 +148,10 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) avctx->block_align = BLKSIZE; break; default: - ret = AVERROR(EINVAL); - goto error; + return AVERROR(EINVAL); } return 0; -error: - return ret; } static av_cold int adpcm_encode_close(AVCodecContext *avctx) @@ -725,8 +720,6 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, avpkt->size = pkt_size; *got_packet_ptr = 1; return 0; -error: - return AVERROR(ENOMEM); } static const enum AVSampleFormat sample_fmts[] = {