[FFmpeg-cvslog] fftools/ffmpeg_dec: move decoding counters from InputStream to Decoder

Anton Khirnov git at videolan.org
Tue Jan 30 11:07:28 EET 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Jan 11 10:45:18 2024 +0100| [9be3f80527e2d5918825f1405b720d5f6dcb5e16] | committer: Anton Khirnov

fftools/ffmpeg_dec: move decoding counters from InputStream to Decoder

This is a step towards decoupling Decoder and InputStream.

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

 fftools/ffmpeg.h       | 11 +++++------
 fftools/ffmpeg_dec.c   | 16 ++++++++--------
 fftools/ffmpeg_demux.c |  4 ++--
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 227929b022..db9bd8cc7a 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -285,6 +285,11 @@ typedef struct Decoder {
 
     const uint8_t   *subtitle_header;
     int              subtitle_header_size;
+
+    // number of frames/samples retrieved from the decoder
+    uint64_t         frames_decoded;
+    uint64_t         samples_decoded;
+    uint64_t         decode_errors;
 } Decoder;
 
 typedef struct InputStream {
@@ -346,12 +351,6 @@ typedef struct InputStream {
     enum AVHWDeviceType hwaccel_device_type;
     char  *hwaccel_device;
     enum AVPixelFormat hwaccel_output_format;
-
-    /* stats */
-    // number of frames/samples retrieved from the decoder
-    uint64_t frames_decoded;
-    uint64_t samples_decoded;
-    uint64_t decode_errors;
 } InputStream;
 
 typedef struct InputFile {
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 8a7d82244b..58be466e4c 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -445,14 +445,14 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt,
     if (ret < 0) {
         av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n",
                av_err2str(ret));
-        ist->decode_errors++;
+        dp->dec.decode_errors++;
         return exit_on_error ? ret : 0;
     }
 
     if (!got_output)
         return pkt ? 0 : AVERROR_EOF;
 
-    ist->frames_decoded++;
+    dp->dec.frames_decoded++;
 
     // XXX the queue for transferring data to consumers runs
     // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that
@@ -512,7 +512,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
                pkt ? "packet" : "EOF", av_err2str(ret));
 
         if (ret != AVERROR_EOF) {
-            ist->decode_errors++;
+            dp->dec.decode_errors++;
             if (!exit_on_error)
                 ret = 0;
         }
@@ -537,7 +537,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
             return ret;
         } else if (ret < 0) {
             av_log(dp, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret));
-            ist->decode_errors++;
+            dp->dec.decode_errors++;
 
             if (exit_on_error)
                 return ret;
@@ -567,7 +567,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
         frame->time_base = dec->pkt_timebase;
 
         if (dec->codec_type == AVMEDIA_TYPE_AUDIO) {
-            ist->samples_decoded += frame->nb_samples;
+            dp->dec.samples_decoded += frame->nb_samples;
 
             audio_ts_process(dp, frame);
         } else {
@@ -579,7 +579,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
             }
         }
 
-        ist->frames_decoded++;
+        dp->dec.frames_decoded++;
 
         ret = sch_dec_send(dp->sch, dp->sch_idx, frame);
         if (ret < 0) {
@@ -707,8 +707,8 @@ void *decoder_thread(void *arg)
         }
         ret = 0;
 
-        err_rate = (ist->frames_decoded || ist->decode_errors) ?
-                   ist->decode_errors / (ist->frames_decoded + ist->decode_errors) : 0.f;
+        err_rate = (dp->dec.frames_decoded || dp->dec.decode_errors) ?
+                   dp->dec.decode_errors / (dp->dec.frames_decoded + dp->dec.decode_errors) : 0.f;
         if (err_rate > max_error_rate) {
             av_log(dp, AV_LOG_FATAL, "Decode error rate %g exceeds maximum %g\n",
                    err_rate, max_error_rate);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index b2cbde2aa5..5a58bb735a 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -796,9 +796,9 @@ static void demux_final_stats(Demuxer *d)
         if (ist->decoding_needed) {
             av_log(f, AV_LOG_VERBOSE,
                    "%"PRIu64" frames decoded; %"PRIu64" decode errors",
-                   ist->frames_decoded, ist->decode_errors);
+                   ist->decoder->frames_decoded, ist->decoder->decode_errors);
             if (type == AVMEDIA_TYPE_AUDIO)
-                av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
+                av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->decoder->samples_decoded);
             av_log(f, AV_LOG_VERBOSE, "; ");
         }
 



More information about the ffmpeg-cvslog mailing list