Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates
@ 2023-05-08  9:17 Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 02/22] fftools/ffmpeg: reindent after previous commit Anton Khirnov
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

Move them to a separate function called right after timestamp
discontinuity processing. This is now possible, since these values have
no interaction with decoding anymore.
---
This set goes on top of the repeat_pict/ticks_per_frame set, and can
also be obtained from branch 'ffmpeg_ist_dts' at
https://git.khirnov.net/libav
---
 fftools/ffmpeg.c | 105 +++++++++++++++++++++++++----------------------
 1 file changed, 55 insertions(+), 50 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index e2ada7a352..2bd3ce3f13 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1375,19 +1375,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
 
     AVPacket *avpkt = ist->pkt;
 
-    if (!ist->saw_first_ts) {
-        ist->first_dts =
-        ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
-        if (pkt && pkt->pts != AV_NOPTS_VALUE) {
-            ist->first_dts =
-            ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
-        }
-        ist->saw_first_ts = 1;
-    }
-
-    if (ist->next_dts == AV_NOPTS_VALUE)
-        ist->next_dts = ist->dts;
-
     if (pkt) {
         av_packet_unref(avpkt);
         ret = av_packet_ref(avpkt, pkt);
@@ -1395,10 +1382,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             return ret;
     }
 
-    if (pkt && pkt->dts != AV_NOPTS_VALUE) {
-        ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
-    }
-
     // while we have more to decode or while the decoder did output something on EOF
     while (ist->decoding_needed) {
         int64_t duration_pts = 0;
@@ -1477,39 +1460,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
         }
     }
 
-    if (pkt) {
-        ist->dts = ist->next_dts;
-        switch (par->codec_type) {
-        case AVMEDIA_TYPE_AUDIO:
-            av_assert1(pkt->duration >= 0);
-            if (par->sample_rate) {
-                ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
-                                  par->sample_rate;
-            } else {
-                ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-            }
-            break;
-        case AVMEDIA_TYPE_VIDEO:
-            if (ist->framerate.num) {
-                // TODO: Remove work-around for c99-to-c89 issue 7
-                AVRational time_base_q = AV_TIME_BASE_Q;
-                int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
-                ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
-            } else if (pkt->duration) {
-                ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-            } else if(ist->dec_ctx->framerate.num != 0) {
-                int fields = (ist->codec_desc &&
-                              (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
-                             ist->last_pkt_repeat_pict + 1 : 2;
-                AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
-                                                 (AVRational){ 2, 1 });
-
-                ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
-            }
-            break;
-        }
-    }
-
     if (!pkt && !ist->decoding_needed)
         eof_reached = 1;
 
@@ -1900,6 +1850,58 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
         ts_discontinuity_detect(ifile, ist, pkt);
 }
 
+static void ist_dts_update(InputStream *ist, AVPacket *pkt)
+{
+    const AVCodecParameters *par = ist->par;
+
+    if (!ist->saw_first_ts) {
+        ist->first_dts =
+        ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+        if (pkt->pts != AV_NOPTS_VALUE) {
+            ist->first_dts =
+            ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
+        }
+        ist->saw_first_ts = 1;
+    }
+
+    if (ist->next_dts == AV_NOPTS_VALUE)
+        ist->next_dts = ist->dts;
+
+    if (pkt->dts != AV_NOPTS_VALUE)
+        ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
+
+        ist->dts = ist->next_dts;
+        switch (par->codec_type) {
+        case AVMEDIA_TYPE_AUDIO:
+            av_assert1(pkt->duration >= 0);
+            if (par->sample_rate) {
+                ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
+                                  par->sample_rate;
+            } else {
+                ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+            }
+            break;
+        case AVMEDIA_TYPE_VIDEO:
+            if (ist->framerate.num) {
+                // TODO: Remove work-around for c99-to-c89 issue 7
+                AVRational time_base_q = AV_TIME_BASE_Q;
+                int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
+                ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
+            } else if (pkt->duration) {
+                ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+            } else if(ist->dec_ctx->framerate.num != 0) {
+                int fields = (ist->codec_desc &&
+                              (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
+                             ist->last_pkt_repeat_pict + 1 : 2;
+                AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
+                                                 (AVRational){ 2, 1 });
+
+                ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
+            }
+            break;
+        }
+}
+
 /*
  * Return
  * - 0 -- one packet was read and processed
@@ -1985,6 +1987,9 @@ static int process_input(int file_index)
     // detect and try to correct for timestamp discontinuities
     ts_discontinuity_process(ifile, ist, pkt);
 
+    // update estimated/predicted dts
+    ist_dts_update(ist, pkt);
+
     if (debug_ts) {
         av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
                ifile->index, pkt->stream_index,
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 02/22] fftools/ffmpeg: reindent after previous commit
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 03/22] fftools/ffmpeg: stop using decoder properties in ist_dts_update() Anton Khirnov
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg.c | 58 ++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2bd3ce3f13..817b643c48 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1870,36 +1870,36 @@ static void ist_dts_update(InputStream *ist, AVPacket *pkt)
     if (pkt->dts != AV_NOPTS_VALUE)
         ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
 
-        ist->dts = ist->next_dts;
-        switch (par->codec_type) {
-        case AVMEDIA_TYPE_AUDIO:
-            av_assert1(pkt->duration >= 0);
-            if (par->sample_rate) {
-                ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
-                                  par->sample_rate;
-            } else {
-                ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-            }
-            break;
-        case AVMEDIA_TYPE_VIDEO:
-            if (ist->framerate.num) {
-                // TODO: Remove work-around for c99-to-c89 issue 7
-                AVRational time_base_q = AV_TIME_BASE_Q;
-                int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
-                ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
-            } else if (pkt->duration) {
-                ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-            } else if(ist->dec_ctx->framerate.num != 0) {
-                int fields = (ist->codec_desc &&
-                              (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
-                             ist->last_pkt_repeat_pict + 1 : 2;
-                AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
-                                                 (AVRational){ 2, 1 });
-
-                ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
-            }
-            break;
+    ist->dts = ist->next_dts;
+    switch (par->codec_type) {
+    case AVMEDIA_TYPE_AUDIO:
+        av_assert1(pkt->duration >= 0);
+        if (par->sample_rate) {
+            ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
+                              par->sample_rate;
+        } else {
+            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
         }
+        break;
+    case AVMEDIA_TYPE_VIDEO:
+        if (ist->framerate.num) {
+            // TODO: Remove work-around for c99-to-c89 issue 7
+            AVRational time_base_q = AV_TIME_BASE_Q;
+            int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
+            ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
+        } else if (pkt->duration) {
+            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+        } else if(ist->dec_ctx->framerate.num != 0) {
+            int fields = (ist->codec_desc &&
+                          (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
+                         ist->last_pkt_repeat_pict + 1 : 2;
+            AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
+                                             (AVRational){ 2, 1 });
+
+            ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
+        }
+        break;
+    }
 }
 
 /*
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 03/22] fftools/ffmpeg: stop using decoder properties in ist_dts_update()
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 02/22] fftools/ffmpeg: reindent after previous commit Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 04/22] fftools/ffmpeg_demux: move preparing DemuxMsg to separate function Anton Khirnov
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

This code runs post-demuxing and is not synchronized with the decoder
output (which may be delayed with respect to its input by arbitrary and
unknowable amounts), so accessing any decoder properties is incorrect.
---
 fftools/ffmpeg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 817b643c48..ca6ff780c3 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1856,7 +1856,7 @@ static void ist_dts_update(InputStream *ist, AVPacket *pkt)
 
     if (!ist->saw_first_ts) {
         ist->first_dts =
-        ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+        ist->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
         if (pkt->pts != AV_NOPTS_VALUE) {
             ist->first_dts =
             ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
@@ -1889,11 +1889,11 @@ static void ist_dts_update(InputStream *ist, AVPacket *pkt)
             ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
         } else if (pkt->duration) {
             ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-        } else if(ist->dec_ctx->framerate.num != 0) {
+        } else if (ist->par->framerate.num != 0) {
             int fields = (ist->codec_desc &&
                           (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
                          ist->last_pkt_repeat_pict + 1 : 2;
-            AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
+            AVRational field_rate = av_mul_q(ist->par->framerate,
                                              (AVRational){ 2, 1 });
 
             ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 04/22] fftools/ffmpeg_demux: move preparing DemuxMsg to separate function
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 02/22] fftools/ffmpeg: reindent after previous commit Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 03/22] fftools/ffmpeg: stop using decoder properties in ist_dts_update() Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 05/22] fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed Anton Khirnov
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

Will be useful in following commits, which will move more code into this
function.
---
 fftools/ffmpeg_demux.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1872e87d57..b16a20a87b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -257,6 +257,26 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
     SHOW_TS_DEBUG("demuxer+tsfixup");
 }
 
+// process an input packet into a message to send to the consumer thread
+// src is always cleared by this function
+static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
+{
+    AVPacket *pkt;
+
+    pkt = av_packet_alloc();
+    if (!pkt) {
+        av_packet_unref(src);
+        return AVERROR(ENOMEM);
+    }
+    av_packet_move_ref(pkt, src);
+
+    ts_fixup(d, pkt, &msg->repeat_pict);
+
+    msg->pkt = pkt;
+
+    return 0;
+}
+
 static void thread_set_name(InputFile *f)
 {
     char name[16];
@@ -336,15 +356,10 @@ static void *input_thread(void *arg)
             }
         }
 
-        ts_fixup(d, pkt, &msg.repeat_pict);
-
-        msg.pkt = av_packet_alloc();
-        if (!msg.pkt) {
-            av_packet_unref(pkt);
-            ret = AVERROR(ENOMEM);
+        ret = input_packet_process(d, &msg, pkt);
+        if (ret < 0)
             break;
-        }
-        av_packet_move_ref(msg.pkt, pkt);
+
         ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
         if (flags && ret == AVERROR(EAGAIN)) {
             flags = 0;
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 05/22] fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (2 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 04/22] fftools/ffmpeg_demux: move preparing DemuxMsg to separate function Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 06/22] fftools/ffmpeg: move post-demux packet processing to ffmpeg_demux Anton Khirnov
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

This way computing it and using it for streamcopy does not need to
happen in sync. Will be useful in following commits, where updating
InputStream.dts will be moved to the demuxing thread.
---
 fftools/ffmpeg.c       | 22 ++++++++++++++++++++--
 fftools/ffmpeg.h       |  7 +++++++
 fftools/ffmpeg_demux.c |  1 +
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ca6ff780c3..2a39d767cd 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1368,6 +1368,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
 {
     InputFile *f = input_files[ist->file_index];
     const AVCodecParameters *par = ist->par;
+    int64_t dts_est = AV_NOPTS_VALUE;
     int ret = 0;
     int repeating = 0;
     int eof_reached = 0;
@@ -1463,6 +1464,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
     if (!pkt && !ist->decoding_needed)
         eof_reached = 1;
 
+    if (pkt && pkt->opaque_ref) {
+        DemuxPktData *pd = (DemuxPktData*)pkt->opaque_ref->data;
+        dts_est = pd->dts_est;
+    }
+
     duration_exceeded = 0;
     if (f->recording_time != INT64_MAX) {
         int64_t start_time = 0;
@@ -1470,7 +1476,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
             start_time += start_at_zero ? 0 : f->start_time_effective;
         }
-        if (ist->dts >= f->recording_time + start_time)
+        if (dts_est >= f->recording_time + start_time)
             duration_exceeded = 1;
     }
 
@@ -1484,7 +1490,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             continue;
         }
 
-        of_streamcopy(ost, pkt, ist->dts);
+        of_streamcopy(ost, pkt, dts_est);
     }
 
     return !eof_reached;
@@ -1900,6 +1906,18 @@ static void ist_dts_update(InputStream *ist, AVPacket *pkt)
         }
         break;
     }
+
+    av_assert0(!pkt->opaque_ref);
+    if (ist->streamcopy_needed) {
+        DemuxPktData *pd;
+
+        pkt->opaque_ref = av_buffer_allocz(sizeof(*pd));
+        if (!pkt->opaque_ref)
+            report_and_exit(AVERROR(ENOMEM));
+        pd = (DemuxPktData*)pkt->opaque_ref->data;
+
+        pd->dts_est = ist->dts;
+    }
 }
 
 /*
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b0319f0ed0..8a5d5b13c8 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -95,6 +95,12 @@ typedef struct {
 } AudioChannelMap;
 #endif
 
+typedef struct DemuxPktData {
+    // estimated dts in AV_TIME_BASE_Q,
+    // to be used when real dts is missing
+    int64_t dts_est;
+} DemuxPktData;
+
 typedef struct OptionsContext {
     OptionGroup *g;
 
@@ -337,6 +343,7 @@ typedef struct InputStream {
     int discard;             /* true if stream data should be discarded */
     int user_set_discard;
     int decoding_needed;     /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
+    int streamcopy_needed;
 #define DECODING_FOR_OST    1
 #define DECODING_FOR_FILTER 2
     // should attach FrameData as opaque_ref after decoding
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index b16a20a87b..eda838f84c 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -584,6 +584,7 @@ static void ist_use(InputStream *ist, int decoding_needed)
     ist->discard          = 0;
     ist->st->discard      = ist->user_set_discard;
     ist->decoding_needed |= decoding_needed;
+    ist->streamcopy_needed |= !decoding_needed;
 
     if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) {
         int ret = dec_open(ist);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 06/22] fftools/ffmpeg: move post-demux packet processing to ffmpeg_demux
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (3 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 05/22] fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

