diff mbox series

[FFmpeg-devel,18/21] fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder

Message ID 20230614164908.28712-18-anton@khirnov.net
State Accepted
Commit e89a6d1089d5afdb15f4eb118f24a0a98ac9ae93
Headers show
Series [FFmpeg-devel,01/21] fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov June 14, 2023, 4:49 p.m. UTC
It does not need to be visible outside of decoding code.
---
 fftools/ffmpeg.h       |  4 ----
 fftools/ffmpeg_dec.c   | 26 ++++++++++++++++++--------
 fftools/ffmpeg_demux.c |  1 -
 3 files changed, 18 insertions(+), 13 deletions(-)
diff mbox series

Patch

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 879101fe21..36e28aaa07 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);