Skip to content

Commit

Permalink
utils: Factor out AVERROR to string function
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Buitenhuis <[email protected]>
  • Loading branch information
dwbuiten committed Apr 29, 2024
1 parent 72b5035 commit a6e19b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/core/indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ void SetOptions(T const& src, void *opt, OptionMapper<T>(&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
8 changes: 2 additions & 6 deletions src/core/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a6e19b7

Please sign in to comment.