That is a more appropriate place for this code and will allow hiding
more of InputStream.

The value of repeat_pict extracted from libavformat internal parser no
longer needs to be trasmitted outside of the demuxing thread.

Move readrate handling to the demuxer thread. This has to be done in the
same commit, since it reads InputStream.dts,nb_packets, which are now
set in the demuxer thread.
---
 fftools/ffmpeg.c       | 188 -----------------------------
 fftools/ffmpeg.h       |   6 -
 fftools/ffmpeg_demux.c | 266 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 233 insertions(+), 227 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2a39d767cd..ee92587798 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1772,154 +1772,6 @@ static void decode_flush(InputFile *ifile)
     }
 }
 
-static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
-                                    AVPacket *pkt)
-{
-    const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
-    int disable_discontinuity_correction = copy_ts;
-    int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
-                                       AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
-
-    if (copy_ts && ist->next_dts != AV_NOPTS_VALUE &&
-        fmt_is_discont && ist->st->pts_wrap_bits < 60) {
-        int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
-                                            pkt->time_base, AV_TIME_BASE_Q,
-                                            AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
-        if (FFABS(wrap_dts - ist->next_dts) < FFABS(pkt_dts - ist->next_dts)/10)
-            disable_discontinuity_correction = 0;
-    }
-
-    if (ist->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
-        int64_t delta = pkt_dts - ist->next_dts;
-        if (fmt_is_discont) {
-            if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
-                pkt_dts + AV_TIME_BASE/10 < ist->dts) {
-                ifile->ts_offset_discont -= delta;
-                av_log(NULL, AV_LOG_WARNING,
-                       "timestamp discontinuity for stream #%d:%d "
-                       "(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
-                       ist->file_index, ist->st->index, ist->st->id,
-                       av_get_media_type_string(ist->par->codec_type),
-                       delta, ifile->ts_offset_discont);
-                pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
-                if (pkt->pts != AV_NOPTS_VALUE)
-                    pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
-            }
-        } else {
-            if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
-                av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt->dts, ist->next_dts, pkt->stream_index);
-                pkt->dts = AV_NOPTS_VALUE;
-            }
-            if (pkt->pts != AV_NOPTS_VALUE){
-                int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
-                delta = pkt_pts - ist->next_dts;
-                if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
-                    av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt->pts, ist->next_dts, pkt->stream_index);
-                    pkt->pts = AV_NOPTS_VALUE;
-                }
-            }
-        }
-    } else if (ist->next_dts == AV_NOPTS_VALUE && !copy_ts &&
-               fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
-        int64_t delta = pkt_dts - ifile->last_ts;
-        if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
-            ifile->ts_offset_discont -= delta;
-            av_log(NULL, AV_LOG_DEBUG,
-                   "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
-                   delta, ifile->ts_offset_discont);
-            pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
-            if (pkt->pts != AV_NOPTS_VALUE)
-                pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
-        }
-    }
-
-    ifile->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
-}
-
-static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
-                                     AVPacket *pkt)
-{
-    int64_t offset = av_rescale_q(ifile->ts_offset_discont, AV_TIME_BASE_Q,
-                                  pkt->time_base);
-
-    // apply previously-detected timestamp-discontinuity offset
-    // (to all streams, not just audio/video)
-    if (pkt->dts != AV_NOPTS_VALUE)
-        pkt->dts += offset;
-    if (pkt->pts != AV_NOPTS_VALUE)
-        pkt->pts += offset;
-
-    // detect timestamp discontinuities for audio/video
-    if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
-         ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
-        pkt->dts != AV_NOPTS_VALUE)
-        ts_discontinuity_detect(ifile, ist, pkt);
-}
-
-static void ist_dts_update(InputStream *ist, AVPacket *pkt)
-{
-    const AVCodecParameters *par = ist->par;
-
-    if (!ist->saw_first_ts) {
-        ist->first_dts =
-        ist->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
-        if (pkt->pts != AV_NOPTS_VALUE) {
-            ist->first_dts =
-            ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
-        }
-        ist->saw_first_ts = 1;
-    }
-
-    if (ist->next_dts == AV_NOPTS_VALUE)
-        ist->next_dts = ist->dts;
-
-    if (pkt->dts != AV_NOPTS_VALUE)
-        ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
-
-    ist->dts = ist->next_dts;
-    switch (par->codec_type) {
-    case AVMEDIA_TYPE_AUDIO:
-        av_assert1(pkt->duration >= 0);
-        if (par->sample_rate) {
-            ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
-                              par->sample_rate;
-        } else {
-            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-        }
-        break;
-    case AVMEDIA_TYPE_VIDEO:
-        if (ist->framerate.num) {
-            // TODO: Remove work-around for c99-to-c89 issue 7
-            AVRational time_base_q = AV_TIME_BASE_Q;
-            int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
-            ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
-        } else if (pkt->duration) {
-            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
-        } else if (ist->par->framerate.num != 0) {
-            int fields = (ist->codec_desc &&
-                          (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
-                         ist->last_pkt_repeat_pict + 1 : 2;
-            AVRational field_rate = av_mul_q(ist->par->framerate,
-                                             (AVRational){ 2, 1 });
-
-            ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
-        }
-        break;
-    }
-
-    av_assert0(!pkt->opaque_ref);
-    if (ist->streamcopy_needed) {
-        DemuxPktData *pd;
-
-        pkt->opaque_ref = av_buffer_allocz(sizeof(*pd));
-        if (!pkt->opaque_ref)
-            report_and_exit(AVERROR(ENOMEM));
-        pd = (DemuxPktData*)pkt->opaque_ref->data;
-
-        pd->dts_est = ist->dts;
-    }
-}
-
 /*
  * Return
  * - 0 -- one packet was read and processed
@@ -1979,46 +1831,6 @@ static int process_input(int file_index)
 
     ist = ifile->streams[pkt->stream_index];
 
-    ist->data_size += pkt->size;
-    ist->nb_packets++;
-
-    /* add the stream-global side data to the first packet */
-    if (ist->nb_packets == 1) {
-        for (i = 0; i < ist->st->nb_side_data; i++) {
-            AVPacketSideData *src_sd = &ist->st->side_data[i];
-            uint8_t *dst_data;
-
-            if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX)
-                continue;
-
-            if (av_packet_get_side_data(pkt, src_sd->type, NULL))
-                continue;
-
-            dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size);
-            if (!dst_data)
-                report_and_exit(AVERROR(ENOMEM));
-
-            memcpy(dst_data, src_sd->data, src_sd->size);
-        }
-    }
-
-    // detect and try to correct for timestamp discontinuities
-    ts_discontinuity_process(ifile, ist, pkt);
-
-    // update estimated/predicted dts
-    ist_dts_update(ist, pkt);
-
-    if (debug_ts) {
-        av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
-               ifile->index, pkt->stream_index,
-               av_get_media_type_string(ist->par->codec_type),
-               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base),
-               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base),
-               av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base),
-               av_ts2str(input_files[ist->file_index]->ts_offset),
-               av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q));
-    }
-
     sub2video_heartbeat(ist, pkt->pts);
 
     process_input_packet(ist, pkt, 0);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8a5d5b13c8..1900f3deb6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -380,12 +380,6 @@ typedef struct InputStream {
 
     int           wrap_correction_done;
 
-    // the value of AVCodecParserContext.repeat_pict from the AVStream parser
-    // for the last packet returned from ifile_get_packet()
-    // -1 if unknown
-    // FIXME: this is a hack, the avstream parser should not be used
-    int last_pkt_repeat_pict;
-
     int64_t filter_in_rescale_delta_last;
 
     // when forcing constant input framerate through -r,
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index eda838f84c..9082de6a80 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -92,9 +92,6 @@ typedef struct Demuxer {
 typedef struct DemuxMsg {
     AVPacket *pkt;
     int looping;
-
-    // repeat_pict from the demuxer-internal parser
-    int repeat_pict;
 } DemuxMsg;
 
 static DemuxStream *ds_from_ist(InputStream *ist)
@@ -188,13 +185,167 @@ static int seek_to_start(Demuxer *d)
     return ret;
 }
 
-static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
+static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
+                                    AVPacket *pkt)
+{
+    const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
+    int disable_discontinuity_correction = copy_ts;
+    int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
+                                       AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
+
+    if (copy_ts && ist->next_dts != AV_NOPTS_VALUE &&
+        fmt_is_discont && ist->st->pts_wrap_bits < 60) {
+        int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
+                                            pkt->time_base, AV_TIME_BASE_Q,
+                                            AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+        if (FFABS(wrap_dts - ist->next_dts) < FFABS(pkt_dts - ist->next_dts)/10)
+            disable_discontinuity_correction = 0;
+    }
+
+    if (ist->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
+        int64_t delta = pkt_dts - ist->next_dts;
+        if (fmt_is_discont) {
+            if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
+                pkt_dts + AV_TIME_BASE/10 < ist->dts) {
+                ifile->ts_offset_discont -= delta;
+                av_log(NULL, AV_LOG_WARNING,
+                       "timestamp discontinuity for stream #%d:%d "
+                       "(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
+                       ist->file_index, ist->st->index, ist->st->id,
+                       av_get_media_type_string(ist->par->codec_type),
+                       delta, ifile->ts_offset_discont);
+                pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
+                if (pkt->pts != AV_NOPTS_VALUE)
+                    pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
+            }
+        } else {
+            if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
+                av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt->dts, ist->next_dts, pkt->stream_index);
+                pkt->dts = AV_NOPTS_VALUE;
+            }
+            if (pkt->pts != AV_NOPTS_VALUE){
+                int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
+                delta = pkt_pts - ist->next_dts;
+                if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
+                    av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt->pts, ist->next_dts, pkt->stream_index);
+                    pkt->pts = AV_NOPTS_VALUE;
+                }
+            }
+        }
+    } else if (ist->next_dts == AV_NOPTS_VALUE && !copy_ts &&
+               fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
+        int64_t delta = pkt_dts - ifile->last_ts;
+        if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
+            ifile->ts_offset_discont -= delta;
+            av_log(NULL, AV_LOG_DEBUG,
+                   "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
+                   delta, ifile->ts_offset_discont);
+            pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
+            if (pkt->pts != AV_NOPTS_VALUE)
+                pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
+        }
+    }
+
+    ifile->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
+}
+
+static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
+                                     AVPacket *pkt)
+{
+    int64_t offset = av_rescale_q(ifile->ts_offset_discont, AV_TIME_BASE_Q,
+                                  pkt->time_base);
+
+    // apply previously-detected timestamp-discontinuity offset
+    // (to all streams, not just audio/video)
+    if (pkt->dts != AV_NOPTS_VALUE)
+        pkt->dts += offset;
+    if (pkt->pts != AV_NOPTS_VALUE)
+        pkt->pts += offset;
+
+    // detect timestamp discontinuities for audio/video
+    if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
+         ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
+        pkt->dts != AV_NOPTS_VALUE)
+        ts_discontinuity_detect(ifile, ist, pkt);
+}
+
+static int ist_dts_update(InputStream *ist, AVPacket *pkt)
+{
+    const AVCodecParameters *par = ist->par;
+
+    if (!ist->saw_first_ts) {
+        ist->first_dts =
+        ist->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+        if (pkt->pts != AV_NOPTS_VALUE) {
+            ist->first_dts =
+            ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
+        }
+        ist->saw_first_ts = 1;
+    }
+
+    if (ist->next_dts == AV_NOPTS_VALUE)
+        ist->next_dts = ist->dts;
+
+    if (pkt->dts != AV_NOPTS_VALUE)
+        ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
+
+    ist->dts = ist->next_dts;
+    switch (par->codec_type) {
+    case AVMEDIA_TYPE_AUDIO:
+        av_assert1(pkt->duration >= 0);
+        if (par->sample_rate) {
+            ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
+                              par->sample_rate;
+        } else {
+            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+        }
+        break;
+    case AVMEDIA_TYPE_VIDEO:
+        if (ist->framerate.num) {
+            // TODO: Remove work-around for c99-to-c89 issue 7
+            AVRational time_base_q = AV_TIME_BASE_Q;
+            int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
+            ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
+        } else if (pkt->duration) {
+            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+        } else if (ist->par->framerate.num != 0) {
+            AVRational field_rate = av_mul_q(ist->par->framerate,
+                                             (AVRational){ 2, 1 });
+            int fields = 2;
+
+            if (ist->codec_desc                                 &&
+                (ist->codec_desc->props & AV_CODEC_PROP_FIELDS) &&
+                av_stream_get_parser(ist->st))
+                fields = 1 + av_stream_get_parser(ist->st)->repeat_pict;
+
+            ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
+        }
+        break;
+    }
+
+    av_assert0(!pkt->opaque_ref);
+    if (ist->streamcopy_needed) {
+        DemuxPktData *pd;
+
+        pkt->opaque_ref = av_buffer_allocz(sizeof(*pd));
+        if (!pkt->opaque_ref)
+            return AVERROR(ENOMEM);
+        pd = (DemuxPktData*)pkt->opaque_ref->data;
+
+        pd->dts_est = ist->dts;
+    }
+
+    return 0;
+}
+
+static int ts_fixup(Demuxer *d, AVPacket *pkt)
 {
     InputFile *ifile = &d->f;
     InputStream *ist = ifile->streams[pkt->stream_index];
     DemuxStream  *ds = ds_from_ist(ist);
     const int64_t start_time = ifile->start_time_effective;
     int64_t duration;
+    int ret;
 
     pkt->time_base = ist->st->time_base;
 
@@ -249,19 +400,27 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
     if (pkt->dts != AV_NOPTS_VALUE)
         pkt->dts += duration;
 
-    *repeat_pict = -1;
-    if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
-        av_stream_get_parser(ist->st))
-        *repeat_pict = av_stream_get_parser(ist->st)->repeat_pict;
-
     SHOW_TS_DEBUG("demuxer+tsfixup");
