Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 16/25] fftools/ffmpeg: store stream media type in OutputStream
Date: Thu, 13 Apr 2023 16:12:14 +0200
Message-ID: <20230413141223.17245-16-anton@khirnov.net> (raw)
In-Reply-To: <20230413141223.17245-1-anton@khirnov.net>

Reduces access to a deeply nested muxer property
OutputStream.st->codecpar->codec_type for this fundamental and immutable
stream property.

Besides making the code shorter, this will allow making the AVStream
(OutputStream.st) private to the muxer in the future.
---
 fftools/ffmpeg.c          |  4 ++--
 fftools/ffmpeg.h          |  2 ++
 fftools/ffmpeg_mux.c      | 11 +++++------
 fftools/ffmpeg_mux_init.c | 26 ++++++++++++--------------
 4 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 33b2f72d90..30b42b4fde 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -748,12 +748,12 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
         const AVCodecContext * const enc = ost->enc_ctx;
         const float q = enc ? ost->quality / (float) FF_QP2LAMBDA : -1;
 
-        if (vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+        if (vid && ost->type == AVMEDIA_TYPE_VIDEO) {
             av_bprintf(&buf, "q=%2.1f ", q);
             av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n",
                        ost->file_index, ost->index, q);
         }
-        if (!vid && ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+        if (!vid && ost->type == AVMEDIA_TYPE_VIDEO) {
             float fps;
             uint64_t frame_number = atomic_load(&ost->packets_written);
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5833c13812..f08f5db49e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -578,6 +578,8 @@ typedef struct Encoder Encoder;
 typedef struct OutputStream {
     const AVClass *class;
 
+    enum AVMediaType type;
+
     int file_index;          /* file index */
     int index;               /* stream index in the output file */
 
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index b316925115..eb64d8c3ff 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -62,7 +62,6 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
 {
     MuxStream *ms = ms_from_ost(ost);
     AVFormatContext *s = mux->fc;
-    AVStream *st = ost->st;
     int64_t fs;
     uint64_t frame_num;
     int ret;
@@ -74,10 +73,10 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         goto fail;
     }
 
-    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
+    if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
         pkt->pts = pkt->dts = AV_NOPTS_VALUE;
 
-    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+    if (ost->type == AVMEDIA_TYPE_VIDEO) {
         if (ost->frame_rate.num && ost->is_cfr) {
             if (pkt->duration > 0)
                 av_log(ost, AV_LOG_WARNING, "Overriding packet duration by frame rate, this should not happen\n");
@@ -101,12 +100,12 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
                      - FFMIN3(pkt->pts, pkt->dts, ms->last_mux_dts + 1)
                      - FFMAX3(pkt->pts, pkt->dts, ms->last_mux_dts + 1);
         }
-        if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) &&
+        if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) &&
             pkt->dts != AV_NOPTS_VALUE &&
             ms->last_mux_dts != AV_NOPTS_VALUE) {
             int64_t max = ms->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);
             if (pkt->dts < max) {
-                int loglevel = max - pkt->dts > 2 || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
+                int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
                 if (exit_on_error)
                     loglevel = AV_LOG_ERROR;
                 av_log(s, loglevel, "Non-monotonous DTS in output stream "
@@ -136,7 +135,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
     if (debug_ts) {
         av_log(ost, AV_LOG_INFO, "muxer <- type:%s "
                 "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n",
-                av_get_media_type_string(st->codecpar->codec_type),
+                av_get_media_type_string(ost->type),
                 av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base),
                 av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base),
                 av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->st->time_base),
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index bc14cabad4..129973d9f0 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -108,7 +108,7 @@ static int check_opt_bitexact(void *ctx, const AVDictionary *opts,
 static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
                           OutputStream *ost, const AVCodec **enc)
 {
-    enum AVMediaType type = ost->st->codecpar->codec_type;
+    enum AVMediaType type = ost->type;
     char *codec_name = NULL;
 
     *enc = NULL;
@@ -117,7 +117,7 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
         MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
         if (!codec_name) {
             ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
-                                                         NULL, ost->st->codecpar->codec_type);
+                                                         NULL, ost->type);
             *enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
             if (!*enc) {
                 av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed "
@@ -127,7 +127,7 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
                 return AVERROR_ENCODER_NOT_FOUND;
             }
         } else if (strcmp(codec_name, "copy")) {
-            *enc = find_codec_or_die(ost, codec_name, ost->st->codecpar->codec_type, 1);
+            *enc = find_codec_or_die(ost, codec_name, ost->type, 1);
             ost->st->codecpar->codec_id = (*enc)->id;
         }
     }
@@ -410,6 +410,7 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type)
 
     ms->ost.file_index = mux->of.index;
     ms->ost.index      = mux->of.nb_streams - 1;
+    ms->ost.type       = type;
 
     ms->ost.class = &output_stream_class;
 
