diff mbox series

[FFmpeg-devel,14/24] fftools/ffmpeg_filter: move sub2video subtitle queue to InputFilterPriv

Message ID 20230528091416.17927-14-anton@khirnov.net
State Accepted
Commit a6d67b11f5b83b72d1df37a88c864dc854374488
Headers show
Series [FFmpeg-devel,01/24] fftools/ffmpeg_mux_init: merge ost_add_from_filter() to ost_add() | 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 May 28, 2023, 9:14 a.m. UTC
This queue should be associated with a specific filtergraph input - if
a subtitle stream is sent to multiple filters then each should have its
own queue.
---
 fftools/ffmpeg.h        |  1 -
 fftools/ffmpeg_filter.c | 26 +++++++++++++++-----------
 2 files changed, 15 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index fa5824ee7b..d4aff5cc7c 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -374,7 +374,6 @@  typedef struct InputStream {
     struct sub2video {
         int64_t last_pts;
         int64_t end_pts;
-        AVFifo *sub_queue;    ///< queue of AVSubtitle* before filter init
         AVFrame *frame;
         int w, h;
         unsigned int initialize; ///< marks if sub2video_update should force an initialization
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index acfd83244b..2a73e3a3e3 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -104,6 +104,10 @@  typedef struct InputFilterPriv {
         AVChannelLayout     ch_layout;
     } fallback;
 
+    struct {
+        ///< queue of AVSubtitle* before filter init
+        AVFifo *queue;
+    } sub2video;
 } InputFilterPriv;
 
 static InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter)
@@ -593,7 +597,6 @@  void fg_free(FilterGraph **pfg)
     for (int j = 0; j < fg->nb_inputs; j++) {
         InputFilter *ifilter = fg->inputs[j];
         InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
-        InputStream     *ist = ifp->ist;
 
         if (ifp->frame_queue) {
             AVFrame *frame;
@@ -601,11 +604,11 @@  void fg_free(FilterGraph **pfg)
                 av_frame_free(&frame);
             av_fifo_freep2(&ifp->frame_queue);
         }
-        if (ist && ist->sub2video.sub_queue) {
+        if (ifp->sub2video.queue) {
             AVSubtitle sub;
-            while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0)
+            while (av_fifo_read(ifp->sub2video.queue, &sub, 1) >= 0)
                 avsubtitle_free(&sub);
-            av_fifo_freep2(&ist->sub2video.sub_queue);
+            av_fifo_freep2(&ifp->sub2video.queue);
         }
 
         av_channel_layout_uninit(&ifp->fallback.ch_layout);
@@ -1495,10 +1498,11 @@  int configure_filtergraph(FilterGraph *fg)
 
     /* process queued up subtitle packets */
     for (i = 0; i < fg->nb_inputs; i++) {
-        InputStream *ist = ifp_from_ifilter(fg->inputs[i])->ist;
-        if (ist->sub2video.sub_queue && ist->sub2video.frame) {
+        InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]);
+        InputStream     *ist = ifp->ist;
+        if (ifp->sub2video.queue && ist->sub2video.frame) {
             AVSubtitle tmp;
-            while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) {
+            while (av_fifo_read(ifp->sub2video.queue, &tmp, 1) >= 0) {
                 sub2video_update(ist, INT64_MIN, &tmp);
                 avsubtitle_free(&tmp);
             }
@@ -1649,16 +1653,16 @@  int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *subtitle)
     } else {
         AVSubtitle sub;
 
-        if (!ist->sub2video.sub_queue)
-            ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW);
-        if (!ist->sub2video.sub_queue)
+        if (!ifp->sub2video.queue)
+            ifp->sub2video.queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW);
+        if (!ifp->sub2video.queue)
             return AVERROR(ENOMEM);
 
         ret = copy_av_subtitle(&sub, subtitle);
         if (ret < 0)
             return ret;
 
-        ret = av_fifo_write(ist->sub2video.sub_queue, &sub, 1);
+        ret = av_fifo_write(ifp->sub2video.queue, &sub, 1);
         if (ret < 0) {
             avsubtitle_free(&sub);
             return ret;