From patchwork Mon Jan 24 14:45:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33770 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:e71a:0:0:0:0:0 with SMTP id b26csp386352ioh; Mon, 24 Jan 2022 06:47:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuvqK8T0WYrw5EBczQbxHxCmv5+o/Q6FtlRbYvDNNqIur/SYZCi4U1VNOZWKwc0EVqtQ99 X-Received: by 2002:a17:907:7601:: with SMTP id jx1mr12845269ejc.696.1643035650320; Mon, 24 Jan 2022 06:47:30 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j9si8797719edf.349.2022.01.24.06.47.29; Mon, 24 Jan 2022 06:47:30 -0800 (PST) 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=@outlook.com header.s=selector1 header.b=vDbp8nXR; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B5CA568B08A; Mon, 24 Jan 2022 16:46:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070075.outbound.protection.outlook.com [40.92.70.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F50368B056 for ; Mon, 24 Jan 2022 16:46:54 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kEorFNIMCWdti55qmxUR0Sii+wNCjSR9PH/qrbDg1tXAT/AnKlG0SWY/IizKkzxKqxa82qO8zD1BD0eEFM4djGlezJy7IIIi9QNHE1X0US8iIcytGtvJTJoK2yJTeJvQDesX2gQX81Dy/6rJZt2q4SgptNqF3M2ZYLlYaQ4mtLLAmlh7k/RmSTyL3q3wHqJ9vJItkpbNC+pUhsr/SF3RyEkDfbBBZv2brizEJk9jtr1SCtfGGf8rzBJ4hOyxS7zKrSMXEjn5LVGxnGMHwLqqa59WNn6ntHpLaSiYKBIZTwYpyFtIhc+B3kFnD/S+METLhapWIB9s0E+iJP/cold16g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BNjzTB91zizCdKRrQmjmgGx3g+qBHMKMWvgK427Mahw=; b=fyNcUQM3nmAAXw7vGS2ZSD6PVExYP9Q3iLRagnigFMPtUWvTI9ULhJrJuE6cy5AEhiBfhq3FpEtZ+fxkZHpFKzFn9/mYDaDD81KVZHzEVFyy37l0uPd128l3SXrebO06ch7Rd8/ZmzzoP6p275jfYDuh1wPvon/k6cRWbKEjrWHfKqEJRrw5jraZt+dxCSd8Y2LLBbPUnAeHt3gkZH+WX45XGex1WgGySwggGTX9BS2E0ZDeWdzK5o5MojMKMgef4PydIChaKt3jDP1dnqDCpVIdiTK5d0EB3Bx37aXojlnPYcF1D1Pua+h9cgxQpvzKQKeOUILLlTgsC9L0AHNU8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BNjzTB91zizCdKRrQmjmgGx3g+qBHMKMWvgK427Mahw=; b=vDbp8nXR/oZR5bEBk5kMfF5JI+WA2eryZZup2C489oGMMDJBE9CFlY2TO4ETCRkYYUAEJjXE4wTe28VNobRlRBsrQt8k0wVxEfAbVYjbDHwwWJ/WQasvYKEheG/lOvxFRpCw2edy+b1v/5zrmp97rD3gX8Wudi9Sj0y9Xaub1/wAX5Whf7f8mXdLdAbewTD/QCzBGfAHiai0LcxRPDLjwj0rurpF8ys9tJN6XBh9Ny+dnROLJuI3Xtd/xj8dbjdGkBemDd7HNU4qj7heyFGYU/T2e1mWpuMN+fFbMNG1cKX81ojUQcHUg7rmcjV7iLsaso4gXgjAlghYfUNayUixQg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5236.eurprd03.prod.outlook.com (2603:10a6:20b:c4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.17; Mon, 24 Jan 2022 14:46:53 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%4]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 14:46:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 24 Jan 2022 15:45:51 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [auDj1v+lBaQSqkHIIHxP0gwYD0lLQX4p] X-ClientProxiedBy: AM5PR0201CA0016.eurprd02.prod.outlook.com (2603:10a6:203:3d::26) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220124144616.559446-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2893b3a5-2d05-4199-502c-08d9df485cab X-MS-TrafficTypeDiagnostic: AM6PR03MB5236:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QLed98lV6hCPIzdOpbYGfcjaEIPCcgRT5JdflUEjLP2Mu9gMoCEwawGMUH8sVhqosW/a8gSXC/YzEMdn64cp8PSWnXUzlFU3/G3cyv3mQSggpXUNQN7A2cbfRgo5DxxQkJJGrnb7ziCqAc5X56iok7Z7Fxdxv4jYCNQ2Kb/baYNMdic+t9WkPf1xqI8XOIBtTIykQbooVz8uaKEebxj78ez+LOCEiLMOHcKSZI6B8qFCIrXNWEiGwJ33sR3Kob7ywwG72j/KXAktYfUGDYuiWI7KyVwEermpbn7pmZoCRJHoD9gYTGJ9v9zuM9hwmZ6bcYS0FO9QttC3qlHqBjOEW/vPRoDJjlnGpQOm3vvGhuiJvAUCJpctFY/nV0KL1aEGl7Hcj3mHRfaya+Yd1QGYD3aLOUrFfj+Ee7O9TzNb3lBx5mSZHRCPjWmelNTVJYnpgTbvYISZj0oiPFKqR8vNkKQbXmWAuWzBBsgJ2E47NgnJK4zuCCgtaXuWPsM5lPNWYsL2BM6gNsoo2n9tIQ1pafy9kniuJOOh1wCKP6dz5jGcpWoalSAqb4DTs0tHLmQ9wjwmzeqqFRW4xSWKdUN8rg== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +9YESvzVXM4npkcdKm5ny9tLEdYeR8TSwJ3nus3G9/QEFlP9kfBQypdTwE25YV1aOv6VxCfcphx4BYw+VK4MAaDltO6VeP2RXe4h4GC2zg00jK+2q1AZvuC/bJzXrL+dtut1JEaIenYmjeadG+ghWYqd+h04hAe1H++K+zR8tuqipnOGP9mdIV8BFARLCKfx5JLjJoSSDTxvlwiWaVGfQtwYC61TgeobFiJBWjqc0p3wISQkhcsR4sf6QsshevgNIlWjkIa6Tf7Q+VMAJNaZXFktVPi9HIu+o7VUhdCbi+SqSjubTQz7M/GVrhf1KXSz3alf+853M5m5rrPrCTIgsMCuWOLpQiVvJoEAGLqTWqNwuUhqDulNGatMrCLF7UnVERNi+o+UIK7inXQ974XuKBgXQssryOaKGfBq+rNTXK3BwsmbysiaD60NfFWAtVqT1kH56M8HSFY/t38n180rjO9I4C5FxRPVoI+l2rE+NBGv8VW9pYEkjfQ26J159vQPC4azMqExbBC6oNJzdYzyE7FWcp1KsRopPXTR0Xtravl+yEKpH8GF2dWbCq+9gBHibZbEyn3DGvnICii191jYrVHU/r437nbZFMznJDBplhVGGHbrh+9BYK++21FZQtlcXsYthBFISn7My/cR0VvSmYIui5uXBPnX6OR6J7x22Vnugk3wHDxrxuy25S6Ti277wo9IAKjHiBVIt9fcOteHkmeB/gIqL34uYTGdL0OEntZO/slRgJHj3yONf6XUiiymcYsjt6oQygQTRiehYzs6fQ1s3UDikiqVAbbJb9+Q6hVmkcfI1ow/RKbOdQWLyBTdn4U9sLZB7wgXt+b1spV6mNzkiJNNQSQJedExaicPlpCR5l8Hf5HtsFxJi8dj+oQjF1oEqujmnKyp2ALBn1ztiQf4GbpFPT2lkw+wzx/mQWOJ4XAscfdOu4E5PpJa1mh0zRbB7pV5zxsuZKBC2OfC+A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2893b3a5-2d05-4199-502c-08d9df485cab X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2022 14:46:53.7037 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR03MB5236 Subject: [FFmpeg-devel] [PATCH v2 06/31] lavc/avcodec: switch to new FIFO API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Anton Khirnov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bPVwdBJVjYw6 From: Anton Khirnov --- libavcodec/avcodec.c | 17 ++++++----------- libavcodec/decode.c | 24 +++++++++--------------- libavcodec/internal.h | 2 +- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c00a9b2af8..4df834c708 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->es.in_frame = av_frame_alloc(); avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); - avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props)); + avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), + AV_FIFO_FLAG_AUTO_GROW); if (!avci->buffer_frame || !avci->buffer_pkt || !avci->es.in_frame || !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { @@ -399,13 +400,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_packet_unref(avci->buffer_pkt); av_packet_unref(avci->last_pkt_props); - while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { - av_fifo_generic_read(avci->pkt_props, - avci->last_pkt_props, sizeof(*avci->last_pkt_props), - NULL); + while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0) av_packet_unref(avci->last_pkt_props); - } - av_fifo_reset(avci->pkt_props); av_frame_unref(avci->es.in_frame); av_packet_unref(avci->in_pkt); @@ -464,12 +460,11 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); if (avci->pkt_props) { - while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { + while (av_fifo_can_read(avci->pkt_props)) { av_packet_unref(avci->last_pkt_props); - av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, - sizeof(*avci->last_pkt_props), NULL); + av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); } - av_fifo_freep(&avci->pkt_props); + av_fifo_freep2(&avci->pkt_props); } av_packet_free(&avci->last_pkt_props); diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 0912f86a14..4023d2dd2e 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -165,26 +165,19 @@ static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt) int ret = 0; if (IS_EMPTY(avci->last_pkt_props)) { - if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) { - av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, - sizeof(*avci->last_pkt_props), NULL); - } else + if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0) return copy_packet_props(avci->last_pkt_props, pkt); } - if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) { - ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt)); - if (ret < 0) - return ret; - } - ret = copy_packet_props(&tmp, pkt); if (ret < 0) return ret; - av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL); + ret = av_fifo_write(avci->pkt_props, &tmp, 1); + if (ret < 0) + av_packet_unref(&tmp); - return 0; + return ret; } static int decode_bsfs_init(AVCodecContext *avctx) @@ -543,9 +536,10 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) avci->draining_done = 1; if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) && - IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) - av_fifo_generic_read(avci->pkt_props, - avci->last_pkt_props, sizeof(*avci->last_pkt_props), NULL); + IS_EMPTY(avci->last_pkt_props)) { + // May fail if the FIFO is empty. + av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); + } if (!ret) { frame->best_effort_timestamp = guess_correct_pts(avctx, diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 72ca1553f6..4e864535f1 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -149,7 +149,7 @@ typedef struct AVCodecInternal { * for decoding. */ AVPacket *last_pkt_props; - AVFifoBuffer *pkt_props; + AVFifo *pkt_props; /** * temporary buffer used for encoders to store their bitstream