[FFmpeg-cvslog] fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder

Anton Khirnov git at videolan.org
Mon Jun 19 12:11:30 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Jun 14 16:16:50 2023 +0200| [e89a6d1089d5afdb15f4eb118f24a0a98ac9ae93] | committer: Anton Khirnov

fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder

It does not need to be visible outside of decoding code.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e89a6d1089d5afdb15f4eb118f24a0a98ac9ae93
---

 fftools/ffmpeg.h       |  4 ----
 fftools/ffmpeg_dec.c   | 26 ++++++++++++++++++--------
 fftools/ffmpeg_demux.c |  1 -
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b4b55f5a73..63ca542337 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -359,10 +359,6 @@ typedef struct InputStream {
     int autorotate;
 
     int fix_sub_duration;
-    struct { /* previous decoded subtitle and related variables */
-        int got_output;
-        AVSubtitle subtitle;
-    } prev_sub;
 
     struct sub2video {
         int w, h;
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index a425b701d4..36f418eec8 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -47,6 +47,12 @@ struct Decoder {
     int64_t         last_filter_in_rescale_delta;
     int             last_frame_sample_rate;
 
+    /* previous decoded subtitle and related variables */
+    struct {
+        int got_output;
+        AVSubtitle subtitle;
+    } prev_sub;
+
     pthread_t       thread;
     /**
      * Queue for sending coded packets from the main thread to
@@ -102,6 +108,8 @@ void dec_free(Decoder **pdec)
     av_frame_free(&dec->frame);
     av_packet_free(&dec->pkt);
 
+    avsubtitle_free(&dec->prev_sub.subtitle);
+
     av_freep(pdec);
 }
 
@@ -378,24 +386,25 @@ static void sub2video_flush(InputStream *ist)
 
 static int process_subtitle(InputStream *ist, AVSubtitle *subtitle)
 {
+    Decoder *d = ist->decoder;
     int got_output = 1;
     int ret = 0;
 
     if (ist->fix_sub_duration) {
         int end = 1;
-        if (ist->prev_sub.got_output) {
-            end = av_rescale(subtitle->pts - ist->prev_sub.subtitle.pts,
+        if (d->prev_sub.got_output) {
+            end = av_rescale(subtitle->pts - d->prev_sub.subtitle.pts,
                              1000, AV_TIME_BASE);
-            if (end < ist->prev_sub.subtitle.end_display_time) {
+            if (end < d->prev_sub.subtitle.end_display_time) {
                 av_log(NULL, AV_LOG_DEBUG,
                        "Subtitle duration reduced from %"PRId32" to %d%s\n",
-                       ist->prev_sub.subtitle.end_display_time, end,
+                       d->prev_sub.subtitle.end_display_time, end,
                        end <= 0 ? ", dropping it" : "");
-                ist->prev_sub.subtitle.end_display_time = end;
+                d->prev_sub.subtitle.end_display_time = end;
             }
         }
-        FFSWAP(int,         got_output, ist->prev_sub.got_output);
-        FFSWAP(AVSubtitle, *subtitle,   ist->prev_sub.subtitle);
+        FFSWAP(int,         got_output, d->prev_sub.got_output);
+        FFSWAP(AVSubtitle, *subtitle,   d->prev_sub.subtitle);
         if (end <= 0)
             goto out;
     }
@@ -430,8 +439,9 @@ out:
 
 int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
 {
+    Decoder *d = ist->decoder;
     int ret = AVERROR_BUG;
-    AVSubtitle *prev_subtitle = &ist->prev_sub.subtitle;
+    AVSubtitle *prev_subtitle = &d->prev_sub.subtitle;
     AVSubtitle subtitle;
 
     if (!ist->fix_sub_duration || !prev_subtitle->num_rects ||
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1c6a5aab7b..5d3e043793 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -816,7 +816,6 @@ static void ist_free(InputStream **pist)
     dec_free(&ist->decoder);
 
     av_dict_free(&ist->decoder_opts);
-    avsubtitle_free(&ist->prev_sub.subtitle);
     av_freep(&ist->filters);
     av_freep(&ist->outputs);
     av_freep(&ist->hwaccel_device);



More information about the ffmpeg-cvslog mailing list