From fa1c8e73888a7b5c8e18697f2c8647f39d1eed1a Mon Sep 17 00:00:00 2001 From: Michal Adamczak Date: Wed, 8 Jun 2022 16:30:00 +0200 Subject: [PATCH] transcode2() error-tolerant I was reviewing transcode2() source vs old transcode() and found out that in old code errors in decode loop were "tolerated". What I mean by that is that such error was interrupting the decode loop but the flushing of the filters would still be performed. transcode2() was modified accordingly to replicate previous code's behaviour. --- ffmpeg/logging.h | 7 +++++++ ffmpeg/transcoder.c | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ffmpeg/logging.h b/ffmpeg/logging.h index 570aa5421f..e4ed36fa78 100644 --- a/ffmpeg/logging.h +++ b/ffmpeg/logging.h @@ -19,6 +19,13 @@ av_log(NULL, AV_LOG_ERROR, "ERROR: %s:%d] %s : %s\n", __FILE__, __LINE__, msg, e return ret; \ } +#define LPMS_ERR_BREAK(msg) {\ +char errstr[AV_ERROR_MAX_STRING_SIZE] = {0}; \ +if (!ret) ret = AVERROR(EINVAL); \ +if (ret <-1) av_strerror(ret, errstr, sizeof errstr); \ +av_log(NULL, AV_LOG_ERROR, "ERROR: %s:%d] %s : %s\n", __FILE__, __LINE__, msg, errstr); \ +break; \ +} #define LPMS_WARN(msg) {\ av_log(NULL, AV_LOG_WARNING, "WARNING: %s:%d] %s\n", __FILE__, __LINE__, msg); \ diff --git a/ffmpeg/transcoder.c b/ffmpeg/transcoder.c index f5dfe63163..1b94a96f56 100755 --- a/ffmpeg/transcoder.c +++ b/ffmpeg/transcoder.c @@ -614,22 +614,22 @@ int transcode2(struct transcode_thread *h, break; } else if (ret < 0) { // demuxing error - LPMS_ERR(transcode_cleanup, "Unable to read input"); + LPMS_ERR_BREAK("Unable to read input"); } // all is fine, handle packet just received ist = ictx->ic->streams[ipkt->stream_index]; if (AVMEDIA_TYPE_VIDEO == ist->codecpar->codec_type) { // video packet ret = handle_video_packet(h, decoded_results, ipkt, iframe); - if (ret < 0) goto transcode_cleanup; + if (ret < 0) break; } else if (AVMEDIA_TYPE_AUDIO == ist->codecpar->codec_type) { // audio packet ret = handle_audio_packet(h, decoded_results, ipkt, iframe); - if (ret < 0) goto transcode_cleanup; + if (ret < 0) break; } else { // other types of packets (used only for transmuxing) handle_other_packet(h, ipkt); - if (ret < 0) goto transcode_cleanup; + if (ret < 0) break; } av_packet_unref(ipkt); } @@ -651,7 +651,7 @@ int transcode2(struct transcode_thread *h, // retry continue; } - if (ret < 0) LPMS_ERR(transcode_cleanup, "Flushing failed"); + if (ret < 0) LPMS_ERR_BREAK("Flushing failed"); ist = ictx->ic->streams[stream_index]; if (AVMEDIA_TYPE_VIDEO == ist->codecpar->codec_type) { handle_video_frame(h, ist, decoded_results, iframe);