From a6e19b7194111f26118909d64483bdc4713a35ce Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Mon, 29 Apr 2024 20:15:41 +0100 Subject: [PATCH] utils: Factor out AVERROR to string function Signed-off-by: Derek Buitenhuis --- src/core/indexing.cpp | 8 ++------ src/core/utils.cpp | 7 +++++++ src/core/utils.h | 1 + src/core/videosource.cpp | 8 ++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/indexing.cpp b/src/core/indexing.cpp index 1ac07861e6..c13b8ee599 100644 --- a/src/core/indexing.cpp +++ b/src/core/indexing.cpp @@ -587,13 +587,9 @@ FFMS_Index *FFMS_Indexer::DoIndexing() { av_packet_unref(Packet); } av_packet_free(&Packet); - if (IsIOError(ret)) { - char error[1024]; - av_strerror(ret, error, 1024); - std::string cerr(error); + if (IsIOError(ret)) throw FFMS_Exception(FFMS_ERROR_INDEXING, FFMS_ERROR_FILE_READ, - "Indexing failed: " + cerr); - } + "Indexing failed: " + AVErrorToString(ret)); TrackIndices->Finalize(AVContexts, FormatContext->iformat->name); return TrackIndices.release(); diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 8a3a519d97..192b3c6bb7 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -171,3 +171,10 @@ bool IsIOError(int error) { return false; } } + +std::string AVErrorToString(int ret) { + char error[1024]; + av_strerror(ret, error, 1024); + std::string cerr(error); + return cerr; +} diff --git a/src/core/utils.h b/src/core/utils.h index bd310995c1..14492d9798 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -135,5 +135,6 @@ void SetOptions(T const& src, void *opt, OptionMapper(&options)[N]) { int ResizerNameToSWSResizer(const char *ResizerName); bool IsSamePath(const char *p1, const char *p2); bool IsIOError(int error); +std::string AVErrorToString(int ret); #endif diff --git a/src/core/videosource.cpp b/src/core/videosource.cpp index bd1bfbff9f..018c0059c0 100644 --- a/src/core/videosource.cpp +++ b/src/core/videosource.cpp @@ -791,13 +791,9 @@ void FFMS_VideoSource::DecodeNextFrame(int64_t &AStartTime, int64_t &Pos) { ret = av_read_frame(FormatContext, Packet); } } - if (IsIOError(ret)) { - char err[1024]; - av_strerror(ret, err, 1024); - std::string serr(err); + if (IsIOError(ret)) throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_FILE_READ, - "Failed to read packet: " + serr); - } + "Failed to read packet: " + AVErrorToString(ret)); // Flush final frames DecodePacket(Packet);