[FFmpeg-devel] [PATCH 07/31] fftools/ffmpeg_dec: move decoding counters from InputStream to Decoder
Anton Khirnov
anton at khirnov.net
Wed Jan 24 10:16:37 EET 2024
This is a step towards decoupling Decoder and InputStream.
---
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 15d49d0d69..4a59a4b392 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, "; ");
}
--
2.42.0
More information about the ffmpeg-devel
mailing list