+
+    // detect and try to correct for timestamp discontinuities
+    ts_discontinuity_process(ifile, ist, pkt);
+
+    // update estimated/predicted dts
+    ret = ist_dts_update(ist, pkt);
+    if (ret < 0)
+        return ret;
+
+    return 0;
 }
 
 // process an input packet into a message to send to the consumer thread
 // src is always cleared by this function
 static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
 {
+    InputFile     *f = &d->f;
+    InputStream *ist = f->streams[src->stream_index];
     AVPacket *pkt;
+    int ret = 0;
 
     pkt = av_packet_alloc();
     if (!pkt) {
@@ -270,13 +429,74 @@ static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
     }
     av_packet_move_ref(pkt, src);
 
-    ts_fixup(d, pkt, &msg->repeat_pict);
+    ret = ts_fixup(d, pkt);
+    if (ret < 0)
+        goto fail;
+
+    ist->data_size += pkt->size;
+    ist->nb_packets++;
+
+    /* add the stream-global side data to the first packet */
+    if (ist->nb_packets == 1) {
+        for (int i = 0; i < ist->st->nb_side_data; i++) {
+            AVPacketSideData *src_sd = &ist->st->side_data[i];
+            uint8_t *dst_data;
+
+            if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX)
+                continue;
+
+            if (av_packet_get_side_data(pkt, src_sd->type, NULL))
+                continue;
+
+            dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size);
+            if (!dst_data) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
+
+            memcpy(dst_data, src_sd->data, src_sd->size);
+        }
+    }
+
+    if (debug_ts) {
+        av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s off:%s off_time:%s\n",
+               f->index, pkt->stream_index,
+               av_get_media_type_string(ist->par->codec_type),
+               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base),
+               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base),
+               av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base),
+               av_ts2str(input_files[ist->file_index]->ts_offset),
+               av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q));
+    }
 
     msg->pkt = pkt;
