diff mbox series

[FFmpeg-devel,14/21] fftools/ffmpeg_dec: stop using Decoder.pkt

Message ID 20230614164908.28712-14-anton@khirnov.net
State Accepted
Commit 7d4e00ccf0b77dab1bf74320b26af968ba670394
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 is only used for flushing the subtitle decoder, so allocate a
dedicated packet for that.

Keep Decoder.pkt unused for now, it will be repurposed in future
commits.
---
 fftools/ffmpeg_dec.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 586be83dc1..f9053c424b 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -385,10 +385,20 @@  out:
 
 static int transcode_subtitles(InputStream *ist, const AVPacket *pkt)
 {
+    AVPacket *flush_pkt = NULL;
     AVSubtitle subtitle;
     int got_output;
-    int ret = avcodec_decode_subtitle2(ist->dec_ctx,
-                                       &subtitle, &got_output, pkt);
+    int ret;
+
+    if (!pkt) {
+        flush_pkt = av_packet_alloc();
+        if (!flush_pkt)
+            return AVERROR(ENOMEM);
+    }
+
+    ret = avcodec_decode_subtitle2(ist->dec_ctx, &subtitle, &got_output,
+                                   pkt ? pkt : flush_pkt);
+    av_packet_free(&flush_pkt);
 
     if (ret < 0) {
         av_log(ist, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
@@ -399,7 +409,7 @@  static int transcode_subtitles(InputStream *ist, const AVPacket *pkt)
     }
 
     if (ret < 0 || !got_output) {
-        if (!pkt->size)
+        if (!pkt)
             sub2video_flush(ist);
         return ret < 0 ? ret : AVERROR_EOF;
     }
@@ -432,7 +442,7 @@  int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
     int ret;
 
     if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE)
-        return transcode_subtitles(ist, pkt ? pkt : d->pkt);
+        return transcode_subtitles(ist, pkt);
 
     // With fate-indeo3-2, we're getting 0-sized packets before EOF for some
     // reason. This seems like a semi-critical bug. Don't trigger EOF, and