From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CE10940E26 for ; Fri, 31 Dec 2021 12:36:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C31F368AFEC; Fri, 31 Dec 2021 14:36:34 +0200 (EET) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064038.outbound.protection.outlook.com [40.92.64.38]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF65668A417 for ; Fri, 31 Dec 2021 14:36:28 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NL/GfXE6gzWBJO6oBMwVotY/SRRXq1Oo3rEgzOmgenyDbxUIoSNRZD2KaYdW+aaaZbcGjeQu/9llX0BZDTHt5+0JGVEWvCkr3cZ5XDndJmPMs0jUHrGOARnmWm65dcew3rtyx4NOUYjjaiiYDosz1sihp6a4eTWc8DQFGg6uKe6P2dj/G0l0u8WT+2kvtk6glBU0Xv7qRFBm9A/x41bYMDnp6X6gL4aa46NEwPT3CdZGdc3RNEAhZ1wV6u83SqAIwy6rSj+vqBzDhUSCIGzApxi+TEjhTcvIjHkfHHQ6pugilE/Gg74FKyOCbiPigaH5srJ3RY0IXggryFIXBuItVQ== 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=KUJ3DP/Ra3k0xbYQ0vY3rTzS7433Fp26cUqZCslCZbE=; b=OQJyM3wLs9hqgoFBT7FSPmxVMTsyjq8G8H9Z6fcLg+99JabUZAPYeQpoBDeqpXDNijfycQvf4Ae0AQsa6dbdehNwBBgitJD/RwJ3NBmlQ94ewbwH403lTFZ+bH/oHchJpNLYdtURPywhm7VUv5LJxk4fTMgVzsXvD5vtGZxziSvjG1xjgikZaJ6dKYpH2lA953TNB0GMuq4pedzyWdcCcU85UuqXa4uLeoiYlKPUY6MehD3RDiv1v3XdxVkj04x54du9dDTlyU7eQwszJ+rT16P45bWauEspVz4LleehFtWqFMnoAmhm4CUl6tEokGI3lYWU2laPGmAwgMbU0X4GyQ== 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=KUJ3DP/Ra3k0xbYQ0vY3rTzS7433Fp26cUqZCslCZbE=; b=u3NXzA8/pG194vA13NvTg0esVQU+bK9P8jcBPsM8l7aPQxjQeSsGUb8B6aXHJtpJSrpR6UtTe7HaIZf7nhIP358+QqJWRFPk+QxKMxe3JJCtEwaBaZRb7rQrm/4s//Fh2OZo3ccVOlcVhpNNHM2hVLDU0hhfGV1BW5dS/bxve2caDQo/7+nO3x9dmfL8zoRnny8pI4VC6jdxWBTZLosucQ/qQhOTj2Z0sK6uVHOPtQUJPZIAiJgDir7evJ8VzgBdkMYZefba8Qh/sP/HldafjoQZNtJvxkHn8wOAzLThCuPX4vEq8Za2Njly4sJ12tI+fwO9cKYEzoJ3Q6d/V6iIMA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AS8PR03MB7270.eurprd03.prod.outlook.com (2603:10a6:20b:2e4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.14; Fri, 31 Dec 2021 12:36:27 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::19fc:be9f:2c9c:53f5]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::19fc:be9f:2c9c:53f5%6]) with mapi id 15.20.4844.014; Fri, 31 Dec 2021 12:36:27 +0000 Message-ID: Date: Fri, 31 Dec 2021 13:36:26 +0100 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20211227002613.25069-1-cus@passwd.hu> <20211227002613.25069-2-cus@passwd.hu> From: Andreas Rheinhardt In-Reply-To: <20211227002613.25069-2-cus@passwd.hu> X-TMN: [8VSK885JjGarY6oOBc/pRUkFExrNlaul] X-ClientProxiedBy: AM6P194CA0078.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:8f::19) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <47ca93d7-62e2-9648-d24e-bd19bfc0397a@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 51904a79-af79-48f8-14ec-08d9cc5a29df X-MS-TrafficTypeDiagnostic: AS8PR03MB7270:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H4qxql+XZsIscBm3xeBnb1VxsdM3/5BrVlNQaqd3lzxLoREYO5fs03f3fZ7TSse4mNiEhq/kAEPtfHoCQQDyGwcif9B7ZqJ2GlywSMgqtZC1YiXtygkUwu/LWg9hZuoGyJMdQMrmRhgHXiuTdQTTP85jesa+iWzLW3HLenA6V+DoIG76nBsMo8izZGakWnICHuSu94iNp77991I/q5jrPXU89oyilWF+3YjoVF3ikflQQZjaGRTQk23+vCdvCqfY0RSKaDWHhD1ZSmOCaryiEjQwUl8w9trMFGt1sCeLSElOvzOaQgBznkDrSgP/mMX9Uk6WDwQW9c/sGGE9uZG+KP7uja0wozZGH4autXe8DNdJVqnXtRJSWhjo4kzfuZMb1l8ko1siYxquYHTAtWnWPVxCP1v2ODNKQJuzbfakPCskYoWLZsY9Qia/6uAWzjA5ll/6OniPWfX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-8?B?QmlaOFVvVnErZ2xndzd4QUxhRFFrQkNDWXRZMHl1c3A0MDRlZ3Y1Ulc1TWZQ?= =?utf-8?B?eHVmUi84eng1eEUrNmdXUURFVjRtTFd1cWlESXMzMnBWVWFiSlVNanBKOHJx?= =?utf-8?B?eGU2MUFMaUI3dGJQVkY4RkRxaUVkUitDc2tSYzh2U3R3ZjJwUG0wZzd5Ukcx?= =?utf-8?B?VFVTS2xYcnM4VUNIajJuRUVUQm8rQjhuR0xnKzEzNVFHcmZPZzRoSEx3elZk?= =?utf-8?B?dzc3THNhamZ1MmxNaFRSOFhiZ1cyTUdub1RwWkVyNThlVzRoUkthZzFjbjFT?= =?utf-8?B?dnpJVzlZZSt4d2I1UWVYK2p1WXgvTjZxQTYxcThpWlVSa1RkUVhDcVdVTGx6?= =?utf-8?B?NVkwaTVkVjVTQmxuck1uSllKVVNka2crOGw3SGpBNmR5TThqaEFRL1ZiTWdH?= =?utf-8?B?MWV4SFhSdnhGblQvWTJYMjNMWHdoRHlDSzBqSGxVeThCLzJ1ZkMybXpIelNL?= =?utf-8?B?bG45S0VNUWRvbmNXRzA1Mmw1TDd4VkFFaVV3Z0JUMThVVjF5NitOU0FNYUxL?= =?utf-8?B?cFVHRVJITlg5L2oxcWZ2RmlrWkQrMjlCRlovWjgySk0zUXZOdz09?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51904a79-af79-48f8-14ec-08d9cc5a29df X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Dec 2021 12:36:27.3587 (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: AS8PR03MB7270 Subject: Re: [FFmpeg-devel] [PATCH 2/5] avformat/movenc: factorize data shifting 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Marton Balint: > And move data shift function from movenc to utils. > > Signed-off-by: Marton Balint > --- > libavformat/internal.h | 7 ++++++ > libavformat/movenc.c | 55 ++--------------------------------------- > libavformat/utils.c | 56 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 65 insertions(+), 53 deletions(-) > > diff --git a/libavformat/internal.h b/libavformat/internal.h > index 2ba795d669..63235ce5cf 100644 > --- a/libavformat/internal.h > +++ b/libavformat/internal.h > @@ -1019,4 +1019,11 @@ 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); > + > #endif /* AVFORMAT_INTERNAL_H */ > diff --git a/libavformat/movenc.c b/libavformat/movenc.c > index 0f912dd012..40ad4f8642 100644 > --- a/libavformat/movenc.c > +++ b/libavformat/movenc.c > @@ -7150,13 +7150,8 @@ static int compute_sidx_size(AVFormatContext *s) > > static int shift_data(AVFormatContext *s) > { > - int ret = 0, moov_size; > + int moov_size; > MOVMuxContext *mov = s->priv_data; > - int64_t pos, pos_end; > - uint8_t *buf, *read_buf[2]; > - int read_buf_id = 0; > - int read_size[2]; > - AVIOContext *read_pb; > > if (mov->flags & FF_MOV_FLAG_FRAGMENT) > moov_size = compute_sidx_size(s); > @@ -7165,53 +7160,7 @@ static int shift_data(AVFormatContext *s) > if (moov_size < 0) > return moov_size; > > - buf = av_malloc(moov_size * 2); > - if (!buf) > - return AVERROR(ENOMEM); > - read_buf[0] = buf; > - read_buf[1] = buf + moov_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 " > - "the second pass (faststart)\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, mov->reserved_header_pos + moov_size, SEEK_SET); > - > - /* start reading at where the new moov will be placed */ > - avio_seek(read_pb, mov->reserved_header_pos, 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], moov_size); \ > - read_buf_id ^= 1; \ > -} while (0) > - > - /* shift data by chunk of at most moov_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); > - ff_format_io_close(s, &read_pb); > - > -end: > - av_free(buf); > - return ret; > + return ff_format_shift_data(s, mov->reserved_header_pos, moov_size); > } > > static int mov_write_trailer(AVFormatContext *s) > diff --git a/libavformat/utils.c b/libavformat/utils.c > index 332ba534d2..a78797ef57 100644 > --- a/libavformat/utils.c > +++ b/libavformat/utils.c > @@ -2035,3 +2035,59 @@ const char *av_disposition_to_string(int disposition) > > return NULL; > } > + > +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); This avio_tell() is redundant: avio_seek() returns the new position on non-error and in this case it is equal to read_start. > + > +#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); > + ff_format_io_close(s, &read_pb); > + > +end: > + av_free(buf); > + return ret; > +} > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".