From patchwork Sun Jul 31 20:37:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 37055 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp2132018pzb; Sun, 31 Jul 2022 13:38:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR7GjA1V2wmjY+061bZgTmakVPCnvyFv1SbxHb1++1MS2BxESsM1xtXI6ZMct/igrZppHVc3 X-Received: by 2002:aa7:db44:0:b0:43d:267c:edd9 with SMTP id n4-20020aa7db44000000b0043d267cedd9mr11428128edt.385.1659299913251; Sun, 31 Jul 2022 13:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659299913; cv=none; d=google.com; s=arc-20160816; b=gNNY+jOc6TWRUfJHOvBu+vqVEOzOcGQGeYeaWpq2pukggnd4bgl+ETc+sgSS7Is/Er PNnOULGBY8t/0cpFoWVjewuJnejnPRx6mP+WaNZnq1TroCcuVGNu92SOg0GVTHpG/iEE cW5iy/NnAaI+MvJdO+GMIruqpDoMGsafTu3b+HI4VL2iAbd0ge9kML/RekgkrGWNl8Gr 5DmyMBzTqCyo0KAOp7gJjehkD0/QF4okrs2jpJw6Hru5FQhKi6ufhpcYvYkHhsvH0Uw6 B038ZX6E+uAt6YzqElEk4yiHbhqMHY1NZle2Ld/LQZKU6EdW4PJJuR9ia4kyMq7kmkIz AI5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=XakbfS9DOWg7VfTbM1L0vP5N0Kh5yFcddWLfdToIa/4=; b=baMhQjzMeo5yRzOsRg4vOzZGmc9YEqGjpUfU6FrwdnS1p8/0GD6aSUuwOCHOTUDBv5 voyCuapoMKUoiWR0VGEKB0Hu9JG0mfCHzMFGHLddbULH9H3cqxL3AzTdnBUsfpup/9pU 1z0NijbND+5jjiuD5au5R7NwDCAnXK1EUVG9wqOPLt34N1CvR0zj8edYFpt4n3i6B50i WyYeK9FArN61b0Af3+gm2b5g6Up2s+sNXGS7FEew1BYwRPH7LJRkMjn9FS0hzPWLeUY4 7pBhRApqbYlu4D0liOX2VuVGBwV6DXeEi1sePJTul4XIgPKrj6wOixoNq2sojscK3VpN PzTQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hw9-20020a170907a0c900b0072f4443d336si7324830ejc.201.2022.07.31.13.38.32; Sun, 31 Jul 2022 13:38:33 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF67768B916; Sun, 31 Jul 2022 23:38:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40FCA680741 for ; Sun, 31 Jul 2022 23:38:21 +0300 (EEST) Received: by mail-pj1-f45.google.com with SMTP id x2-20020a17090ab00200b001f4da5cdc9cso3098977pjq.0 for ; Sun, 31 Jul 2022 13:38:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QYhsk5zYxbS88nELYjPGnREFyxNe9LcTtCfrRD0FKxc=; b=IkVgvSOsbAyerZD7yTSnYW/VbCNw2+ko2W3uWMnBxBktFTcyZhU5ePwRfOGFRxA3RU TrMT1Vvl35dy+yk1FGbhnvUNG/wxqwqm10rQTeyly1pb9z1B33GANyvIpjR7Fh9vTck1 ViAVxgE+4FcBCRZGmykPtKmJrdPatV5c3n2qQEzEOhPG6GLEVV4P4BQ01BE/r6xDLXzx ZBBM8WhHx1qsvxg5ad3eQAWDsJgf2MneKu1Lj3xjA87ukWdfDLkk3kTnPvY0TD/7FYS/ kjo2a73Yyp58OeoAr8AOmHpMJTl6MezETQCDMgDqLxy4jj+uGYUgPbHGut+n9d7ozMz1 b0Xw== X-Gm-Message-State: ACgBeo0ZyfoKAE//panOnUfz7VmMXBziNpkcUlNbhRmCNvBX4uz6jVJo 4ffLxFN5B7Z90tvpAf6bjeFrZyENhYU= X-Received: by 2002:a17:902:bf0a:b0:16e:90d9:a42d with SMTP id bi10-20020a170902bf0a00b0016e90d9a42dmr10824134plb.12.1659299898409; Sun, 31 Jul 2022 13:38:18 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id 127-20020a621785000000b005252defb016sm1637437pfx.122.2022.07.31.13.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 13:38:17 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Sun, 31 Jul 2022 13:38:00 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jul 2022 13:37:57 -0700 Message-Id: <20220731203758.15667-1-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_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 Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WGnC8KnOnQMb From: Pierre-Anthony Lemieux As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html. Note that ff_stream_params_copy() does not copy: * the index field * the attached_pic if its size is 0 --- libavformat/avformat.c | 41 ++++++++++++++++++++++++++++++++++++++++ libavformat/fifo.c | 2 +- libavformat/internal.h | 12 ++++++++++++ libavformat/mux.h | 9 --------- libavformat/mux_utils.c | 28 --------------------------- libavformat/segment.c | 2 +- libavformat/tee.c | 2 +- libavformat/webm_chunk.c | 2 +- 8 files changed, 57 insertions(+), 41 deletions(-) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 30d6ea6a49..1d0ac5ab7e 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -235,6 +235,47 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream *src) return 0; } +int ff_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; + + if (src->attached_pic.size > 0) { + ret = av_packet_ref(&dst->attached_pic, &src->attached_pic); + if (ret < 0) + return ret; + } else { + av_packet_unref(&dst->attached_pic); + } + + return 0; +} + AVProgram *av_new_program(AVFormatContext *ac, int id) { AVProgram *program = NULL; diff --git a/libavformat/fifo.c b/libavformat/fifo.c index ead2bdc5cf..fef116d040 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -509,7 +509,7 @@ static int fifo_mux_init(AVFormatContext *avf, const AVOutputFormat *oformat, if (!st) return AVERROR(ENOMEM); - ret = ff_stream_encode_params_copy(st, avf->streams[i]); + ret = ff_stream_params_copy(st, avf->streams[i]); if (ret < 0) return ret; } diff --git a/libavformat/internal.h b/libavformat/internal.h index b6b8fbf56f..87a00bbae3 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); +/** + * 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 + */ +int ff_stream_params_copy(AVStream *dst, 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..a8f3e94714 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -169,7 +169,7 @@ static int segment_mux_init(AVFormatContext *s) if (!(st = avformat_new_stream(oc, NULL))) return AVERROR(ENOMEM); - ret = ff_stream_encode_params_copy(st, ist); + ret = ff_stream_params_copy(st, ist); if (ret < 0) return ret; opar = st->codecpar; diff --git a/libavformat/tee.c b/libavformat/tee.c index f1f2a9d2a5..dbfad604d0 100644 --- a/libavformat/tee.c +++ b/libavformat/tee.c @@ -289,7 +289,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave) goto end; } - ret = ff_stream_encode_params_copy(st2, st); + ret = ff_stream_params_copy(st2, st); if (ret < 0) goto end; } diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index d69db3a004..39f21fce7a 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -94,7 +94,7 @@ static int webm_chunk_init(AVFormatContext *s) if (!(st = avformat_new_stream(oc, NULL))) return AVERROR(ENOMEM); - if ((ret = ff_stream_encode_params_copy(st, ost)) < 0) + if ((ret = ff_stream_params_copy(st, ost)) < 0) return ret; if (wc->http_method)