diff mbox series

[FFmpeg-devel,33/36] fftools/ffmpeg_dec: merge check_decode_result() into its callers

Message ID 20230517102029.541-33-anton@khirnov.net
State Accepted
Commit ab3493006f04fbd87a2672986003f5eab354b630
Headers show
Series [FFmpeg-devel,01/36] fftools/ffmpeg: shorten a variable name | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed

Commit Message

Anton Khirnov May 17, 2023, 10:20 a.m. UTC
Not only is this easier to read, this also makes the code shorter.
---
 fftools/ffmpeg_dec.c | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 58bb7a7344..79e9c04fc1 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -31,24 +31,6 @@ 
 
 #include "ffmpeg.h"
 
-static void check_decode_result(InputStream *ist, int got_output, int ret)
-{
-    if (ret < 0)
-        ist->decode_errors++;
-
-    if (ret < 0 && exit_on_error)
-        exit_program(1);
-
-    if (got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
-        if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) {
-            av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
-                   "corrupt decoded frame\n");
-            if (exit_on_error)
-                exit_program(1);
-        }
-    }
-}
-
 static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame)
 {
     int i, ret;
@@ -385,10 +367,9 @@  static int transcode_subtitles(InputStream *ist, const AVPacket *pkt)
                 av_err2str(ret));
         if (exit_on_error)
             exit_program(1);
+        ist->decode_errors++;
     }
 
-    check_decode_result(ist, got_output, ret);
-
     if (ret < 0 || !got_output) {
         if (!pkt->size)
             sub2video_flush(ist);
@@ -448,9 +429,6 @@  int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
         update_benchmark("decode_%s %d.%d", type_desc,
                          ist->file_index, ist->st->index);
 
-        if (ret != AVERROR_EOF && ret != AVERROR(EAGAIN))
-            check_decode_result(ist, ret >= 0, ret);
-
         if (ret == AVERROR(EAGAIN)) {
             av_assert0(pkt); // should never happen during flushing
             return 0;
@@ -470,9 +448,17 @@  int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
             av_log(ist, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
             if (exit_on_error)
                 exit_program(1);
+            ist->decode_errors++;
             return ret;
         }
 
+        if (frame->decode_error_flags || (frame->flags & AV_FRAME_FLAG_CORRUPT)) {
+            av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING,
+                   "corrupt decoded frame\n");
+            if (exit_on_error)
+                exit_program(1);
+        }
+
         if (ist->want_frame_data) {
             FrameData *fd;