From patchwork Tue Jun 21 02:30:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 36358 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1976242pzb; Mon, 20 Jun 2022 19:31:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uTgTJlhO0eXqhOZ9DsJzQeQXzaxQiKvBIrH49txAcVLeC8FuC3RYMqhrroHmbCQGCNVk5j X-Received: by 2002:a17:906:221b:b0:708:a007:5a77 with SMTP id s27-20020a170906221b00b00708a0075a77mr23987410ejs.566.1655778669347; Mon, 20 Jun 2022 19:31:09 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e26-20020a056402331a00b0043586cdd881si882346eda.260.2022.06.20.19.31.08; Mon, 20 Jun 2022 19:31:09 -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=@outlook.com header.s=selector1 header.b=fhNTGSxq; 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 5942868B60F; Tue, 21 Jun 2022 05:31:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2037.outbound.protection.outlook.com [40.92.89.37]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAE6F68B4BF for ; Tue, 21 Jun 2022 05:30:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hm8/ltt3yFQssdG/nT2F9yRGGEfmx85lfSvF+XhGlGPxQyzUOYTyvmSsb/UCu6ApNUOKpzSRuOCLU5aBipGY82wxvmHDZvmAA75mvB+z8DHdFEB7Dv1HcG3K01UYA5cBJbzWZVvyBbP5Pj2I16iqi4A+W9wq5btx3H/7OKt7BVaji0nslv7Z1bJjr4vubuD4Jr0U7/dLnIKH8Ow3KHPGsWRYisxvwa9bCtoLGSh3VTEqUe5S9pk9ElxX/PZLmJmJ07e0PUisxMNgyqjYY5ENWjaTrkwuy0l6gzbz3dvHaUdYuXDj6xoPkagfuAGZWb0wlHstbGE930fFFhrHwh+6NA== 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=+sl/7Rk/91iC8L48rH3I3OE/5AjSg+ff33ggmHC8ePE=; b=TGD/p7Tn7sxaVQOGsV6rVAV/FPo3hgiMgMTy0vZUE2daSTVPjr+JmQd1vRyDe/o8ZyH8WeQHpnCdnReCx2XTPfl7ABn/3bqSNKw9aCJbF4mUVelp8J1k7Al13xrY+McKGqbhOlJIHwy8XNpKcmJnKmbNv6r5/aShmu/OC0zoK++CrF44hQMiqzXjZ5ZYH2IyqYtQL88zlYSAQAucqXiCBWwIKj3OZjbrAtNxKujW0sy/Y43s5HMasC/ADBGX6eHdhEZhvkmgJLaTwkDHcWyXCsUaVvPfV0hmtLKZmyL13LE8R1Bc+tapZpsGP2Sz1lL3mJPRLqlJ+yU57fqrHf0UuQ== 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=+sl/7Rk/91iC8L48rH3I3OE/5AjSg+ff33ggmHC8ePE=; b=fhNTGSxqCS/VyUgi5rK9FdtF6YZd8Y/v6w/DhC6SB5PtyGhvw/KbM0k/dAaM/5Fz/Dl58BopLiNyk4hFNLOSKjDX89BLNFlsMSakdcAU2mYvuSIYsTNVd5twbtnLl02GvYe/RchOUNUReRxBErIYegvAcpfobFwrDnpn505zTksdKMNCW4qkTShQwCL1+CIbp3YhRLdir/nhxwG85qSQled+6ctuC5DS8+Cqi4U8XRLswm6EMYhJaSxTHHn7mEtYdhEKq7VMwWNGsGEvRwVXtqujjhcBymOA+iycUVn8yUimzLjLEnXfkL3a0II2NDX4oYD1oxcQBfK3DrUi3NAmSg== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by PAXPR01MB9074.eurprd01.prod.exchangelabs.com (2603:10a6:102:2b4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.18; Tue, 21 Jun 2022 02:30:54 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c%10]) with mapi id 15.20.5353.022; Tue, 21 Jun 2022 02:30:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Jun 2022 04:30:33 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [vGgQP8w4+nxWVlCVtWhSgB+CeO+KIzPj] X-ClientProxiedBy: ZR0P278CA0017.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::27) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220621023038.3322391-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca2a92dd-9966-4a3d-b9f5-08da532e0c9a X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEtlA26CjnCS1VxapTOXeNoSgarjVwEegyw+Hz2Ngrivg0TdY6wZ5KDSt+k4fZHph25h79zViuqo70HVAf2m1xlrSEoQV4WkuHktXef6l8TWfn8/YuC0E7PaHBLjagQ+3QqIlHpeMUGuBXxWcmWGXBzRaKLNFo3aXokrwL+NpimwdcnSZf13QEkeXtIcCSYvDb3BDCt9p+haOmEhzT3knbpXtNbwJYV3GszPfxxRYp6R6zsC9ley9aNOy13KIQIR3EBKBXWZZUVFQgp0OmABqLl16usQPqqIsKNR9v/02Tjc/wgQ5n7AtX/FM+bzlocZ7+C9C3MN9AfU4FV4y0DMAkEyvOvHHTzoPEpgZS+Uo6uV0LkxZ1YhSSyw+t+MkiOJ4xbtbpGxdVFe1dnhzPf0znX46kK0ZfN5J0b3dPfMF1rMyKSEoHLSrtt4+HnnQ9AQnsj/XdAO0LRWSOjgSKA0R34fzp2AHf2/1KxWVPqosm/EqkAoFK4xb2qEps+ag+l2j8hQAeuwRq8qBo8zon7IryN5cKBMO9fVVKvReO9F6PgVkiFPPOAgzsB6RO+H+IJqAG704PUBpyT5z1Y4m+OAnFrAz8YaT71rFpxEO0dfnct1OFxRef7UknssKr9jvztSwIu1CxqWzMQ+viXyzRb5pODXCM+vGE5yy8Snbo6MW4qvDxIh8M8hab/EkMz0s8/qw1KlRRugWxpH6v6VgfSRfiyiuaaA1QwK6eXyDEkQqPeKcPsBXl5mo0Fri8qx+ciqBU1ifTik7A271WGguBsWb9i3 X-MS-TrafficTypeDiagnostic: PAXPR01MB9074:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8oMAG+u7A05F+TZRoFwiJYaq2J0ncp0giu50lVbvFiBQNHcRllsewyCJxBGqhY91D6LBejcj0p7X5Jy1zGb+Hpk7qzBDNDS24rw3GQZrdBNJoa0c34+zv3Lx8OCBb5wqU4BpGMrOzew8Ci31XhQA38rMJDVb9Td/yBmAcP+PnynwDt28jv6lIjVDi5Y0J3KmY1tbljLBsb/VUq8G8ztV+1VhKATMpDyNuWZqn29XreZ7P22ha5mps+MpQqCaXUUShz5WUiPVFjbHjW32NBjLHg4mIEfFvA4MQrqHHNcdhg8ZPGLjYWaPr6mN12VbvYyVWirhu/4fHftmRffJ9PWAPOf539AMyMkYDmzEXl5V+J7rbn+xlQGQGUJZYSzkpEiiN06En713MqhPA+8giXlu4Ailp5P6oQqqUThPys+U/qrJys+xgtLiLPKB9enUlIBi0+FcST3qPxw/hdbaupHZIJH5cfZSeP68lal32xkriYvdJzLVF/JXsmnoNqmF6wBAPrBdrNKvdNf+0F5Of98ATar10U7w8iQm/GQbBchyff5QLo8JXxlRvoigl1JXQGU9dgYIsSgg5CLOZKPFnzGuxw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FN5RvtC9dHXBPTa/bAYHwfr+JtfNJ9L0eLKIrQRLxH72U/kTncKgGH5FoFQxctU+WAoI3EfJ0cCvfXb4p8ZzjnLgDtHLl/L8LFTBPoKvVEmhbN7E9ZwpWCUVdGX3bf28o2ASDbo1LzHSRsOnJi+MzDtevAWV6BZUA7lAXDWCrBm3BXn068AEoQT64UNwZHEwdK0tbMUPvv2fEjv66zoHNVr18vYqd9Dhf+Y2bQ0gvrFQy22DWH5LApE9WcKHBaO5zcAa+/BaLpBGPdsx810191GAOSE02WLTp/epHY6U/xsZNqoPnKIkIZmKkMiw2uxK3NkPNWTB/IXr3m/kvdobgTMY9WyxXfemQ1FixvizOd/6fJqQl+/YnS8cQORBtRN/T982dhjApKRHbNb3z/GvKPgb9Io9KIC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W722Z1DA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca2a92dd-9966-4a3d-b9f5-08da532e0c9a X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2022 02:30:47.5164 (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: PAXPR01MB9074 Subject: [FFmpeg-devel] [PATCH 1/6] avformat/matroskaenc: Split assembling CodecPrivate from writing it 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GMiq3B+snBhK This is in preparation for splitting writing and updating extradata more thoroughly later. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 74 ++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 163af8aec8..b4756832eb 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1099,9 +1099,9 @@ static int get_aac_sample_rates(AVFormatContext *s, MatroskaMuxContext *mkv, } #endif -static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, - const AVCodecParameters *par, - AVIOContext *dyn_cp) +static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn_cp, + const AVCodecParameters *par, + unsigned *size_to_reserve) { switch (par->codec_id) { case AV_CODEC_ID_VORBIS: @@ -1112,7 +1112,7 @@ static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, return ff_isom_write_av1c(dyn_cp, par->extradata, par->extradata_size, 1); else - put_ebml_void(pb, 4 + 3); + *size_to_reserve = 4 + 3; break; #if CONFIG_MATROSKA_MUXER case AV_CODEC_ID_FLAC: @@ -1139,7 +1139,7 @@ static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, if (par->extradata_size) avio_write(dyn_cp, par->extradata, par->extradata_size); else - put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4); + *size_to_reserve = 4 + MAX_PCE_SIZE + 2; break; #endif default: @@ -1153,21 +1153,21 @@ static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, return 0; } -static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, - AVCodecParameters *par, - int native_id, int qt_id) +static int mkv_assemble_codecprivate(AVFormatContext *s, AVIOContext *dyn_cp, + AVCodecParameters *par, + int native_id, int qt_id, + uint8_t **codecpriv, int *codecpriv_size, + unsigned *size_to_reserve) { MatroskaMuxContext av_unused *const mkv = s->priv_data; - AVIOContext *dyn_cp; - uint8_t *codecpriv; - int ret, codecpriv_size; + int ret; - ret = avio_open_dyn_buf(&dyn_cp); - if (ret < 0) - return ret; + *size_to_reserve = 0; if (native_id) { - ret = mkv_write_native_codecprivate(s, pb, par, dyn_cp); + ret = mkv_assemble_native_codecprivate(s, dyn_cp, par, size_to_reserve); + if (ret < 0) + return ret; #if CONFIG_MATROSKA_MUXER } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) { if (qt_id) { @@ -1193,7 +1193,7 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, if (!par->codec_tag && par->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n", avcodec_get_name(par->codec_id)); - ret = AVERROR(EINVAL); + return AVERROR(EINVAL); } ff_put_bmp_header(dyn_cp, par, 0, 0, mkv->flipped_raw_rgb); @@ -1204,7 +1204,7 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, if (!tag) { av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n", avcodec_get_name(par->codec_id)); - ret = AVERROR(EINVAL); + return AVERROR(EINVAL); } if (!par->codec_tag) par->codec_tag = tag; @@ -1213,14 +1213,32 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, #endif } - if (ret >= 0) { - codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv); - if ((ret = dyn_cp->error) >= 0 && codecpriv_size) - put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, - codecpriv_size); - } - ffio_free_dyn_buf(&dyn_cp); - return ret; + *codecpriv_size = avio_get_dyn_buf(dyn_cp, codecpriv); + if (dyn_cp->error < 0) + return dyn_cp->error; + return 0; +} + +static int mkv_write_codecprivate(AVFormatContext *s, MatroskaMuxContext *mkv, + AVCodecParameters *par, + int native_id, int qt_id, AVIOContext *pb) +{ + AVIOContext *const dyn_bc = mkv->tmp_bc; + uint8_t *codecpriv; + unsigned size_to_reserve; + int ret, codecpriv_size; + + ret = mkv_assemble_codecprivate(s, dyn_bc, par, native_id, qt_id, + &codecpriv, &codecpriv_size, &size_to_reserve); + if (ret < 0) + goto end; + if (codecpriv_size) + put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, codecpriv_size); + if (size_to_reserve) + put_ebml_void(pb, size_to_reserve); +end: + ffio_reset_dyn_buf(dyn_bc); + return 0; } #define MAX_VIDEO_COLOR_ELEMS 20 @@ -1833,7 +1851,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (!IS_WEBM(mkv) || par->codec_id != AV_CODEC_ID_WEBVTT) { track->codecpriv_offset = avio_tell(pb); - ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id); + ret = mkv_write_codecprivate(s, mkv, par, native_id, qt_id, pb); if (ret < 0) return ret; } @@ -2626,7 +2644,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) return ret; memcpy(par->extradata, side_data, side_data_size); avio_seek(mkv->track.bc, track->codecpriv_offset, SEEK_SET); - mkv_write_codecprivate(s, mkv->track.bc, par, 1, 0); + mkv_write_codecprivate(s, mkv, par, 1, 0, mkv->track.bc); filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv->track.bc) - track->codecpriv_offset); if (filler) put_ebml_void(mkv->track.bc, filler); @@ -2649,7 +2667,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) } par->extradata = side_data; avio_seek(mkv->track.bc, track->codecpriv_offset, SEEK_SET); - mkv_write_codecprivate(s, mkv->track.bc, par, 1, 0); + mkv_write_codecprivate(s, mkv, par, 1, 0, mkv->track.bc); par->extradata = old_extradata; } break;