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 7C88640B46 for ; Sat, 6 Aug 2022 09:43:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5B9368B56D; Sat, 6 Aug 2022 12:43:28 +0300 (EEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (unknown [40.92.90.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51A6F68AF5D for ; Sat, 6 Aug 2022 12:43:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mXZhlidWlp34D3+OOPrXWlHA6pqNWrOPnxYCxP/2LQLVFvib5qszsjKB3tP7kbSYg9caVjEFZuSPaU2lbeI+JKWLP1IPpTkcxBoAeabm9sa88OleYK26/TMuUDuZCtDLaXpd4h8Fo3T3iNYnUTt5UHkJG1ajALwXMKMOoAS5+HUNkmv9pv+E4/ogzfaq8dx0Ks51dDklQwLGDPZoMCOjCeCxylpVuP3GhtYHynEmUZc/WPOJqlgLEgZ0ctWRQv3GLoi792HzIuNYMjmYsYNuysY1/9oa0E7rdypL5X26vmHmWPx6AtzfFlZBf91bk4WsGVYC35hI/y8tLgQ6wfCMBQ== 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=ODoEHV4Cs+mCWE0Tb2epBLuARpMJBtAh0iWEpdi1sgM=; b=kQ0PyC66XoRDaTJgy8hJ7glvGP0GAg14jJ4VIVUC3EWC8NwMaroIi4jvWlSzFMrzsM55cmBLaZFo9X/bv9IeqQ+53z6zAg4WgUbJAscXGc7NpZP5sD/ztGnJDrPMTp/ayAjP6+eI92Lzb6hEt7YNDgd52F0OvWfVGVF/BL8bM9mNLHSNY7NTAmLwJUoZpQ5gLdk5OWR7C4DsIPrxgM6VnjdWWaOCMJaQEczV8Tpr6gqCepctEP6myaV3DiHg7VkRnTIousIa41YN6WRKtxGzyTK/9OuyFeN9IA/whLEU2JhrC6SmBosZEuy73oJKgSklwiGlwDNZ+L+X6HhdLoCHxA== 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=ODoEHV4Cs+mCWE0Tb2epBLuARpMJBtAh0iWEpdi1sgM=; b=c5y4mUi3Vxp9XsPjoCw7t72BQHIpqVEeKJQCAzzv8RwxapyvH91YPsYRqRHVDnt5j6QmflDAyqTO7aNdIdRsuJgps4vyf7+fHJ41HJq6g/r3VFRXo4yf9jkkqBk69NYvwFkfrG0vw+5Pueiq5GOpnol+MD25N2OzJmA6//Rb7c9Y0SIpno1qeM3mN1FQvO8tdOkI42Iwb2tgesVye+zh+Q7UYF3vcWa4V8JnYtlAXCfjTs2luhfV3M+ljCA9WA/lOvCxWuWw5NyAINYqpQ/LBGKyjUOPAkKRShTWPn0GrJmd3d65nFKUQZFph/apTbvq/R5XYobRaGDI5zT/4Y+yZg== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by AM6PR01MB6166.eurprd01.prod.exchangelabs.com (2603:10a6:20b:ec::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.17; Sat, 6 Aug 2022 06:22:33 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::210e:b627:bcc9:8c46%11]) with mapi id 15.20.5504.016; Sat, 6 Aug 2022 06:22:33 +0000 Message-ID: Date: Sat, 6 Aug 2022 08:22:30 +0200 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220805152032.1382-1-pal@sandflow.com> From: Andreas Rheinhardt In-Reply-To: <20220805152032.1382-1-pal@sandflow.com> X-TMN: [wIL7oAliDGjRcjXaAj6zIfidREe0w/gV] X-ClientProxiedBy: ZR0P278CA0034.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::21) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <5d7f5d41-42c0-cc28-e1a9-8933bc07823d@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 963c046c-7687-4d48-4dcd-08da77740c2e X-MS-TrafficTypeDiagnostic: AM6PR01MB6166:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nctLtDCKOEipVH6tpwqxdJeeEFc0PTx38lN+5RJFDLSGzDUgyPQGRzrpq4Pg3ERrzacEEX9FWmdPaH3H8LSG6E0td+/aSTNBs2WGO7tMPQCUjpJxfkRqEjcsN3co5t5iq3W90vo71jahcHtZmTjaeRMm5v+5Bc1ZwTZdG0Mg4XhoiAP8pEKgJJsiRhztaGedO5e3DowuSUUGYEFd6oCCx1XfaRxJlcEQ2nRopNbxpJwQT0ZiPia5MPP8QHSu8eZoTa1Ky+BaJaMmx+X3tBXSJH834fwjKLrFqI20YuK8cOod1K4+JRZvID0r0STNhbmM764jBJbucFx1Li9m1mbTJqmzbbafnXMB9HzJyuL6g/yu3gCm5/iL6aQc4+I2ZOmgZsas6xBbwpefbCAL98HvMEGxC9ckC6/2Nol9L7QCVQNKu2Es94MM2tqgtjX9i4S+jE2jtEexIiC3D0L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Nvck85WHZvQ09qbDdjUDA5N2plMjVUajdz?= =?utf-8?B?dXdLbndpVWx6MnpzL0hXM0o2L2phNHdsQ0hNTWFiTjNsd1dLbDNURUl1R2ph?= =?utf-8?B?dTRtRUNJeUEzTGwrazdBYnE5b1IyQlhoY1hyVk9YQXh5NEpQa2tQMUEzR1Nv?= =?utf-8?B?Y3EvT2JiR0xKMWRBR2NvMzdIZWtzcFVkTDdxVUtDRVIrd0orYnVTcGtXM3dE?= =?utf-8?Q?Y6Ivh9ehJILaRBiiVE=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 963c046c-7687-4d48-4dcd-08da77740c2e X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2022 06:22:33.3744 (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: AM6PR01MB6166 Subject: Re: [FFmpeg-devel] [PATCH v6 1/2] avformat: refactor ff_stream_encode_params_copy() to stream_params_copy() 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: pal@sandflow.com: > From: Pierre-Anthony Lemieux > > Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299685.html > > --- > libavformat/avformat.c | 68 ++++++++++++++++++++++++++++++++++++++++ > libavformat/fifo.c | 8 ++--- > libavformat/internal.h | 12 +++++++ > libavformat/mux.h | 9 ------ > libavformat/mux_utils.c | 28 ----------------- > libavformat/segment.c | 6 ++-- > libavformat/tee.c | 7 ++--- > libavformat/webm_chunk.c | 6 ++-- > 8 files changed, 89 insertions(+), 55 deletions(-) > > diff --git a/libavformat/avformat.c b/libavformat/avformat.c > index 30d6ea6a49..64c9d71a24 100644 > --- a/libavformat/avformat.c > +++ b/libavformat/avformat.c > @@ -235,6 +235,74 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream *src) > return 0; > } > > +/** > + * Copy all stream parameters from source to destination stream, with the > + * exception of: > + * * the index field, which is usually set by avformat_new_stream() > + * * the attached_pic field, if attached_pic.size is 0 or less > + * > + * @param dst pointer to destination AVStream > + * @param src pointer to source AVStream > + * @return >=0 on success, AVERROR code on error > + */ > +static int stream_params_copy(AVStream *dst, const AVStream *src) > +{ > + int ret; > + > + dst->id = src->id; > + dst->time_base = src->time_base; > + dst->start_time = src->start_time; > + dst->duration = src->duration; > + dst->nb_frames = src->nb_frames; > + dst->disposition = src->disposition; > + dst->discard = src->discard; > + dst->sample_aspect_ratio = src->sample_aspect_ratio; > + dst->avg_frame_rate = src->avg_frame_rate; > + dst->event_flags = src->event_flags; > + dst->r_frame_rate = src->r_frame_rate; > + dst->pts_wrap_bits = src->pts_wrap_bits; > + > + av_dict_free(&dst->metadata); > + ret = av_dict_copy(&dst->metadata, src->metadata, 0); > + if (ret < 0) > + return ret; > + > + ret = avcodec_parameters_copy(dst->codecpar, src->codecpar); > + if (ret < 0) > + return ret; > + > + ret = ff_stream_side_data_copy(dst, src); > + if (ret < 0) > + return ret; > + > + av_packet_unref(&dst->attached_pic); > + if (src->attached_pic.size > 0) { I'd rather have it that you check for attached_pic.data instead (even if this might mean that avformat_queue_attached_pictures() might warn for the dst stream lateron because of a packet with size zero). That way you would be copying the packet iff the src packet is set (side-data only attached pics don't exist). This would also mean that the behaviour of attached pic would no longer be exceptional, i.e. it needn't be documented. > + ret = av_packet_ref(&dst->attached_pic, &src->attached_pic); > + if (ret < 0) > + return ret; > + } > + > + return 0; > +} > + > +AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src) > +{ > + AVStream *st; > + int ret; > + > + st = avformat_new_stream(dst_ctx, NULL); > + if (!st) > + return NULL; > + > + ret = stream_params_copy(st, src); > + if (ret < 0) { > + ff_remove_stream(dst_ctx, st); > + return NULL; > + } > + > + return st; > +} > + > AVProgram *av_new_program(AVFormatContext *ac, int id) > { > AVProgram *program = NULL; > diff --git a/libavformat/fifo.c b/libavformat/fifo.c > index ead2bdc5cf..55d413b952 100644 > --- a/libavformat/fifo.c > +++ b/libavformat/fifo.c > @@ -505,13 +505,11 @@ static int fifo_mux_init(AVFormatContext *avf, const AVOutputFormat *oformat, > avf2->flags = avf->flags; > > for (i = 0; i < avf->nb_streams; ++i) { > - AVStream *st = avformat_new_stream(avf2, NULL); > + AVStream *st = NULL; > + > + st = ff_stream_clone(avf2, avf->streams[i]); > if (!st) > return AVERROR(ENOMEM); > - > - ret = ff_stream_encode_params_copy(st, avf->streams[i]); > - if (ret < 0) > - return ret; > } > > return 0; > diff --git a/libavformat/internal.h b/libavformat/internal.h > index b6b8fbf56f..6dd763950f 100644 > --- a/libavformat/internal.h > +++ b/libavformat/internal.h > @@ -625,6 +625,18 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags); > */ > int ff_stream_side_data_copy(AVStream *dst, const AVStream *src); > > +/** > + * Create a new stream and copy to it all parameters from a source stream, > + * with the exception of: > + * * the index field, which is set when the new stream is created > + * * the attached_pic field, if attached_pic.size is 0 or less> + * > + * @param dst_ctx pointer to the context in which the new stream is created > + * @param src pointer to source AVStream > + * @return pointer to the new stream or NULL on error > + */ > +AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src); > + > /** > * Wrap ffurl_move() and log if error happens. > * > diff --git a/libavformat/mux.h b/libavformat/mux.h > index c01da82194..1bfcaf795f 100644 > --- a/libavformat/mux.h > +++ b/libavformat/mux.h > @@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size) > */ > int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options); > > -/** > - * Copy encoding parameters from source to destination stream > - * > - * @param dst pointer to destination AVStream > - * @param src pointer to source AVStream > - * @return >=0 on success, AVERROR code on error > - */ > -int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src); > - > /** > * Parse creation_time in AVFormatContext metadata if exists and warn if the > * parsing fails. > diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c > index eb8ea3d560..2fa2ab5b0f 100644 > --- a/libavformat/mux_utils.c > +++ b/libavformat/mux_utils.c > @@ -121,34 +121,6 @@ int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **op > return 0; > } > > -int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) > -{ > - int ret; > - > - dst->id = src->id; > - dst->time_base = src->time_base; > - dst->nb_frames = src->nb_frames; > - dst->disposition = src->disposition; > - dst->sample_aspect_ratio = src->sample_aspect_ratio; > - dst->avg_frame_rate = src->avg_frame_rate; > - dst->r_frame_rate = src->r_frame_rate; > - > - av_dict_free(&dst->metadata); > - ret = av_dict_copy(&dst->metadata, src->metadata, 0); > - if (ret < 0) > - return ret; > - > - ret = avcodec_parameters_copy(dst->codecpar, src->codecpar); > - if (ret < 0) > - return ret; > - > - ret = ff_stream_side_data_copy(dst, src); > - if (ret < 0) > - return ret; > - > - return 0; > -} > - > int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds) > { > AVDictionaryEntry *entry; > diff --git a/libavformat/segment.c b/libavformat/segment.c > index fa435d9f32..fc1810e074 100644 > --- a/libavformat/segment.c > +++ b/libavformat/segment.c > @@ -167,11 +167,9 @@ static int segment_mux_init(AVFormatContext *s) > AVStream *st, *ist = s->streams[i]; > AVCodecParameters *ipar = ist->codecpar, *opar; > > - if (!(st = avformat_new_stream(oc, NULL))) > + st = ff_stream_clone(oc, ist); > + if (! st) > return AVERROR(ENOMEM); > - ret = ff_stream_encode_params_copy(st, ist); > - if (ret < 0) > - return ret; > opar = st->codecpar; > if (!oc->oformat->codec_tag || > av_codec_get_id (oc->oformat->codec_tag, ipar->codec_tag) == opar->codec_id || > diff --git a/libavformat/tee.c b/libavformat/tee.c > index f1f2a9d2a5..acbd3dfb84 100644 > --- a/libavformat/tee.c > +++ b/libavformat/tee.c > @@ -284,14 +284,11 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) > } > tee_slave->stream_map[i] = stream_count++; > > - if (!(st2 = avformat_new_stream(avf2, NULL))) { > + st2 = ff_stream_clone(avf2, st); > + if (! st2) { Unnecessary whitespace here and above. > ret = AVERROR(ENOMEM); > goto end; > } > - > - ret = ff_stream_encode_params_copy(st2, st); > - if (ret < 0) > - goto end; > } > > ret = ff_format_output_open(avf2, filename, &options); > diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c > index d69db3a004..9e71a1209d 100644 > --- a/libavformat/webm_chunk.c > +++ b/libavformat/webm_chunk.c > @@ -91,12 +91,10 @@ static int webm_chunk_init(AVFormatContext *s) > if ((ret = av_dict_copy(&oc->metadata, s->metadata, 0)) < 0) > return ret; > > - if (!(st = avformat_new_stream(oc, NULL))) > + st = ff_stream_clone(oc, ost); > + if (!st) > return AVERROR(ENOMEM); > > - if ((ret = ff_stream_encode_params_copy(st, ost)) < 0) > - return ret; > - > if (wc->http_method) > if ((ret = av_dict_set(&dict, "method", wc->http_method, 0)) < 0) > 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".