@@ -422,8 +423,6 @@ static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type)
 static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc,
                              OutputStream *ost)
 {
-    AVStream *st = ost->st;
-
     if (ost->filters_script && ost->filters) {
         av_log(ost, AV_LOG_ERROR, "Both -filter and -filter_script set\n");
         exit_program(1);
@@ -434,8 +433,7 @@ static char *get_ost_filters(const OptionsContext *o, AVFormatContext *oc,
     else if (ost->filters)
         return av_strdup(ost->filters);
 
-    return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
-                     "null" : "anull");
+    return av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull");
 }
 
 static void check_streamcopy_filters(const OptionsContext *o, AVFormatContext *oc,
@@ -1594,7 +1592,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u
     for (int i = 0; i < oc->nb_streams; i++) {
         OutputStream *ost = of->streams[i];
         MuxStream     *ms = ms_from_ost(ost);
-        enum AVMediaType type = ost->st->codecpar->codec_type;
+        enum AVMediaType type = ost->type;
 
         ost->sq_idx_encode = -1;
         ost->sq_idx_mux    = -1;
@@ -1628,7 +1626,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u
         for (int i = 0; i < oc->nb_streams; i++) {
             OutputStream *ost = of->streams[i];
             MuxStream     *ms = ms_from_ost(ost);
-            enum AVMediaType type = ost->st->codecpar->codec_type;
+            enum AVMediaType type = ost->type;
 
             if (!IS_AV_ENC(ost, type))
                 continue;
@@ -1657,7 +1655,7 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u
         for (int i = 0; i < oc->nb_streams; i++) {
             OutputStream *ost = of->streams[i];
             MuxStream     *ms = ms_from_ost(ost);
-            enum AVMediaType type = ost->st->codecpar->codec_type;
+            enum AVMediaType type = ost->type;
 
             if (!IS_INTERLEAVED(type))
                 continue;
@@ -2113,7 +2111,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
     for (int i = 0; i < ctx->nb_streams; i++) {
         OutputStream *ost = of->streams[i];
 
-        nb_streams[ost->st->codecpar->codec_type]++;
+        nb_streams[ost->type]++;
 
         MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st);
 
@@ -2123,7 +2121,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
             ost->st->disposition = ost->ist->st->disposition;
 
             if (ost->st->disposition & AV_DISPOSITION_DEFAULT)
-                have_default[ost->st->codecpar->codec_type] = 1;
+                have_default[ost->type] = 1;
         }
     }
 
@@ -2146,7 +2144,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o)
         // "Suitable" means the first of that type, skipping attached pictures.
         for (int i = 0; i < ctx->nb_streams; i++) {
             OutputStream *ost = of->streams[i];
-            enum AVMediaType type = ost->st->codecpar->codec_type;
+            enum AVMediaType type = ost->type;
 
             if (nb_streams[type] < 2 || have_default[type] ||
                 ost->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
@@ -2239,7 +2237,7 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o)
 
         MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st);
 
-        if (!(ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
+        if (!(ost->type == AVMEDIA_TYPE_VIDEO &&
               ost->enc_ctx && forced_keyframes))
             continue;
 
-- 
2.39.1

_______________________________________________
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".

  parent reply	other threads:[~2023-04-13 14:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 14:11 [FFmpeg-devel] [PATCH 01/25] fftools/ffmpeg_mux_init: move new_output_stream() lower in the file Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 02/25] fftools/ffmpeg_mux_init: restructure output stream creation Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 03/25] fftools/ffmpeg: move init_output_stream_streamcopy() to ffmpeg_mux_init Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 04/25] fftools/ffmpeg_mux_init: remove a redundant check Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 05/25] fftools/ffmpeg: move a miplaced assignment Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 06/25] fftools/ffmpeg: move a check to a more appropriate place Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 07/25] fftools/ffmpeg: drop unnecessary indirection Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 08/25] fftools/ffmpeg_mux_init: consolidate input stream flagging code Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 09/25] fftools/ffmpeg: add a function adding a destination filter for InputStream Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 10/25] fftools/ffmpeg: stop setting InputStream fields from muxing/filtering code Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 11/25] fftools/ffmpeg: move opening decoders to a new file Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 12/25] fftools/ffmpeg_dec: reindent after previous commit Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 13/25] fftools/ffmpeg_dec: drop useless abort_codec_experimental() Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 14/25] fftools/ffmpeg: open decoders right after we know they are needed Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 15/25] fftools/ffmpeg: initialize no-filter streams earlier Anton Khirnov
2023-04-13 14:12 ` Anton Khirnov [this message]
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 17/25] fftools/ffmpeg: add muxer-input codec parameters to OutputStream Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 18/25] fftools/ffmpeg: move do_streamcopy() to ffmpeg_mux Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 19/25] fftools/ffmpeg_mux: use output stream parameters in of_streamcopy() Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 20/25] fftools/ffmpeg_mux: stop using filter_in_rescale_delta_last for streamcopy Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg_mux: make ts_copy_start private to muxing code Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 22/25] fftools/ffmpeg_mux: make streamcopy_started " Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 23/25] fftools/ffmpeg_mux: make copy_prior_start " Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 24/25] fftools/ffmpeg_mux: make copy_initial_nonkeyframes " Anton Khirnov
2023-04-13 14:12 ` [FFmpeg-devel] [PATCH 25/25] fftools/ffmpeg_enc: make data_size_enc private to encoding code Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230413141223.17245-16-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git