+    pkt      = NULL;
+
+fail:
+    av_packet_free(&pkt);
 
     return 0;
 }
 
+static void readrate_sleep(Demuxer *d)
+{
+    InputFile *f = &d->f;
+        int64_t file_start = copy_ts * (
+                              (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
+                              (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
+                             );
+        int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
+        for (int i = 0; i < f->nb_streams; i++) {
+            InputStream *ist = f->streams[i];
+            int64_t stream_ts_offset, pts, now;
+            stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
+            pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
+            now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
+            if (pts - burst_until > now)
+                av_usleep(pts - burst_until - now);
+        }
+}
+
 static void thread_set_name(InputFile *f)
 {
     char name[16];
@@ -360,6 +580,9 @@ static void *input_thread(void *arg)
         if (ret < 0)
             break;
 
+        if (f->readrate)
+            readrate_sleep(d);
+
         ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
         if (flags && ret == AVERROR(EAGAIN)) {
             flags = 0;
@@ -456,7 +679,6 @@ fail:
 int ifile_get_packet(InputFile *f, AVPacket **pkt)
 {
     Demuxer *d = demuxer_from_ifile(f);
-    InputStream *ist;
     DemuxMsg msg;
     int ret;
 
@@ -466,25 +688,6 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
             return ret;
     }
 
-    if (f->readrate) {
-        int i;
-        int64_t file_start = copy_ts * (
-                              (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
-                              (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
-                             );
-        int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
-        for (i = 0; i < f->nb_streams; i++) {
-            InputStream *ist = f->streams[i];
-            int64_t stream_ts_offset, pts, now;
-            if (!ist->nb_packets) continue;
-            stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
-            pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
-            now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
-            if (pts - burst_until > now)
-                return AVERROR(EAGAIN);
-        }
-    }
-
     ret = av_thread_message_queue_recv(d->in_thread_queue, &msg,
                                        d->non_blocking ?
                                        AV_THREAD_MESSAGE_NONBLOCK : 0);
@@ -493,9 +696,6 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
     if (msg.looping)
         return 1;
 
-    ist = f->streams[msg.pkt->stream_index];
-    ist->last_pkt_repeat_pict = msg.repeat_pict;
-
     *pkt = msg.pkt;
     return 0;
 }
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_demux: reindent after previous commit
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (4 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 06/22] fftools/ffmpeg: move post-demux packet processing to ffmpeg_demux Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg: drop unused decode_video() parameter Anton Khirnov
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_demux.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 9082de6a80..d49bb8317c 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -481,20 +481,20 @@ fail:
 static void readrate_sleep(Demuxer *d)
 {
     InputFile *f = &d->f;
-        int64_t file_start = copy_ts * (
-                              (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
-                              (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
-                             );
-        int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
-        for (int i = 0; i < f->nb_streams; i++) {
-            InputStream *ist = f->streams[i];
-            int64_t stream_ts_offset, pts, now;
-            stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
-            pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
-            now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
-            if (pts - burst_until > now)
-                av_usleep(pts - burst_until - now);
-        }
+    int64_t file_start = copy_ts * (
+                          (f->start_time_effective != AV_NOPTS_VALUE ? f->start_time_effective * !start_at_zero : 0) +
+                          (f->start_time != AV_NOPTS_VALUE ? f->start_time : 0)
+                         );
+    int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
+    for (int i = 0; i < f->nb_streams; i++) {
+        InputStream *ist = f->streams[i];
+        int64_t stream_ts_offset, pts, now;
+        stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
+        pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
+        now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
+        if (pts - burst_until > now)
+            av_usleep(pts - burst_until - now);
+    }
 }
 
 static void thread_set_name(InputFile *f)
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg: drop unused decode_video() parameter
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (5 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_demux: move InputStream.{nb_packets, data_size} to private data Anton Khirnov
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ee92587798..9cf94f2a22 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1026,7 +1026,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
 }
 
 static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output,
-                        int64_t *duration_pts, int eof, int *decode_failed)
+                        int eof, int *decode_failed)
 {
     AVFrame *decoded_frame = ist->decoded_frame;
     int ret = 0, err = 0;
@@ -1091,7 +1091,6 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output,
     }
 
     best_effort_timestamp= decoded_frame->best_effort_timestamp;
-    *duration_pts = decoded_frame->duration;
 
     if (ist->framerate.num)
         best_effort_timestamp = ist->cfr_next_pts++;
@@ -1385,7 +1384,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
 
     // while we have more to decode or while the decoder did output something on EOF
     while (ist->decoding_needed) {
-        int64_t duration_pts = 0;
         int got_output = 0;
         int decode_failed = 0;
 
@@ -1396,7 +1394,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             av_packet_unref(avpkt);
             break;
         case AVMEDIA_TYPE_VIDEO:
-            ret = decode_video    (ist, repeating ? NULL : avpkt, &got_output, &duration_pts, !pkt,
+            ret = decode_video    (ist, repeating ? NULL : avpkt, &got_output, !pkt,
                                    &decode_failed);
 
             av_packet_unref(avpkt);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_demux: move InputStream.{nb_packets, data_size} to private data
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (6 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg: drop unused decode_video() parameter Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_demux: move InputStream.[saw_]first_d?ts " Anton Khirnov
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

They are no longer used outside of ffmpeg_demux.
---
 fftools/ffmpeg.h       |  4 ----
 fftools/ffmpeg_demux.c | 19 +++++++++++++------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 1900f3deb6..8e96f27d5d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -436,10 +436,6 @@ typedef struct InputStream {
     enum AVPixelFormat hwaccel_pix_fmt;
 
     /* stats */
-    // combined size of all the packets read
-    uint64_t data_size;
-    /* number of packets successfully read for this stream */
-    uint64_t nb_packets;
     // number of frames/samples retrieved from the decoder
     uint64_t frames_decoded;
     uint64_t samples_decoded;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d49bb8317c..3c0d67fe00 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -62,6 +62,11 @@ typedef struct DemuxStream {
 
     int64_t min_pts; /* pts with the smallest value in a current stream */
     int64_t max_pts; /* pts with the higher value in a current stream */
+
+    /* number of packets successfully read for this stream */
+    uint64_t nb_packets;
+    // combined size of all the packets read
+    uint64_t data_size;
 } DemuxStream;
 
 typedef struct Demuxer {
@@ -419,6 +424,7 @@ static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
 {
     InputFile     *f = &d->f;
     InputStream *ist = f->streams[src->stream_index];
+    DemuxStream  *ds = ds_from_ist(ist);
     AVPacket *pkt;
     int ret = 0;
 
@@ -433,11 +439,11 @@ static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
     if (ret < 0)
         goto fail;
 
-    ist->data_size += pkt->size;
-    ist->nb_packets++;
+    ds->data_size += pkt->size;
+    ds->nb_packets++;
 
     /* add the stream-global side data to the first packet */
-    if (ist->nb_packets == 1) {
+    if (ds->nb_packets == 1) {
         for (int i = 0; i < ist->st->nb_side_data; i++) {
             AVPacketSideData *src_sd = &ist->st->side_data[i];
             uint8_t *dst_data;
@@ -710,15 +716,16 @@ static void demux_final_stats(Demuxer *d)
 
     for (int j = 0; j < f->nb_streams; j++) {
         InputStream *ist = f->streams[j];
+        DemuxStream  *ds = ds_from_ist(ist);
         enum AVMediaType type = ist->par->codec_type;
 
-        total_size    += ist->data_size;
-        total_packets += ist->nb_packets;
+        total_size    += ds->data_size;
+        total_packets += ds->nb_packets;
 
         av_log(f, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
                f->index, j, av_get_media_type_string(type));
         av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
-               ist->nb_packets, ist->data_size);
+               ds->nb_packets, ds->data_size);
 
         if (ist->decoding_needed) {
             av_log(f, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_demux: move InputStream.[saw_]first_d?ts to private data
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (7 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_demux: move InputStream.{nb_packets, data_size} to private data Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_demux: move InputStream.[next_]dts " Anton Khirnov
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

They are no longer used outside of ffmpeg_demux.
---
 fftools/ffmpeg.h       |  2 --
 fftools/ffmpeg_demux.c | 22 ++++++++++++++--------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8e96f27d5d..e4a697af54 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -367,7 +367,6 @@ typedef struct InputStream {
     /* predicted dts of the next packet read for this stream or (when there are
      * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
     int64_t       next_dts;
-    int64_t first_dts;       ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
     int64_t       dts;       ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
 
     // pts/estimated duration of the last decoded frame
@@ -388,7 +387,6 @@ typedef struct InputStream {
 
     int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
 
-    int saw_first_ts;
     AVDictionary *decoder_opts;
     AVRational framerate;               /* framerate forced with -r */
     int top_field_first;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 3c0d67fe00..0b27d54870 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -60,6 +60,10 @@ typedef struct DemuxStream {
 
     double ts_scale;
 
+    int saw_first_ts;
+    ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
+    int64_t first_dts;
+
     int64_t min_pts; /* pts with the smallest value in a current stream */
     int64_t max_pts; /* pts with the higher value in a current stream */
 
@@ -274,18 +278,19 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
         ts_discontinuity_detect(ifile, ist, pkt);
 }
 
-static int ist_dts_update(InputStream *ist, AVPacket *pkt)
+static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
 {
+    InputStream *ist = &ds->ist;
     const AVCodecParameters *par = ist->par;
 
-    if (!ist->saw_first_ts) {
-        ist->first_dts =
+    if (!ds->saw_first_ts) {
+        ds->first_dts =
         ist->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
         if (pkt->pts != AV_NOPTS_VALUE) {
-            ist->first_dts =
+            ds->first_dts =
             ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
         }
-        ist->saw_first_ts = 1;
+        ds->saw_first_ts = 1;
     }
 
     if (ist->next_dts == AV_NOPTS_VALUE)
@@ -411,7 +416,7 @@ static int ts_fixup(Demuxer *d, AVPacket *pkt)
     ts_discontinuity_process(ifile, ist, pkt);
 
     // update estimated/predicted dts
-    ret = ist_dts_update(ist, pkt);
+    ret = ist_dts_update(ds, pkt);
     if (ret < 0)
         return ret;
 
@@ -494,8 +499,9 @@ static void readrate_sleep(Demuxer *d)
     int64_t burst_until = AV_TIME_BASE * d->readrate_initial_burst;
     for (int i = 0; i < f->nb_streams; i++) {
         InputStream *ist = f->streams[i];
+        DemuxStream  *ds = ds_from_ist(ist);
         int64_t stream_ts_offset, pts, now;
-        stream_ts_offset = FFMAX(ist->first_dts != AV_NOPTS_VALUE ? ist->first_dts : 0, file_start);
+        stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
         pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
         now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
         if (pts - burst_until > now)
@@ -976,7 +982,7 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
         ist->discard = 1;
         st->discard  = AVDISCARD_ALL;
         ist->nb_samples = 0;
-        ist->first_dts = AV_NOPTS_VALUE;
+        ds->first_dts   = AV_NOPTS_VALUE;
         ist->next_dts  = AV_NOPTS_VALUE;
 
         ds->min_pts = INT64_MAX;
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_demux: move InputStream.[next_]dts to private data
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (8 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_demux: move InputStream.[saw_]first_d?ts " Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_demux: move InputStream.wrap_correction_done " Anton Khirnov
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

They are no longer used outside of ffmpeg_demux.
---
 fftools/ffmpeg.h       |  4 ---
 fftools/ffmpeg_demux.c | 59 +++++++++++++++++++++++++-----------------
 2 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index e4a697af54..b8c0e7db84 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -364,10 +364,6 @@ typedef struct InputStream {
     AVRational framerate_guessed;
 
     int64_t       start;     /* time when read started */
-    /* predicted dts of the next packet read for this stream or (when there are
-     * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
-    int64_t       next_dts;
-    int64_t       dts;       ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
 
     // pts/estimated duration of the last decoded frame
     // * in decoder timebase for video,
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 0b27d54870..7e34292b3a 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -64,6 +64,12 @@ typedef struct DemuxStream {
     ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
     int64_t first_dts;
 
+    /* predicted dts of the next packet read for this stream or (when there are
+     * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
+    int64_t       next_dts;
+    ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
+    int64_t       dts;
+
     int64_t min_pts; /* pts with the smallest value in a current stream */
     int64_t max_pts; /* pts with the higher value in a current stream */
 
@@ -197,25 +203,26 @@ static int seek_to_start(Demuxer *d)
 static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
                                     AVPacket *pkt)
 {
+    DemuxStream *ds = ds_from_ist(ist);
     const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
     int disable_discontinuity_correction = copy_ts;
     int64_t pkt_dts = av_rescale_q_rnd(pkt->dts, pkt->time_base, AV_TIME_BASE_Q,
                                        AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
 
-    if (copy_ts && ist->next_dts != AV_NOPTS_VALUE &&
+    if (copy_ts && ds->next_dts != AV_NOPTS_VALUE &&
         fmt_is_discont && ist->st->pts_wrap_bits < 60) {
         int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<<ist->st->pts_wrap_bits),
                                             pkt->time_base, AV_TIME_BASE_Q,
                                             AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
-        if (FFABS(wrap_dts - ist->next_dts) < FFABS(pkt_dts - ist->next_dts)/10)
+        if (FFABS(wrap_dts - ds->next_dts) < FFABS(pkt_dts - ds->next_dts)/10)
             disable_discontinuity_correction = 0;
     }
 
-    if (ist->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
-        int64_t delta = pkt_dts - ist->next_dts;
+    if (ds->next_dts != AV_NOPTS_VALUE && !disable_discontinuity_correction) {
+        int64_t delta = pkt_dts - ds->next_dts;
         if (fmt_is_discont) {
             if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
-                pkt_dts + AV_TIME_BASE/10 < ist->dts) {
+                pkt_dts + AV_TIME_BASE/10 < ds->dts) {
                 ifile->ts_offset_discont -= delta;
                 av_log(NULL, AV_LOG_WARNING,
                        "timestamp discontinuity for stream #%d:%d "
@@ -229,19 +236,23 @@ static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
             }
         } else {
             if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
-                av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt->dts, ist->next_dts, pkt->stream_index);
+                av_log(NULL, AV_LOG_WARNING,
+                       "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n",
+                       pkt->dts, ds->next_dts, pkt->stream_index);
                 pkt->dts = AV_NOPTS_VALUE;
             }
             if (pkt->pts != AV_NOPTS_VALUE){
                 int64_t pkt_pts = av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
-                delta = pkt_pts - ist->next_dts;
+                delta = pkt_pts - ds->next_dts;
                 if (FFABS(delta) > 1LL * dts_error_threshold * AV_TIME_BASE) {
-                    av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt->pts, ist->next_dts, pkt->stream_index);
+                    av_log(NULL, AV_LOG_WARNING,
+                           "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n",
+                           pkt->pts, ds->next_dts, pkt->stream_index);
                     pkt->pts = AV_NOPTS_VALUE;
                 }
             }
         }
-    } else if (ist->next_dts == AV_NOPTS_VALUE && !copy_ts &&
+    } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
                fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
         int64_t delta = pkt_dts - ifile->last_ts;
         if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
@@ -285,39 +296,39 @@ static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
 
     if (!ds->saw_first_ts) {
         ds->first_dts =
-        ist->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
+        ds->dts = ist->st->avg_frame_rate.num ? - ist->par->video_delay * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
         if (pkt->pts != AV_NOPTS_VALUE) {
             ds->first_dts =
-            ist->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
+            ds->dts += av_rescale_q(pkt->pts, pkt->time_base, AV_TIME_BASE_Q);
         }
         ds->saw_first_ts = 1;
     }
 
-    if (ist->next_dts == AV_NOPTS_VALUE)
-        ist->next_dts = ist->dts;
+    if (ds->next_dts == AV_NOPTS_VALUE)
+        ds->next_dts = ds->dts;
 
     if (pkt->dts != AV_NOPTS_VALUE)
-        ist->next_dts = ist->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
+        ds->next_dts = ds->dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
 
-    ist->dts = ist->next_dts;
+    ds->dts = ds->next_dts;
     switch (par->codec_type) {
     case AVMEDIA_TYPE_AUDIO:
         av_assert1(pkt->duration >= 0);
         if (par->sample_rate) {
-            ist->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
+            ds->next_dts += ((int64_t)AV_TIME_BASE * par->frame_size) /
                               par->sample_rate;
         } else {
-            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+            ds->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
         }
         break;
     case AVMEDIA_TYPE_VIDEO:
         if (ist->framerate.num) {
             // TODO: Remove work-around for c99-to-c89 issue 7
             AVRational time_base_q = AV_TIME_BASE_Q;
-            int64_t next_dts = av_rescale_q(ist->next_dts, time_base_q, av_inv_q(ist->framerate));
-            ist->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
+            int64_t next_dts = av_rescale_q(ds->next_dts, time_base_q, av_inv_q(ist->framerate));
+            ds->next_dts = av_rescale_q(next_dts + 1, av_inv_q(ist->framerate), time_base_q);
         } else if (pkt->duration) {
-            ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
+            ds->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
         } else if (ist->par->framerate.num != 0) {
             AVRational field_rate = av_mul_q(ist->par->framerate,
                                              (AVRational){ 2, 1 });
@@ -328,7 +339,7 @@ static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
                 av_stream_get_parser(ist->st))
                 fields = 1 + av_stream_get_parser(ist->st)->repeat_pict;
 
-            ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
+            ds->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
         }
         break;
     }
@@ -342,7 +353,7 @@ static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
             return AVERROR(ENOMEM);
         pd = (DemuxPktData*)pkt->opaque_ref->data;
 
-        pd->dts_est = ist->dts;
+        pd->dts_est = ds->dts;
     }
 
     return 0;
@@ -502,7 +513,7 @@ static void readrate_sleep(Demuxer *d)
         DemuxStream  *ds = ds_from_ist(ist);
         int64_t stream_ts_offset, pts, now;
         stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
-        pts = av_rescale(ist->dts, 1000000, AV_TIME_BASE);
+        pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
         now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
         if (pts - burst_until > now)
             av_usleep(pts - burst_until - now);
@@ -983,7 +994,7 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
         st->discard  = AVDISCARD_ALL;
         ist->nb_samples = 0;
         ds->first_dts   = AV_NOPTS_VALUE;
-        ist->next_dts  = AV_NOPTS_VALUE;
+        ds->next_dts    = AV_NOPTS_VALUE;
 
         ds->min_pts = INT64_MAX;
         ds->max_pts = INT64_MIN;
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_demux: move InputStream.wrap_correction_done to private data
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (9 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_demux: move InputStream.[next_]dts " Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_demux: move InputStream.streamcopy_needed " Anton Khirnov
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

It is no longer used outside of ffmpeg_demux.
---
 fftools/ffmpeg.h       | 2 --
 fftools/ffmpeg_demux.c | 9 +++++----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b8c0e7db84..559381531e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -373,8 +373,6 @@ typedef struct InputStream {
     AVRational    last_frame_tb;
     int           last_frame_sample_rate;
 
-    int           wrap_correction_done;
-
     int64_t filter_in_rescale_delta_last;
 
     // when forcing constant input framerate through -r,
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 7e34292b3a..ff77f90c9e 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -60,6 +60,7 @@ typedef struct DemuxStream {
 
     double ts_scale;
 
+    int wrap_correction_done;
     int saw_first_ts;
     ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
     int64_t first_dts;
@@ -383,21 +384,21 @@ static int ts_fixup(Demuxer *d, AVPacket *pkt)
 
     SHOW_TS_DEBUG("demuxer");
 
-    if (!ist->wrap_correction_done && start_time != AV_NOPTS_VALUE &&
+    if (!ds->wrap_correction_done && start_time != AV_NOPTS_VALUE &&
         ist->st->pts_wrap_bits < 64) {
         int64_t stime, stime2;
 
         stime = av_rescale_q(start_time, AV_TIME_BASE_Q, pkt->time_base);
         stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
-        ist->wrap_correction_done = 1;
+        ds->wrap_correction_done = 1;
 
         if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
             pkt->dts -= 1ULL<<ist->st->pts_wrap_bits;
-            ist->wrap_correction_done = 0;
+            ds->wrap_correction_done = 0;
         }
         if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) {
             pkt->pts -= 1ULL<<ist->st->pts_wrap_bits;
-            ist->wrap_correction_done = 0;
+            ds->wrap_correction_done = 0;
         }
     }
 
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_demux: move InputStream.streamcopy_needed to private data
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (10 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_demux: move InputStream.wrap_correction_done " Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg: simplify tracking -readrate start time Anton Khirnov
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

It is no longer used outside of ffmpeg_demux.
---
 fftools/ffmpeg.h       | 1 -
 fftools/ffmpeg_demux.c | 8 ++++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 559381531e..7eb6301c74 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -343,7 +343,6 @@ typedef struct InputStream {
     int discard;             /* true if stream data should be discarded */
     int user_set_discard;
     int decoding_needed;     /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
-    int streamcopy_needed;
 #define DECODING_FOR_OST    1
 #define DECODING_FOR_FILTER 2
     // should attach FrameData as opaque_ref after decoding
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index ff77f90c9e..d5924c05aa 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -60,6 +60,8 @@ typedef struct DemuxStream {
 
     double ts_scale;
 
+    int streamcopy_needed;
+
     int wrap_correction_done;
     int saw_first_ts;
     ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
@@ -346,7 +348,7 @@ static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
     }
 
     av_assert0(!pkt->opaque_ref);
-    if (ist->streamcopy_needed) {
+    if (ds->streamcopy_needed) {
         DemuxPktData *pd;
 
         pkt->opaque_ref = av_buffer_allocz(sizeof(*pd));
@@ -806,10 +808,12 @@ void ifile_close(InputFile **pf)
 
 static void ist_use(InputStream *ist, int decoding_needed)
 {
+    DemuxStream *ds = ds_from_ist(ist);
+
     ist->discard          = 0;
     ist->st->discard      = ist->user_set_discard;
     ist->decoding_needed |= decoding_needed;
-    ist->streamcopy_needed |= !decoding_needed;
+    ds->streamcopy_needed |= !decoding_needed;
 
     if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) {
         int ret = dec_open(ist);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg: simplify tracking -readrate start time
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (11 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_demux: move InputStream.streamcopy_needed " Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: move discarding unused programs to ffmpeg_demux Anton Khirnov
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

There is no point in having a per-stream wallclock start time, since
they are all computed at the same instant. Keep a per-file start time
instead, initialized when the demuxer thread starts.
---
 fftools/ffmpeg.c       | 8 --------
 fftools/ffmpeg.h       | 2 --
 fftools/ffmpeg_demux.c | 6 +++++-
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9cf94f2a22..40e97ad486 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1498,14 +1498,6 @@ static int transcode_init(void)
 {
     int ret = 0;
 
-    /* init framerate emulation */
-    for (int i = 0; i < nb_input_files; i++) {
-        InputFile *ifile = input_files[i];
-        if (ifile->readrate)
-            for (int j = 0; j < ifile->nb_streams; j++)
-                ifile->streams[j]->start = av_gettime_relative();
-    }
-
     /* discard unused programs */
     for (int i = 0; i < nb_input_files; i++) {
         InputFile *ifile = input_files[i];
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7eb6301c74..d1af94590d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -362,8 +362,6 @@ typedef struct InputStream {
 
     AVRational framerate_guessed;
 
-    int64_t       start;     /* time when read started */
-
     // pts/estimated duration of the last decoded frame
     // * in decoder timebase for video,
     // * in last_frame_tb (may change during decoding) for audio
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d5924c05aa..1f8f3a73bd 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -88,6 +88,8 @@ typedef struct Demuxer {
     // name used for logging
     char log_name[32];
 
+    int64_t wallclock_start;
+
     /* number of times input stream should be looped */
     int loop;
     /* actual duration of the longest stream in a file at the moment when
@@ -517,7 +519,7 @@ static void readrate_sleep(Demuxer *d)
         int64_t stream_ts_offset, pts, now;
         stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
         pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
-        now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
+        now = (av_gettime_relative() - d->wallclock_start) * f->readrate + stream_ts_offset;
         if (pts - burst_until > now)
             av_usleep(pts - burst_until - now);
     }
@@ -546,6 +548,8 @@ static void *input_thread(void *arg)
 
     thread_set_name(f);
 
+    d->wallclock_start = av_gettime_relative();
+
     while (1) {
         DemuxMsg msg = { NULL };
 
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: move discarding unused programs to ffmpeg_demux
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (12 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg: simplify tracking -readrate start time Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

This is a more appropriate place for this code.
---
 fftools/ffmpeg.c       | 16 ----------------
 fftools/ffmpeg_demux.c | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 40e97ad486..725ffca631 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1498,22 +1498,6 @@ static int transcode_init(void)
 {
     int ret = 0;
 
-    /* discard unused programs */
-    for (int i = 0; i < nb_input_files; i++) {
-        InputFile *ifile = input_files[i];
-        for (int j = 0; j < ifile->ctx->nb_programs; j++) {
-            AVProgram *p = ifile->ctx->programs[j];
-            int discard  = AVDISCARD_ALL;
-
-            for (int k = 0; k < p->nb_stream_indexes; k++)
-                if (!ifile->streams[p->stream_index[k]]->discard) {
-                    discard = AVDISCARD_DEFAULT;
-                    break;
-                }
-            p->discard = discard;
-        }
-    }
-
     /* dump the stream mapping */
     av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
     for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1f8f3a73bd..1b268719aa 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -525,6 +525,21 @@ static void readrate_sleep(Demuxer *d)
     }
 }
 
+static void discard_unused_programs(InputFile *ifile)
+{
+        for (int j = 0; j < ifile->ctx->nb_programs; j++) {
+            AVProgram *p = ifile->ctx->programs[j];
+            int discard  = AVDISCARD_ALL;
+
+            for (int k = 0; k < p->nb_stream_indexes; k++)
+                if (!ifile->streams[p->stream_index[k]]->discard) {
+                    discard = AVDISCARD_DEFAULT;
+                    break;
+                }
+            p->discard = discard;
+        }
+}
+
 static void thread_set_name(InputFile *f)
 {
     char name[16];
@@ -548,6 +563,8 @@ static void *input_thread(void *arg)
 
     thread_set_name(f);
 
+    discard_unused_programs(f);
+
     d->wallclock_start = av_gettime_relative();
 
     while (1) {
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg_demux: reindent after previous commit
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (13 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: move discarding unused programs to ffmpeg_demux Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg: replace print_error() by more meaningful messages Anton Khirnov
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_demux.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1b268719aa..4b1e7e5254 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -527,17 +527,17 @@ static void readrate_sleep(Demuxer *d)
 
 static void discard_unused_programs(InputFile *ifile)
 {
-        for (int j = 0; j < ifile->ctx->nb_programs; j++) {
-            AVProgram *p = ifile->ctx->programs[j];
-            int discard  = AVDISCARD_ALL;
+    for (int j = 0; j < ifile->ctx->nb_programs; j++) {
+        AVProgram *p = ifile->ctx->programs[j];
+        int discard  = AVDISCARD_ALL;
 
-            for (int k = 0; k < p->nb_stream_indexes; k++)
-                if (!ifile->streams[p->stream_index[k]]->discard) {
-                    discard = AVDISCARD_DEFAULT;
-                    break;
-                }
-            p->discard = discard;
-        }
+        for (int k = 0; k < p->nb_stream_indexes; k++)
+            if (!ifile->streams[p->stream_index[k]]->discard) {
+                discard = AVDISCARD_DEFAULT;
+                break;
+            }
+        p->discard = discard;
+    }
 }
 
 static void thread_set_name(InputFile *f)
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg: replace print_error() by more meaningful messages
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (14 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg: log corrupt-frame errors to the appropriate context Anton Khirnov
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg.c       | 5 ++---
 fftools/ffmpeg_demux.c | 3 ++-
 fftools/ffmpeg_mux.c   | 4 +++-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 725ffca631..981714d027 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1756,12 +1756,10 @@ static void decode_flush(InputFile *ifile)
 static int process_input(int file_index)
 {
     InputFile *ifile = input_files[file_index];
-    AVFormatContext *is;
     InputStream *ist;
     AVPacket *pkt;
     int ret, i;
 
-    is  = ifile->ctx;
     ret = ifile_get_packet(ifile, &pkt);
 
     if (ret == AVERROR(EAGAIN)) {
@@ -1775,7 +1773,8 @@ static int process_input(int file_index)
     }
     if (ret < 0) {
         if (ret != AVERROR_EOF) {
-            print_error(is->url, ret);
+            av_log(ifile, AV_LOG_ERROR,
+                   "Error retrieving a packet from demuxer: %s\n", av_err2str(ret));
             if (exit_on_error)
                 exit_program(1);
         }
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 4b1e7e5254..1d596d1b29 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1405,7 +1405,8 @@ int ifile_open(const OptionsContext *o, const char *filename)
     /* open the input file with generic avformat function */
     err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
     if (err < 0) {
-        print_error(filename, err);
+        av_log(d, AV_LOG_ERROR,
+               "Error opening input: %s\n", av_err2str(err));
         if (err == AVERROR_PROTOCOL_NOT_FOUND)
             av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
         exit_program(1);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index afcd4df99b..36ed482072 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -139,7 +139,9 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
 
     ret = av_interleaved_write_frame(s, pkt);
     if (ret < 0) {
-        print_error("av_interleaved_write_frame()", ret);
+        av_log(ost, AV_LOG_ERROR,
+               "Error submitting a packet to the muxer: %s\n",
+               av_err2str(ret));
         goto fail;
     }
 
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg: log corrupt-frame errors to the appropriate context
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (15 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg: replace print_error() by more meaningful messages Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg: stop accessing input format from decoding code Anton Khirnov
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 981714d027..092c5e179a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -779,8 +779,8 @@ static void check_decode_result(InputStream *ist, int *got_output, int ret)
 
     if (*got_output && ist) {
         if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
-            av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
-                   "%s: corrupt decoded frame in stream %d\n", input_files[ist->file_index]->ctx->url, ist->st->index);
+            av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
+                   "corrupt decoded frame\n");
             if (exit_on_error)
                 exit_program(1);
         }
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg: stop accessing input format from decoding code
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (16 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg: log corrupt-frame errors to the appropriate context Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg_demux: move InputFile.ts_offset_discont, last_ts to private data Anton Khirnov
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

Export the corresponding flag in InputFile instead. This will allow
making the demuxer AVFormatContext private in future commits, similarly
to what was previously done for muxers.
---
 fftools/ffmpeg.c       | 5 ++---
 fftools/ffmpeg.h       | 3 +++
 fftools/ffmpeg_demux.c | 2 ++
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 092c5e179a..45efa75047 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -976,7 +976,6 @@ static int decode_audio(InputStream *ist, const AVPacket *pkt, int *got_output,
 static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame)
 {
     const InputFile   *ifile = input_files[ist->file_index];
-    const int container_nots = !!(ifile->ctx->iformat->flags & AVFMT_NOTIMESTAMPS);
     int64_t codec_duration = 0;
 
     // XXX lavf currently makes up frame durations when they are not provided by
@@ -986,7 +985,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 && !container_nots)
+    if (frame->duration > 0 && !ifile->format_nots)
         return frame->duration;
 
     if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) {
@@ -998,7 +997,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 && container_nots)
+    if (codec_duration > 0 && ifile->format_nots)
         return codec_duration;
 
     // when timestamps are available, repeat last frame's actual duration
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d1af94590d..5863ca1faf 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -442,6 +442,9 @@ typedef struct InputFile {
 
     int index;
 
+    // input format has no timestamps
+    int format_nots;
+
     AVFormatContext *ctx;
     int eof_reached;      /* true if eof reached */
     int eagain;           /* true if last read attempt returned EAGAIN */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1d596d1b29..2882f4308a 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1504,6 +1504,8 @@ int ifile_open(const OptionsContext *o, const char *filename)
     d->duration = 0;
     d->time_base = (AVRational){ 1, 1 };
 
+    f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS);
+
     f->readrate = o->readrate ? o->readrate : 0.0;
     if (f->readrate < 0.0f) {
         av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", f->readrate);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg_demux: move InputFile.ts_offset_discont, last_ts to private data
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (17 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg: stop accessing input format from decoding code Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg_demux: stop logging to demuxer context Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 22/22] fftools/ffmpeg: rename transcode_init() Anton Khirnov
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

They are no longer used outside of ffmpeg_demux.
---
 fftools/ffmpeg.h       |  5 -----
 fftools/ffmpeg_demux.c | 31 +++++++++++++++++++------------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 5863ca1faf..f88792d7eb 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -455,11 +455,6 @@ typedef struct InputFile {
      */
     int64_t start_time_effective;
     int64_t ts_offset;
-    /**
-     * Extra timestamp offset added by discontinuity handling.
-     */
-    int64_t ts_offset_discont;
-    int64_t last_ts;
     int64_t start_time;   /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
     int64_t recording_time;
 
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 2882f4308a..461f819e9e 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -90,6 +90,12 @@ typedef struct Demuxer {
 
     int64_t wallclock_start;
 
+    /**
+     * Extra timestamp offset added by discontinuity handling.
+     */
+    int64_t ts_offset_discont;
+    int64_t last_ts;
+
     /* number of times input stream should be looped */
     int loop;
     /* actual duration of the longest stream in a file at the moment when
@@ -205,9 +211,10 @@ static int seek_to_start(Demuxer *d)
     return ret;
 }
 
-static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
+static void ts_discontinuity_detect(Demuxer *d, InputStream *ist,
                                     AVPacket *pkt)
 {
+    InputFile *ifile = &d->f;
     DemuxStream *ds = ds_from_ist(ist);
     const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
     int disable_discontinuity_correction = copy_ts;
@@ -228,13 +235,13 @@ static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
         if (fmt_is_discont) {
             if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
                 pkt_dts + AV_TIME_BASE/10 < ds->dts) {
-                ifile->ts_offset_discont -= delta;
+                d->ts_offset_discont -= delta;
                 av_log(NULL, AV_LOG_WARNING,
                        "timestamp discontinuity for stream #%d:%d "
                        "(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
                        ist->file_index, ist->st->index, ist->st->id,
                        av_get_media_type_string(ist->par->codec_type),
-                       delta, ifile->ts_offset_discont);
+                       delta, d->ts_offset_discont);
                 pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
                 if (pkt->pts != AV_NOPTS_VALUE)
                     pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
@@ -258,26 +265,26 @@ static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
             }
         }
     } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
-               fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
-        int64_t delta = pkt_dts - ifile->last_ts;
+               fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
+        int64_t delta = pkt_dts - d->last_ts;
         if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
-            ifile->ts_offset_discont -= delta;
+            d->ts_offset_discont -= delta;
             av_log(NULL, AV_LOG_DEBUG,
                    "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
-                   delta, ifile->ts_offset_discont);
+                   delta, d->ts_offset_discont);
             pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
             if (pkt->pts != AV_NOPTS_VALUE)
                 pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, pkt->time_base);
         }
     }
 
-    ifile->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
+    d->last_ts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
 }
 
-static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
+static void ts_discontinuity_process(Demuxer *d, InputStream *ist,
                                      AVPacket *pkt)
 {
-    int64_t offset = av_rescale_q(ifile->ts_offset_discont, AV_TIME_BASE_Q,
+    int64_t offset = av_rescale_q(d->ts_offset_discont, AV_TIME_BASE_Q,
                                   pkt->time_base);
 
     // apply previously-detected timestamp-discontinuity offset
@@ -291,7 +298,7 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
     if ((ist->par->codec_type == AVMEDIA_TYPE_VIDEO ||
          ist->par->codec_type == AVMEDIA_TYPE_AUDIO) &&
         pkt->dts != AV_NOPTS_VALUE)
-        ts_discontinuity_detect(ifile, ist, pkt);
+        ts_discontinuity_detect(d, ist, pkt);
 }
 
 static int ist_dts_update(DemuxStream *ds, AVPacket *pkt)
@@ -429,7 +436,7 @@ static int ts_fixup(Demuxer *d, AVPacket *pkt)
     SHOW_TS_DEBUG("demuxer+tsfixup");
 
     // detect and try to correct for timestamp discontinuities
-    ts_discontinuity_process(ifile, ist, pkt);
+    ts_discontinuity_process(d, ist, pkt);
 
     // update estimated/predicted dts
     ret = ist_dts_update(ds, pkt);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg_demux: stop logging to demuxer context
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (18 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg_demux: move InputFile.ts_offset_discont, last_ts to private data Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 22/22] fftools/ffmpeg: rename transcode_init() Anton Khirnov
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

Only the demuxer itself should do that.
---
 fftools/ffmpeg_demux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 461f819e9e..0d265cbfea 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -641,14 +641,14 @@ static void *input_thread(void *arg)
         if (flags && ret == AVERROR(EAGAIN)) {
             flags = 0;
             ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
-            av_log(f->ctx, AV_LOG_WARNING,
+            av_log(f, AV_LOG_WARNING,
                    "Thread message queue blocking; consider raising the "
                    "thread_queue_size option (current value: %d)\n",
                    d->thread_queue_size);
         }
         if (ret < 0) {
             if (ret != AVERROR_EOF)
-                av_log(f->ctx, AV_LOG_ERROR,
+                av_log(f, AV_LOG_ERROR,
                        "Unable to send packet to main thread: %s\n",
                        av_err2str(ret));
             av_packet_free(&msg.pkt);
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [FFmpeg-devel] [PATCH 22/22] fftools/ffmpeg: rename transcode_init()
  2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
                   ` (19 preceding siblings ...)
  2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg_demux: stop logging to demuxer context Anton Khirnov
@ 2023-05-08  9:17 ` Anton Khirnov
  20 siblings, 0 replies; 22+ messages in thread
From: Anton Khirnov @ 2023-05-08  9:17 UTC (permalink / raw)
  To: ffmpeg-devel

It does no initialization anymore, except for setting
transcode_init_done - the bulk of the function is printing the
input/output maps. It also cannot fail anymore, so remove the useless
return value.
---
 fftools/ffmpeg.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 45efa75047..ebd793a98c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1493,11 +1493,8 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
     return !eof_reached;
 }
 
-static int transcode_init(void)
+static void print_stream_maps(void)
 {
-    int ret = 0;
-
-    /* dump the stream mapping */
     av_log(NULL, AV_LOG_INFO, "Stream mapping:\n");
     for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
         for (int j = 0; j < ist->nb_filters; j++) {
@@ -1570,13 +1567,6 @@ static int transcode_init(void)
             av_log(NULL, AV_LOG_INFO, " (copy)");
         av_log(NULL, AV_LOG_INFO, "\n");
     }
-
-    if (ret)
-        return ret;
-
-    atomic_store(&transcode_init_done, 1);
-
-    return 0;
 }
 
 /**
@@ -1854,9 +1844,9 @@ static int transcode(void)
     InputStream *ist;
     int64_t timer_start;
 
-    ret = transcode_init();
-    if (ret < 0)
-        return ret;
+    print_stream_maps();
+
+    atomic_store(&transcode_init_done, 1);
 
     if (stdin_interaction) {
         av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
-- 
2.39.2

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-05-08  9:21 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-08  9:17 [FFmpeg-devel] [PATCH 01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 02/22] fftools/ffmpeg: reindent after previous commit Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 03/22] fftools/ffmpeg: stop using decoder properties in ist_dts_update() Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 04/22] fftools/ffmpeg_demux: move preparing DemuxMsg to separate function Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 05/22] fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 06/22] fftools/ffmpeg: move post-demux packet processing to ffmpeg_demux Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 07/22] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 08/22] fftools/ffmpeg: drop unused decode_video() parameter Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 09/22] fftools/ffmpeg_demux: move InputStream.{nb_packets, data_size} to private data Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 10/22] fftools/ffmpeg_demux: move InputStream.[saw_]first_d?ts " Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 11/22] fftools/ffmpeg_demux: move InputStream.[next_]dts " Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 12/22] fftools/ffmpeg_demux: move InputStream.wrap_correction_done " Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 13/22] fftools/ffmpeg_demux: move InputStream.streamcopy_needed " Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg: simplify tracking -readrate start time Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 15/22] fftools/ffmpeg: move discarding unused programs to ffmpeg_demux Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 16/22] fftools/ffmpeg_demux: reindent after previous commit Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 17/22] fftools/ffmpeg: replace print_error() by more meaningful messages Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 18/22] fftools/ffmpeg: log corrupt-frame errors to the appropriate context Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg: stop accessing input format from decoding code Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 20/22] fftools/ffmpeg_demux: move InputFile.ts_offset_discont, last_ts to private data Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 21/22] fftools/ffmpeg_demux: stop logging to demuxer context Anton Khirnov
2023-05-08  9:17 ` [FFmpeg-devel] [PATCH 22/22] fftools/ffmpeg: rename transcode_init() Anton Khirnov

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