27 #include <com/avpkit/ferry/Logger.h>
28 #include <com/avpkit/core/Error.h>
29 #include <com/avpkit/core/FfmpegIncludes.h>
34 VS_LOG_SETUP(VS_CPP_PACKAGE);
36 namespace com {
namespace avpkit {
namespace core
39 struct ErrorMappingTable {
44 static struct ErrorMappingTable sErrorMappingTable[] = {
45 { AVERROR(EIO), IError::ERROR_IO },
46 { AVERROR(EDOM), IError::ERROR_NUMEXPECTED },
47 { AVERROR(EINVAL), IError::ERROR_INVALIDDATA },
48 { AVERROR(ENOMEM), IError::ERROR_NOMEM },
49 { AVERROR(EILSEQ), IError::ERROR_NOFMT },
50 { AVERROR(ENOSYS), IError::ERROR_NOTSUPPORTED },
51 { AVERROR(ENOENT), IError::ERROR_NOENT },
52 { AVERROR(EPIPE), IError::ERROR_EOF },
53 { AVERROR_PATCHWELCOME, IError::ERROR_PATCHWELCOME },
54 { AVERROR(EAGAIN), IError::ERROR_AGAIN },
55 { AVERROR(ERANGE), IError::ERROR_RANGE },
56 { AVERROR(EINTR), IError::ERROR_INTERRUPTED },
57 { AVERROR_EOF, IError::ERROR_EOF },
58 { AVERROR_DECODER_NOT_FOUND, IError::ERROR_NOFMT },
59 { AVERROR_DEMUXER_NOT_FOUND, IError::ERROR_NOFMT },
60 { AVERROR_ENCODER_NOT_FOUND, IError::ERROR_NOFMT },
61 { AVERROR_MUXER_NOT_FOUND, IError::ERROR_NOFMT },
62 { AVERROR_OPTION_NOT_FOUND, IError::ERROR_NOFMT },
64 static int32_t sErrorMappingTableSize =
sizeof(sErrorMappingTable)/
sizeof(
struct ErrorMappingTable);
68 mType = IError::ERROR_UNKNOWN;
71 mErrorStr[
sizeof(mErrorStr)-1]=0;
82 const char* retval = 0;
83 if (!*mErrorStr && mErrorNo != 0)
85 #ifdef HAVE_STRERROR_R
86 #ifdef STRERROR_R_CHAR_P
87 retval = strerror_r(AVUNERROR(mErrorNo), mErrorStr,
sizeof(mErrorStr));
89 strerror_r(AVUNERROR(mErrorNo), mErrorStr,
sizeof(mErrorStr));
93 retval = strerror(AVUNERROR(mErrorNo));
95 if (retval != (
const char*) mErrorStr)
96 strncpy(mErrorStr, retval,
sizeof(mErrorStr)-1);
98 return *mErrorStr ? mErrorStr : 0;
113 Error :: make(int32_t aErrorNo)
118 return make(aErrorNo, errorNumberToType(aErrorNo));
122 Error :: make(Type aType)
124 return make(typeToErrorNumber(aType), aType);
128 Error :: make(int32_t aErrorNo, Type aType)
135 throw std::bad_alloc();
136 retval->mErrorNo = aErrorNo;
137 retval->mType = aType;
139 *(retval->mErrorStr) = 0;
141 catch (std::bad_alloc & e)
143 VS_REF_RELEASE(retval);
146 catch (std::exception & e)
148 VS_LOG_TRACE(
"Error: %s", e.what());
149 VS_REF_RELEASE(retval);
156 Error :: errorNumberToType(int32_t errNo)
160 for(; i < sErrorMappingTableSize; i++)
162 if (sErrorMappingTable[i].mFfmpegError == errNo)
164 retval = sErrorMappingTable[i].mAVPKitError;
168 if (i >= sErrorMappingTableSize) {
169 retval = IError::ERROR_UNKNOWN;
175 Error :: typeToErrorNumber(Type type)
177 int32_t retval = AVERROR(EINVAL);
179 for(; i < sErrorMappingTableSize; i++)
181 if (sErrorMappingTable[i].mAVPKitError == type)
183 retval = sErrorMappingTable[i].mFfmpegError;
187 if (i >= sErrorMappingTableSize) {
188 retval = AVERROR(EINVAL);
virtual int32_t getErrorNumber()
Return the raw integer value that AVPKit returned and was used to create this IError.
virtual Type getType()
Get the OS-independent AVPKit type for this error.
virtual const char * getDescription()
Get a text description for this error.
Type
A set of errors that AVPKit knows about.
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...