From patchwork Tue Jul 12 22:34:12 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: 36764 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:6da0:b0:8b:e47:9dbf with SMTP id wl32csp2313015pzb; Tue, 12 Jul 2022 15:34:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1syrfEix69quQM3TJPpMeQMNaf6d9dPSi9vSyGCgB/OcObITggbRYLmHVscOlJKKak5y95q X-Received: by 2002:a17:907:3e11:b0:72b:49d1:2054 with SMTP id hp17-20020a1709073e1100b0072b49d12054mr385933ejc.78.1657665283115; Tue, 12 Jul 2022 15:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657665283; cv=none; d=google.com; s=arc-20160816; b=Cv6rlmb/Yl1Nwwc8oOqOlzt8k9N7Hs9fzDRR6KxjZD6Eqcv3iU88K7fcaOaHzl9hZP 1HNYBnq41laPJ/l21qzlZfpDqF0sDbeW5ongcBxlJrXI8GSKOZhYLmvMuOhx6kRziZ4P G796YUDkcRVKRDZIJg7dtk/MCH7X4rvMyjdY5a1BwpgpPBjSQ29n4mxb7bskqCM/ijMS sL703IHcRyQFutXV5NU10SlIdeLB0Yyn8eNG4teDw/JFJsv5izxXbaOeskCxtM/oORlr iXAapQWJqrC9Eh3wV8AWdZ4DloI/XESErNPSo1YCliXfkrODG3R/M6HLgda5J3yhH4Bj uYUQ== 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=8vpftZoLeQJ0GPXipq3Z3C7SCF1/3p7rEfwVbsOXnHI=; b=HOHHgL15m5Zh6AdphT8HieAY8pcghCkwtcVITltCVLtWcgCJFHf5SjBA2bCl6VRYYe C7mLKLkgi3NIsn4ygeyk7GF/02Q0bBiFdYWy8qmL0DP3RYBn74jiRt5y3fLSG3bEWnbF A+a9G6zOzcrtEgLir7Gv9lG4Bd/oyKIcBzPCNOWZQSZCM33EjXrgEl/182RDDD4DdE/+ B3FbdyaXn0458wIYwCtLzHRPqDjhZ0S+rM5Mn9/1SEk+h0sy1k1vLK9sc08RBOZZmcHt +zVa1F6K7XUlJ7nr3IVz2/QypK2LdsgofR0iWW/c+sBJ0I4AHHksL143G51Vxh6gVKe2 yRQA== 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 w2-20020a05640234c200b0043a707aa43fsi16918088edc.201.2022.07.12.15.34.42; Tue, 12 Jul 2022 15:34:43 -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 8838468B851; Wed, 13 Jul 2022 01:34:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF45B68B7F0 for ; Wed, 13 Jul 2022 01:34:31 +0300 (EEST) Received: by mail-pf1-f175.google.com with SMTP id g126so8675819pfb.3 for ; Tue, 12 Jul 2022 15:34:31 -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=48f6hcC79OT7bEKG3h7LU3iqY4f/iS1EZuFhA8awNPs=; b=QZF2WuKlGyPolM+wp1RE8Zk3Wc64XAFin/FRR53kUR1tulr6yh7TJ5TfcXlN8zQqFI XcnvaXVHM9qdhnzBKX41vo/IDEtW41eW6uPFuiNAoUjfBIpziqg/9PK/4Uci84oDUZ4b MRdc0b8+M7BMB4gMMLVLeJqcF51meQJ08JsogToEVKfUCdFh3RkyF7egnQQDP2Mkno8f 1B4k+j+7Lkvm0YVFl8WeEq/Q02mBfP7QeP0xnJlWPeqf/VKO7yg+0Kf7FZ9DdtnYyJfY xRgpUVlXm7BZpEpd6bHoBPJTyNgy1DGgLom57b3D87UcsgS6nRN7aZInhmCZPw1Iy0GX RUGg== X-Gm-Message-State: AJIora/XHs/R+9Qh4mxfZKTEhtokg5vzk/Ouk3VsdK8xUaiRw/asudhy h9jBiCrIHepEXVsxsBlsWyZprhKKWmN4Zw== X-Received: by 2002:a05:6a00:f85:b0:52a:c718:ff9 with SMTP id ct5-20020a056a000f8500b0052ac7180ff9mr266701pfb.85.1657665269048; Tue, 12 Jul 2022 15:34:29 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id h191-20020a6283c8000000b0051bba89c2bcsm7336055pfe.58.2022.07.12.15.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 15:34:28 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Tue, 12 Jul 2022 15:34:22 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Jul 2022 15:34:12 -0700 Message-Id: <20220712223413.29940-1-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: xgnVhU0PNXFA From: Pierre-Anthony Lemieux As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html --- libavformat/avformat.c | 38 ++++++++++++++++++++++++++++++++++++++ libavformat/fifo.c | 2 +- libavformat/internal.h | 9 +++++++++ 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, 51 insertions(+), 41 deletions(-) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 30d6ea6a49..a4aa92cd22 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -235,6 +235,44 @@ 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->index = src->index; + 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; + + ret = av_packet_ref(&dst->attached_pic, &src->attached_pic); + if (ret < 0) + return ret; + + 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..f89da85e22 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -625,6 +625,15 @@ 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 + * + * @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)