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 14/31] fftools/ffmpeg_dec: replace InputFile.format_nots with a decoder flag
Date: Wed, 24 Jan 2024 09:16:44 +0100
Message-ID: <20240124081702.4759-14-anton@khirnov.net> (raw)
In-Reply-To: <20240124081702.4759-1-anton@khirnov.net>

Reduces the need to access InputFile from decoding.

This is a step towards decoupling Decoder and InputStream.
---
 fftools/ffmpeg.h       | 5 ++---
 fftools/ffmpeg_dec.c   | 8 ++++----
 fftools/ffmpeg_demux.c | 5 ++---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8b7560b359..e87af70698 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -282,6 +282,8 @@ typedef struct FilterGraph {
 
 enum DecoderFlags {
     DECODER_FLAG_FIX_SUB_DURATION = (1 << 0),
+    // input timestamps are unreliable (guessed by demuxer)
+    DECODER_FLAG_TS_UNRELIABLE    = (1 << 1),
 };
 
 typedef struct Decoder {
@@ -362,9 +364,6 @@ typedef struct InputFile {
 
     int index;
 
-    // input format has no timestamps
-    int format_nots;
-
     AVFormatContext *ctx;
     int64_t input_ts_offset;
     int input_sync_ref;
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index e0d8e27098..f647db3611 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -216,7 +216,7 @@ static void audio_ts_process(DecoderPriv *dp, AVFrame *frame)
 static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame)
 {
     const DecoderPriv    *dp = dp_from_dec(ist->decoder);
-    const InputFile   *ifile = ist->file;
+    const int  ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
     int64_t codec_duration = 0;
 
     // XXX lavf currently makes up frame durations when they are not provided by
@@ -226,7 +226,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
     // durations, then this should be simplified.
 
     // prefer frame duration for containers with timestamps
-    if (frame->duration > 0 && (!ifile->format_nots || ist->framerate.num))
+    if (frame->duration > 0 && (!ts_unreliable || ist->framerate.num))
         return frame->duration;
 
     if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
@@ -238,7 +238,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
     }
 
     // prefer codec-layer duration for containers without timestamps
-    if (codec_duration > 0 && ifile->format_nots)
+    if (codec_duration > 0 && ts_unreliable)
         return codec_duration;
 
     // when timestamps are available, repeat last frame's actual duration
@@ -466,7 +466,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
     if (pkt && pkt->size == 0)
         return 0;
 
-    if (pkt && ifile->format_nots) {
+    if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
         pkt->pts = AV_NOPTS_VALUE;
         pkt->dts = AV_NOPTS_VALUE;
     }
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d804358d55..729d7e476b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -891,7 +891,8 @@ static int ist_use(InputStream *ist, int decoding_needed)
 
     if (decoding_needed && ds->sch_idx_dec < 0) {
         int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
-        int dec_flags = !!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION;
+        int dec_flags = (!!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION) |
+                        (!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE);
 
         ret = sch_add_dec(d->sch, decoder_thread, ist, d->loop && is_audio);
         if (ret < 0)
@@ -1698,8 +1699,6 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
     d->min_pts         = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
     d->max_pts         = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
 
-    f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS);
-
     d->readrate = o->readrate ? o->readrate : 0.0;
     if (d->readrate < 0.0f) {
         av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);
-- 
2.42.0

_______________________________________________
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:[~2024-01-24  8:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24  8:16 [FFmpeg-devel] [PATCH 01/31] fftools/ffmpeg_dec: split Decoder into a private and public part Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 02/31] fftools/ffmpeg_dec: export subtitle_header in Decoder Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 03/31] fftools/ffmpeg_filter: consolidate decoder/filter type checks Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 04/31] fftools/ffmpeg: make decoding AVCodecContext private to the decoder Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 05/31] fftools/ffmpeg_dec: add an AVClass to Decoder Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 06/31] fftools/ffmpeg_dec: pass decoder options as an argument to dec_open() Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 07/31] fftools/ffmpeg_dec: move decoding counters from InputStream to Decoder Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 08/31] fftools/ffmpeg_dec: drop useless and racy code Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 09/31] fftools/ffmpeg_dec: drop a useless log message Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 10/31] fftools/ffmpeg: move decoder existence check to a more appropriate place Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_dec: override video SAR with AVCodecParameters value Anton Khirnov
2024-03-24 22:09   ` Michael Niedermayer
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 12/31] fftools/ffmpeg_dec: stop accesing InputStream.fix_sub_duration Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 13/31] fftools/ffmpeg: refactor disabling decoder threading for attached pictures Anton Khirnov
2024-01-24  8:16 ` Anton Khirnov [this message]
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 15/31] fftools/ffmpeg: move hwaccel_retrieve_data() from ffmpeg_hw to ffmpeg_dec Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 16/31] fftools/ffmpeg_dec: pass hwaccel options to the decoder in a separate struct Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 17/31] fftools/ffmpeg_dec: move flags to DecoderOpts Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 18/31] fftools/ffmpeg_dec: pass forced/estimated framerate though DecoderOpts Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 19/31] fftools/ffmpeg_dec: move setting compute_edt to demuxer Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 20/31] fftools/ffmpeg_dec: pass input timebase through DecoderOpts Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 21/31] fftools/ffmpeg_dec: pass top_field_first " Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 22/31] fftools/ffmpeg_dec: pass decoder name " Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 23/31] fftools/ffmpeg_dec: eliminate InputStream use in hw_device_setup_for_decode() Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 24/31] fftools/ffmpeg_dec: pass AVCodec through DecoderOpts Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 25/31] fftools/ffmpeg_dec: pass AVCodecParameters " Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 26/31] fftools/ffmpeg_dec: remove unnecessary InputStream arguments Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 27/31] fftools/ffmpeg_dec: stop passing InputStream to dec_open() Anton Khirnov
2024-01-25  1:19   ` Michael Niedermayer
2024-01-28  9:40     ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 28/31] fftools/ffmpeg_dec: eliminate all remaining InputStream uses Anton Khirnov
2024-01-24  8:16 ` [FFmpeg-devel] [PATCH 29/31] fftools/ffmpeg: make InputStream.decoding_needed private to demuxer Anton Khirnov
2024-01-24  8:17 ` [FFmpeg-devel] [PATCH 30/31] fftools/ffmpeg: make InputStream.decoder_opts " Anton Khirnov
2024-01-24  8:17 ` [FFmpeg-devel] [PATCH 31/31] fftools/ffmpeg: cosmetics, vertically align Input{File, Stream} 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=20240124081702.4759-14-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