From patchwork Sat May 7 11:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35642 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp2121148pzb; Sat, 7 May 2022 04:29:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybvq5EsfhaZxpLB61QrC9MOzGPW8dFzoTaor36Iuo+gO4F9LJxEtF5J30eyUKKq0UFnenV X-Received: by 2002:a17:906:fccc:b0:6f3:7569:77fd with SMTP id qx12-20020a170906fccc00b006f3756977fdmr6981309ejb.266.1651922996119; Sat, 07 May 2022 04:29:56 -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 q17-20020a170906145100b006e8b4347a42si7651700ejc.440.2022.05.07.04.29.55; Sat, 07 May 2022 04:29:56 -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="qXRE/sMI"; 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 A3A1468B3F2; Sat, 7 May 2022 14:29:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2020.outbound.protection.outlook.com [40.92.91.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DDB7268B3D7 for ; Sat, 7 May 2022 14:29:13 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZrVbEZZeyzxbgtIguCILncFB/taYYFR2WWzNUGdE7l+/sSkJGXBNWsA5RAHZ8W8WnryktsqZVlsHHyaHr8S7MbyE91fpuCIZl69n9ba8wHkPm+zelyQcgo08+f//CsBrL3J0MjWrWDp6YAPAzLlPshH0sHI+kvBI2vuVq9Blnnl9CjDwWsVp7Mrsfif1SsvuHMItXf9xzAgr97pa2U8OIXLixMEooZ+5M28tDutsmrUfft9xguVmSW22l2IVX68VxZpz4GeZr85o65H5mIeaRDqznvVa2uFuzqJFzRBQN1b4izxnnWwal7er8XrtaON8d6pJiHoTpmgoduvTWkPcg== 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=42bQzuAPxChZ17ywoqudbFaomyMqZQvrjK0rknFnFnE=; b=TSVqIhPlvNTbzOa6EAd9WFEmLlgC9qQK48kp1mLn70nm4s8H6gAUNZPijDVLZGFunKDYWkUZdrp9YPJU8G5JefEKZ12PSa+drXUUmXG+/rOqwB8w5/YzjF7FnJZKkJFzzqly7namOdtc6xebghFI1QuFhpDste8WTtt9Zu7VGjxqKbRlY0XrcUKXL61GY7HOQTU5ZBYb9H/CjDToFsV1AN7zmak6yVb6CzfHwIH+lhRVsopFV8MjMH/W6BYeIKjN7isGCr680wRicPEgIdPjliDbWrwm8doMHwzJNYOMWP/t5IbQcXLj28gtwT4uUgOC3tkToe75VjnbaM4jN8usuA== 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=42bQzuAPxChZ17ywoqudbFaomyMqZQvrjK0rknFnFnE=; b=qXRE/sMIp+2O27/z5cC4X3U2+1rLY6sruZada3F8IndYCw/cix+9DYWDOyqEj0GFw3gr3BaP04wA8MQNZNYpSG21zRGqMa8nc/yjd89jFpPhn8zpg3tisLbsty8SwH8p7KFqfXsbbwH2IztEYtZg2nwXZ4SV/LpfgetySHhKLQNNZXLPFoyrSL6Iz5xc4uin5YsDg2Pi7TRdo2GHgLDuhR1SHKi9WO7GP/T4FO/FBdKqnxH9TlPKyZHTwZMIIB5C9j84A1i+lZlq9Jy5mjXIj6svExro2o3DRbLTdY/4cuaJ9RVlTP7ZIhoEsM6WBK/QdYfLf/SBZ0YtPQCk5RAPQg== Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) by DB6PR0102MB2663.eurprd01.prod.exchangelabs.com (2603:10a6:6:e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Sat, 7 May 2022 11:29:01 +0000 Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431]) by AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431%6]) with mapi id 15.20.5206.024; Sat, 7 May 2022 11:29:01 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 7 May 2022 13:27:54 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [hiq0DW6SM+WTM0V5bkFbAVE22xuAiZPj] X-ClientProxiedBy: ZRAP278CA0004.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::14) To AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) X-Microsoft-Original-Message-ID: <20220507112830.406162-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3171d6c-b5be-4a25-7e95-08da301cc89a X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRIovyFjHwHllp74iOQFItwgPy7lSo2OA/mOavC1mNg9VfftA5ag6w0LH8MRGDa7/tnsCNUeUYAr0jiHetMP5TVUA4fBLYbFDMBSEiqWIo4DMCLfn497519Pv0mvhZYJeJMsXVIU+6YunfaRzP6Y9Ml9TFwfQKlPwM0ShpHzKA59zR6hvuNqxCnz5wuCFyrYwozG9zoQWzMKGerMQLvff6rbRAsGl/UHfXtBzY6b4gnVAX1KFdaAraNfK3vJ6UHXZzExgtMUcnZ26jkpJPsDhDHOaqGdT6Jt2cz3I6wC0WZ9rM/i79OpE4DPhwWOlw4xpimnlxycUhA69TTcHDu2JbTMFoK5P6ZxzXea1+k5To+KLk9eVTqL+B9KIZsAfTF74Iqs2Y6HewsndHCoTrHRIEBlDCdFhiZsUs2ewMmMwdigqzCMMN3n29/AydaKBU8IjYCefn76C+rD8BNXOjWbL6+odOZBQqBCOXYPSJk9o1CzncL5duKxr4OfVLQRdB2Inz9SBqkWkIy+fxAs4/n/3OyoLRwRphP1qKCB5pizv1sCu74Ks6+HXPPN2I72oBOXpsmbSxfzmY5/0ZfioE6g4o2P8jdFLVThGX5PaL++lCmaW8uYd+fHvR9Riq+htuZpBfP+hJnf8i4Fh78PBqOsDR/OFY9xCVwTMiehlyR/zGKLpNkhkkQRRDt2jJqUG7hHDOO45vD9xJL+oPfrfnyCuktnjw/7yfwIbR8ghjEJj1sPV07ejMqD0uOOy9sncUqf+I= X-MS-TrafficTypeDiagnostic: DB6PR0102MB2663:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XCfN7eRd/v9/7YDYSpCCIkv7CcniNCipzI7luJKAK94IBBpz66eUvmPc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7sZfTVnQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3171d6c-b5be-4a25-7e95-08da301cc89a X-MS-Exchange-CrossTenant-AuthSource: AS8PR01MB7944.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2022 11:29:01.1163 (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: DB6PR0102MB2663 Subject: [FFmpeg-devel] [PATCH 08/44] avformat/mux_utils: Move ff_format_shift_data to new file for mux utils 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: 8u5SV0twHgHi It is only used by muxers. Given that it is not part of the core muxing code and given that mux.c is already big enough, it is moved to a new file for utility functions for muxing. Signed-off-by: Andreas Rheinhardt --- libavformat/Makefile | 1 + libavformat/internal.h | 7 ---- libavformat/mux.h | 7 ++++ libavformat/mux_utils.c | 81 +++++++++++++++++++++++++++++++++++++++ libavformat/segafilmenc.c | 2 +- libavformat/utils.c | 56 --------------------------- 6 files changed, 90 insertions(+), 64 deletions(-) create mode 100644 libavformat/mux_utils.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 537f5a1124..52c53ea3db 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -17,6 +17,7 @@ OBJS = allformats.o \ isom_tags.o \ metadata.o \ mux.o \ + mux_utils.o \ options.o \ os_support.o \ protocols.o \ diff --git a/libavformat/internal.h b/libavformat/internal.h index a3fdab03af..eb18277cea 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -946,13 +946,6 @@ void ff_format_set_url(AVFormatContext *s, char *url); void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]); -/** - * Make shift_size amount of space at read_start by shifting data in the output - * at read_start until the current IO position. The underlying IO context must - * be seekable. - */ -int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size); - /** * Rescales a timestamp and the endpoints of an interval to which the temstamp * belongs, from a timebase `tb_in` to a timebase `tb_out`. diff --git a/libavformat/mux.h b/libavformat/mux.h index 4f6e8a50e5..c220738942 100644 --- a/libavformat/mux.h +++ b/libavformat/mux.h @@ -96,4 +96,11 @@ enum AVWriteUncodedFrameFlags { }; +/** + * Make shift_size amount of space at read_start by shifting data in the output + * at read_start until the current IO position. The underlying IO context must + * be seekable. + */ +int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size); + #endif /* AVFORMAT_MUX_H */ diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c new file mode 100644 index 0000000000..7b79ffd1fb --- /dev/null +++ b/libavformat/mux_utils.c @@ -0,0 +1,81 @@ +/* + * Various muxing utility functions + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "avio.h" +#include "internal.h" +#include "mux.h" + +int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size) +{ + int ret; + int64_t pos, pos_end; + uint8_t *buf, *read_buf[2]; + int read_buf_id = 0; + int read_size[2]; + AVIOContext *read_pb; + + buf = av_malloc_array(shift_size, 2); + if (!buf) + return AVERROR(ENOMEM); + read_buf[0] = buf; + read_buf[1] = buf + shift_size; + + /* Shift the data: the AVIO context of the output can only be used for + * writing, so we re-open the same output, but for reading. It also avoids + * a read/seek/write/seek back and forth. */ + avio_flush(s->pb); + ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for shifting data\n", s->url); + goto end; + } + + /* mark the end of the shift to up to the last data we wrote, and get ready + * for writing */ + pos_end = avio_tell(s->pb); + avio_seek(s->pb, read_start + shift_size, SEEK_SET); + + avio_seek(read_pb, read_start, SEEK_SET); + pos = avio_tell(read_pb); + +#define READ_BLOCK do { \ + read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], shift_size); \ + read_buf_id ^= 1; \ +} while (0) + + /* shift data by chunk of at most shift_size */ + READ_BLOCK; + do { + int n; + READ_BLOCK; + n = read_size[read_buf_id]; + if (n <= 0) + break; + avio_write(s->pb, read_buf[read_buf_id], n); + pos += n; + } while (pos < pos_end); + ret = ff_format_io_close(s, &read_pb); + +end: + av_free(buf); + return ret; +} diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c index 7a412fe9cc..42d56fccd6 100644 --- a/libavformat/segafilmenc.c +++ b/libavformat/segafilmenc.c @@ -33,8 +33,8 @@ #include "libavutil/intreadwrite.h" #include "libavcodec/bytestream.h" #include "avformat.h" -#include "internal.h" #include "avio_internal.h" +#include "mux.h" typedef struct FILMOutputContext { AVIOContext *header; diff --git a/libavformat/utils.c b/libavformat/utils.c index f31dda9b44..b53e2aff0c 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1832,59 +1832,3 @@ void ff_format_set_url(AVFormatContext *s, char *url) av_freep(&s->url); s->url = url; } - -int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size) -{ - int ret; - int64_t pos, pos_end; - uint8_t *buf, *read_buf[2]; - int read_buf_id = 0; - int read_size[2]; - AVIOContext *read_pb; - - buf = av_malloc_array(shift_size, 2); - if (!buf) - return AVERROR(ENOMEM); - read_buf[0] = buf; - read_buf[1] = buf + shift_size; - - /* Shift the data: the AVIO context of the output can only be used for - * writing, so we re-open the same output, but for reading. It also avoids - * a read/seek/write/seek back and forth. */ - avio_flush(s->pb); - ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL); - if (ret < 0) { - av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for shifting data\n", s->url); - goto end; - } - - /* mark the end of the shift to up to the last data we wrote, and get ready - * for writing */ - pos_end = avio_tell(s->pb); - avio_seek(s->pb, read_start + shift_size, SEEK_SET); - - avio_seek(read_pb, read_start, SEEK_SET); - pos = avio_tell(read_pb); - -#define READ_BLOCK do { \ - read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], shift_size); \ - read_buf_id ^= 1; \ -} while (0) - - /* shift data by chunk of at most shift_size */ - READ_BLOCK; - do { - int n; - READ_BLOCK; - n = read_size[read_buf_id]; - if (n <= 0) - break; - avio_write(s->pb, read_buf[read_buf_id], n); - pos += n; - } while (pos < pos_end); - ret = ff_format_io_close(s, &read_pb); - -end: - av_free(buf); - return ret; -}