[FFmpeg-cvslog] fftools/ffmpeg: split decoding loop out of process_input_packet()
Anton Khirnov
git at videolan.org
Mon May 22 18:12:10 EEST 2023
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed May 17 09:29:30 2023 +0200| [79c1dde5c3225e61aea064809547dd430bb83feb] | committer: Anton Khirnov
fftools/ffmpeg: split decoding loop out of process_input_packet()
process_input_packet() contains two non-interacting pieces of nontrivial
size and complexity - decoding and streamcopy. Separating them makes the
code easier to read.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=79c1dde5c3225e61aea064809547dd430bb83feb
---
fftools/ffmpeg.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b88064a2bc..cc134dc49d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1344,18 +1344,10 @@ static int send_filter_eof(InputStream *ist)
return 0;
}
-/* pkt = NULL means EOF (needed to flush decoder buffers) */
-static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
+static int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
{
- InputFile *f = input_files[ist->file_index];
- const AVCodecParameters *par = ist->par;
- int64_t dts_est = AV_NOPTS_VALUE;
- int ret = 0;
- int repeating = 0;
- int eof_reached = 0;
- int duration_exceeded;
-
AVPacket *avpkt = ist->pkt;
+ int ret, repeating = 0;
if (pkt) {
av_packet_unref(avpkt);
@@ -1365,11 +1357,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
}
// while we have more to decode or while the decoder did output something on EOF
- while (ist->decoding_needed) {
+ while (1) {
int got_output = 0;
int decode_failed = 0;
- switch (par->codec_type) {
+ switch (ist->par->codec_type) {
case AVMEDIA_TYPE_AUDIO:
ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output,
&decode_failed);
@@ -1403,8 +1395,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
}
}
- eof_reached = 1;
- break;
+ return AVERROR_EOF;
}
if (ret < 0) {
@@ -1417,16 +1408,28 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
}
if (!decode_failed || exit_on_error)
exit_program(1);
- break;
+ return ret;
}
if (!got_output)
- break;
+ return 0;
repeating = 1;
}
+}
+
+/* pkt = NULL means EOF (needed to flush decoder buffers) */
+static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
+{
+ InputFile *f = input_files[ist->file_index];
+ int64_t dts_est = AV_NOPTS_VALUE;
+ int ret = 0;
+ int eof_reached = 0;
+ int duration_exceeded;
- if (!pkt && !ist->decoding_needed)
+ if (ist->decoding_needed)
+ ret = dec_packet(ist, pkt, no_eof);
+ if (ret == AVERROR_EOF || (!pkt && !ist->decoding_needed))
eof_reached = 1;
if (pkt && pkt->opaque_ref) {
More information about the ffmpeg-cvslog
mailing list