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 2498242D46 for ; Sat, 6 Aug 2022 23:36:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8DC52680AEB; Sun, 7 Aug 2022 02:36:53 +0300 (EEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51E4E680AEB for ; Sun, 7 Aug 2022 02:36:47 +0300 (EEST) Received: by mail-pf1-f174.google.com with SMTP id f28so5284316pfk.1 for ; Sat, 06 Aug 2022 16:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sandflow-com.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc; bh=T0S85EJoEiUNwzcWDXkdIxKMtZn+9jLrNStlM96MuMk=; b=tRQgFzRquJgpHseZhjxv0ZCGJZRxFwuLSgqw2QU8GkT5OMBBP2Kle7/XPHkRZy6App fn4sZRh/0aDH65WJ8OAKyaB3pY5n/Md3LUUxCbwwahDFQql+np+O8+ieoRf51N3eoy+r PN8b7qiO/N+gavmvZMjXbQxHaoR8N2FC3o7VVz1kULSbyZYuTjaKPmtXeaDEgZ2MyT7a 8QWg5MziDaOGRPk0XXQU/+zV93DhzxUKBXSLawC6PkgE/NrhLU1vYN5UTx4iHxdYYCqC DTSl9922nJOl9g2reNk+lB0usUmmdrBwmAllfdgOxfjVHIUQiphn1I3+tMbBs6zP6ofl S9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc; bh=T0S85EJoEiUNwzcWDXkdIxKMtZn+9jLrNStlM96MuMk=; b=yH1VWdcKcOEn9gP5i7Q3A6pmMcmADwEx0gsMjnPhPKN4o+sPYCtffMvxdNcyMpQo4F YV+tdWNKSHrpR7eXtVwNoTRQ2jia9ltcnfwUJbkO3BmCifl/G9HzOp9wIfLVTuA4SWMW altGCzcTjNkEIDND9JUeNmj3Fmb+zPBELPd7KLSX0HOATM4LoBcFdlcOQHGbnCVNYIYO GA+ejTG1pqO7bUnldVTDuhlh54LvQfqzadnFVz8/gGqyMityGG5Nadus2RruJQOcAfb3 cIVE2Q2pfkExxmoLQOf8HaLONuBAaXU9q/GJxUvcPVrjkTTfsmVx1H5yKNSQcOE+J31P Q1dQ== X-Gm-Message-State: ACgBeo0Xe2unCDEGvLP1t61aX+ygjH3Ts6SKfvOIh0julLasqtkb1Ku9 OKNoMPV2lkFra996VIvU7WvMepzWA8ZDTQ== X-Google-Smtp-Source: AA6agR5wsf7GkdWBF9DDARaD5pdSaLzfAGGZX8CQRlrAieIaT3AjXJra2/IVt6l0/U29bnCLkYXI8A== X-Received: by 2002:a63:31ce:0:b0:41c:8e48:9cef with SMTP id x197-20020a6331ce000000b0041c8e489cefmr10470860pgx.541.1659829004090; Sat, 06 Aug 2022 16:36:44 -0700 (PDT) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com. [209.85.215.182]) by smtp.gmail.com with ESMTPSA id h7-20020a170902680700b0016dbaf3ff2esm5593801plk.22.2022.08.06.16.36.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Aug 2022 16:36:43 -0700 (PDT) Received: by mail-pg1-f182.google.com with SMTP id 13so5614886pgc.8 for ; Sat, 06 Aug 2022 16:36:43 -0700 (PDT) X-Received: by 2002:a63:e255:0:b0:41c:c80:53cb with SMTP id y21-20020a63e255000000b0041c0c8053cbmr10608666pgj.448.1659829002642; Sat, 06 Aug 2022 16:36:42 -0700 (PDT) MIME-Version: 1.0 References: <20220805152032.1382-1-pal@sandflow.com> In-Reply-To: From: Pierre-Anthony Lemieux Date: Sat, 6 Aug 2022 16:36:30 -0700 X-Gmail-Original-Message-ID: Message-ID: To: FFmpeg development discussions and patches 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: On Sat, Aug 6, 2022 at 2:43 AM Andreas Rheinhardt wrote: > > 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. Addressed at v7 > > > + 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. Addressed at v7 > > > 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". _______________________________________________ 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".