From patchwork Sat May 30 16:05:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19988 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 2851544A6AD for ; Sat, 30 May 2020 19:06:02 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC741689EA6; Sat, 30 May 2020 19:06:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D3A6687F99 for ; Sat, 30 May 2020 19:05:56 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id r15so7112659wmh.5 for ; Sat, 30 May 2020 09:05:56 -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:mime-version :content-transfer-encoding; bh=OYrpX7tS9xq5ak4LoJZs0Rsj4m8AOpDPb8zpPXCj4H4=; b=tZMffwXw9EI+hgwU5Oxuawe7VJ1139gnWi3BU1TijyUIizFN1rvvI62LmzgEDGBmMz +NNGnuI634LzjfPg25M37KtJVNbaeWj8KP/Q0P2JCMGSO2GipPV/Voagb+yzDEAdiqT+ 7um62VpCMA4GEbwcUPHJIM60BuRe21DlBb7f6kB2OL7aQEVOTrf1Dy+DJapwhgvWgJdE e6qEWIYtZg6aOhow7VQ0tnEeYe+Vhzi9ND7TR1Biyx/jX3gBnUMVx2zLgawPIaE0lfvE V8UD7zcK+gWgEgzoaUU5uX8+w88ZbQQywFO9oFs/Hw75Oj/Y0GccnCHlS1UC+R1ugE/o MlvQ== 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:mime-version :content-transfer-encoding; bh=OYrpX7tS9xq5ak4LoJZs0Rsj4m8AOpDPb8zpPXCj4H4=; b=qIEduQF29UI4oRswBT5WmwGeAxf/rgZkx1ItX4WkcZ6wHvjUoXhF33pRt9R6X82ifp w7KAwXlgNb5LjY+5OQqQtUddJB+NvUVXqt9tSY6iKHOPZn9fI5bI9RbG/flExh+SM4D2 S2j36Fc4WzEc1Rt83NmeLEdu780K5kC+ZKNK5YsgPC6N3m2FoKPKmDI9toqyFbbDFkaB BgcfOIjSlgMBeFEQL+HP94Q33UiPcBkTgBx32dGcxkjMfF/00xlzpcNGh16OICMMMHAz qBv2mGwJZd+8E+SlvXsD4UXl7kikFdzVneSndAYBQRdOOiKQcPsLHrqIV4h2A7jWFoj9 sZow== X-Gm-Message-State: AOAM532YaKEYRC4W1mY0PxKWNeEb0u+A9MXLWFf4EUA9ChKFlPTT7UGk NX/+ID2e8iS7CDct1qPkihp/tccT X-Google-Smtp-Source: ABdhPJxVpJDwqEFBl2I6VR+/Z+s0fhtKX2p02DLR9P96lNGnTUeqSWNYUBk7YQgm3qn6rSkGWaV2qw== X-Received: by 2002:a1c:1904:: with SMTP id 4mr13219262wmz.125.1590854754515; Sat, 30 May 2020 09:05:54 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:05:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:06 +0200 Message-Id: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/36] avcodec/vp9_superframe_bsf: Check for existence of data before reading it 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index 57681e29e4..34a47aa69e 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -108,6 +108,11 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) if (res < 0) return res; + if (pkt->size <= 0) { + res = AVERROR_INVALIDDATA; + goto done; + } + marker = pkt->data[pkt->size - 1]; if ((marker & 0xe0) == 0xc0) { int nbytes = 1 + ((marker >> 3) & 0x3); From patchwork Sat May 30 16:05:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19989 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 158A944A6AD for ; Sat, 30 May 2020 19:06:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E751F68A800; Sat, 30 May 2020 19:06:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F55F68804B for ; Sat, 30 May 2020 19:06:12 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id r7so7251892wro.1 for ; Sat, 30 May 2020 09:06:12 -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 :mime-version:content-transfer-encoding; bh=Efe3bKu3KIwtRPWXrh+EnvIuDZGYfXq+PPAhhe3+1Ts=; b=jfMmyN2BPo7PcB4gxMKf2AqeYsn4+8HD3q4TZNUJQ8+zZd1drN1EXQW+erM/E2Wcwh I4BfDn6q1xIXhRSJPM8FPYUlX7Ic4+tX+HKZvQlTWT6u0siXJULmZFKMmh2TLP/qjiFY z7plartQU/8S0pfbpyTiq7qFXTzrLY5zyWNjVKtRG+gP+ZPNybEbn8nv0YvrQ4MEF7gK JEbrSe4dzeTlUFqnS2PNUzUpHlH7m01FmmGeBuabNsUvXNAL9qbcgi4K5A4CLZusDGrL DBXE907x4FXKx1Hyecnxml3GEKz0mOxl+ltwIuuJ7HLp29CD0Lq2a23iLZN+/zu6en37 7Bcg== 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:mime-version:content-transfer-encoding; bh=Efe3bKu3KIwtRPWXrh+EnvIuDZGYfXq+PPAhhe3+1Ts=; b=SYoYvLz6tNhQqN+LxR8Fk/vC5ss5TMOgEDypLNcvvxGULU66OG6X0b1ohLzcXzEQwo OYrlytlwhi1cyKGdkpF8ZeNIh2pzMhQ4dSgltpzeTas7R0l9YconXXkzVirryLHf8fwI bpcZKLub+10BAJzNrItw8w6krECoWdlOgw/aPsOfdiTuzZOQhBYhVBbzm6f/kiam7BHo G8hXjq3rbyde7YmUMUneIY76kjmkP4WUPtLLzEo7b4uH0aHJpSQOVMdDZX9ZdB3vES/b tOstrkb/d7f5TpuuYOJZqLdEdLKhlRSGWhyPnd5H5Lrc9yFtUduL8OCl5f++qyXkk1Mt Mikg== X-Gm-Message-State: AOAM533KX1ObHi39nyCzEgY/IGHSfKVa8Terx+i5Lf8PJvbKn0xh4Lww ai5I5q99soCLsrPLAHweedlGsAqW X-Google-Smtp-Source: ABdhPJyHbC7UxuxGXAQ190LqbTuWW5PgqJCnd3jZCHULno+JkuJySlR/Spv/r9pLy/hEIRIV3kpl2w== X-Received: by 2002:a5d:4e03:: with SMTP id p3mr14244415wrt.350.1590854771391; Sat, 30 May 2020 09:06:11 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:10 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:07 +0200 Message-Id: <20200530160541.29517-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/36] avcodec/vp9_superframe_bsf: Reuse vp9_superframe_flush() 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index 34a47aa69e..d9c78c67f5 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -31,6 +31,16 @@ typedef struct VP9BSFContext { AVPacket *cache[MAX_CACHE]; } VP9BSFContext; +static void vp9_superframe_flush(AVBSFContext *ctx) +{ + VP9BSFContext *s = ctx->priv_data; + + // unref cached data + for (int n = 0; n < s->n_cache; n++) + av_packet_unref(s->cache[n]); + s->n_cache = 0; +} + static void stats(AVPacket * const *in, int n_in, unsigned *_max, unsigned *_sum) { @@ -102,7 +112,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) { GetBitContext gb; VP9BSFContext *s = ctx->priv_data; - int res, invisible, profile, marker, uses_superframe_syntax = 0, n; + int res, invisible, profile, marker, uses_superframe_syntax = 0; res = ff_bsf_get_packet_ref(ctx, pkt); if (res < 0) @@ -166,9 +176,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) if (res < 0) goto done; - for (n = 0; n < s->n_cache; n++) - av_packet_unref(s->cache[n]); - s->n_cache = 0; + vp9_superframe_flush(ctx); done: if (res < 0) @@ -191,17 +199,6 @@ static int vp9_superframe_init(AVBSFContext *ctx) return 0; } -static void vp9_superframe_flush(AVBSFContext *ctx) -{ - VP9BSFContext *s = ctx->priv_data; - int n; - - // unref cached data - for (n = 0; n < s->n_cache; n++) - av_packet_unref(s->cache[n]); - s->n_cache = 0; -} - static void vp9_superframe_close(AVBSFContext *ctx) { VP9BSFContext *s = ctx->priv_data; From patchwork Sat May 30 16:05:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19990 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 1F7AE44A6AD for ; Sat, 30 May 2020 19:06:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 039EA68AD79; Sat, 30 May 2020 19:06:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 85F586898AE for ; Sat, 30 May 2020 19:06:13 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id c71so6672606wmd.5 for ; Sat, 30 May 2020 09:06:13 -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 :mime-version:content-transfer-encoding; bh=2Lh/CjjvsvvO2qZ3Z+Q83ET+OBiCGqn1dMl3DZ68I7w=; b=gFSM/xzhcGQE+DfIrtxrypO2H9gFvvnqLplnOmL83HkLZtYSB8WTS3BOXezK0tBNMD mRGL0sw7lehkdaKIBXfkMzxo7QKCBxyOgJPImn633Jpk2l3QhJ+wPm4PRBRj8rHuAFMw NFqzGMXix+vWWhrDwTwy+1A+HTSYhToPYd27NY4+AmFJ3k0IvyIxFg9i3Bd9H60DidVs n7cA8XnCR+gLHM8ax9uonnRx+rlet5+qtsjXlXG4+Q87pQAfuNExi5DdEgx40hS+V2na P8U36EeHb9IGz6qJaTLzX0N+hNxzIlrmalEh4fuzc+W0qnxZd9znZ1SivKg+fgKdwar1 B5zw== 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:mime-version:content-transfer-encoding; bh=2Lh/CjjvsvvO2qZ3Z+Q83ET+OBiCGqn1dMl3DZ68I7w=; b=Fk9zGJwnst74FQBYz2vJ4jIa24iNTu4w4WOYF8Mq4gKiSJWYOJnznTQlTTsmVDLyx+ PbCMKqNBCy4fUkM9gWcVt4HfIq8/nKTjP+nU5UXnNyP9N+WQmutXANKvFYfFZiCIsJR4 KfPk+oL9DkZ1kKLgdGKBQK5DG7NH6NnBvKZFSWbi0+eCGj9mlwKyHMu54TlIhmb5WmjX g2lehB3Sl3JIutoXohOZxiIs5M9DA7SHXJWsoIBJZT2kwvdTr3n+xuhZloaEqN+5svMm p33uMQUTyqmKj8pGRUgohMx3yA7EQRfeI4VPZYiDssNELxPeM5sRiyBqzAePGRlCF7u4 2igQ== X-Gm-Message-State: AOAM532Y2HhA3BLz79h0j6K4NE9Zr9fIEf8A5nrB6wJ7g2+B2NrEvoev fHJHT5sycc6G5BFBTGYRpBVMpK/b X-Google-Smtp-Source: ABdhPJysZPP2PAT24N41oYyQYk4OhYw1kGhVt7SRQOQCAhMQ2zrkq1qiyARtTydQoQhMNVxyqr4xcw== X-Received: by 2002:a1c:2183:: with SMTP id h125mr11980848wmh.88.1590854772536; Sat, 30 May 2020 09:06:12 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:11 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:08 +0200 Message-Id: <20200530160541.29517-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/36] avcodec/vp9_superframe_bsf: Flush bsf upon superframe creation error 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Otherwise we might come into a situation where we have to reject future packets because the cache is already full. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index d9c78c67f5..f330970acc 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -169,12 +169,10 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) av_assert0(s->n_cache > 0); // build superframe - if ((res = merge_superframe(s->cache, s->n_cache, pkt)) < 0) - goto done; + res = merge_superframe(s->cache, s->n_cache, pkt); - res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]); - if (res < 0) - goto done; + if (res >= 0) + res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]); vp9_superframe_flush(ctx); From patchwork Sat May 30 16:05:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19991 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 1B9BA44A6AD for ; Sat, 30 May 2020 19:06:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 02C2768A953; Sat, 30 May 2020 19:06:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE0A168A953 for ; Sat, 30 May 2020 19:06:14 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id l11so7259280wru.0 for ; Sat, 30 May 2020 09:06:14 -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 :mime-version:content-transfer-encoding; bh=A3wTP00qmlo44bNPlpG2GF5jHjok66mMdeSupQnCmJw=; b=tyoPNv4N9/03TKQ2zmLqXyy/trTeu9B1dgOXL7RfYtHAyMIoQyEkaDqdPrlNWHXmN0 vKGVpjq9ipNnq0KLEGzc0ydebAkNUEjZED36VZKmM8J0TfUbU7VyYXtEZPQc6zERT9IL 6/igLye+m3Iu9Cfj2qzi61igzV5YhUMbdGG64NvHIku4kl3qEGUBzQQdb71aLnDtvgHx jhNsLh7dr1E3BStsWA20I3qcShIWtO8RvnK2Oiqp4IkzO7wTjhG74kv+rTPXMrJ1RydF ZTSOsjoYCtnOM8uW2lQtJxqg7YWiNFJSHul+Xn5JwqHVrg62jEqhXzjGt2PFPW64AO7o MYtQ== 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:mime-version:content-transfer-encoding; bh=A3wTP00qmlo44bNPlpG2GF5jHjok66mMdeSupQnCmJw=; b=DOeOdJJ54ftXWFqdzAKMasffPglBRZp1NHGEFPc/0qmGmX+QdJiHN+AfDNHT+XSpId RBwrq//YbZz1YHNYI6O+1Ta56yr2Dpb4Rrl9MSBeE2uR+vfKQEnVglcFY5VUalKWOJBr ueMAs8ScdxUbcFi5rT9PVvBgGs4EFzFfNVpPsHUe0srg3SuTdXwPV/TtzSuHgSPweJJf z8uzhd66IeTRcYBEnsdhScwNntQqyvvgmEoNgORVHR3vLqLqtGhpJG3tYBzfnlCa8Ga+ V9ovjawU4LP7jAor5mppJfiVSNCrTS/6P1oO2h3EC/HO5WMzhDzxfb7mWKBTA+pGSUGl /bHQ== X-Gm-Message-State: AOAM5309cJegrKTMuQnPLwwLCC+X4HGRQ3PIKhRjVZEFtqIRpza1mod1 M0qxwH8cXt4L48bogdxs2BYPtdau X-Google-Smtp-Source: ABdhPJyFqnqd+RJUKkfYfDUxezlOqL5GUyEbyD6wSgz2b+r1vBBsBWbWqBXHGiwZvSNeQnnL/X8eHw== X-Received: by 2002:adf:f84d:: with SMTP id d13mr12887541wrq.99.1590854773883; Sat, 30 May 2020 09:06:13 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:13 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:09 +0200 Message-Id: <20200530160541.29517-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/36] avcodec/vp9_superframe_bsf: Check superframe size for overflow 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is not dangerous now, because init_get_bits8() already restricts the size of each packet to INT_MAX/8 - AV_INPUT_BUFFER_PADDING_SIZE. But it is nevertheless better to check this explicitly. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index f330970acc..a8b58a7fd3 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -42,10 +42,11 @@ static void vp9_superframe_flush(AVBSFContext *ctx) } static void stats(AVPacket * const *in, int n_in, - unsigned *_max, unsigned *_sum) + unsigned *_max, uint64_t *_sum) { int n; - unsigned max = 0, sum = 0; + uint64_t sum = 0; + unsigned max = 0; for (n = 0; n < n_in; n++) { unsigned sz = in[n]->size; @@ -61,15 +62,18 @@ static void stats(AVPacket * const *in, int n_in, static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out) { - unsigned max, sum, mag, marker, n, sz; + unsigned max, mag, marker, n; + uint64_t sum; uint8_t *ptr; int res; stats(in, n_in, &max, &sum); mag = av_log2(max) >> 3; marker = 0xC0 + (mag << 3) + (n_in - 1); - sz = sum + 2 + (mag + 1) * n_in; - res = av_new_packet(out, sz); + sum += 2 + (mag + 1) * n_in; + if (sum > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + return AVERROR(ERANGE); + res = av_new_packet(out, sum); if (res < 0) return res; ptr = out->data; From patchwork Sat May 30 16:05:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19992 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 3D0FB44A6AD for ; Sat, 30 May 2020 19:06:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 252B868AB98; Sat, 30 May 2020 19:06:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A06B68AD9D for ; Sat, 30 May 2020 19:06:16 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id u13so6717160wml.1 for ; Sat, 30 May 2020 09:06:16 -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 :mime-version:content-transfer-encoding; bh=wPWoPmd9DXbqrbjbcW9RPPlWFxsDfB3oJouoA4+iB5E=; b=hozG/1Li/TI1x/1bMlh5UWh90meKGvV7bKY7541jTVCbrKOUIWK/s4eEbwxNLro+/3 lU6/2rVchrKuNyOkRBaMgorGzNyz+8LuP96xnXDso0xV8HWU5zazR3UEEkw3oBRiUUPD eNUCBd5l4FWj/AD4KcszxckYe5ym8zJnfVopbxzV1R3il46frIdd2Xc89wZZ5ggzzoFA yQmsJpUV0ZaRwDU9cPwA5YAa8ByvSw4FmnwOTnwMb8IzPu4qO6bUnpDvty2WrjRCFN4W 7yCCXAd2P7xFeN0OV7Oz9KcquUarqTcdgQR93sn0w8kfWTLQH2SUajd8WUXPNMrqQ8Bq YQUg== 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:mime-version:content-transfer-encoding; bh=wPWoPmd9DXbqrbjbcW9RPPlWFxsDfB3oJouoA4+iB5E=; b=N80YoKu6ohRBXs5ichuPSpy6H5ezy1IBB7wAJ4qP2jgO2eo+j+QR5OUA9EQStvPyiw q/fR5ee9UR9NZagU7LZoUsaMEekvJ22tFMhgW1v6ufjJoqfDabj5/2ol/CRbbHRO1MtW 6kp1bHxY49TD2WHhm2/MD/ssutSs7Vp1r34qlLu99GFLbe2LrfXRp6ikMWmo3KywuBRL JUqafNjmcBWU+tbr/2IIEECJq82Psgq88WkuLtimQH3K+fxXX+H2BYGcpeDOn29EWEcx H6m+K+h3gLKc4vP6mqW9yBhngjg7lJgreN7FeImALXvK0XCABWWt/nMQdoWN0xRTvNds U5fQ== X-Gm-Message-State: AOAM531DZ/KmA0n3mVkww5300ghBIFGwPxXvhy8rwVEsj8Eki1zfI8bR jReFqNEIuRePw4ADrki88Z58GKB/ X-Google-Smtp-Source: ABdhPJxPcbssQhqi55rDbJeuhRfDAKXHUIe5XmJohPupS+hEHYWpQo9++H5DP/Rw7XU86F/SJp9D9A== X-Received: by 2002:a1c:29c4:: with SMTP id p187mr13637192wmp.73.1590854775153; Sat, 30 May 2020 09:06:15 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:14 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:10 +0200 Message-Id: <20200530160541.29517-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/36] avcodec/vp9_superframe_bsf: Allow up to eight frames in a superframe 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Up until now, the bsf errored out with a message that there were too many invisible frames if there were already seven frames cached even when the new frame was not invisible. This has been changed. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index a8b58a7fd3..a7faad3abf 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -158,13 +158,15 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) } else if ((!invisible || uses_superframe_syntax) && !s->n_cache) { // passthrough return 0; - } else if (s->n_cache + 1 >= MAX_CACHE) { + } else if (invisible && s->n_cache + 1 >= MAX_CACHE) { av_log(ctx, AV_LOG_ERROR, "Too many invisible frames\n"); res = AVERROR_INVALIDDATA; goto done; } + av_assert0(s->n_cache < MAX_CACHE); + av_packet_move_ref(s->cache[s->n_cache++], pkt); if (invisible) { From patchwork Sat May 30 16:05:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19993 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 2D3BF44A6AD for ; Sat, 30 May 2020 19:06:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 136D868AF77; Sat, 30 May 2020 19:06:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3FB8568AED0 for ; Sat, 30 May 2020 19:06:17 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id x6so7098823wrm.13 for ; Sat, 30 May 2020 09:06:17 -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 :mime-version:content-transfer-encoding; bh=74cO64PdOvc353Iu9rysAKS42vVJWjsrgatzzfofQh0=; b=dO32kpacSvpTEIzc9FKFEvfapcusjYvHhgH9FLt8prTyQBsoa37aolKUagBoYnzMqk NN8gI9/iVf2A/wsjGsZ+QaHeYAjsHtxxUNJMIs4JEc/qYkP0K0PSPGZzovNxr8PLiaGn XEVYL23ArFKCKGD1XiFxTjZS0qKNAqM0/wv6WpapGoNBuDIHIrrnN9hfUddwXYxXeMCs NDBlSJIs/tPx0KwNHLSQXkyR2aEA/Ykv6tA6e8VunSiFBcjgyd0JIHy8cCAn/Hi+AQbk iNCnrGnmp39onHSWipiL4IQ3RZXfQ4PH5U0l7Tis+AuENk7wu1WfqWkIAYSCOI74iy4S o1hA== 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:mime-version:content-transfer-encoding; bh=74cO64PdOvc353Iu9rysAKS42vVJWjsrgatzzfofQh0=; b=KESQ+JEPE0aHQ6mK7WUMzz0g1JtJtId7Wkd4l+48nwJ9Rd0fP9vBXyp/N8P4W1aqfu hwBtR0+A/jdnoNGjLMJpC9TnuRTvIhk+vQfTsqoTyRg8f6+t3+/azs1Dxz9rfuarWzX8 TyX5+Lmqwi+MxesHXxj4lCCuA0501axmh7/UpLdq8iDYFZrCdhtj/sXFBLXVOe60Uju9 Rugeg9LU8xnO0+scm26QkQGTE9rAKCkk/GO2kAxG6KUbNoySG0WpwMXJBpCcDhOwIUFX 2sJ3MPacJ8srxqlgtaZViEkcL2KOWe1S0Ctd6xmQ4PAD8hFD77usIAg+Q6S4jAxkH3Fv P6dg== X-Gm-Message-State: AOAM533qNlifYF+J22zRnBtrKGOW7hXHIUEU4DuBbQLaVhxiBf3mTQsq 4ijKr7RLTLO/EiOMwUI/8L4UI3hu X-Google-Smtp-Source: ABdhPJxDwtxqEuBhLT0jGiOnw7i9q1dLn1r5Eb8NgvDHuZNuvAQBauqNbf+stJdiZoidxH0qZSZlSQ== X-Received: by 2002:a05:6000:47:: with SMTP id k7mr13238722wrx.233.1590854776290; Sat, 30 May 2020 09:06:16 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:15 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:11 +0200 Message-Id: <20200530160541.29517-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/36] avcodec/vp9_superframe_bsf: Don't restrict packet size to INT_MAX/8 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" by opening a GetBitContext on its data when all the info one cares about is actually in the first byte of data. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index a7faad3abf..29d1c759c7 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -135,8 +135,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) uses_superframe_syntax = pkt->size >= idx_sz && pkt->data[pkt->size - idx_sz] == marker; } - if ((res = init_get_bits8(&gb, pkt->data, pkt->size)) < 0) - goto done; + init_get_bits(&gb, pkt->data, 8); get_bits(&gb, 2); // frame marker profile = get_bits1(&gb); From patchwork Sat May 30 16:05:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19995 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 1ECF444A6AD for ; Sat, 30 May 2020 19:06:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC9D168AF22; Sat, 30 May 2020 19:06:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F56468AB98 for ; Sat, 30 May 2020 19:06:18 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id r9so6704346wmh.2 for ; Sat, 30 May 2020 09:06:18 -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 :mime-version:content-transfer-encoding; bh=+uQBKEE7MNB3VE3pN68H25c/a3cfXlXIUN4GnAiFagE=; b=p5e4iR7kGgtQL79kNvZ4YBSqHHsotaGJURf6wJND08w8PQgct33164obkndEhImWr4 oqq6riDZNWSgnIpzMuEnaTGJxOxfYnB+WOvihJmN/RdSoShqYEXuhAqGUPYGgvV+Fbo/ AvLVSq6/FiTQATsXYQv5wC6ltoZdh1O/bzkIjLu3DV+KYnK7L2UmlM8BHLqi7NUsOZz3 D1llvdxkltcszf9QlXar4nDg56OoUgRoy/IlTLDZ+QHz2seM1jsIuyzeFTOEiJJMRwln vK1I9ks5D0vjd43bxi/kCC/STU7ZznRTjHUtRRFgsq5VnKjmX0bGOrgHU1uZpZUAzuW9 JDnQ== 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:mime-version:content-transfer-encoding; bh=+uQBKEE7MNB3VE3pN68H25c/a3cfXlXIUN4GnAiFagE=; b=jrdVEXkvSYo6JDXawJdGosyjolxh+3wniR35JwoEozsM5ZB/9A5QEpJE3HxYWz1HF1 sHCuiwkr96PMF6G0O3JakI+xJuaJZdweBBQSwJ6VkxOEE3dJ5UYJ7boZQyU/2g1cvJz+ OjRgD3Xu+4SOM+n+7fIPFOmcBNsBM48AfErHSu2RU4Y0iKDf6sKFUnUpQT5dSXikZABW Pjw4HNowQrNYMCAS4taPrLc5vuIvDRq7V7f8ntPkMLef15/74RPKtfU8Mrijt2sSNrzo jtI5fse0LZ0gwGbUf4AuZYG8EWZjUaHPvdP8hgUAQakDnt2ZlRFsE5Q0u+iuHgfiCQaH JzBw== X-Gm-Message-State: AOAM531fdzLhQPSb6XSlU/ad1FmgDCI60zlD4rJwb1AY0CuwhtBL3E5w KrtkGa8DFWwO5/6Eu+sFtDd8sA/6 X-Google-Smtp-Source: ABdhPJxMGk6NdVUx5F9E8tf2RIKCOhJ9AbIJrw1GA4wo7QLs3AsD/Lig30edJZ+SLO644BaMqmG6tA== X-Received: by 2002:a1c:b654:: with SMTP id g81mr13464596wmf.128.1590854777552; Sat, 30 May 2020 09:06:17 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:16 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:12 +0200 Message-Id: <20200530160541.29517-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/36] avcodec/vp9_superframe_split_bsf: Discard frames with size zero 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" They are invalid in VP9. If the packet given to the bsf has a size of zero, it would try to access pkt->data[-1] which could lead to segfaults. And if any of the frames inside a superframe had a size of zero, the code would either read into the next frame or into the superframe index. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_split_bsf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/vp9_superframe_split_bsf.c b/libavcodec/vp9_superframe_split_bsf.c index ed0444561a..6ebecfa8ae 100644 --- a/libavcodec/vp9_superframe_split_bsf.c +++ b/libavcodec/vp9_superframe_split_bsf.c @@ -51,6 +51,11 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out) return ret; in = s->buffer_pkt; + if (in->size <= 0) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + marker = in->data[in->size - 1]; if ((marker & 0xe0) == 0xc0) { int length_size = 1 + ((marker >> 3) & 0x3); @@ -70,7 +75,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out) frame_size |= bytestream2_get_byte(&bc) << (j * 8); total_size += frame_size; - if (frame_size < 0 || total_size > in->size - idx_size) { + if (frame_size <= 0 || total_size > in->size - idx_size) { av_log(ctx, AV_LOG_ERROR, "Invalid frame size in a superframe: %d\n", frame_size); ret = AVERROR(EINVAL); From patchwork Sat May 30 16:05:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19997 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 62B5344A6AD for ; Sat, 30 May 2020 19:06:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4FA9368AFEB; Sat, 30 May 2020 19:06:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 93E7B68AF6D for ; Sat, 30 May 2020 19:06:19 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id c71so6672756wmd.5 for ; Sat, 30 May 2020 09:06:19 -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 :mime-version:content-transfer-encoding; bh=g+qUsPKpzdfyWLDONR49j3TXTwJjKF+DmOHB09tb/vo=; b=ThHsBQxz+duwCFBPk70PJqiTmglekR9sADgQ5yfMN8Q9hNxyms905nA8L7F0rZT+aG mj4JWXfNGjYVdRHwg0c29Jf07yBmN5uGlzh80zKktXvckE5JoiVqN5UrEvvhpNMS0eOr AdwtFOXMPoeVDwbtrI3hlr3AqWFcOAJjbWQ/2/Vg7ctdUG4/90wl0/rRRDeOyH6pJj6T mxCfofEuVQ8kBZIP+2N+tLgkNGyt6AtafNt1lJqcx9N3r2AzemEhu7GJW+KO6Z0wtdrV xaIYm10KNk7bHFguyBfN/EwUDeTLaQSu9eiNUFJx+0S9X3hswQAr1AudAWOwUFfjhOg9 sSGA== 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:mime-version:content-transfer-encoding; bh=g+qUsPKpzdfyWLDONR49j3TXTwJjKF+DmOHB09tb/vo=; b=iamcwJhLSCPRVxK9sAR2jdg2bb5EFKrMrvfh3mbSMhZJRz12fsKeL3aCG4KTxtWxkB dxiiqwFiqIggTHFNB8Pfxn8Fm3JFzxWSd7dWGb6qN1T0QBIbMP3p/FqIeQy6D56z2ZhE qO6z2DxCuX9WnZAs0YrBaEawifJHOXhIiJfHMy3DOW1DlB1hZTC6DcXy/hvcgUcx806N ulBpYr3OVMhjZfRPB3AGJ63h7d2sqjpQ61F9xrgrhqZppTaEWHx1Qxq7PAKWOy762W/F RKT2Sy4NoDAWn/COXymjZqWzPIVvn9NrPqSmjQI8T7hSw5DlAcqOXbCrCy6eV2j9JlqB V48Q== X-Gm-Message-State: AOAM531ku5BjEt/NZZQQt7z0wVk93IwHzJ5ISTEluxDbQCtPWMjsmfLA a1RcEh/z6USpiNDNWtVmvbPirdxt X-Google-Smtp-Source: ABdhPJxzK15C+CQ+qrGr4ghhc/Jta75X2rmncEpdox8PHyuUicfpeIdI32A4hN26xxpNzScO7MUJhQ== X-Received: by 2002:a1c:230a:: with SMTP id j10mr13468815wmj.124.1590854778703; Sat, 30 May 2020 09:06:18 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:13 +0200 Message-Id: <20200530160541.29517-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/36] avcodec/vp9_superframe_split_bsf: Improve returned error message 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If a parsed frame size happens to be so big that it is negative (as an int), the size in the error message would be negative which is nonsense in light of the fact that the size field is an unsigned value in the standard. Change this and also change the type of the variable to unsigned. Also return AVERROR_INVALIDDATA and not AVERROR(EINVAL) in this case as this is clearly invalid data. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_split_bsf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/vp9_superframe_split_bsf.c b/libavcodec/vp9_superframe_split_bsf.c index 6ebecfa8ae..df5b964414 100644 --- a/libavcodec/vp9_superframe_split_bsf.c +++ b/libavcodec/vp9_superframe_split_bsf.c @@ -70,15 +70,15 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out) nb_frames * length_size); for (i = 0; i < nb_frames; i++) { - int frame_size = 0; + unsigned frame_size = 0; for (j = 0; j < length_size; j++) frame_size |= bytestream2_get_byte(&bc) << (j * 8); total_size += frame_size; - if (frame_size <= 0 || total_size > in->size - idx_size) { + if (!frame_size || total_size > in->size - idx_size) { av_log(ctx, AV_LOG_ERROR, - "Invalid frame size in a superframe: %d\n", frame_size); - ret = AVERROR(EINVAL); + "Invalid frame size in a superframe: %u\n", frame_size); + ret = AVERROR_INVALIDDATA; goto fail; } s->sizes[i] = frame_size; From patchwork Sat May 30 16:05:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19998 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 7DE4244A6AD for ; Sat, 30 May 2020 19:06:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6222A68B01A; Sat, 30 May 2020 19:06:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F78668AF9D for ; Sat, 30 May 2020 19:06:21 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id c71so6672796wmd.5 for ; Sat, 30 May 2020 09:06:21 -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 :mime-version:content-transfer-encoding; bh=MGbXr8ScFT/REdSDUQ/AV+dATEHB4DGXbln6RvcDHg0=; b=L1gAEEKELoeQyqCMxj5s5MIm86witebyioAFRbg0i7GpS/zSkpIDLU9jyUhWSe9XFL tyb8+4xOhDm0JCZzmNC7RoJoDxHRZbWnqBw/6EgAEwMpvF8qdy34t7H4e99AZbnSKQv3 Jk2Lv4foftMX1Zh+EtwJvA/Nq5gdR0d3jlR3vAiKOq24Fk19i53T32VDzrXVWHOi4fAL 7tX9BSS9uulfnxMx1hR6OrlUPBdLzegb88pPIZoVqfFdOLMQIqysBdVVIA1ANRi60yen oPlHg9KfXTLRo3/9FEpZ9Q+XFfv5VKU333YG+GLIRog3ncurU9zzsEPD0XhhRfxBafEs 7tPg== 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:mime-version:content-transfer-encoding; bh=MGbXr8ScFT/REdSDUQ/AV+dATEHB4DGXbln6RvcDHg0=; b=TySWrXW+YsY9ByxIDi50mX1k8+5NUMy0h18I9OcO7qDTJHmzZipRduClHXcTI6chQs w7HC1+fvA609ANFuC4JlzMgc797apYl2a4iYbIg4PpP7J2LIrhN1swt5iXu8/2uj9i2G TuwcSSVk5nK8TbBpUw19m7zVMK1v/X89eR9tP8RiCnxWY+F5FOjWjFPPXHLc1mOkMjaF 5Yj50j3aCg+RTOUQRV46sivNEqRUzH3+CpDZXBfczGgzMx67FjOB4QBZCton5zn9+EPe Bp3Zll5VfYs/5jNUyPNb/1tkJCtBHZ+ILLUSv57wBHCt8YtUqfbaLs+97E6CLBmjtKV8 FCDg== X-Gm-Message-State: AOAM531lHuqjFKXHvNXLB9oaPEDsOaSkoJKm1EylN9na1dysrrouB0bx GGQsMOnsKAXWp65EoupiGhVt12/8 X-Google-Smtp-Source: ABdhPJw06HP4h5kbmNx33cY8Rqv1KVBT6KxH3EAeBmyHOt2RQtXW0C9M7vd9yMXHYrWMrhIvC8GLeQ== X-Received: by 2002:a05:600c:34e:: with SMTP id u14mr13836355wmd.16.1590854780174; Sat, 30 May 2020 09:06:20 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:14 +0200 Message-Id: <20200530160541.29517-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/36] avcodec/vp9_superframe_split_bsf: Don't restrict frame_size to INT_MAX/8 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" By using a GetBitContext with a packet's data as buffer, one restricts said packet to a size of about INT_MAX/8. This restriction is not onerous, but unnecessary: The bitreader is only used to read the first byte of data. So change it. Furthermore, given that it has already been checked that the packet's size is > 0, one can omit the check for whether init_get_bits() succeeds and stop unreferencing the packet destined for output on failure as it now never contains any data upon failure. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_split_bsf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavcodec/vp9_superframe_split_bsf.c b/libavcodec/vp9_superframe_split_bsf.c index df5b964414..48c3723206 100644 --- a/libavcodec/vp9_superframe_split_bsf.c +++ b/libavcodec/vp9_superframe_split_bsf.c @@ -108,9 +108,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out) if (s->next_frame >= s->nb_frames) av_packet_unref(s->buffer_pkt); - ret = init_get_bits8(&gb, out->data, out->size); - if (ret < 0) - goto fail; + init_get_bits(&gb, out->data, 8); get_bits(&gb, 2); // frame_marker profile = get_bits1(&gb); @@ -131,8 +129,6 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out) return 0; fail: - if (ret < 0) - av_packet_unref(out); av_packet_unref(s->buffer_pkt); return ret; } From patchwork Sat May 30 16:05:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19994 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 DBA3044A6AD for ; Sat, 30 May 2020 19:06:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C52C168AF9A; Sat, 30 May 2020 19:06:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD79F68AEE4 for ; Sat, 30 May 2020 19:06:22 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id r7so7252188wro.1 for ; Sat, 30 May 2020 09:06:22 -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 :mime-version:content-transfer-encoding; bh=8yrNIZjiZQCKan6uZxvNiZk7AsgEjvTMGXiXhYVmpG4=; b=QG/NyNAGxPtadcRfPe1KgftFAeHdsltSWrpOKnqqU0hTjfJoGNd3pIXlm1fvfRWNqt a/dt/CTaW/Bq0M0pnM0MtRnR+FESImd6u3O/Yaz1vkEjVnT8j/W1UeGZtanR7R3Wrl5W 4Ctcvgrz7YayxhowkP/NiaD1zcDY28/aFW7qosKWqsU6Yu2nnXTlwJqshpJEMsnFlYlk rZC8Rb/2YL2ZvdAgZvtTPI3ZomeW99FS1GkemHsyPxs9Ja0nz1HGtSUZjRRdGGbKYdwM 9r+SQ3dQhoU3nYCUu1OSfAJmGC5jZIUlsDADxTJPWEqKkX7LLBkFRTvur+bb8GoZW9w8 YFmw== 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:mime-version:content-transfer-encoding; bh=8yrNIZjiZQCKan6uZxvNiZk7AsgEjvTMGXiXhYVmpG4=; b=B3UqTISjnUw3oQQZNwpySiGBpsYFAlFE4CVMCih1NYLKUZ3pvNEvT+6FI9ayAln0EA M4tZSKFsy/VDlbl8p4txOhHdzbOjgN1ONuESKIr9rJCXNNRAJDaCHpSg4o1OiAANWV9S A9iaEN/jASUiUAoRxEdGHjcwyIKNr9qx4wMQhcRfSgte99aPmPOlW3+44wVb8wzDWqog mjXVyMghgVnko1LoAoKBER9XX9cUw1B/NJ4AaSOvF+bYwHBkH7l5F302RMchjXQrtsGf JHkch3UpU3f20+deRbeZ+3QhdPp29TzhguWfaAPtRy0+UGOFLeqAQGO50BVwfJvxDvGB lJug== X-Gm-Message-State: AOAM532ehjwlfYj7QEuOjQlbj/yKgEJ2Bfat7LgxIdFhkWMSp7sxjxUN ywnWWM/p0Fedomxv0Yj36vAyK3aE X-Google-Smtp-Source: ABdhPJzzvD+hikxRQwe4PcdfPsLQnuHfinza3hFJ7jStyC+E548fDyrSi9TVHY5u0NeE81xq8Be4Aw== X-Received: by 2002:adf:d0d0:: with SMTP id z16mr14197025wrh.308.1590854782044; Sat, 30 May 2020 09:06:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:15 +0200 Message-Id: <20200530160541.29517-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/36] avcodec/vp9_superframe_split_bsf: Use unchecked bytestream reader 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It has already been checked that there is enough data available. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_split_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/vp9_superframe_split_bsf.c b/libavcodec/vp9_superframe_split_bsf.c index 48c3723206..9f9e495bd5 100644 --- a/libavcodec/vp9_superframe_split_bsf.c +++ b/libavcodec/vp9_superframe_split_bsf.c @@ -72,7 +72,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out) for (i = 0; i < nb_frames; i++) { unsigned frame_size = 0; for (j = 0; j < length_size; j++) - frame_size |= bytestream2_get_byte(&bc) << (j * 8); + frame_size |= bytestream2_get_byteu(&bc) << (j * 8); total_size += frame_size; if (!frame_size || total_size > in->size - idx_size) { From patchwork Sat May 30 16:05:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19996 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 2BDE844A6AD for ; Sat, 30 May 2020 19:06:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0949668AFBB; Sat, 30 May 2020 19:06:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C28E68AD72 for ; Sat, 30 May 2020 19:06:24 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id n5so7154636wmd.0 for ; Sat, 30 May 2020 09:06:24 -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 :mime-version:content-transfer-encoding; bh=+Slcmqy90rOdM6ofrhyrDElnSc1XoOeISCAPq8TqAUc=; b=TzLuKlyHiWaejf6VpJjCFhI11uZ8dryZcEnGzASSmzl0HE5Sq83SOa0ehxMJYfzPyz iT16n5COOzya08ax2Fgf7TL0tb751IiweOQ2nEUmEj2WFvk7jvRr6wJEXgro5dl2SM2d VhfqHBgLXmW5bScbBSpWXo9ScqqTEDnu4Royt38SXOIWMyHwM3HYVvdRsI4vwdGmH1EQ WDnhdXNdE9WrJVZFL4FpcdJ1EVkTgDcnojS4qSAwh7IkUGBxop7NKU5eWTgmUmNXaBRj vsn4bDnxfrzgbck9vW9qxSb/WCTik2UxSqs3wDBMi6+WGJSwLmnviDpoZFuE+4JiRMK9 iQeA== 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:mime-version:content-transfer-encoding; bh=+Slcmqy90rOdM6ofrhyrDElnSc1XoOeISCAPq8TqAUc=; b=RqwrPtFgoyCjPnj0XHZCaHYQW1aaET1pYBwuh5ZK26/tfgkX8Dw93YhdSx5eVdMj59 Lv2Q+VZzUMdUmMPo4h4gQKRkXH1x3gw1xdoZvBiHosk1whP/2Ymjt3R48TTZ6kRnhx86 5ufhIB0wrDJI3U724D+6FWwrI2lL00bzv2n5Cq6axBuL3UhtJSOs4/jbTsmCOCje03SB ayXwTBMuhTx3KKp4QHwVkXIV3qwuUBIX6UGR4QvQjU8chpRJdxmxVCfT0NRxYnfIZySs A9L/TkCevKwRwFkrT++mQf5iVW4g/kuPm1BWkE/62zD+99o4Itl5IULMBKghC4Z8XJ35 yYmw== X-Gm-Message-State: AOAM530qCEgVIS7CEw32KXJXU43HA6n6fzU0enJ+QzZQj3WedJZLLIJF I6UD09Azm2+r5H40ORt4Rnh4FNih X-Google-Smtp-Source: ABdhPJzaf1GZsaxumRccz/U8nGNSbVA2D3A4byc0Kl+4XcOkw82Y4AhiDrvrv7BHWQwwb66k93d0Jg== X-Received: by 2002:a1c:25c3:: with SMTP id l186mr13855802wml.103.1590854783257; Sat, 30 May 2020 09:06:23 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:16 +0200 Message-Id: <20200530160541.29517-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/36] avcodec/vp9_raw_reorder_bsf: Check for existence of data before reading it 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_raw_reorder_bsf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/vp9_raw_reorder_bsf.c b/libavcodec/vp9_raw_reorder_bsf.c index 6562399159..6e77816256 100644 --- a/libavcodec/vp9_raw_reorder_bsf.c +++ b/libavcodec/vp9_raw_reorder_bsf.c @@ -292,6 +292,11 @@ static int vp9_raw_reorder_filter(AVBSFContext *bsf, AVPacket *out) return err; } + if (in->size <= 0) { + av_packet_free(&in); + return AVERROR_INVALIDDATA; + } + if ((in->data[in->size - 1] & 0xe0) == 0xc0) { av_log(bsf, AV_LOG_ERROR, "Input in superframes is not " "supported.\n"); From patchwork Sat May 30 16:05:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19999 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 C487D44A6AD for ; Sat, 30 May 2020 19:06:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A8F8268AFBA; Sat, 30 May 2020 19:06:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9154B68ADF1 for ; Sat, 30 May 2020 19:06:25 +0300 (EEST) Received: by mail-wr1-f44.google.com with SMTP id x6so7099060wrm.13 for ; Sat, 30 May 2020 09:06:25 -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 :mime-version:content-transfer-encoding; bh=hVNi0ov4KwpZXc/Abm8u3TRTn9r00JZ7fYZs+e9JIzk=; b=jhfB+rb4H9f766Sn76Cx0oYfx+HXLMT4uYu0hF9LuvueBW5OoxxugWNhzXypZHacQM TLcisGHXdQxW42uGm8SqZCz0YljFC1o5Wh9i9BLgFybS63U3xz0+o9u1neu0tWuONOaO fdqDwSL21CLaajPII/e9bvDNLwrCx0K03gxmxQ8DABDhlRtrQ5kIG/rrXtW6Aks9a1py c61Qckb8pl+kiBWGBbeYa1RwdLHySMM4UEQyVVUfRdw1I7m7QeH0m/hUnnI8+MkIHz9T /oxrPCiZlV5oJW2Es3+TRHwz5JBibtPgUX/BfnmLBvxpfNUiicIzp1rc3Wpj7m3m4Z1B fOvg== 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:mime-version:content-transfer-encoding; bh=hVNi0ov4KwpZXc/Abm8u3TRTn9r00JZ7fYZs+e9JIzk=; b=Gwjl/HCTeLeFTh5dqYgLQHtPRr8l5Tkjm/e7zWsRDGo+ROTa4dpnIlfAvKfb6NkcqI lBjZJ2sezGQOS6RXlxyhmA+4dkTh5CrGZv6j9unPQguFg9tBgWRxzlTFPkwJu0tJqxpp W8BGpfK4pYwb3GWPB78kPfn5vbebv6q1mGjaCKN74/sKBDoEdFFSK7FDSGucLa+8UqdQ j6gvneT4DlHAEvLYSEQE8v999n1Mdidbr5eH3iUG9FqAY547Z0/oy4Szl/kX9Eaps6Ml EZ9XgBHMqktyXM3JijIOiRThMrujABX9acPxujqmYX+4nZcBDcoIbgQw0sob+viL8/e/ yfeQ== X-Gm-Message-State: AOAM532mZQn3RuSN3obUb2bm0w5/Fu76m7rUcMP0mU0lF7cE+CZnHkmw crLnhpT/QDin1LZVyQh2dA9oMQQI X-Google-Smtp-Source: ABdhPJyWIwgFSZJIeT6ypJg/TS2dViZ6y702keMRUKu0gkhBd1y47Gavanzdo0zvNh6k2Qcg+6cucg== X-Received: by 2002:adf:ca0e:: with SMTP id o14mr14841365wrh.254.1590854784564; Sat, 30 May 2020 09:06:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:17 +0200 Message-Id: <20200530160541.29517-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/36] avcodec/mp3_header_decompress_bsf: Don't output uninitialized CRC 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/mp3_header_decompress_bsf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c index 44c174c21c..fe021deed3 100644 --- a/libavcodec/mp3_header_decompress_bsf.c +++ b/libavcodec/mp3_header_decompress_bsf.c @@ -85,7 +85,7 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) header |= (bitrate_index&1)<<9; header |= (bitrate_index>>1)<<12; - header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0 + header |= (frame_size == buf_size + 4)<<16; ret = av_new_packet(out, frame_size); if (ret < 0) @@ -109,6 +109,10 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) } } + if (frame_size == buf_size + 6) { + //FIXME actually set a correct crc instead of 0 + AV_WN16(out->data + 4, 0); + } AV_WB32(out->data, header); ret = 0; From patchwork Sat May 30 16:05:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20000 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 933F144A6AD for ; Sat, 30 May 2020 19:06:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 82C4468B038; Sat, 30 May 2020 19:06:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E9A7768AEBC for ; Sat, 30 May 2020 19:06:26 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id h5so1247857wrc.7 for ; Sat, 30 May 2020 09:06:26 -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 :mime-version:content-transfer-encoding; bh=4WtmIVoFNLme2K0ElTDQi6n09sAM/ZsSGvp76uoNeZE=; b=LktALCR9Od8/pNhlmLhPzmZ1XUOVJ7TjT54SIkanhRDnNHyDORlbeHiT13GJ0z7r4x JWyTwMeKVcACj5V5z0YD7Mh+E/Uk83n+hxZvc9Ami0+TMt3ZV4r/vB7i2GWfIh4CaXIx yoTIllgpMaPeuulppQF8ejDN2tVs2p7nUMMTB27PBagVDSrQYy4K2Vjy3obAuKDGgdXW BQsc/AgkRmuVn4yrbvbx6SXt15YCT/IW56ygQd/xh0smsocP2qIf32l1Tp3bg2R2pfud 8DTj81EkH9ePrh9gm1+JDgVxpHFgQlr3y06tjhmV0ff8xRdw6LN0nw6A5IqBtRRPq63A OIRQ== 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:mime-version:content-transfer-encoding; bh=4WtmIVoFNLme2K0ElTDQi6n09sAM/ZsSGvp76uoNeZE=; b=nWQznnXRksI3zu87u3wEC0tDugFcooJ8RqmqgCMQh+VhlmOKdjPJ56vM22tgzRdkLU +vsZsL+hHK8nUZiyKbtealXeZdyleFFFiNmYS+sKxiwoTSZ3CHO4X5ScR4ErvhJcPfQa KslaOIBORtN8+qqFlGrQoYQQ6ZbFsBoONrD+h3RdqZIE2QpXhFyzBLb86XqhlwiJVWlU sbZJiS1WTzCeh9f5jt+0sys0pjb3GlCkEjfk+dhU+Bdc9KjdiKMNDtD+EcR2P+hNy2Uv mZS9BdGnklJZ+9AloUF9F0z72MS+ScP7JLsqF9ik1B2mXivJx9D6RSFMJ5Qyf1LednVl 4Zng== X-Gm-Message-State: AOAM532jD484nzSNz/k7pTRoTUR7gF0MzjtEUU9BBPuUc7ep2F8XGXnO bR4yVnSzXkNXdRT6HmD46R/2u1g6 X-Google-Smtp-Source: ABdhPJzaMratPgpsQXCXxG7O0coqLnfxyULPN4NURK1ZcWv2W3MgD3b85YCz6PtVrIbjjuy2zwvVgA== X-Received: by 2002:a5d:5483:: with SMTP id h3mr1296245wrv.10.1590854786019; Sat, 30 May 2020 09:06:26 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:18 +0200 Message-Id: <20200530160541.29517-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/36] avcodec/mp3_header_decompress_bsf: Improve 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Up until now, the mp3_header_decompress bsf used a single variable for two purposes in a bitfield-like manner: To contain the bitrate index as well as whether the padding_bit is set. The former was contained in bits 1-4, while the latter was given by bit 0. This made the code hard to understand. This commit changes this by using dedicated variables for the bitrate index as well as for the offset of the old data in the new buffer. The latter implicitly contains whether the padding_bit is set. Also add const to the pointer to the source data; it is of course not modified. Signed-off-by: Andreas Rheinhardt --- libavcodec/mp3_header_decompress_bsf.c | 35 ++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c index fe021deed3..3d357dd27e 100644 --- a/libavcodec/mp3_header_decompress_bsf.c +++ b/libavcodec/mp3_header_decompress_bsf.c @@ -32,8 +32,8 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) uint32_t header; int sample_rate= ctx->par_in->sample_rate; int sample_rate_index=0; - int lsf, mpeg25, bitrate_index, frame_size, ret; - uint8_t *buf; + int lsf, mpeg25, bitrate_index, frame_size, offset, ret; + const uint8_t *buf; int buf_size; ret = ff_bsf_get_packet(ctx, &in); @@ -69,23 +69,25 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off - for(bitrate_index=2; bitrate_index<30; bitrate_index++){ - frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; - frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); - if(frame_size == buf_size + 4) - break; - if(frame_size == buf_size + 6) + for (bitrate_index = 1; bitrate_index < 15; bitrate_index++) { + frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index]; + frame_size = (frame_size * 144000) / (sample_rate << lsf); + offset = frame_size - buf_size; + if (3 <= offset && offset <= 6) break; } - if(bitrate_index == 30){ + if (bitrate_index == 15) { av_log(ctx, AV_LOG_ERROR, "Could not find bitrate_index.\n"); ret = AVERROR(EINVAL); goto fail; } - header |= (bitrate_index&1)<<9; - header |= (bitrate_index>>1)<<12; - header |= (frame_size == buf_size + 4)<<16; + header |= bitrate_index << 12; + if (offset & 1) { + header |= 1 << 9; // padding_bit + frame_size++; + offset++; + } ret = av_new_packet(out, frame_size); if (ret < 0) @@ -95,10 +97,10 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) av_packet_unref(out); goto fail; } - memcpy(out->data + frame_size - buf_size, buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE); + memcpy(out->data + offset, buf, buf_size); if(ctx->par_in->channels==2){ - uint8_t *p= out->data + frame_size - buf_size; + uint8_t *p = out->data + offset; if(lsf){ FFSWAP(int, p[1], p[2]); header |= (p[1] & 0xC0)>>2; @@ -109,10 +111,11 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) } } - if (frame_size == buf_size + 6) { + if (offset == 6) { //FIXME actually set a correct crc instead of 0 AV_WN16(out->data + 4, 0); - } + } else + header |= 1 << 16; // protection_bit AV_WB32(out->data, header); ret = 0; From patchwork Sat May 30 16:05:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20001 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 80C7D44A6AD for ; Sat, 30 May 2020 19:06:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 697FD68B035; Sat, 30 May 2020 19:06:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E942E68AEEB for ; Sat, 30 May 2020 19:06:28 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id p5so1257033wrw.9 for ; Sat, 30 May 2020 09:06:28 -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 :mime-version:content-transfer-encoding; bh=FmCvo+R03bx9krm5ySr5EDT1IbNqt4jsT14cvMZ1fJM=; b=QVLqb1cp1mHKk9lVeC5ely0XfR/hgInbKpD5ien+EH2c7Ami6Hoyj8NDbc+sGDtFlt FTa4ucMRnJRGtFndU4JJpB5M5MH0tXrIKywFAAuUpmNwxkRz+/PAG5nOGdI3tN2rqNtp ATwCnFoc5wAFE8Rfla6Pw4rHGZFFkErr9LqqJayIFiqZVekoUr27XWwtIEwUNmqhqFGU boPjpTawQ2Vfqe2CAR9QvQy6mv5ubnt0Pg/l/DxQ2+LVVZCcj/cga89IN7uCimqaHo8q RfIZgHz82WRdrsugH6EjqwvJQfJY/wRhVJBqRy8jeQAbfptIf3Losw66Ux8Zj6EJ92CG Sehw== 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:mime-version:content-transfer-encoding; bh=FmCvo+R03bx9krm5ySr5EDT1IbNqt4jsT14cvMZ1fJM=; b=kxrEg2X1uwguwq+TT8AHeqYCSOSx+0pXN/V3hCSgwG4giiwuZ26DSSw9UgU5iIkWct y1Wgt7JXLECJqgOu1/Iit9gMHjxEE+1yogmx5Ofm5maSJcrj9IkXmZL9zkBF6z/fTcCD CnoMgAInwbxYU//22AIELcy8gRaXZ8E2wOfbDEqHV4/mkPK0X4z8w5vXdvQEORvh0Svp 2JbLCu3rzqJlvoQ3+VdiIqpPPQGmpXDRXhw1D0fEUE/ItkajB/NTaVzgHFDOeHH/Bhy0 iJtoHcqGB94FUk5WKDJDUYuAAEOvrzREK0B/awLFPlWgfIwgTg4nAehPYzSs9pqPoDn6 wyww== X-Gm-Message-State: AOAM533x62g3r9pqeTVg5NtvrZZ/kXwQaVXoWMnz2SjPN6sb8S0Pik6c Qv7Y39NAj0g6ACAiIOiKtReqPc0k X-Google-Smtp-Source: ABdhPJwSrrjtatdomlws4uwxx8K3pfaV1CnRTfXBRa7cAr2SsIXwvb2rVzDx38Wt8VmIcFT8MdE3Yw== X-Received: by 2002:a5d:52c6:: with SMTP id r6mr13610268wrv.74.1590854787872; Sat, 30 May 2020 09:06:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:19 +0200 Message-Id: <20200530160541.29517-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/36] avcodec/mjpega_dump_header_bsf: Make code more robust wrt overflow 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpega_dump_header_bsf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index ab68f9c3e9..40c4c690ab 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -42,7 +42,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) if (ret < 0) return ret; - ret = av_new_packet(out, in->size + 44); + ret = av_new_packet(out, in->size + 44U); if (ret < 0) goto fail; @@ -58,29 +58,29 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) bytestream_put_be16(&out_buf, 42); /* size */ bytestream_put_be32(&out_buf, 0); bytestream_put_buffer(&out_buf, "mjpg", 4); - bytestream_put_be32(&out_buf, in->size + 44); /* field size */ - bytestream_put_be32(&out_buf, in->size + 44); /* pad field size */ + bytestream_put_be32(&out_buf, in->size + 44U); /* field size */ + bytestream_put_be32(&out_buf, in->size + 44U); /* pad field size */ bytestream_put_be32(&out_buf, 0); /* next ptr */ for (i = 0; i < in->size - 1; i++) { if (in->data[i] == 0xff) { switch (in->data[i + 1]) { - case DQT: dqt = i + 46; break; - case DHT: dht = i + 46; break; - case SOF0: sof0 = i + 46; break; + case DQT: dqt = i + 46U; break; + case DHT: dht = i + 46U; break; + case SOF0: sof0 = i + 46U; break; case SOS: bytestream_put_be32(&out_buf, dqt); /* quant off */ bytestream_put_be32(&out_buf, dht); /* huff off */ bytestream_put_be32(&out_buf, sof0); /* image off */ - bytestream_put_be32(&out_buf, i + 46); /* scan off */ - bytestream_put_be32(&out_buf, i + 46 + AV_RB16(in->data + i + 2)); /* data off */ + bytestream_put_be32(&out_buf, i + 46U); /* scan off */ + bytestream_put_be32(&out_buf, i + 46U + AV_RB16(in->data + i + 2)); /* data off */ bytestream_put_buffer(&out_buf, in->data + 2, in->size - 2); /* skip already written SOI */ out->size = out_buf - out->data; av_packet_free(&in); return 0; case APP1: - if (i + 8 < in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) { + if (i + 8U < in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) { av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n"); av_packet_unref(out); av_packet_move_ref(out, in); From patchwork Sat May 30 16:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20002 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 9C3F844A6AD for ; Sat, 30 May 2020 19:06:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81E1468B070; Sat, 30 May 2020 19:06:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F54168AFA6 for ; Sat, 30 May 2020 19:06:30 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id f185so7145864wmf.3 for ; Sat, 30 May 2020 09:06:30 -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 :mime-version:content-transfer-encoding; bh=ez0QBypIUGAwLevQX5Mpfp4o7EjqjfAfofvN9beRUI4=; b=DGWLLZu7eZ+pCcuH1HnJGzmhnxQXcSnIzGobsBvtMsPAR09lmPk12SlSYfoLaBeoII gcaMxZTzB9PDSpSLS7B1hHLNbJUXr5tcxXB4Apdto7yWqh0c1MX4TpnewgP5Q2GZrjmc oVfxG3YrxFrCnnPCKB5JltSqeGnG6KHizPDCg4bgN+rLIkVCjKDVNxCvWVhkMwvmZb6h lwr0hGlEryP3Zxkk6u7InhIduKTDlo82JC0uq2MQhWPS3Oakv7vIp8hiAKyAID2rNki4 7OUTGPFHRb4QuEWZkN5SZm3Q31b0Di8/PBGyD32s7j0gnkd1YWABmlG69Tk3bhPXzIw2 zILw== 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:mime-version:content-transfer-encoding; bh=ez0QBypIUGAwLevQX5Mpfp4o7EjqjfAfofvN9beRUI4=; b=M9QzwGnr7Jf6r4PDdSazD0WTc6CuWjHnmPrTdALi7T+nSTqxo3j1rhf7aYrwmeJwZ1 KzXm5KBIJKtMZVA3lSqeYfSjIfAXr3YqVEh+PpTboYxIccwEFlEy8minh/oLpTo3Bdk1 h5xwFHCpem0nXd+so5dxkMU1rmIJSnN7KUxIHil8TcVUd3lYeDPUp6S32H5vv6I6D5xu TTMTFtpvsnJKETlVVgmAJq+qvTCCWow5XuqY7zJU0SlNMvVTI0Rft4e2qdBwWyU11yRv gQ0u4FVgtw25a6wywDFkAHLiqVnFxvqhymbWCR+tZizaHn9EI2AaBChvDot2cKHTx3S/ p/2w== X-Gm-Message-State: AOAM530dyIHht8UDlP/BCWUusW5bT9coxc3LW4NcP69HmAsrnovj5qdq nWcMjWXKH0zvdN3hlB5a5U0mmqrp X-Google-Smtp-Source: ABdhPJz1if2S9ru9Imn3kfaY5NiFDri25x73WuXEryBoSkN2LjsABnFRS0hYRR4u9K8FweAT07foGg== X-Received: by 2002:a7b:cae2:: with SMTP id t2mr13852999wml.150.1590854789303; Sat, 30 May 2020 09:06:29 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:20 +0200 Message-Id: <20200530160541.29517-15-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/36] avcodec/mjpega_dump_header_bsf: Don't overread 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When encountering an SOS marker, the two bytes after this marker are read, too. So one needs to make sure that these two bytes are still part of the packet's data. And when one checks whether the input already is of the desired format, one has to make sure that the place where one searches the "mjpg" tag is actually contained in the given data. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpega_dump_header_bsf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index 40c4c690ab..1cd2b48719 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -62,7 +62,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) bytestream_put_be32(&out_buf, in->size + 44U); /* pad field size */ bytestream_put_be32(&out_buf, 0); /* next ptr */ - for (i = 0; i < in->size - 1; i++) { + for (i = 0; i < in->size - 3; i++) { if (in->data[i] == 0xff) { switch (in->data[i + 1]) { case DQT: dqt = i + 46U; break; @@ -80,7 +80,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) av_packet_free(&in); return 0; case APP1: - if (i + 8U < in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) { + if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) { av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n"); av_packet_unref(out); av_packet_move_ref(out, in); @@ -90,7 +90,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) } } } - av_log(ctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n"); + av_log(ctx, AV_LOG_ERROR, "No valid SOS marker in bitstream\n"); fail: av_packet_unref(out); av_packet_free(&in); From patchwork Sat May 30 16:05:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20003 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 96B3C44A6AD for ; Sat, 30 May 2020 19:06:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F4F368B096; Sat, 30 May 2020 19:06:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C84F68B00A for ; Sat, 30 May 2020 19:06:31 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id f5so7144995wmh.2 for ; Sat, 30 May 2020 09:06:31 -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 :mime-version:content-transfer-encoding; bh=hDWtWs85vmKn1IdaWKQsZwGW7f+TreR5LAvhAFCPorw=; b=c6Gjy/6YoYXYS6cZ1G2C5j+ZFNedfNcNCQ346IivruYaWQwmUd82aAe3hVBPl9PxhK 6wmfOSIjuvWC7ScjhPJSz0sxqcYNnHjTilWCqLmR0lmfpuB9OE8WDXT9MiNJgeTbr3r8 vlGgmq7mn6ijbqBLHdj7NI5rblgViT8j9oyeUL098FaH3uKc4SCnCZ2JaZRCUC5Gsf5H ERzNfhYyK0P3JnwTVhiFrJ//Nf4A6XpFqpcgI71PQBaGH7iMYSMK/dQP1Bbxuob1f+RW 9h2+FTC8Y+GDfA325MGEtCEXdwWkFjjp2ym6GgIfr0uxkRYyacbyzZrN+zZlRfpiciVk PeCw== 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:mime-version:content-transfer-encoding; bh=hDWtWs85vmKn1IdaWKQsZwGW7f+TreR5LAvhAFCPorw=; b=nFDGkm9e921127Yycd97BT09RnSI5Wr0+OgZyk2qP8fwKty7lHCwGosGkFxb1NDopC p43HQ7Y/gdwtS6iFIq3qlSF9dBVZFEgeZEPLiiHiFvTqrNXEQ6V+lAWlhyxXeHkynUKv z/IlKhxhUezQu6FPjOk5lJfHjvxpbub+pBvygAny9Hh3gqKtT+w6qSGB7CE9H6mRACLE CjPb1331m2fgY9LnCY0Pqj1hx0fyY6zggNyKHwNCP9SKt3zs6WTTtTlYsQP6jk4wFlWx RKNO5nmfKYU1YRRxxrFhzw1b2GKV2HndH2plukKhJwHuxJ6Mn9Cyl+Zsb1rcmKHcIgbw WOWw== X-Gm-Message-State: AOAM532ePH7WggklXg3SdDUrRjehBC6nGY2wLtu7x6IlbbYzgsEVhqfO fiZHyiwO35+XC27W/aLrGKNCJfaV X-Google-Smtp-Source: ABdhPJycLnuE3r2QbnpQZOLpqHXS4teBFCSlyWldpls6UrRMc5+r0oi27gCEMPRAX4pF4OgP+2ojIw== X-Received: by 2002:a7b:c5cc:: with SMTP id n12mr13633106wmk.69.1590854790467; Sat, 30 May 2020 09:06:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:21 +0200 Message-Id: <20200530160541.29517-16-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/36] avcodec/mjpega_dump_header_bsf: Only allocate when necessary 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This avoids having to free a buffer that hasn't been used at all. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpega_dump_header_bsf.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index 1cd2b48719..4608fe550b 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -42,6 +42,13 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) if (ret < 0) return ret; + for (i = 0; i < in->size - 3; i++) { + if (in->data[i] == 0xff) { + switch (in->data[i + 1]) { + case DQT: dqt = i + 46U; break; + case DHT: dht = i + 46U; break; + case SOF0: sof0 = i + 46U; break; + case SOS: ret = av_new_packet(out, in->size + 44U); if (ret < 0) goto fail; @@ -61,14 +68,6 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) bytestream_put_be32(&out_buf, in->size + 44U); /* field size */ bytestream_put_be32(&out_buf, in->size + 44U); /* pad field size */ bytestream_put_be32(&out_buf, 0); /* next ptr */ - - for (i = 0; i < in->size - 3; i++) { - if (in->data[i] == 0xff) { - switch (in->data[i + 1]) { - case DQT: dqt = i + 46U; break; - case DHT: dht = i + 46U; break; - case SOF0: sof0 = i + 46U; break; - case SOS: bytestream_put_be32(&out_buf, dqt); /* quant off */ bytestream_put_be32(&out_buf, dht); /* huff off */ bytestream_put_be32(&out_buf, sof0); /* image off */ @@ -82,7 +81,6 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) case APP1: if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) { av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n"); - av_packet_unref(out); av_packet_move_ref(out, in); av_packet_free(&in); return 0; From patchwork Sat May 30 16:05:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20006 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 3AB0544A43F for ; Sat, 30 May 2020 19:09:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 32BFF68B074; Sat, 30 May 2020 19:06:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D408F68B028 for ; Sat, 30 May 2020 19:06:32 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id l26so6704571wme.3 for ; Sat, 30 May 2020 09:06:32 -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 :mime-version:content-transfer-encoding; bh=TlgiCBav88bjQr82Fhhh2UBddHWbuqLJrF/Nqo5+gxc=; b=bTlHfJAP5MlKnql1/Ku7gmOJ04uTi2CaYZwBfi/d6wPBFL7TiVpP38twriSje16Thb XL2S/vW7XzyG1nhZSnlwlSUXtL7EizZGHZ1SyNfAg6GpEW9/Y+wZsq7ArBnOMVTn8rhs 6IM2D0QWGRkpVxjKaj1NKDzywkzpXULZoclG+th75pHQnXCPUiobmNX01nFgBXs9XTA+ vmiD1pQlaj22kOqdm1QgczSRs3HPhKdryZrveeLbmTts76tanBu41vpbBoYo+TzC18SZ uFa/nTM8wsSloeAGZqvVBIt/zBMgqctjZID7I1OybJfEcPZktddk0oEqqKRVA0IJWb8B I01Q== 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:mime-version:content-transfer-encoding; bh=TlgiCBav88bjQr82Fhhh2UBddHWbuqLJrF/Nqo5+gxc=; b=fNENcjZEtdD9ruNhKxyZm3rIWrSzY4/H1/I51ZoKXT7kalWKd7aMCqWuIQ5wD4ShIh qT68kwfq0b57zKwhPHBD16Ez5Wh6LMVOp5bCEW1GvlHb6N1phmJzazjRJ72PxIc+KRpa 7ev0gaWZgm52jyGw/wmmFIlstgVJoK7OG+5MJ0NqmJ0D/DUHKEctXLr9YTel8Nz8Zmjs BMcta7bZ+w+iwQlDtoxWXQMyUidIXZeAHpzpjnqhdjicymkeWvlmtSYPS8VtIuuuK6Wu a4Buj1s/NdJEFEl/w2B9jqYK4+35WWggWpISOv3uJVpTeH1UIp5oxcKwmQ10ulFdEsNX j8jA== X-Gm-Message-State: AOAM533YcduxKLGxwaPKzsi0YKmAp6E2d6Kxpdo+sYZOZX3vTC1O7xpP CYgIaVJTneD4StcIMUeg9dorEXk4 X-Google-Smtp-Source: ABdhPJwrvzr1J+Ph5Es+LBolgycLOUTNKQIS1o/YROvf4qUdFu5gpxojZfX6DF7doRRbUh0Qu3sb5Q== X-Received: by 2002:a1c:1904:: with SMTP id 4mr13221178wmz.125.1590854791879; Sat, 30 May 2020 09:06:31 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:22 +0200 Message-Id: <20200530160541.29517-17-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/36] avcodec/hevc_mp4toannexb_bsf: Check NAL size against available input 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The hevc_mp4toannexb bsf does not explicitly check whether a NAL unit is so big that it extends beyond the end of the input packet; it does so only implicitly by using the checked version of the bytestream2 API. But this has downsides compared to real checks: It can lead to huge allocations (up to 2GiB) even when the input packet is just a few bytes. And furthermore it leads to uninitialized data being output. So add a check to error out early if it happens. Also check directly whether there is enough data for the length field. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_mp4toannexb_bsf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index a880d9ba9a..ba1deb2848 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -142,10 +142,14 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) int nalu_type; int is_irap, add_extradata, extra_size, prev_size; + if (bytestream2_get_bytes_left(&gb) < s->length_size) { + ret = AVERROR_INVALIDDATA; + goto fail; + } for (i = 0; i < s->length_size; i++) nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb); - if (nalu_size < 2) { + if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) { ret = AVERROR_INVALIDDATA; goto fail; } From patchwork Sat May 30 16:05:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20004 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 E911744A6AD for ; Sat, 30 May 2020 19:06:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D88F568B0B2; Sat, 30 May 2020 19:06:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31BFB68B038 for ; Sat, 30 May 2020 19:06:34 +0300 (EEST) Received: by mail-wm1-f44.google.com with SMTP id n5so7154914wmd.0 for ; Sat, 30 May 2020 09:06:34 -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 :mime-version:content-transfer-encoding; bh=0u2Z84unXVwKDMIDhq2499bDLBmY+YmRA0AjMKPf+L8=; b=sgIa8VuA7x+cSktJ6RB0CRHQ6J2Uvzie2yf/jsCfCBeVxWdqFEUGilEiWCSEvuxMiq FPwivxMMdyXDJ8cKXS3K/241DS/xSvZwiiaZAZ/bz8rEnGaSfAUNxlhMEqfhxD2QSgxp aLxT4RH6MGNRkYyfj15yY0stWL6CLWOE8JhgXaXoRTGGjTz2B9t+HQOBgoXqXDGGHJ5f bQ6CPRRMz1yCO5k7jKuaA8il/9igQjW0EsEO7SCvz1AnwNGxML4elshyNeCeZOt8dY+W fLaiTxOFksler00hkhCIj9LQg1nXyTGlkgu5DjLCQW2ow2eBr1boJzG7jcgY21fKnhAI Gnxw== 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:mime-version:content-transfer-encoding; bh=0u2Z84unXVwKDMIDhq2499bDLBmY+YmRA0AjMKPf+L8=; b=ixGgc231MaYaGnRmo1dO5kGAXdQMRmkKtI4MU14Ganh8Si591CHKJTiWebELvi8+uI Yz2fTkB6RbM976fLy7gUTpGVeznPe15LzDhLw44/VC8kfM0L7c7jmnUATkWYhlYj7KFG K4N0VOGPoqCjd+9VzIRcRT7WE78eZHeh++y8gSgvxdXaJyLM9sYNEgV+JWnFhYUOJjTH a7CNJPnRAeg1tjGIX+V9hMMl3pyzlnoO9T1aIwqgHn1oEDshcMZk0UDqOFx3xpHp5SmN w7+oDF7YBduc7p5zww29MJ9xgh4rwp0T22pE3D9wGeXGzWdRmlii4peFHN5ksIZQRpQf FszQ== X-Gm-Message-State: AOAM53197Uo+Yd7OulwkfEN0WwudtPkJOir9mXA5v4sF/WZxmSc5KAZ/ HF3aVNNfrpA13JPmryiVXHc/HxvK X-Google-Smtp-Source: ABdhPJyD0e2LuN8isQ/Jf3px6tIWePspo5Kv/kHkfh5/G/Yzs7u8Qr/JBgyskKHptOdPT91AjiW94A== X-Received: by 2002:a1c:4c16:: with SMTP id z22mr14415700wmf.17.1590854793071; Sat, 30 May 2020 09:06:33 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:23 +0200 Message-Id: <20200530160541.29517-18-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/36] avcodec/bytestream: Add unchecked bytestream2 peek functions 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/bytestream.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h index 0516a6e3dc..d0033f14f3 100644 --- a/libavcodec/bytestream.h +++ b/libavcodec/bytestream.h @@ -77,11 +77,15 @@ static av_always_inline type bytestream2_get_ ## name(GetByteContext *g) \ } \ return bytestream2_get_ ## name ## u(g); \ } \ +static av_always_inline type bytestream2_peek_ ## name ## u(GetByteContext *g) \ +{ \ + return read(g->buffer); \ +} \ static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g) \ { \ if (g->buffer_end - g->buffer < bytes) \ return 0; \ - return read(g->buffer); \ + return bytestream2_peek_ ## name ## u(g); \ } DEF(uint64_t, le64, 8, AV_RL64, AV_WL64) From patchwork Sat May 30 16:05:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20007 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 8277644A43F for ; Sat, 30 May 2020 19:09:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8861768AF0D; Sat, 30 May 2020 19:06:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CC5668AF2D for ; Sat, 30 May 2020 19:06:35 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id r9so6704830wmh.2 for ; Sat, 30 May 2020 09:06:35 -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 :mime-version:content-transfer-encoding; bh=2gAqY3ctS+qFf+B5YNkxCDXoHNukU+fc1jIKUdf9TeI=; b=YI9s7qciWVex7ubOUE+j8Z6GLvpQBRnMNtLWcu6SA5qSyaONMbYSXqwuNFXtikxjgM kk9cQHMc7WkVOEWogMb6/9HS9rjTJyAiSll1kDMtAzmoO38u0mjbqeeXuRdDDKr2DeYd M0V0QWD5s0U5K0n4PcngprR4NK0hNOZ3IakXURRUWMH6oW83yKa41vESnddPj162DaXx DIfVoBGitGI+3YzF/rWDpzVPhMyzeOCn9w341DhcKvKWi9/rmxXAmLhD99fmm35jKRyL ioGFny7R22+KHA3z7UxzLbph+pj500OtGG6fggkCwMidFo91iEwcbebodaXAEKG6uVU6 7TDQ== 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:mime-version:content-transfer-encoding; bh=2gAqY3ctS+qFf+B5YNkxCDXoHNukU+fc1jIKUdf9TeI=; b=PoxTSW2POthat4aIU0fR6Pw81U6ObpxFJe2wt0gPiQgSMxwgDFW2a94S70LF7uYCT+ rpaKkTHf6Ld4DhNcKln075NUfR02dWl7oX+Sd0pu+8u7k1bS2SWhis5JXEDrGB1cpqtA 8w1lo6YtZAoX79QDMsVW+v7yU4/6gKhGpdWYet+F33g9ZgGhCjmH+2wdsshyPTqErb8C DNiCktV+pglyju7VviRoTQjVTJQMqOa8LO3T+oWToSh8T10XcKjwHMtLE/nGLSWJ+vgb 49vTn9cBrEF5kGYGvPs1egI6hoqvZHhBVGWx5ytGFUFK+RQDm37h2Ud9jCMZea0a/fGF 7N+Q== X-Gm-Message-State: AOAM532Rt1EdKlKJYuNuCx6uaCr/XrNfaIaU+msW3L3hdaeVG2FeXcvt +F3XMnFgZdJYHp2+Gxm0NL3Tz6JZ X-Google-Smtp-Source: ABdhPJz1HQAhCswtlTRtBPn8a7zh+1Rltyg9Mw0vnT9EbQU8SwNGZmT3l7y+YiLvIkRehwD9jUZEQw== X-Received: by 2002:a1c:2702:: with SMTP id n2mr14047931wmn.107.1590854794434; Sat, 30 May 2020 09:06:34 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:24 +0200 Message-Id: <20200530160541.29517-19-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/36] avcodec/hevc_mp4toannexb_bsf: Use unchecked bytestream2 API 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" We already check manually and error out on invalid data, so we don't have to rely on the implicit checks provided by the safe version of the bytestream2 API. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_mp4toannexb_bsf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index ba1deb2848..634bfe9c46 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -147,14 +147,14 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) goto fail; } for (i = 0; i < s->length_size; i++) - nalu_size = (nalu_size << 8) | bytestream2_get_byte(&gb); + nalu_size = (nalu_size << 8) | bytestream2_get_byteu(&gb); if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) { ret = AVERROR_INVALIDDATA; goto fail; } - nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f; + nalu_type = (bytestream2_peek_byteu(&gb) >> 1) & 0x3f; /* prepend extradata to IRAP frames */ is_irap = nalu_type >= 16 && nalu_type <= 23; @@ -176,7 +176,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) if (extra_size) memcpy(out->data + prev_size, ctx->par_out->extradata, extra_size); AV_WB32(out->data + prev_size + extra_size, 1); - bytestream2_get_buffer(&gb, out->data + prev_size + 4 + extra_size, nalu_size); + bytestream2_get_bufferu(&gb, out->data + prev_size + 4 + extra_size, nalu_size); } ret = av_packet_copy_props(out, in); From patchwork Sat May 30 16:05:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20008 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 B179744A43F for ; Sat, 30 May 2020 19:09:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4DB8A68B0C4; Sat, 30 May 2020 19:06:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 721FD68AFCC for ; Sat, 30 May 2020 19:06:36 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id r9so6704857wmh.2 for ; Sat, 30 May 2020 09:06:36 -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 :mime-version:content-transfer-encoding; bh=03LV6CdqXn3cycMllnn5XWSLbWS8cJQ/I9wSuE7Q1uY=; b=s1FVI044dnskMRP0JBThDe7wT563gpfdEOCSrxRBNPPQFyINVDQtqGEnNH188jFO2t vfMNwt0V7mILe3hFSxn82UQUHBv6+8B0Ukf3tirIOwFkZ8OuasQKR0GvYSpMlgGLoAx+ PneIkAabLSDP+/p4kkIOc6Kbq59E2/YMKeKh7PigEGqXAQ+ls2eSx0BjGlst6lcZcLAe AoI4z//xr/tcrXQnacfcKbcPQHc+VBKFaGZ3zqMnq6P4cX38YCl9QFFpHShq3hVCd1b9 egJeZ5HfrxqEa2fLqYk4pZcd1ZV8fRpc7erPzhCyS+RvTXoef6dzsFkVMYWESY5GOxby cJlg== 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:mime-version:content-transfer-encoding; bh=03LV6CdqXn3cycMllnn5XWSLbWS8cJQ/I9wSuE7Q1uY=; b=TBgevvs6iU41Qzsa86gtx9UQ5KcK1r+/tc28Sc6FP7l+A9u7OSCjzgvhoRkYpgnJrF aqXc1BTqe6RAK3KNdfeay+U8paFuwLT75+4NO9GFcERfTEKwJypFb0203t6hC+Sr2Uea RMsgfLC0rWF0/NayqJbsTYBR3/EbjdP7Ub//JwevF1kRsePENAmJlWrhtBGe1txvS8fg SBdyU22bjaMB95ShEfJf99dl4B1dwTnlYsYtiHNOOfrsnwZURdpHrT5J6W8VR5BuTzBd mLB1YSVtyyGHvp07a+ldX0+UU08mhz6kXwauz5wpB9fSzw9LeBci8bD23j4yYgorpfsQ awIQ== X-Gm-Message-State: AOAM531UaXdWjT1tr6/76mot7qzhzONrQqQkG4fYCIJWd8Usy/5YFA/T wHOyK3N8DUDqzkjT0TdME6W9yigF X-Google-Smtp-Source: ABdhPJzRpWbTU4t5ePSYv3TlukI81v58I9mK5DsouuZnU74M1zkb7vcX5uhaU01xlwkWJQqqrJ8+8w== X-Received: by 2002:a1c:b7d5:: with SMTP id h204mr14374015wmf.39.1590854795619; Sat, 30 May 2020 09:06:35 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:34 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:25 +0200 Message-Id: <20200530160541.29517-20-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/36] avcodec/hevc_mp4toannexb_bsf: Stop reallocating output buffer 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Instead parse the input packet twice: Once to get the size of the output packet to be allocated (and to check the input packet for consistency) and once to actually copy the data. Not reallocating the output buffer also means that one can now use a PutByteContext for writing; it improves readability. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_mp4toannexb_bsf.c | 43 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index 634bfe9c46..3776d5b279 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -119,10 +119,9 @@ static int hevc_mp4toannexb_init(AVBSFContext *ctx) static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) { HEVCBSFContext *s = ctx->priv_data; + PutByteContext pb; AVPacket *in; - GetByteContext gb; - int got_irap = 0; int i, ret = 0; ret = ff_bsf_get_packet(ctx, &in); @@ -135,12 +134,17 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) return 0; } + for (int pass = 0; pass < 2; pass++) { + GetByteContext gb; + uint64_t out_size = 0; + int got_irap = 0; + bytestream2_init(&gb, in->data, in->size); while (bytestream2_get_bytes_left(&gb)) { uint32_t nalu_size = 0; int nalu_type; - int is_irap, add_extradata, extra_size, prev_size; + int is_irap, add_extradata, extra_size; if (bytestream2_get_bytes_left(&gb) < s->length_size) { ret = AVERROR_INVALIDDATA; @@ -162,21 +166,28 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) extra_size = add_extradata * ctx->par_out->extradata_size; got_irap |= is_irap; - if (FFMIN(INT_MAX, SIZE_MAX) < 4ULL + nalu_size + extra_size) { - ret = AVERROR_INVALIDDATA; - goto fail; - } - - prev_size = out->size; + if (!pass) { + out_size += extra_size + 4ULL + nalu_size; + bytestream2_skipu(&gb, nalu_size); + } else { + if (extra_size) + bytestream2_put_bufferu(&pb, ctx->par_out->extradata, extra_size); + bytestream2_put_be32u(&pb, 1); + bytestream2_copy_bufferu(&pb, &gb, nalu_size); + } + } - ret = av_grow_packet(out, 4 + nalu_size + extra_size); - if (ret < 0) - goto fail; + if (!pass) { + if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { + ret = AVERROR(ERANGE); + goto fail; + } + ret = av_new_packet(out, out_size); + if (ret < 0) + goto fail; - if (extra_size) - memcpy(out->data + prev_size, ctx->par_out->extradata, extra_size); - AV_WB32(out->data + prev_size + extra_size, 1); - bytestream2_get_bufferu(&gb, out->data + prev_size + 4 + extra_size, nalu_size); + bytestream2_init_writer(&pb, out->data, out->size); + } } ret = av_packet_copy_props(out, in); From patchwork Sat May 30 16:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20009 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 6FB1844A43F for ; Sat, 30 May 2020 19:09:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 06BD368B0D6; Sat, 30 May 2020 19:06:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFA6B68AEEB for ; Sat, 30 May 2020 19:06:37 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id j10so7159830wrw.8 for ; Sat, 30 May 2020 09:06:37 -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 :mime-version:content-transfer-encoding; bh=4kFEXqhLclpN3pCkCYpulyhW8n8IrgwL3Ex4Y8yRYiQ=; b=D6Oom1dwBOBo+/Ns2dp0KQFCkepkBmH4yyLiLI/ByaB12ZzNSQi1G12eZhF96yWCsS tDnLffMigkXTSfPKJaHPhMZA57mS/t4h1GBbSjFYosDxkEQJFv5w47B0U3XNmvCvGA1p BqRNiIOinHof0F6yWuN9MfhaRfdn8vKZIlIhvISdcidREkFDEt7tZ+0dfP1qcCf52q8P AW11jxPzSwSRhNKWWOhLeuReNV1zRlf2IBqffbsZDUVt188/0f5Gb3QwTGcQgBq/nj/6 jEEtMwfzcmWvhUN2Zfaf7LFFulrMyUA7vRMFbiLzDIdHMcp8TBUeXuxMLAOU20nzTszT yg4A== 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:mime-version:content-transfer-encoding; bh=4kFEXqhLclpN3pCkCYpulyhW8n8IrgwL3Ex4Y8yRYiQ=; b=XKMlSiDmyeiTHlj6dMrrxU3aqrGuLlbWdZKmuBPjgNT7f57e10V7cQjoY2uBqwKsTY PzyWscXGb65m3LhoMeKYEe+IzlX/22j2fWgr737HEVt2dZ7119Xd5QxFvyhK5l8OvhMy RXs9A3/VlwmmGn17FweHGvsVcdqwVvtDYcMSCI7soOePNMA13UC2dxCe6OOFiMR8m8EO bukceIKCz0O7tSJSPO1ottyvu57AqNCO9bj50t2PrqDWy/fH4SVTpFO0UJRhfd9jGHdP xHUsjKwLhF6M/jZeSYuxceM2hB4nEU6TkBiTG75z/glmjvLUYUtvZyba9VZrIX1kGuSP I2eg== X-Gm-Message-State: AOAM530Uo9DcNTNYKEGrNveMATly1dXKxBmNQcH/DTPLcuJmBxStJl8H 1tjIFkAGHqDL+w8/v+NRD0T/7zXX X-Google-Smtp-Source: ABdhPJwQEkKVzln8lZtZ0Pv/WdX0tVOdyY6cxgS56WkeZR1LtX1zScF3MchzAm2TfOTuabyxaiV1GQ== X-Received: by 2002:adf:a283:: with SMTP id s3mr13039868wra.147.1590854796782; Sat, 30 May 2020 09:06:36 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:26 +0200 Message-Id: <20200530160541.29517-21-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/36] avcodec/hevc_mp4toannexb_bsf: Reindent after last commit 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" While just at it, use a smaller scope for a loop counter. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_mp4toannexb_bsf.c | 45 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index 3776d5b279..731ff2e7d3 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -121,8 +121,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) HEVCBSFContext *s = ctx->priv_data; PutByteContext pb; AVPacket *in; - - int i, ret = 0; + int ret; ret = ff_bsf_get_packet(ctx, &in); if (ret < 0) @@ -139,32 +138,32 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) uint64_t out_size = 0; int got_irap = 0; - bytestream2_init(&gb, in->data, in->size); + bytestream2_init(&gb, in->data, in->size); - while (bytestream2_get_bytes_left(&gb)) { - uint32_t nalu_size = 0; - int nalu_type; + while (bytestream2_get_bytes_left(&gb)) { + uint32_t nalu_size = 0; + int nalu_type; int is_irap, add_extradata, extra_size; - if (bytestream2_get_bytes_left(&gb) < s->length_size) { - ret = AVERROR_INVALIDDATA; - goto fail; - } - for (i = 0; i < s->length_size; i++) - nalu_size = (nalu_size << 8) | bytestream2_get_byteu(&gb); + if (bytestream2_get_bytes_left(&gb) < s->length_size) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + for (int i = 0; i < s->length_size; i++) + nalu_size = (nalu_size << 8) | bytestream2_get_byteu(&gb); - if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) { - ret = AVERROR_INVALIDDATA; - goto fail; - } + if (nalu_size < 2 || nalu_size > bytestream2_get_bytes_left(&gb)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } - nalu_type = (bytestream2_peek_byteu(&gb) >> 1) & 0x3f; + nalu_type = (bytestream2_peek_byteu(&gb) >> 1) & 0x3f; - /* prepend extradata to IRAP frames */ - is_irap = nalu_type >= 16 && nalu_type <= 23; - add_extradata = is_irap && !got_irap; - extra_size = add_extradata * ctx->par_out->extradata_size; - got_irap |= is_irap; + /* prepend extradata to IRAP frames */ + is_irap = nalu_type >= 16 && nalu_type <= 23; + add_extradata = is_irap && !got_irap; + extra_size = add_extradata * ctx->par_out->extradata_size; + got_irap |= is_irap; if (!pass) { out_size += extra_size + 4ULL + nalu_size; @@ -175,7 +174,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) bytestream2_put_be32u(&pb, 1); bytestream2_copy_bufferu(&pb, &gb, nalu_size); } - } + } if (!pass) { if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { From patchwork Sat May 30 16:05:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20021 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bac9:0:0:0:0:0 with SMTP id a9csp1499740ybk; Sat, 30 May 2020 09:10:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0BaeHcy6IEJDmI7O9dRONqB1xTTNAx53PAB49p577hszwJspo86+xTwpwkdfWi6epWU+e X-Received: by 2002:adf:dcd2:: with SMTP id x18mr13746682wrm.258.1590855008557; Sat, 30 May 2020 09:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590855008; cv=none; d=google.com; s=arc-20160816; b=ogbpB7wlRBUh2jfpuDQUW/qnr1dVZVZq3r5BjyIhVePcJulGZr9edUh3CXJ2Og0MTN 4UnsToW+kdAm0DtfiMpPagmreVqcaTUyWGQDUdr2SZyOWXHEtUoL6o2RqY/SVZVo3H5N 0CcwNsFozpPUFKR58ieq1UWq7jpZXjizj5MWAzIw3Z5INawpuri5t2Nofffuu5YSP4Lw rVZG5oqC2Wh7FgvC8E9Q85l+D7x4rkj24KPlLv/YhNQf1Z9K8S6HzlrpO4bnZggbn8hj AEl7DnIJsGxoXBlSVeTMafs8WpUPWjrk0lvfFNBIptvIwX7FzVPw3p8QrEyXDTgIIsj8 V8Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=JC4QoaHCzpw8uavGvjExB6A8j7EwVsGrcGS/jyNV2ew=; b=zA+NSW6Ra6lqDe6e+sOPHrLb0TxT1DumX/gURPga44KOWVQUlov1L+SpeAzWJx8K8V Nl19U/1NtgKSq0SzorRzaO4ZGPoERt0AtduMlecsFtbXhdXI/fu4SU0iCCbuaOxUVS/G 2+4nHVLBrvWsVNKos4B1CF+j5buBYpJ+xYVPhLMqSEUskxJSb/xbVwqPpb/YXnhAnkvU 043rniZSOlG+rR6mU0grWgL0XYBUulC2YWNUV4vWuTt9O8eKg9yVolwaZLtsJUXIRRtT P+5EhnUPpPM8HyXCbcgd4rDOjnT5DP0oT+hgkyv9NONp0ptmGutNp5R8uvebFbV2I2WI x9og== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NKKZFr4y; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w4si6576542wrl.88.2020.05.30.09.10.08; Sat, 30 May 2020 09:10:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NKKZFr4y; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3A61368B0EF; Sat, 30 May 2020 19:06:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2ECA768ABEF for ; Sat, 30 May 2020 19:06:39 +0300 (EEST) Received: by mail-wm1-f47.google.com with SMTP id v19so6729400wmj.0 for ; Sat, 30 May 2020 09:06: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=PWHwiPQa4Y6HXkDCrJdP36XeVvqgQVq8Cg+u7md93os=; b=NKKZFr4y9/qFpoPn9SS3ZwrgYsY3eGqwwEmy6DDQlj2qC1zbD7eDXTDlQOOjbi0/BU VmFj/KgOKpz5O4kAvDYWroWw/Pje/HLEQCVpXLZN6WR6sqYAUHD9whSuFgzZqOYxfdEc Sbzr7hGn04N3tw1CdkwVHCGM39I4xrGXzyuXr4OYAnwKcSSRs3Fe8iSAt5FXbgJXOXC0 57hwi+Br3LeC1iRkA1tDTV7F6vTRdDMlbd1U4r53parBzY/nJAz2ey61YKqEfPWZ/gT6 Ff1c0Zl1OCI/C66caCMk4E4hQVX4rWa2gFH2HCBoWsGpy2kC9KzjJ67K53ib1vdWH9IT PE5w== 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:mime-version:content-transfer-encoding; bh=PWHwiPQa4Y6HXkDCrJdP36XeVvqgQVq8Cg+u7md93os=; b=svRsfoFuNUOWmWGCDL0yi0K5NOQc5UMms3nVYattQ+2r3KINRbuDIIy6O9SA295VFS GO3ABIBPI6HD0bL4dYNxPv/jExRitZbm/c9EGD5dIba865RBP0aRhmJcUMpYscyBPhT6 g93Ple2uHT8M7e7mHHBXKJxiYQQvZocXs5roTOycOLNpBnKiec5CXqHb3teDswDc97MG Nw7Yn6F00VrscVG7cHqsQE8VOlUzvW1UIvh6hH9bUbFwnQarIJQlAJ7fJ7kq3gg4lunG dRvaKw7bqaKw+hwezckavC2RFbZwm1DP5maELBbRh3uPfOv15ZG6E1Zh+i+jB6u7byY9 P45Q== X-Gm-Message-State: AOAM533gRaJZwKuuvZeCq2dqz+aHzf1xPastMHQWrKv/U0KyaHTlWmFK fCBfZ6dh5sRxVs1GLFzcHob5+qwP X-Received: by 2002:a7b:c0c8:: with SMTP id s8mr14301082wmh.134.1590854798074; Sat, 30 May 2020 09:06:38 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:37 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:27 +0200 Message-Id: <20200530160541.29517-22-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/36] avcodec/h264_mp4toannexb_bsf: Improve returned error code 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VglKZyh4iWde Content-Length: 1322 Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_mp4toannexb_bsf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 2822644b10..91cabcf170 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -270,7 +270,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) if (!j) { if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { - ret = AVERROR_INVALIDDATA; + ret = AVERROR(ERANGE); goto fail; } ret = av_new_packet(opkt, out_size); From patchwork Sat May 30 16:05:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20005 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 299A144A6AD for ; Sat, 30 May 2020 19:06:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1336C68B075; Sat, 30 May 2020 19:06:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7120D68B06C for ; Sat, 30 May 2020 19:06:40 +0300 (EEST) Received: by mail-wr1-f53.google.com with SMTP id q11so7235032wrp.3 for ; Sat, 30 May 2020 09:06:40 -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 :mime-version:content-transfer-encoding; bh=Q6BXeLowgHVOEAzvS3zejF0hX4h0QSs0WpSTmQGYoKc=; b=HuTPDTQ9bD4Ppe7MxlB8u8x9ZNnIbTZIGFpzVFUWbHZCIO4AM5rEpXhN1t0NEqizh5 oDFn63Im2cG8AV+R+lv2kOS+V02aYunpfdmpxLqseAMvD7WC75SV9yxWLgnWPv71b/O4 uwi8L404tyFnTW0LJ1zf+JYBQbu80J2NpFJa56Bs+DfhQMIfZWCW9cXMajK3Epfk2MD2 fehzAj6RsXkSvP+tp4o8ZFHr6/W+QWyfSUQDjelEhJyzB3Wzqrr+rJzmgwhATUHxPEh0 5B6fEIJqKBO7Xd8NxOFsOmnAwri23q5ffENrXfIcywZjPp7lv54E9w59kIa6IqnukAYa jauQ== 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:mime-version:content-transfer-encoding; bh=Q6BXeLowgHVOEAzvS3zejF0hX4h0QSs0WpSTmQGYoKc=; b=FNcJDcF0t9XVWvfSUxf7v0YraC2f0bUNma/JWbOkNMga4zV4VopCZhsmPh5xha+urH AM8vWUUl04iccg1wxKGxywTsZVC8y2WCj8sDPA9FW5ODNEbr74+BSlORv3QJjsfcFt/p FGr1KtLynK6hmq6MQ+OntNhMx4ahI+xD3DpQ1zkjyhopg6wv5CwbgvkF5/MEpXv7SvjV CfP8R5b76TzNo2X+a540lH3z6GnWSTKLDqztk9iIZZOqw550xXjoHfUiO7ympKgZ0INf w4wH9hYwIV+0Y5Xts2DWSZ1jkqIJBSysMc3InGSfDDQF4EQUyklAD9DGneKxMJ+IF7Wa KLqQ== X-Gm-Message-State: AOAM533PIMD0Z7i1+QtRVf8O29baKZbpXGXy+lMXpE4fchSOXy2WAOPZ CN6v0lwjOK9SdwUQoI3DVwDJuZgM X-Google-Smtp-Source: ABdhPJwD1xEGQb2PUTfr+Fs++4QcgaDxoz+MPHTEVcWdRnfeompgiPgCSajCUbdrgu8xCjb4RX9IhA== X-Received: by 2002:adf:ecce:: with SMTP id s14mr2004890wro.154.1590854799206; Sat, 30 May 2020 09:06:39 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:28 +0200 Message-Id: <20200530160541.29517-23-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/36] avcodec/utils: Add utility functions for bsf 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Several bitstream filters (e.g. dump_extradata, imxdump, mjpeg2jpeg, mjpegadump, mp3decomp, ...) don't buffer packets; instead, they just modify the buffer of one packet and don't change any other of the packet's non-buffer properties. The usual approach of these bitstream filters is to use separate packets for in- and output as follows: 1. Get the input packet via ff_bsf_get_packet() which entails an allocation. 2. Use av_new_packet() to allocate a big enough buffer in the output packet. 3. Perform the actual work of the bitstream filter, i.e. fill the output buffer. 4. Use av_packet_copy_props() to copy the non-buffer fields of the input packet to the output packet. 5. Free the input packet and return. This commit adds two utility functions that allow a different approach: A function to (re)allocate a refcounted buffer with zeroed padding and a function to replace a packet's buffer and the buffer-related fields with information from an AVBufferRef. This allows to modify the bitstream filters as follows: 1. Get the packet via ff_bsf_get_packet_ref(). 2. Use ff_buffer_padded_realloc() to get a big enough refcounted buffer. 3. Perform the actual work of the bitstream filter. 4. Use ff_packet_replace_buffer() to replace the old data in the packet with the modified one and return. The first of these functions is just packet_alloc() from avpacket.c which has been made non-static. Signed-off-by: Andreas Rheinhardt --- An earlier version put the declarations to internal.h, but James suggested putting them into bsf_internal.h (or actually, into bsf.h because bsf_internal.h didn't exist back then), so I went with this. There is currently no user that actually makes use of the reallocation feature; it was initially thought for hevc_mp4toannexb, but then I decided to make it no longer reallocate the output buffer at all any more. But I kept this functionality. Might be useful some day. libavcodec/avpacket.c | 21 ++++++++++++++++----- libavcodec/bsf_internal.h | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 033f2d8f26..c8f3b0cf7a 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -27,6 +27,7 @@ #include "libavutil/mathematics.h" #include "libavutil/mem.h" +#include "bsf_internal.h" #include "bytestream.h" #include "internal.h" #include "packet.h" @@ -69,7 +70,7 @@ void av_packet_free(AVPacket **pkt) av_freep(pkt); } -static int packet_alloc(AVBufferRef **buf, int size) +int ff_buffer_padded_realloc(AVBufferRef **buf, int size) { int ret; if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) @@ -87,7 +88,7 @@ static int packet_alloc(AVBufferRef **buf, int size) int av_new_packet(AVPacket *pkt, int size) { AVBufferRef *buf = NULL; - int ret = packet_alloc(&buf, size); + int ret = ff_buffer_padded_realloc(&buf, size); if (ret < 0) return ret; @@ -621,7 +622,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src) goto fail; if (!src->buf) { - ret = packet_alloc(&dst->buf, src->size); + ret = ff_buffer_padded_realloc(&dst->buf, src->size); if (ret < 0) goto fail; av_assert1(!src->size || src->data); @@ -674,7 +675,7 @@ int av_packet_make_refcounted(AVPacket *pkt) if (pkt->buf) return 0; - ret = packet_alloc(&pkt->buf, pkt->size); + ret = ff_buffer_padded_realloc(&pkt->buf, pkt->size); if (ret < 0) return ret; av_assert1(!pkt->size || pkt->data); @@ -694,7 +695,7 @@ int av_packet_make_writable(AVPacket *pkt) if (pkt->buf && av_buffer_is_writable(pkt->buf)) return 0; - ret = packet_alloc(&buf, pkt->size); + ret = ff_buffer_padded_realloc(&buf, pkt->size); if (ret < 0) return ret; av_assert1(!pkt->size || pkt->data); @@ -770,3 +771,13 @@ int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp) return 0; } + +void ff_packet_replace_buffer(AVPacket *pkt, AVBufferRef *buf) +{ + av_buffer_unref(&pkt->buf); + + pkt->buf = buf; + pkt->data = buf->data; + av_assert1(buf->size >= AV_INPUT_BUFFER_PADDING_SIZE); + pkt->size = buf->size - AV_INPUT_BUFFER_PADDING_SIZE; +} diff --git a/libavcodec/bsf_internal.h b/libavcodec/bsf_internal.h index fefd5b8905..edaacaa2dd 100644 --- a/libavcodec/bsf_internal.h +++ b/libavcodec/bsf_internal.h @@ -19,6 +19,7 @@ #ifndef AVCODEC_BSF_INTERNAL_H #define AVCODEC_BSF_INTERNAL_H +#include "libavutil/buffer.h" #include "libavutil/log.h" #include "bsf.h" @@ -42,6 +43,32 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt); */ int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt); +/** + * (Re)allocate an AVBufferRef to an effective size of size. In addition, + * the buffer will have AV_BUFFER_INPUT_PADDING_SIZE bytes of zeroed padding + * at the end. + * + * @param buf Pointer to pointer to an AVBufferRef. Must not be NULL; + * *buf will be reallocated to the desired size; if *buf is NULL, + * it will be allocated, otherwise it must be writable. + * @param size Desired usable size. + * @return Zero on success, negative error code on failure. + * *buf is unchanged on error. + */ +int ff_buffer_padded_realloc(AVBufferRef **buf, int size); + +/** + * Unreference the packet's buf and replace it with the given buf. + * The packet's data and size fields will be updated with the information + * from buf, too. + * + * @param pkt Pointer to a packet to modify. Must not be NULL. + * @param buf Pointer to an AVBufferRef. Must not be NULL. + * buf will be owned by pkt afterwards. Its size must include + * AV_INPUT_BUFFER_PADDING_SIZE bytes of padding at the end. + */ +void ff_packet_replace_buffer(AVPacket *pkt, AVBufferRef *buf); + const AVClass *ff_bsf_child_class_next(const AVClass *prev); #endif /* AVCODEC_BSF_INTERNAL_H */ From patchwork Sat May 30 16:05:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20010 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 78A4F44AA6F for ; Sat, 30 May 2020 19:10:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DFC4168AE41; Sat, 30 May 2020 19:06:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3529368B08F for ; Sat, 30 May 2020 19:06:41 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id l10so7154071wrr.10 for ; Sat, 30 May 2020 09:06: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 :mime-version:content-transfer-encoding; bh=UYfhXXOFTG4qMnZAHdpfEolmdwsFmdzGIqJlPI0ncD8=; b=LRIBCgrUmtfCWCIdd85nFUjVXnjKVPjv+vQGT1nDe9SWKYlv448dKa6WhH2pUnkPLP 15cEYkT0uDFZ+KXkevW6wUCZbxbdBna5xB9TIiuOiB1Ntg5VlxxaYpcA74ceDW9nJ/Ap FcJGPZt6pROkJJ8NhVE157ByEZa9gFDKsKMSX6sbgHqzwQZ9MhM2qLRA1Wak505GkD33 MDyOsYbeKaFKBO62Xcxv24Q75DjXs9TO4O7yArBkvHi9xEAJhbcSZyqrM4RuYwEBsVxQ FlP4IShhOjky+l+yji9ibAYo/pphBhhCevHnzEsXrELeqEGRGDs7XgZJbJHFSnCtqdQf XXYQ== 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:mime-version:content-transfer-encoding; bh=UYfhXXOFTG4qMnZAHdpfEolmdwsFmdzGIqJlPI0ncD8=; b=p/UaN/mwRSNkacf9lXPu8H9YWq/N5+5r9NZLdZkk98lyA+NQF/h32TF7OX44vhMI95 3kiroIKT9HNA/Eb3XwXiaeXz7zdYmMmgKaVfNZk465lGM8pfJGWnpEWoatzBMDe1hYov wOlERhgu0hWhh7tXK4wApDbiBbWIvINEnu3/abJYx1vge0O4lQUQWW/xHuj9xkA2CQNC CNhWRz3nBQtc9C/T+G6M6ChlkTSkPpG1ZtwoPrmVg4Dy3rGSfLbPrPUkpYWnptrWf9xQ PeFlqkkQZFrXM0OoF1x0Ji86IOQsMLZn3k4i+6DzWIsADEedvjkedKqhHLJW4QN6zQ+S qa8g== X-Gm-Message-State: AOAM532zz9MylwDFCILAiWr8adUWXweL2JbWQcy8OrWREJLxHb5aKhWt DSIuzVuPdAD+gimJaVgPOG2Mbp6l X-Google-Smtp-Source: ABdhPJzC4bnhLc7DKLJmrhpCbZPOsAXmbreXwg5/NzGBltClB2sahjpijfFwkPT1zf40Sz1aUn5WCA== X-Received: by 2002:a5d:604b:: with SMTP id j11mr13771196wrt.193.1590854800306; Sat, 30 May 2020 09:06:40 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:39 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:29 +0200 Message-Id: <20200530160541.29517-24-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/36] avcodec/h264_mp4toannexb_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_mp4toannexb_bsf.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 91cabcf170..75b38e1be3 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -166,35 +166,33 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx) return 0; } -static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) +static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt) { H264BSFContext *s = ctx->priv_data; - AVPacket *in; uint8_t unit_type, new_idr, sps_seen, pps_seen; const uint8_t *buf; const uint8_t *buf_end; + AVBufferRef *out_buf = NULL; uint8_t *out; uint64_t out_size; int ret; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; /* nothing to filter */ if (!s->extradata_parsed) { - av_packet_move_ref(opkt, in); - av_packet_free(&in); return 0; } - buf_end = in->data + in->size; + buf_end = pkt->data + pkt->size; #define LOG_ONCE(...) \ if (j) \ av_log(__VA_ARGS__) for (int j = 0; j < 2; j++) { - buf = in->data; + buf = pkt->data; new_idr = s->new_idr; sps_seen = s->idr_sps_seen; pps_seen = s->idr_pps_seen; @@ -273,28 +271,25 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) ret = AVERROR(ERANGE); goto fail; } - ret = av_new_packet(opkt, out_size); + ret = ff_buffer_padded_realloc(&out_buf, out_size); if (ret < 0) goto fail; - out = opkt->data; + out = out_buf->data; } } #undef LOG_ONCE - av_assert1(out_size == opkt->size); + ff_packet_replace_buffer(pkt, out_buf); + + av_assert1(out_size == pkt->size); s->new_idr = new_idr; s->idr_sps_seen = sps_seen; s->idr_pps_seen = pps_seen; - ret = av_packet_copy_props(opkt, in); - if (ret < 0) - goto fail; - fail: if (ret < 0) - av_packet_unref(opkt); - av_packet_free(&in); + av_packet_unref(pkt); return ret; } From patchwork Sat May 30 16:05:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20013 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 4F0E344AA6F for ; Sat, 30 May 2020 19:10:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC9BF68B03C; Sat, 30 May 2020 19:06:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA3B568B0B2 for ; Sat, 30 May 2020 19:06:42 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id c71so6673377wmd.5 for ; Sat, 30 May 2020 09:06: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 :mime-version:content-transfer-encoding; bh=DVWWFW107OK7Z0Mjw9eU1wtAFw2sLWk371W2iN85b08=; b=tk5ChCWafp/rY9qtBAKvT3whm/ENtuNEa76iPlP+W3rL2YBWpm1W1HkhKpUikEC2J7 XXf5NBxY/PARsjhjPk1GcJrbAF6lsSwlq6WUADHN+NesLuYKjTDaIAAK2+wgdxAa9LrV 7ZdFber1UfhTiw4owdcl0eIkBtv7j4dr/BLo3bqlMi6GlZFDf3h6b+tsc/3VEy6dEcIc KPp5RfzpK4C2nqdVUSXErW9AIqmW6Sy9enrg1pxPfuEbtgfOMyWPaytOL2+DMevK1kKh Q9ywUI2Xh6LLGx1+3+5OPdHE57xNUozLtY/MpZz6b4zoRZoDt7ysDTQ8mMI6PBMVoLyl T3iA== 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:mime-version:content-transfer-encoding; bh=DVWWFW107OK7Z0Mjw9eU1wtAFw2sLWk371W2iN85b08=; b=Y+irVRvejXVkiW6OZnRRX/WI6/4bm8EWTb6POgmYdPN6T0pR5/LXsaglnlalOxHmQF HCOxVVh/2iGw8Bgrh2z4/q5X+L5O409cXb1exefcxSl5oRNFeiANpcfz48Vj9fkFvIqx yGVgQsHBiqX/vWhNO2gF2Z32gt7CJjY/FSJuP8WX9ePHA4Kkd6WrqMelf4ckPNcoya56 vZYWcTT05zDPYlth7W4le8PEscUefMkfE5ebKdWKxL6PwmMqQ8in6TOK62fG+k4RCQTd WkdeF2f9n8ulsrpO1q1fXwyKXaNzt95R00eI+XTqJvxd7Av86fm4prG2t68TP2S7a7uc +9Ww== X-Gm-Message-State: AOAM5328fMJmZht9g/pw8UJ9ohjt11+I9kW/Kc44sEQ7NTPl33pQtS++ w7j3lEuheHomDthZEv5Wn8HQJkLk X-Google-Smtp-Source: ABdhPJwe064RtOJVP/AGNvkvvtvYrfthbJTXzo7nM7epQW83CzSa4rCGTO1JeDTSX5BD4o2Sme9vmA== X-Received: by 2002:a1c:6884:: with SMTP id d126mr13549926wmc.121.1590854801683; Sat, 30 May 2020 09:06:41 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:40 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:30 +0200 Message-Id: <20200530160541.29517-25-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/36] avcodec/hevc_mp4toannexb_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_mp4toannexb_bsf.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index 731ff2e7d3..9450efe2c8 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -116,20 +116,18 @@ static int hevc_mp4toannexb_init(AVBSFContext *ctx) return 0; } -static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) +static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt) { HEVCBSFContext *s = ctx->priv_data; PutByteContext pb; - AVPacket *in; + AVBufferRef *out = NULL; int ret; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; if (!s->extradata_parsed) { - av_packet_move_ref(out, in); - av_packet_free(&in); return 0; } @@ -138,7 +136,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) uint64_t out_size = 0; int got_irap = 0; - bytestream2_init(&gb, in->data, in->size); + bytestream2_init(&gb, pkt->data, pkt->size); while (bytestream2_get_bytes_left(&gb)) { uint32_t nalu_size = 0; @@ -181,7 +179,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) ret = AVERROR(ERANGE); goto fail; } - ret = av_new_packet(out, out_size); + ret = ff_buffer_padded_realloc(&out, out_size); if (ret < 0) goto fail; @@ -189,14 +187,11 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) } } - ret = av_packet_copy_props(out, in); - if (ret < 0) - goto fail; + ff_packet_replace_buffer(pkt, out); fail: if (ret < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return ret; } From patchwork Sat May 30 16:05:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20014 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 9706744AA6F for ; Sat, 30 May 2020 19:10:46 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 71F3568B13A; Sat, 30 May 2020 19:06:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1783C68B0C4 for ; Sat, 30 May 2020 19:06:44 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id c3so7122189wru.12 for ; Sat, 30 May 2020 09:06: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 :mime-version:content-transfer-encoding; bh=RyP2Vog+jWokv2ZR7nBghAh2Ibz0gjwky51/38kt50o=; b=Y2mdPqIkMBKs9mxCxlM1SyFKEhZacxPcHRHAyJCIsXEH/nnZc/4pVaW5UOWN+fXS2i TmV1q2qCLBpyDZEh+x5jgGJs/244qUtqfIhXMZ5J15LuuxFKwb69S7WGN0Bw3Enwdn0G EIQP8BHOcR/NwClknZYZ+6xatbmEmTWsG+tQYWtfs6XzGGagEcy7tiJ61wBas9kjRJht 524FkHP8ebqOqJEm6WRhj4xr6r0B0RjH67uLHgAuO5kcsPzuwezBhssgXTK1Hl6q3bgm hEvpmgFJT7z5yMxo6Z1tXhjSUNfjJ55RNA/b4yDAp+3qYWX0C4RSeLebSk52re9yMZyc OXKg== 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:mime-version:content-transfer-encoding; bh=RyP2Vog+jWokv2ZR7nBghAh2Ibz0gjwky51/38kt50o=; b=tCZsmIh8tTI55zlW88EpHSgCvtBpRRqD1G7cVSQTswPHet48n2EoZR9bJBOrb0+4Uh +p8Aw4XL50DQVHVA4H/Xlp6uRJK+fDApNelfZ+diYnKsebj1MLMoyo3hoSy52aazZFtZ a6z6pafUEFCeeX2+uhoEuvUEHyckyLNhq5IITrhHmGY3zZwSyO//11DcVO9XJ1GCJlwB h+fAiSG5t/Ias440FwturaUoroKB8b9rY/9YO7GTT6tunxWDxdHjGgIc1hWkYedxV2xK HGakGSLQ1P0WxpLNT2YqTfdeM6g+wdURsQnaJ+75JyBkcR0QkTCOTJj6PH0er1/WKYye GnxQ== X-Gm-Message-State: AOAM533wLCovecKCqzKmnQA03pr6xpJwcTlY9VhFM79qchbnkXOPlLxm TUfu/GZM+bfhTtRY0zqlY8ZDhDk4 X-Google-Smtp-Source: ABdhPJxmaUQ+h5MD5h3NVA+cCJbOU+XSytTNed5Y5JCbSDjlc3opl3qnBPf75Leedi12ZNdpDnrbJw== X-Received: by 2002:a5d:6750:: with SMTP id l16mr13885397wrw.295.1590854803174; Sat, 30 May 2020 09:06:43 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:42 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:31 +0200 Message-Id: <20200530160541.29517-26-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/36] avcodec/mjpega_dump_header_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpega_dump_header_bsf.c | 39 +++++++++++++---------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index 4608fe550b..2d49b042ec 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -31,29 +31,27 @@ #include "mjpeg.h" -static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) +static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt) { - AVPacket *in; uint8_t *out_buf; unsigned dqt = 0, dht = 0, sof0 = 0; int ret = 0, i; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - for (i = 0; i < in->size - 3; i++) { - if (in->data[i] == 0xff) { - switch (in->data[i + 1]) { + for (i = 0; i < pkt->size - 3; i++) { + if (pkt->data[i] == 0xff) { + switch (pkt->data[i + 1]) { case DQT: dqt = i + 46U; break; case DHT: dht = i + 46U; break; case SOF0: sof0 = i + 46U; break; case SOS: - ret = av_new_packet(out, in->size + 44U); - if (ret < 0) - goto fail; + { + AVBufferRef *out = NULL; - ret = av_packet_copy_props(out, in); + ret = ff_buffer_padded_realloc(&out, pkt->size + 44U); if (ret < 0) goto fail; @@ -65,24 +63,22 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) bytestream_put_be16(&out_buf, 42); /* size */ bytestream_put_be32(&out_buf, 0); bytestream_put_buffer(&out_buf, "mjpg", 4); - bytestream_put_be32(&out_buf, in->size + 44U); /* field size */ - bytestream_put_be32(&out_buf, in->size + 44U); /* pad field size */ - bytestream_put_be32(&out_buf, 0); /* next ptr */ + bytestream_put_be32(&out_buf, pkt->size + 44U); /* field size */ + bytestream_put_be32(&out_buf, pkt->size + 44U); /* pad field size */ + bytestream_put_be32(&out_buf, 0); /* next ptr */ bytestream_put_be32(&out_buf, dqt); /* quant off */ bytestream_put_be32(&out_buf, dht); /* huff off */ bytestream_put_be32(&out_buf, sof0); /* image off */ bytestream_put_be32(&out_buf, i + 46U); /* scan off */ - bytestream_put_be32(&out_buf, i + 46U + AV_RB16(in->data + i + 2)); /* data off */ - bytestream_put_buffer(&out_buf, in->data + 2, in->size - 2); /* skip already written SOI */ + bytestream_put_be32(&out_buf, i + 46U + AV_RB16(pkt->data + i + 2)); /* data off */ + bytestream_put_buffer(&out_buf, pkt->data + 2, pkt->size - 2); /* skip already written SOI */ - out->size = out_buf - out->data; - av_packet_free(&in); + ff_packet_replace_buffer(pkt, out); return 0; + } case APP1: - if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) { + if (i + 12U <= pkt->size && AV_RL32(pkt->data + i + 8) == AV_RL32("mjpg")) { av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n"); - av_packet_move_ref(out, in); - av_packet_free(&in); return 0; } } @@ -90,8 +86,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out) } av_log(ctx, AV_LOG_ERROR, "No valid SOS marker in bitstream\n"); fail: - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return AVERROR_INVALIDDATA; } From patchwork Sat May 30 16:05:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20015 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 A3DCA44AA6F for ; Sat, 30 May 2020 19:10:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6727F68B14F; Sat, 30 May 2020 19:06:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6570668B0DF for ; Sat, 30 May 2020 19:06:45 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id h5so1248454wrc.7 for ; Sat, 30 May 2020 09:06:45 -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 :mime-version:content-transfer-encoding; bh=/O0m7X+li93e8fyS21wjbh7p1NDVkH2w02nyej6svMA=; b=oYJRuOcyD8zDZx75+WGxu7n8iYGbXRJU+PiVQYBB8HEGNDbyOsgTUFfnrLq5PH31n7 5BaLcZq6sRKrT1qC/YP+quduDTV841DSx+04eWaa+mZcF9BMa6BAFuq1r6bvRmme3iEW 4NuNUxPh9Nvtg1h+HJZqT3dCdl67KhcXChMdOSZVlN3++MXpP2bJD4h8jbBag4tdo2zH Kr0pim0yZ0IGQ41pZYmNnBfZ/OhcrR5BiEKNAdBY0jRY/0khY1Amsvet1+/Q2jBERN4Z 0h45B9QDnAd8g4E0Uf1A0YKHtvUgjmq1PRKXcLcNJpMtTTkxAKez7nu8691Lq3aiHzIY of+A== 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:mime-version:content-transfer-encoding; bh=/O0m7X+li93e8fyS21wjbh7p1NDVkH2w02nyej6svMA=; b=dcuJRVpjCdULPEzEh0bGkfi52Hyk9hEBMCvj04WOSk+Espp87gt4PZWrTiL949hkBy eO2VnGWMXyq2wIU81HNk8Cq6chR8pd4tqUq6a8VHYup75MNPipAS/i0v/SwnWOmrVwsS nnNVpivfJe6lNPeZK7y04BIeF578SVoMN+8RyFNMCGPP/D6rB1N2Ee5TSTfromvgIIKr XK24whnttnzRvH+BJKF7FFxpdUcL4Zw0C8xSKEQB9/9kX8K/L82EQOK0G0kX9YFhSgY8 VMdiHI8AcdRL9Jika3XD7t3V4QLdkyC0HJOP3AdvGlgvnqvUAVdUsqf41+rF+PD10qnJ QbxQ== X-Gm-Message-State: AOAM531RoR8G9+Sx3lKv6qHReK/mu4m9QRj0SdAYyyqzPcNxPf1nvvEU kkkw2ZLykPY6uzGuM1doBj/q5cwU X-Google-Smtp-Source: ABdhPJxEV8SI/2SVrncZ5n1afmUGrDdn6LJoq/bio5jd/UyOvrX2kb7bU1CuxzJloFdDt6PnaE33HA== X-Received: by 2002:a5d:4d01:: with SMTP id z1mr14988283wrt.29.1590854804537; Sat, 30 May 2020 09:06:44 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:43 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:32 +0200 Message-Id: <20200530160541.29517-27-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 27/36] avcodec/mjpega_dump_header_bsf: 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Reindentation; furthermore, the names of the out and out_buf variables have been switched: The latter is now an AVBufferRef * whereas the former is directly used for writing. And some variables have been put into a smaller scope. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpega_dump_header_bsf.c | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index 2d49b042ec..4ea55e88ba 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -33,15 +33,14 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt) { - uint8_t *out_buf; unsigned dqt = 0, dht = 0, sof0 = 0; - int ret = 0, i; + int ret; ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - for (i = 0; i < pkt->size - 3; i++) { + for (int i = 0; i < pkt->size - 3; i++) { if (pkt->data[i] == 0xff) { switch (pkt->data[i + 1]) { case DQT: dqt = i + 46U; break; @@ -49,31 +48,32 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt) case SOF0: sof0 = i + 46U; break; case SOS: { - AVBufferRef *out = NULL; + AVBufferRef *out_buf = NULL; + uint8_t *out; - ret = ff_buffer_padded_realloc(&out, pkt->size + 44U); - if (ret < 0) - goto fail; + ret = ff_buffer_padded_realloc(&out_buf, pkt->size + 44U); + if (ret < 0) + goto fail; - out_buf = out->data; - bytestream_put_byte(&out_buf, 0xff); - bytestream_put_byte(&out_buf, SOI); - bytestream_put_byte(&out_buf, 0xff); - bytestream_put_byte(&out_buf, APP1); - bytestream_put_be16(&out_buf, 42); /* size */ - bytestream_put_be32(&out_buf, 0); - bytestream_put_buffer(&out_buf, "mjpg", 4); - bytestream_put_be32(&out_buf, pkt->size + 44U); /* field size */ - bytestream_put_be32(&out_buf, pkt->size + 44U); /* pad field size */ - bytestream_put_be32(&out_buf, 0); /* next ptr */ - bytestream_put_be32(&out_buf, dqt); /* quant off */ - bytestream_put_be32(&out_buf, dht); /* huff off */ - bytestream_put_be32(&out_buf, sof0); /* image off */ - bytestream_put_be32(&out_buf, i + 46U); /* scan off */ - bytestream_put_be32(&out_buf, i + 46U + AV_RB16(pkt->data + i + 2)); /* data off */ - bytestream_put_buffer(&out_buf, pkt->data + 2, pkt->size - 2); /* skip already written SOI */ + out = out_buf->data; + bytestream_put_byte(&out, 0xff); + bytestream_put_byte(&out, SOI); + bytestream_put_byte(&out, 0xff); + bytestream_put_byte(&out, APP1); + bytestream_put_be16(&out, 42); /* size */ + bytestream_put_be32(&out, 0); + bytestream_put_buffer(&out, "mjpg", 4); + bytestream_put_be32(&out, pkt->size + 44U); /* field size */ + bytestream_put_be32(&out, pkt->size + 44U); /* pad field size */ + bytestream_put_be32(&out, 0); /* next ptr */ + bytestream_put_be32(&out, dqt); /* quant off */ + bytestream_put_be32(&out, dht); /* huff off */ + bytestream_put_be32(&out, sof0); /* image off */ + bytestream_put_be32(&out, i + 46U); /* scan off */ + bytestream_put_be32(&out, i + 46U + AV_RB16(pkt->data + i + 2)); /* data off */ + bytestream_put_buffer(&out, pkt->data + 2, pkt->size - 2); /* skip already written SOI */ - ff_packet_replace_buffer(pkt, out); + ff_packet_replace_buffer(pkt, out_buf); return 0; } case APP1: From patchwork Sat May 30 16:05:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20023 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bac9:0:0:0:0:0 with SMTP id a9csp1500364ybk; Sat, 30 May 2020 09:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOwgmKyCkHRTlM8XsC+2hBeRiQbBSpP69C3O5hy/QR34qVB8J/eQFxL3/f+VEJP3LAu9uN X-Received: by 2002:adf:ff82:: with SMTP id j2mr13361910wrr.375.1590855072411; Sat, 30 May 2020 09:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590855072; cv=none; d=google.com; s=arc-20160816; b=KdQmSDvwMQsqm3mrosisAfhejBguDvYlVDZy0a+OgO7jwKfi/XShhtSzBZxmx37b8G ZtFPvc8EwGGz+slC2wh85bVOD4sJ1D236Pha9s/EqJaDEPZq1K4mlTUIkYBC3wDJpJxa e1rq51cjpKzFujyu1peOd28pW4UmBLoVtVThwKiwK6hYZNIz4UEP+2ogO17bxbYHDpsr KKdAirFfnbO30gd8vLPF8Rp+xpFSseyhc7AwHjuffXxxCZm6spwjPIqqXMBFX2ILaIQr iwsGyOhdUbNEab5SaMK+YlHRFmADKJEINxs2Ru+PqCNaUMy2OuyESbwo9wWFJwEWq9u+ nKmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=xa1kpI0dWUS83U2NoiYtJhrru/uBjID8lbyuSZC6IqM=; b=KG3IVpSB+9ATJLMVG0y72D7JfczBNO1ukSbuaqOVLPzuvSB5z9iLGayZArs6GfPSLF 1TrZE1dFE0pJyKXy72mrNiWtNTrNUrUlnXKRgdulYV3hy0FxYIYQ3pUpfBUWqqSLMONr AY8/ArLBa6tuK0pzDRRicA/fp0080vxjaE5lZWwGnBR2BkSuw86GDAVih1jN75AyIu4q wwWeBOsYnq8LaAEIieR29eqhA6MCorZox390+iIuSYcp7O6HW2fhvklht3vYk1aIdq0Q mBmlCYJjXj4iti8GnrL5pmm/+daq92gKek7VQ6uErcFatQWK2nrKA7BUbdAk1sXuvgOO ewDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="j/hu9Uy6"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j3si12175274wrt.396.2020.05.30.09.11.12; Sat, 30 May 2020 09:11:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="j/hu9Uy6"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 747C868B0F2; Sat, 30 May 2020 19:06:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 70B3168B0F0 for ; Sat, 30 May 2020 19:06:46 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id j10so7160075wrw.8 for ; Sat, 30 May 2020 09:06: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 :mime-version:content-transfer-encoding; bh=LCc7lqyWt2o7ij24E960rNxSI0VqDVgkJg5cS3i1ms4=; b=j/hu9Uy6kJZJgW/47iZrX6EQglSqpFA0gIwKShoyNccHe/wpZfwOJeUrhigBHE/DiV pN+sqvV0iDxMqnnfOms1CWPNLYVuR+48R2ssNI1pC8f46cdB4o10pw43zFSxgNlU1R5W 8vW/nmF6R2GL9aQXj2KYXM7Kr1O8KKlKVAeMRn2SkSjyf275pze99MIBk0bdbZSvdyoy hFEhxRjX2dA/MPXzQfW5E9/Q0+GOlQ+IMKmiqzK1jVWkoi/JPuhx4dIfIKdLMmSfE1QP R0/p2zX0ZUkR0vgDj3VwULOGNK0w78to+6s9Iprmh54aPSvI/nsmUjAilGKrApoMWgca HSOw== 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:mime-version:content-transfer-encoding; bh=LCc7lqyWt2o7ij24E960rNxSI0VqDVgkJg5cS3i1ms4=; b=RSUir5nZYnQz2i3rKx+axlAaPBs8uBHO7L9uzRZt0tiQYbSpLRX5ow596iYrx1O9qN c4o8Q+vOuAZSvaQyIKVY2g2xkl0fwPMWhNrDqG/PRcquTM7zYF29kk/FNNd7OJE2/7YN NkVsZ1tU6r5nmrFVpsp3ne6jZJ+mptJsVKNLEf82SEKknBCVNbKZcqcoNlmGrLm1+mDt +MwF3taJA6zfg3M09n/ESM468noZM4wyfzm/ndqMpYEhRuPjavNsmXtmktoGR9wwkiZ/ XQsjOX1IDiXywu2SSMXRTM3OctxHNjB+7t5d4Iq0hzn0CHwXX3dtpBo6pzGxp0fHDQrW 4pvw== X-Gm-Message-State: AOAM530icCgaFJf+Y09XFEFlqqoM3AABG1uOZpE4lWviWDbW8Gg3taa9 tQxwSRRoLMhwsw+ExJG+Nc1S8PIj X-Received: by 2002:a5d:4c45:: with SMTP id n5mr14084298wrt.341.1590854805485; Sat, 30 May 2020 09:06:45 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:44 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:33 +0200 Message-Id: <20200530160541.29517-28-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/36] avcodec/mjpega_dump_header_bsf: Miscellaneous improvements 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uxxp3ziavHoB Content-Length: 2201 1. Instead of comparing two values read via AV_RL32 one can read both via AV_RN32 and compare the values. 2. Errors like AVERROR(ENOMEM) from failed allocations are now always forwarded. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpega_dump_header_bsf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c index 4ea55e88ba..98fd2f9250 100644 --- a/libavcodec/mjpega_dump_header_bsf.c +++ b/libavcodec/mjpega_dump_header_bsf.c @@ -77,7 +77,7 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt) return 0; } case APP1: - if (i + 12U <= pkt->size && AV_RL32(pkt->data + i + 8) == AV_RL32("mjpg")) { + if (i + 12U <= pkt->size && AV_RN32(pkt->data + i + 8) == AV_RN32("mjpg")) { av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n"); return 0; } @@ -85,9 +85,10 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *pkt) } } av_log(ctx, AV_LOG_ERROR, "No valid SOS marker in bitstream\n"); + ret = AVERROR_INVALIDDATA; fail: av_packet_unref(pkt); - return AVERROR_INVALIDDATA; + return ret; } static const enum AVCodecID codec_ids[] = { From patchwork Sat May 30 16:05:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20016 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 5A2DE44AC08 for ; Sat, 30 May 2020 19:11:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B039A68B16A; Sat, 30 May 2020 19:06:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0BDF068AFBE for ; Sat, 30 May 2020 19:06:48 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id t18so7190446wru.6 for ; Sat, 30 May 2020 09:06: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 :mime-version:content-transfer-encoding; bh=NDxecd/XFRVJzBk5Hc6PqcAzNTQieXP1g0F6rTZ87lE=; b=BP4zCZBs/Qgmct8DW9whVQ+zmgjnBbUpgAj4viU0qpy2gmEHJJVTOq6tdLNur0ZbdF a1Z/OghFB2RQ3MYELP1jounuKCKFv1WZyXfUlGHAGm376BS3cN9XSW6B/B1DH4RNR1pB E4fsrBwuTx90m1MsFIzWeaKORTNJnBHkbkiPB0g3YdC47zZp9CzbYhxR03a4Zi8vrsgr JHaW1UW6O8qjxBq31aWFtv9ytykAS3boeaphPcgmroxi1+TpfRdiU5kow42dQCeQcKYb 64QVMeYLMkexnOHgE5e8Ft68C8dC48uJK+OFWi65cgklKhRinxfSLzvXLeQmc74uGsBv arlA== 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:mime-version:content-transfer-encoding; bh=NDxecd/XFRVJzBk5Hc6PqcAzNTQieXP1g0F6rTZ87lE=; b=a7jyzA0/1fcRi1rPZ5EnxewD/VososGPj22WjkXlZkWUNVP5CiCowBUq9jvdWANi8E vngO1MdxIEfQl0km5ChYj81YcMG0ZUAfvuB0fUQZAmRL66Wsj2F3HPIDlCrnyV6U/k6t 4axlo8BMv/7bSfh8UdSFbxky60Zqs42M/ZXSVnMNZxpsfDB8l3CecMP4CUSohe5v7X12 czEYBwwjWv+yDDdnqOYceC+JpOjmBbZLAD5niOJuz97z6KoUuLgW5PXm4TnlXZv6yxYu NpLmPlUzplbeIJgNWmeSj3PGEKRzrwu7EHTH2FASfuNeQasqeJI+13jpE64Brs0chWko 4znw== X-Gm-Message-State: AOAM531p0my5/njEwdivB8RxZlmOvqEgnVzk8JcijNhSuX12L5MB3Hij 7aImUuuT7TxDNr4TdlHYrh/mv8SJ X-Google-Smtp-Source: ABdhPJz1tp52o4RGxtS4K+oWseeFOiZPDFAZtEEJAGF66wr02JtaKQtiZMvJCIQL99KdYbCR/m3gew== X-Received: by 2002:a5d:5449:: with SMTP id w9mr14154956wrv.106.1590854807024; Sat, 30 May 2020 09:06:47 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:46 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:34 +0200 Message-Id: <20200530160541.29517-29-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 29/36] avcodec/movsub_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/movsub_bsf.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c index 6e29fa8e50..b5b714ce7e 100644 --- a/libavcodec/movsub_bsf.c +++ b/libavcodec/movsub_bsf.c @@ -23,37 +23,33 @@ #include "bsf.h" #include "bsf_internal.h" -static int text2movsub(AVBSFContext *ctx, AVPacket *out) +static int text2movsub(AVBSFContext *ctx, AVPacket *pkt) { - AVPacket *in; + AVBufferRef *out = NULL; int ret = 0; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - if (in->size > 0xffff) { + if (pkt->size > 0xffff) { ret = AVERROR_INVALIDDATA; goto fail; } - ret = av_new_packet(out, in->size + 2); + ret = ff_buffer_padded_realloc(&out, pkt->size + 2); if (ret < 0) { - ret = AVERROR(ENOMEM); goto fail; } - ret = av_packet_copy_props(out, in); - if (ret < 0) - goto fail; + AV_WB16(out->data, pkt->size); + memcpy(out->data + 2, pkt->data, pkt->size); - AV_WB16(out->data, in->size); - memcpy(out->data + 2, in->data, in->size); + ff_packet_replace_buffer(pkt, out); fail: if (ret < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return ret; } From patchwork Sat May 30 16:05:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20017 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 8FA1544AC08 for ; Sat, 30 May 2020 19:11:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7843668B119; Sat, 30 May 2020 19:06:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EB6168AFA1 for ; Sat, 30 May 2020 19:06:49 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id f5so7145491wmh.2 for ; Sat, 30 May 2020 09:06: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 :mime-version:content-transfer-encoding; bh=6eBSeExlYUVUSCn81gmFVQcs0mXZjL509uEWIEuZEvI=; b=NrDYg8mFxRm8eFr5xo3mTOFqLjOZqpbzqKB1c8V26L/2E4eEA2WjPqkpaySemGwCoe 4/rmItF+4/UFSOOZ5s9h1uOdDjALRzWFL37DQB8uCgCNwpuaE5mYGh5rKJ/fCKWRxndt DOE8MAJZM4x6/SLVRSyem3KRrCBOyCgHR2PTkiOsN0N5FaV6RkpEnjYFUvQ2YRPalRfd tvwq+T/4jGsMWGJjO3d9M+mZHeLlrjaWs9+ZoWBAaHt1uk+RVY6tmc8L2tPQfmP7VKk0 fqJCRXnQTrwW89WUYEefHFKC4wB8az7qAN9JeYRYeV44N8/GhWkx12DkRd9U5qQ82ufu fbow== 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:mime-version:content-transfer-encoding; bh=6eBSeExlYUVUSCn81gmFVQcs0mXZjL509uEWIEuZEvI=; b=Raby0w7l/2RPBag2dL0Px1vzq2ApObc1UfjIVdOvID/hZzbUJ1iSO8ctKUWrHiMpfb n+mGLDbw8uqWykye+OiaXre1wWZgSQdgYCMJq55o+mLLGz2qF8rK6yqYaDIl3D3sJGaS jMYYAofwLp92BtoWtY+Y+XiUTE4lnSk2V4FvRscXNI+v/7jgyDNFMt1tKuiOiWd4Fx8t bhuEea3Ftc/sr4RFEZ1qQHZIf8aI+YnOK3h98iQ+t7oRd1fvRpcHhoaV9RZDI6XOFlu1 L7vNMuJXqHjUwnGeVZ470pxc/OPrfFTqrTmEHQGfU0O+5eLXXfDT8oqSwVaQx4EG5LD/ gEqg== X-Gm-Message-State: AOAM530+b1YxZw669dkkBsehORVkp4vQOD8f0OKsKoRfIMcbj7lksIXI PWkpQDSXGTUDfVqfR+LySjb34Sgb X-Google-Smtp-Source: ABdhPJyo9YGf7ah0uj5Hye1DOJu43eWAVvr/RyJrdvF4VyMdLaWWGGAomlo5hpcN/zb7PRHif6F7CA== X-Received: by 2002:a1c:305:: with SMTP id 5mr13447484wmd.60.1590854808268; Sat, 30 May 2020 09:06:48 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:47 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:35 +0200 Message-Id: <20200530160541.29517-30-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 30/36] avcodec/imx_dump_header_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/imx_dump_header_bsf.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/libavcodec/imx_dump_header_bsf.c b/libavcodec/imx_dump_header_bsf.c index e2b6a15591..95f8f31f66 100644 --- a/libavcodec/imx_dump_header_bsf.c +++ b/libavcodec/imx_dump_header_bsf.c @@ -30,39 +30,35 @@ #include "bytestream.h" -static int imx_dump_header(AVBSFContext *ctx, AVPacket *out) +static int imx_dump_header(AVBSFContext *ctx, AVPacket *pkt) { /* MXF essence element key */ static const uint8_t imx_header[16] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }; - AVPacket *in; + AVBufferRef *out = NULL; int ret = 0; uint8_t *out_buf; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - ret = av_new_packet(out, in->size + 20); - if (ret < 0) - goto fail; + ret = ff_buffer_padded_realloc(&out, pkt->size + 20U); + if (ret < 0) { + av_packet_unref(pkt); + return ret; + } out_buf = out->data; bytestream_put_buffer(&out_buf, imx_header, 16); bytestream_put_byte(&out_buf, 0x83); /* KLV BER long form */ - bytestream_put_be24(&out_buf, in->size); - bytestream_put_buffer(&out_buf, in->data, in->size); + bytestream_put_be24(&out_buf, pkt->size); + bytestream_put_buffer(&out_buf, pkt->data, pkt->size); - ret = av_packet_copy_props(out, in); - if (ret < 0) - goto fail; + ff_packet_replace_buffer(pkt, out); -fail: - if (ret < 0) - av_packet_unref(out); - av_packet_free(&in); - return ret; + return 0; } static const enum AVCodecID codec_ids[] = { From patchwork Sat May 30 16:05:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20018 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 56D7244AC08 for ; Sat, 30 May 2020 19:11:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 35A1668B11A; Sat, 30 May 2020 19:06:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5C25B68AFD8 for ; Sat, 30 May 2020 19:06:50 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id e1so7211323wrt.5 for ; Sat, 30 May 2020 09:06:50 -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 :mime-version:content-transfer-encoding; bh=gmuJiDHhmtdCKCiALo/tWx/v99QNJOo+HNBraVW3+vc=; b=sfcnSct0i9icaL7A3niwZM9PX6ac7jQ9Q5QnpRBwowo6AEnDpM7bRlDMd1gGx2PdrD zBjm/ijrV6g8khRn0qoxzArzCpAYYiGVKyKVaXarpnsGPBKKHiieEQiGaqok4jaruxlW QCj7hf9HE1gtxrQ43tn6q5e0WjuNxXpAkOlt2gRJt85xWYclUF9FucLGEkhWxezgOWuP n7RGtToMovdZFZnnIeecXh3rBOriji6pR4XKvVQY0D9gNG5NaPisWJM310tKvLfYlaHZ XrBKAlwlEEjz3I9qLg7isMqPXv0qG7l+MeyIjSyjqx06YzF4urK4HMowjkHFWOpr13VR hwSw== 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:mime-version:content-transfer-encoding; bh=gmuJiDHhmtdCKCiALo/tWx/v99QNJOo+HNBraVW3+vc=; b=bBZ9O61HLzRt9nMOAbqZmxQwe1lVTLmZ7x5MaL4VGNCSHjX9QYvUMhVW2qMwg8nb/Y lxKDzRNSscmoUaI1eZ9GGQEc2G3mGZwGnky5eU1nBbicCVWhA1SiGP/MruRZXHwRbaHG 2g4XGke7iILBa2DQl67CqTkZKVzvkB485n553py2POP75NnHEkJwGk08sSlCnMciUSiC rnsRj0IWws8sDuTAFk+z7DW59vbYw1Y70Qxewwg78pEG+b8kOY9jqenbUugITdL/EBnH w1h1rPmltz22UjSSTPqzr2AV0jacojVnLydFnWDnb/n2aPI7UgPLQsq1SLUU+0dxGyFD GE2A== X-Gm-Message-State: AOAM532mzE6/HbNDQuxDO5k/Zc4wfVQpRereCqmYpSia93NHYjS5HpHU 1/9bkDB5MUS1RC30DTNY8pRPByPh X-Google-Smtp-Source: ABdhPJwC0Y7Tnb2Bx38qXSn8AnTrNMtTbl549wPPtju//Xv+aJxVLSOtgmizQinTOv86tiIXgc8nUg== X-Received: by 2002:adf:a50e:: with SMTP id i14mr2109832wrb.21.1590854809510; Sat, 30 May 2020 09:06:49 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:48 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:36 +0200 Message-Id: <20200530160541.29517-31-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 31/36] avcodec/mjpeg2jpeg_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpeg2jpeg_bsf.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/libavcodec/mjpeg2jpeg_bsf.c b/libavcodec/mjpeg2jpeg_bsf.c index b30f391bf9..dc729cfd95 100644 --- a/libavcodec/mjpeg2jpeg_bsf.c +++ b/libavcodec/mjpeg2jpeg_bsf.c @@ -77,40 +77,40 @@ static uint8_t *append_dht_segment(uint8_t *buf) return buf; } -static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket *out) +static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket *pkt) { - AVPacket *in; + AVBufferRef *out = NULL; int ret = 0; int input_skip, output_size; uint8_t *output; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - if (in->size < 12) { + if (pkt->size < 12) { av_log(ctx, AV_LOG_ERROR, "input is truncated\n"); ret = AVERROR_INVALIDDATA; goto fail; } - if (AV_RB16(in->data) != 0xffd8) { + if (AV_RB16(pkt->data) != 0xffd8) { av_log(ctx, AV_LOG_ERROR, "input is not MJPEG\n"); ret = AVERROR_INVALIDDATA; goto fail; } - if (in->data[2] == 0xff && in->data[3] == APP0) { - input_skip = (in->data[4] << 8) + in->data[5] + 4; + if (pkt->data[2] == 0xff && pkt->data[3] == APP0) { + input_skip = AV_RB16(pkt->data + 4) + 4; } else { input_skip = 2; } - if (in->size < input_skip) { + if (pkt->size < input_skip) { av_log(ctx, AV_LOG_ERROR, "input is truncated\n"); ret = AVERROR_INVALIDDATA; goto fail; } - output_size = in->size - input_skip + + output_size = pkt->size - input_skip + sizeof(jpeg_header) + dht_segment_size; - ret = av_new_packet(out, output_size); + ret = ff_buffer_padded_realloc(&out, output_size); if (ret < 0) goto fail; @@ -118,16 +118,13 @@ static int mjpeg2jpeg_filter(AVBSFContext *ctx, AVPacket *out) output = append(output, jpeg_header, sizeof(jpeg_header)); output = append_dht_segment(output); - output = append(output, in->data + input_skip, in->size - input_skip); + output = append(output, pkt->data + input_skip, pkt->size - input_skip); - ret = av_packet_copy_props(out, in); - if (ret < 0) - goto fail; + ff_packet_replace_buffer(pkt, out); fail: if (ret < 0) - av_packet_unref(out); - av_packet_free(&in); + av_packet_unref(pkt); return ret; } From patchwork Sat May 30 16:05:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20011 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 B305744AA6F for ; Sat, 30 May 2020 19:10:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B62C868B19B; Sat, 30 May 2020 19:06:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E13F68B10E for ; Sat, 30 May 2020 19:06:51 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id t18so7190584wru.6 for ; Sat, 30 May 2020 09:06:51 -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 :mime-version:content-transfer-encoding; bh=tpS+qpl4Jmjq9ZNHJ42G31dyhZBOlZfxajnQ/HMRuns=; b=qd6Hpz0RnXIzIauozM7bNSv6YZOWWZNeC5dvu+B6hOZkWWesHRrvGhydwL1K7IpWYl uTh7pkGYVbFUVhNQU5U+8WsU/H3m1w5pHfgMAaxnDsEIrwLsE266cDnzG1z1HQuB/hDV esBnhFz7TxO2z9nw3xl/QXNzpK0SI/VkDIX0GbPoB77CKvDJZkRmTyn6tT4dW+4crNrP Fdsam1IJ4WkqaLQhKM6672u2NmeeQvTvOIkoZZgtPRBIOVENdGnhTcDm4Mx/FCsgYELc K2ifzXF5Rn8MVjEZI1vPduCT7a44h7nCn2PJnbJwBowCzIPGIAItM0O3H0Vm7ImAbvA7 YTjw== 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:mime-version:content-transfer-encoding; bh=tpS+qpl4Jmjq9ZNHJ42G31dyhZBOlZfxajnQ/HMRuns=; b=tJSF1d92ZOD/kisZUxG2T+NvxTKH0PsvC+qqI+IXakz7xF7BtJL2TGZg4AiKWfeeWg EAswgZB/CUC9b/33ddVpyTh0PjVo/t2FdEIxCjG8IqTzC4svbzRiTpTIw1BOCRhUG7/8 rp4jH1rNny6jg6qzRV5v2qHs8dhFvwOFSvj3WUMlTRNrzr7JItlnkq2qppYEo3Dz9vmN z9IQz1LZsfYmrPpl+yGgBJAiILfrsA1VH6UNEZFmcWdQFTfXVrd6/84hsONcf3YwJiu5 D3HGjI226aUPaKrRYpyvjU/UrjG7wW4sbKwH4NDPgFOCZBhkUvAw7JaL8EXb02r6/J2O xTnQ== X-Gm-Message-State: AOAM533HGqSXRhZYYvjom9Y/iPvRAA5yCq91zSMHQGlfXyqdXY5xG3dl nOrWUnCE637lpscBn+vziC8KPJgC X-Google-Smtp-Source: ABdhPJz9u4gZs4oSkquqtYOmXWjkn8Zfu+eqkEeUY+o7nd6rCdyrF3ocL1GFovOuzIo9zAh07Nk7jQ== X-Received: by 2002:adf:e3c4:: with SMTP id k4mr13726525wrm.262.1590854810754; Sat, 30 May 2020 09:06:50 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:50 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:37 +0200 Message-Id: <20200530160541.29517-32-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 32/36] avcodec/mp3_header_decompress_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/mp3_header_decompress_bsf.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c index 3d357dd27e..29ab5721ef 100644 --- a/libavcodec/mp3_header_decompress_bsf.c +++ b/libavcodec/mp3_header_decompress_bsf.c @@ -26,28 +26,25 @@ #include "mpegaudiodata.h" -static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) +static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *pkt) { - AVPacket *in; uint32_t header; int sample_rate= ctx->par_in->sample_rate; int sample_rate_index=0; int lsf, mpeg25, bitrate_index, frame_size, offset, ret; + AVBufferRef *out = NULL; const uint8_t *buf; int buf_size; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; - buf = in->data; - buf_size = in->size; + buf = pkt->data; + buf_size = pkt->size; header = AV_RB32(buf); if(ff_mpa_check_header(header) >= 0){ - av_packet_move_ref(out, in); - av_packet_free(&in); - return 0; } @@ -89,14 +86,9 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) offset++; } - ret = av_new_packet(out, frame_size); + ret = ff_buffer_padded_realloc(&out, frame_size); if (ret < 0) goto fail; - ret = av_packet_copy_props(out, in); - if (ret < 0) { - av_packet_unref(out); - goto fail; - } memcpy(out->data + offset, buf, buf_size); if(ctx->par_in->channels==2){ @@ -118,10 +110,13 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out) header |= 1 << 16; // protection_bit AV_WB32(out->data, header); + ff_packet_replace_buffer(pkt, out); + ret = 0; fail: - av_packet_free(&in); + if (ret < 0) + av_packet_unref(pkt); return ret; } From patchwork Sat May 30 16:05:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20029 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bac9:0:0:0:0:0 with SMTP id a9csp1500953ybk; Sat, 30 May 2020 09:12:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/hePSv1IewKVEwFL/Fkca0M9yAFxRCmc4AttIFZtk6fP/zJmBlkbe6Zuh3urufh/+slx1 X-Received: by 2002:a5d:6b81:: with SMTP id n1mr13700282wrx.411.1590855121964; Sat, 30 May 2020 09:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590855121; cv=none; d=google.com; s=arc-20160816; b=FiZHQAIfcQw6Coq8q46po0vIFnZhmog9fXE8KHJlbMtIIsjxhlEPyTCCbDI7I8HM35 RmMi0cFehK3XaXnnN30n6U20RUnpZsDl9jhSlrmoIgtUw0kVnpdudSwgERKXCblAhRMh r+LW64fo0HUPurVKTY9sgySvQHd/tFcq2wZ6MMvRJNESQca01tyjZT6As/wBzoWz8t7y MHqO8GnDH4CcfGsIAN71Piz1PK3xIp4pPbq/2UKIlVCbNXq3sId19QVwGEBaTSb987r3 9CqEXGCABHfSIUvv+iuv+NAZs4Xk1ghwAjktwpOzFMCuuRFOOfqH7UnXIAvzbCKdCoA7 uhLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Dd0ShlStgd58sQ3vvYT+SQzHopuZvZrCIsiEKl/uufc=; b=gfIVJGqCjt6o1xRNu4H1xlHJC3+UsVBc5Jywvf9TugP24d2xYJA3yMtYLMGiHc1IWQ i1xhfGVw8tJ+QRv2T8b1pkYxpnpee5acWpf+n+tG2mDADdC+6YMszbGkc9PJbfzm912I dIajc2IzHClVgJMiH+s3o+gMl/Bj1zhkiBvFHfX/1Bg2Pioi2r/OviFckqGRoEYOMDb4 M88CHtVrJYcwM68/8r6u6Of7zO6loTfLQ76BUyI+fd8cFYfpn6AHduhcHsPjuByzk1cj Q5BBjPodMf2oSqBCRYiFIFvtM1KwkuvgJTwA6PnYyKWMyb0TW2fA/WfsGSdJAISVGThQ OmTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WD3vKZyI; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l9si3060913wmg.167.2020.05.30.09.12.01; Sat, 30 May 2020 09:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WD3vKZyI; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A36968B087; Sat, 30 May 2020 19:07:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9058568B112 for ; Sat, 30 May 2020 19:06:52 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id r15so7114255wmh.5 for ; Sat, 30 May 2020 09:06:52 -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 :mime-version:content-transfer-encoding; bh=7AbrS/LXwDv+Tr0duKSmTkM/zIqXkJasgcmSL42KJpc=; b=WD3vKZyIgzbg9V1xHrfoJIVQyaQwrZMwOoLvC6/0gDch6PGiaz2hhj0ANTS0iaogwI DNqw6sONupUzRH7x8jdFE891zrEbXWa8ev6cXpbN1avojHVOlGMDyM60oYfIpUjeG7tX 1cSb4WXtdIvYNrw5wGrxPc1iDPqZFbNgXtRCkZoii9bf3LrnPlF9jBgvHnsXE/QKq0xQ ldNcjHDvOVvHoy1Cx5hB61+oMtz1qA4MEiSe1d5FYykhkhgDFzVFQpmAxc60HKNDYeqc uUkr0YkUbNP9uSRVst3PgYx6aNYkxuNJnpT+BadUI74XSTFjF3m2TiupJDxzp7i0FdWD rbhQ== 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:mime-version:content-transfer-encoding; bh=7AbrS/LXwDv+Tr0duKSmTkM/zIqXkJasgcmSL42KJpc=; b=t2HJ1hY9DLkMNDica6PhtmbR5oIvYUoNc2q5IoPsoDfYuPjklqeJGu0sQD1o3lRNCx kP817eW+dDvihmxOOax291oyXeTSFGfiPV4cyMwT83cMtC+dGBwSRT0aoSGAHgpKN6n9 Q+uobv2yCTfSewdHavB81lRY9Z3wp+AHpEgs5eI7/q0H8IVO7p+1UGvT6fThGSGOBqCf liLdYfTMjedVL2zxkTY3D+MqMTvd+LK2U4r5qe9mSK5RHVs9kFwILBf6yCxlLnoSA8UG ia4cHGDTsBHQ/J8Rdqp00o9vHFkepj4if+BTcWSkrPrwr7kr4PS2ynFYLXV5/xLQMpgB 59cw== X-Gm-Message-State: AOAM5332StN3W0OK9J62M9e8+BxdD3KM7RfEyL1blV/h4mQVsL5o05G6 mOsgZYYATnsGK80+vrMXYap5umHW X-Received: by 2002:a1c:230a:: with SMTP id j10mr13470509wmj.124.1590854811724; Sat, 30 May 2020 09:06:51 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:51 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:38 +0200 Message-Id: <20200530160541.29517-33-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 33/36] avcodec/dump_extradata_bsf: Store pointer for access 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8A3t5T8uo85P Content-Length: 3457 Using par->extradata instead of ctx->par_in->extradata makes the code more readable and removes an overlong line. Furthermore, check for extradata_size instead of for the existence of extradata as nothing needs to be done in case extradata_size is zero. Signed-off-by: Andreas Rheinhardt --- libavcodec/dump_extradata_bsf.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c index b6ef8b3e6b..be5e23ba5b 100644 --- a/libavcodec/dump_extradata_bsf.c +++ b/libavcodec/dump_extradata_bsf.c @@ -40,6 +40,7 @@ typedef struct DumpExtradataContext { static int dump_extradata(AVBSFContext *ctx, AVPacket *out) { DumpExtradataContext *s = ctx->priv_data; + const AVCodecParameters *par; AVPacket *in = &s->pkt; int ret = 0; @@ -47,17 +48,17 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out) if (ret < 0) return ret; - if (ctx->par_in->extradata && + if ((par = ctx->par_in)->extradata_size && (s->freq == DUMP_FREQ_ALL || (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) && - (in->size < ctx->par_in->extradata_size || - memcmp(in->data, ctx->par_in->extradata, ctx->par_in->extradata_size))) { - if (in->size >= INT_MAX - ctx->par_in->extradata_size) { + (in->size < par->extradata_size || + memcmp(in->data, par->extradata, par->extradata_size))) { + if (in->size >= INT_MAX - par->extradata_size) { ret = AVERROR(ERANGE); goto fail; } - ret = av_new_packet(out, in->size + ctx->par_in->extradata_size); + ret = av_new_packet(out, in->size + par->extradata_size); if (ret < 0) goto fail; @@ -67,8 +68,8 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out) goto fail; } - memcpy(out->data, ctx->par_in->extradata, ctx->par_in->extradata_size); - memcpy(out->data + ctx->par_in->extradata_size, in->data, in->size); + memcpy(out->data, par->extradata, par->extradata_size); + memcpy(out->data + par->extradata_size, in->data, in->size); } else { av_packet_move_ref(out, in); } From patchwork Sat May 30 16:05:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20028 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bac9:0:0:0:0:0 with SMTP id a9csp1501115ybk; Sat, 30 May 2020 09:12:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvaoorEbne8Ep7CWbiYlzrTZtBGRd0sCPDtp+PtTAw+/VmmfUBaQOYwcdvJDT6gJZ0/QhQ X-Received: by 2002:a5d:6087:: with SMTP id w7mr15341469wrt.158.1590855136052; Sat, 30 May 2020 09:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590855136; cv=none; d=google.com; s=arc-20160816; b=ntNLJe67yDEHu6a6VbQrMGpFxtc1EbtHJXsavRK1VXMDKW70HF/vzydfi/n6Lv0jYp 0/NvEH+2iumGWnuF4i/btveDg6yHXJzwTf155O9pyj3p6Vt4xyl3Qz33UjsLO3FKTI7H GJsmqyrPCkQ69Fgt4qHm2WUTFn4ANKm2F9yvHGk0s8hw6FY1xyLLPd8t9daShSspT3wX X+0yuCIni7wmR5YwyuMgavO1xBJn8mpXWNYU1ft/coFTe0bKLIv3iPEqszU9WWGrL4e3 FUgOtS2SWlw2UItxeN1vTUhiG28UYAznjauv5EEt/VoAdhb3mE24oXduzzzn768TEc27 B7KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=JLGL70+7V8VDkYLx3dLQvMBt1L1QhXPe/P6b05BgUHQ=; b=NNCIsOsc2nf3vFQTpHPF0LFbshmwCDvMil7vCgHkxZt6s4z9nZMQDLqGWmFWr9QuEA 66IPsLW6T4gw1gWBAHiHnohHbvSN9je1BfQRSSpIzjLJPTfxIK2cYsYEVeRR//5MA0c7 W+dRHEZAiLxFnPgcbw0gPcuvCfx8CnANEVIVfCexJHx3prcNf1y1+1OOsEux0HiPZ1Ap sw5lirQ8frVsZR3ZyS+5PnnxOAfRTrqSfbv8rF3qkIQg0m08E/3+ev3G19RyKoYJXQsF ZO4vmfkI4azXlOuJRFpLFKlqZJXmof0GMLiGi+XRMghpvr3oT3N60KyNUc30c54k062v 7ScQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=HxcMHCkH; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l19si2724327wmj.222.2020.05.30.09.12.15; Sat, 30 May 2020 09:12:16 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=HxcMHCkH; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 290AC68AAD8; Sat, 30 May 2020 19:07:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3CE96687F99 for ; Sat, 30 May 2020 19:06:54 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id f185so7146544wmf.3 for ; Sat, 30 May 2020 09:06:54 -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 :mime-version:content-transfer-encoding; bh=mnldynUCgNEX5eWemzZMpNT2oqEoMGu48Af7wtdtKFU=; b=HxcMHCkHCBRFuB/f4KWXYKdXrnh/UqIZJ7as8RDpMCcYA3XALAwifYhiCLNlq/WC4O qiAEZuRozqeI687qA/TvbOwFAk5xooutiqWAf5CF5aaW3ax8jWxx6xtBGiS7OvpNKaWw 6EUgwQoayy/9FnxXgiod5YarFvAMT5OIdJeI1yVy770FJsqPlCua+MAYk4nisBpzoNvG vlB8DuvnYNVV0aBNh3+VzWVNJlTR2PhLgfDdJk3Mm5pz83gPPCWHCyyBoua3Jso8bmKx dMwKz7zQjuE38xBows6T0gXpPjql1HiF6FP1AsNau/2GbEq9XTx3PD3VQF7LiCjqIkjk WQmQ== 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:mime-version:content-transfer-encoding; bh=mnldynUCgNEX5eWemzZMpNT2oqEoMGu48Af7wtdtKFU=; b=ikrtRdh5MJnamOKeEQmy+7ZvHvvG/tS/olu0Uaa9oOfetmOtHm2O/Tpo9ZPyCvFCCH zmWQ1G1nvJ1TnExl3/qN8kgvtOqZI6zXi8ATzWeyHaX0HKFWEg2kdiybXFiriwhtRXZS 3aMj3zqIpoepGLn+Uqnv3T8VWvC+Z3Cso2lGNe2SdftrPi2fmByWurOzP2dQqRYAHAAl sjLUKJWAiPFaoA0866/LqQ9dNAuIF6ovUaBM8IDJKts2RD9gpQIdztKaZ3DWbTAdTnXs U8jqP1BooQ1ay2Zok4P8thSOJ1Fvk72rxJOBhChNHP3ZJB+d/8n7mbIreeOz+RrNGFA8 9pNw== X-Gm-Message-State: AOAM533zOUrh7kG88OluTE3EKWiGUttrYXFNkZPasvIQi42dlM5nOtD9 fcq68jxjy/UJq95aFuhWauS1Przh X-Received: by 2002:a1c:dc44:: with SMTP id t65mr14582778wmg.128.1590854813345; Sat, 30 May 2020 09:06:53 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:52 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:39 +0200 Message-Id: <20200530160541.29517-34-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 34/36] avcodec/dump_extradata_bsf: Remove intermediate packet 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZNaqeJaVuNEI Content-Length: 3899 This commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/dump_extradata_bsf.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c index be5e23ba5b..5df7e064cf 100644 --- a/libavcodec/dump_extradata_bsf.c +++ b/libavcodec/dump_extradata_bsf.c @@ -33,49 +33,44 @@ enum DumpFreq { typedef struct DumpExtradataContext { const AVClass *class; - AVPacket pkt; int freq; } DumpExtradataContext; -static int dump_extradata(AVBSFContext *ctx, AVPacket *out) +static int dump_extradata(AVBSFContext *ctx, AVPacket *pkt) { DumpExtradataContext *s = ctx->priv_data; const AVCodecParameters *par; - AVPacket *in = &s->pkt; int ret = 0; - ret = ff_bsf_get_packet_ref(ctx, in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; if ((par = ctx->par_in)->extradata_size && (s->freq == DUMP_FREQ_ALL || - (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) && - (in->size < par->extradata_size || - memcmp(in->data, par->extradata, par->extradata_size))) { - if (in->size >= INT_MAX - par->extradata_size) { + (s->freq == DUMP_FREQ_KEYFRAME && pkt->flags & AV_PKT_FLAG_KEY)) && + (pkt->size < par->extradata_size || + memcmp(pkt->data, par->extradata, par->extradata_size))) { + AVBufferRef *out = NULL; + + if (pkt->size >= INT_MAX - par->extradata_size) { ret = AVERROR(ERANGE); goto fail; } - ret = av_new_packet(out, in->size + par->extradata_size); + ret = ff_buffer_padded_realloc(&out, pkt->size + par->extradata_size); if (ret < 0) goto fail; - ret = av_packet_copy_props(out, in); - if (ret < 0) { - av_packet_unref(out); - goto fail; - } - memcpy(out->data, par->extradata, par->extradata_size); - memcpy(out->data + par->extradata_size, in->data, in->size); - } else { - av_packet_move_ref(out, in); + memcpy(out->data + par->extradata_size, pkt->data, pkt->size); + + ff_packet_replace_buffer(pkt, out); } fail: - av_packet_unref(in); + if (ret < 0) + av_packet_unref(pkt); return ret; } From patchwork Sat May 30 16:05:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20012 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 B6B4B44AA6F for ; Sat, 30 May 2020 19:10:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6AC8A68AE2D; Sat, 30 May 2020 19:07:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A1D8968B162 for ; Sat, 30 May 2020 19:06:55 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id f5so7145671wmh.2 for ; Sat, 30 May 2020 09:06:55 -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 :mime-version:content-transfer-encoding; bh=b0yv26UOKtr2fXtdbEKf+1AZ/CXV04FoXy42f7QFrMw=; b=s6X7vvnf7VrFAMBdymjaDTco8nN0TnqwAJxxTiFD5KRUFeM+1RN/LhTr8FAOvw+i7b 2t/ngHjf0oHLNoTQ+1iIpJYp0mp0G7S9VZO3pMFrRWtVT25HsbmObbhUz/7eebf0LbnV Skwa1iFUrFMQ/i5dR6djWyYZ7JKV7ny+ZOQG0Re4E5znymGmVafuEWx+YSL7pBybonve OJXrAWX5q8q9C05fkbkSU9SvUHgae+QxmO5/bjoXbVtsxwOxMhHLwOFLoV4nsnwVR+pl NQuZHgnra59PvvVqt/ff+psazoHRVQsTO75fmpdxDpiCsaLUS6j+jrwjlIaEd+tXr3P0 3j6g== 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:mime-version:content-transfer-encoding; bh=b0yv26UOKtr2fXtdbEKf+1AZ/CXV04FoXy42f7QFrMw=; b=ahDFp1X0zLUsMIiekw6quwpfiqtgh1Nkokb6irUbBAVu52VZe6J9qO1toYycymMQ2X 8UdSXhtTncelGlFqzwYOCn1ESEleqDcd7sOcRQ6E6Pfckm5ZWQrVd+mPV5Q+ShiGVuEu YzfsyAcyYDAHU03DF0xtlmhyVbTL8JUtN+tjKt1c3tHJkm8g/vBm4sbnY/QQUBnhkVgG 0xADoDiNuKAvmg468AciLzVS5+cJUeNobbBDrhshxxxhJVMDOVKupGNLosf4EtQD01GX ONBk5SxvuBFTKa5TrJYwhkx/Nf9mxc6WN2GnOv7dEa804XhLkrwKyFmguIv/OGa7IRMz LLIQ== X-Gm-Message-State: AOAM530fOuQPeYo7Q33/lvkPLkt+uM6FwQtlPJeJmz90dlwAyM8MmlA5 qZ9bRJASl51+EK74XqeyNTqICuLB X-Google-Smtp-Source: ABdhPJzssn8Fu0BvgNsVIOus9p7BigSPJHvTJqD8MA/uL4nlm+WgUM85ea+P4G7fKiSbOWM2rTpRYQ== X-Received: by 2002:a1c:a444:: with SMTP id n65mr12826462wme.99.1590854814677; Sat, 30 May 2020 09:06:54 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:40 +0200 Message-Id: <20200530160541.29517-35-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 35/36] avcodec/vp9_superframe_bsf: Only store what is needed later 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This commit ends storing all the packets for later use. Instead the only part that is actually needed later is kept: The buffer. This avoids copies of packet structures and also makes the init function superfluous. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 45 +++++++++++++-------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index 29d1c759c7..6d6b2c57de 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -27,8 +27,8 @@ #define MAX_CACHE 8 typedef struct VP9BSFContext { + AVBufferRef *cache[MAX_CACHE]; int n_cache; - AVPacket *cache[MAX_CACHE]; } VP9BSFContext; static void vp9_superframe_flush(AVBSFContext *ctx) @@ -37,11 +37,11 @@ static void vp9_superframe_flush(AVBSFContext *ctx) // unref cached data for (int n = 0; n < s->n_cache; n++) - av_packet_unref(s->cache[n]); + av_buffer_unref(&s->cache[n]); s->n_cache = 0; } -static void stats(AVPacket * const *in, int n_in, +static void stats(AVBufferRef * const *in, int n_in, unsigned *_max, uint64_t *_sum) { int n; @@ -60,10 +60,11 @@ static void stats(AVPacket * const *in, int n_in, *_sum = sum; } -static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out) +static int merge_superframe(AVBufferRef * const *in, int n_in, AVPacket *pkt) { unsigned max, mag, marker, n; uint64_t sum; + AVBufferRef *out = NULL; uint8_t *ptr; int res; @@ -73,7 +74,7 @@ static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out) sum += 2 + (mag + 1) * n_in; if (sum > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) return AVERROR(ERANGE); - res = av_new_packet(out, sum); + res = ff_buffer_padded_realloc(&out, sum); if (res < 0) return res; ptr = out->data; @@ -107,7 +108,9 @@ static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out) break; } *ptr++ = marker; - av_assert0(ptr == &out->data[out->size]); + + ff_packet_replace_buffer(pkt, out); + av_assert0(ptr == &pkt->data[pkt->size]); return 0; } @@ -166,19 +169,21 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) av_assert0(s->n_cache < MAX_CACHE); - av_packet_move_ref(s->cache[s->n_cache++], pkt); + // move the packet's buffer into the cache + pkt->buf->data = pkt->data; + pkt->buf->size = pkt->size; + s->cache[s->n_cache++] = pkt->buf; + pkt->buf = NULL; if (invisible) { - return AVERROR(EAGAIN); + res = AVERROR(EAGAIN); + goto done; } av_assert0(s->n_cache > 0); // build superframe res = merge_superframe(s->cache, s->n_cache, pkt); - if (res >= 0) - res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]); - vp9_superframe_flush(ctx); done: @@ -187,21 +192,6 @@ done: return res; } -static int vp9_superframe_init(AVBSFContext *ctx) -{ - VP9BSFContext *s = ctx->priv_data; - int n; - - // alloc cache packets - for (n = 0; n < MAX_CACHE; n++) { - s->cache[n] = av_packet_alloc(); - if (!s->cache[n]) - return AVERROR(ENOMEM); - } - - return 0; -} - static void vp9_superframe_close(AVBSFContext *ctx) { VP9BSFContext *s = ctx->priv_data; @@ -209,7 +199,7 @@ static void vp9_superframe_close(AVBSFContext *ctx) // free cached data for (n = 0; n < MAX_CACHE; n++) - av_packet_free(&s->cache[n]); + av_buffer_unref(&s->cache[n]); } static const enum AVCodecID codec_ids[] = { @@ -220,7 +210,6 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = { .name = "vp9_superframe", .priv_data_size = sizeof(VP9BSFContext), .filter = vp9_superframe_filter, - .init = vp9_superframe_init, .flush = vp9_superframe_flush, .close = vp9_superframe_close, .codec_ids = codec_ids, From patchwork Sat May 30 16:05:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20019 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 1878244AD87 for ; Sat, 30 May 2020 19:12:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 33E6268B20F; Sat, 30 May 2020 19:07:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C002768B1CA for ; Sat, 30 May 2020 19:06:56 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id k26so7139754wmi.4 for ; Sat, 30 May 2020 09:06:56 -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 :mime-version:content-transfer-encoding; bh=5/BVTGaeR51tH9kYHaGtoaqztdUamc4uRhagnwPXzko=; b=HPAeDJOF+M2WiHtx8GC68X+zsoI6xdrZcMF/YWqHJlFq3ROKb+WjKE18t77ZoE0+47 veuzuycIv08P+HPO9xpy691nAZpRL2MSfSz+oS6nmqcPALiByCxIsVQ+FM1OIaHpDYd3 2YTo8aNFFL97sfvHiE4S7IDzv06XeOlaVOq+6w//NPbZesmdMG1Dc0srPUc8ErUgs4AL mDtu6u/gLGcz4D5uGuAWeAHQtibg+fircG2agYoAhzB+3ANrNz19cKLeDQuaitsswVFe 6B+8nG/USKvkalamCgAwEyRZi4JCG1oCdl9UtWoyLqSAgXH+ACEYFzDLmrXQlrvIIago 96Xw== 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:mime-version:content-transfer-encoding; bh=5/BVTGaeR51tH9kYHaGtoaqztdUamc4uRhagnwPXzko=; b=A1pH+zIHm4n58pNK8Ux0P9txgzEHfv0wLzKG1YO2GG28RcfuAIkA/gRR+x+pfkuS0l 2d9rlIpLwlme7Es10y3f45DHwGC36rJKPyDnPUXEYbNaQI4mvH2juGRYO4BKCO1xLp2W mo4KXiN3DFqvPx4R7p9XDohoXGVDpX2w4ulcFUm6YULaeEKwvOXWAvdYyiPibA9O4OYg NMuNT0r0GsYDChT1izmsJGBlMuXugBXEZkpsT7X6lXuk58sFrMKy4mhMmuiADpioLxny pgav2iohS4uD8Y95VN7vn3UzstblVr+lET7FOtssJVx/bzVxjPIobc9P0/H9Ure/7bDH /oLQ== X-Gm-Message-State: AOAM530UawpRq18nuyzvBBDAJYjDuTrmABIkkiBt+eGVQB/aUWinaouh 51z0QVgE0+gsOQGzFALcWQYn2d4D X-Google-Smtp-Source: ABdhPJw5ErLIaCPq591Nrm5yDnyulRCiqJTDRH7Diei7esz11qfOJ0yKZREB8C23/6oQ4M4//l50Ag== X-Received: by 2002:a7b:cae2:: with SMTP id t2mr13854341wml.150.1590854815869; Sat, 30 May 2020 09:06:55 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:55 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:41 +0200 Message-Id: <20200530160541.29517-36-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 36/36] avcodec/vp9_superframe_bsf: Merge close and flush 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" They are essentially identical now. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9_superframe_bsf.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c index 6d6b2c57de..278f5a47a6 100644 --- a/libavcodec/vp9_superframe_bsf.c +++ b/libavcodec/vp9_superframe_bsf.c @@ -31,7 +31,7 @@ typedef struct VP9BSFContext { int n_cache; } VP9BSFContext; -static void vp9_superframe_flush(AVBSFContext *ctx) +static void vp9_superframe_close_flush(AVBSFContext *ctx) { VP9BSFContext *s = ctx->priv_data; @@ -184,7 +184,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt) // build superframe res = merge_superframe(s->cache, s->n_cache, pkt); - vp9_superframe_flush(ctx); + vp9_superframe_close_flush(ctx); done: if (res < 0) @@ -192,16 +192,6 @@ done: return res; } -static void vp9_superframe_close(AVBSFContext *ctx) -{ - VP9BSFContext *s = ctx->priv_data; - int n; - - // free cached data - for (n = 0; n < MAX_CACHE; n++) - av_buffer_unref(&s->cache[n]); -} - static const enum AVCodecID codec_ids[] = { AV_CODEC_ID_VP9, AV_CODEC_ID_NONE, }; @@ -210,7 +200,7 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = { .name = "vp9_superframe", .priv_data_size = sizeof(VP9BSFContext), .filter = vp9_superframe_filter, - .flush = vp9_superframe_flush, - .close = vp9_superframe_close, + .flush = vp9_superframe_close_flush, + .close = vp9_superframe_close_flush, .codec_ids = codec_ids, };