Include the libmfx error code and its description
Anton Khirnov authored on 2016/06/26 04:38:10... | ... |
@@ -54,39 +54,67 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id) |
54 | 54 |
return AVERROR(ENOSYS); |
55 | 55 |
} |
56 | 56 |
|
57 |
-int ff_qsv_error(int mfx_err) |
|
57 |
+static const struct { |
|
58 |
+ mfxStatus mfxerr; |
|
59 |
+ int averr; |
|
60 |
+ const char *desc; |
|
61 |
+} qsv_errors[] = { |
|
62 |
+ { MFX_ERR_NONE, 0, "success" }, |
|
63 |
+ { MFX_ERR_UNKNOWN, AVERROR_UNKNOWN, "unknown error" }, |
|
64 |
+ { MFX_ERR_NULL_PTR, AVERROR(EINVAL), "NULL pointer" }, |
|
65 |
+ { MFX_ERR_UNSUPPORTED, AVERROR(ENOSYS), "unsupported" }, |
|
66 |
+ { MFX_ERR_MEMORY_ALLOC, AVERROR(ENOMEM), "failed to allocate memory" }, |
|
67 |
+ { MFX_ERR_NOT_ENOUGH_BUFFER, AVERROR(ENOMEM), "insufficient input/output buffer" }, |
|
68 |
+ { MFX_ERR_INVALID_HANDLE, AVERROR(EINVAL), "invalid handle" }, |
|
69 |
+ { MFX_ERR_LOCK_MEMORY, AVERROR(EIO), "failed to lock the memory block" }, |
|
70 |
+ { MFX_ERR_NOT_INITIALIZED, AVERROR_BUG, "not initialized" }, |
|
71 |
+ { MFX_ERR_NOT_FOUND, AVERROR(ENOSYS), "specified object was not found" }, |
|
72 |
+ { MFX_ERR_MORE_DATA, AVERROR(EAGAIN), "expect more data at input" }, |
|
73 |
+ { MFX_ERR_MORE_SURFACE, AVERROR(EAGAIN), "expect more surface at output" }, |
|
74 |
+ { MFX_ERR_ABORTED, AVERROR_UNKNOWN, "operation aborted" }, |
|
75 |
+ { MFX_ERR_DEVICE_LOST, AVERROR(EIO), "device lost" }, |
|
76 |
+ { MFX_ERR_INCOMPATIBLE_VIDEO_PARAM, AVERROR(EINVAL), "incompatible video parameters" }, |
|
77 |
+ { MFX_ERR_INVALID_VIDEO_PARAM, AVERROR(EINVAL), "invalid video parameters" }, |
|
78 |
+ { MFX_ERR_UNDEFINED_BEHAVIOR, AVERROR_BUG, "undefined behavior" }, |
|
79 |
+ { MFX_ERR_DEVICE_FAILED, AVERROR(EIO), "device failed" }, |
|
80 |
+ { MFX_ERR_MORE_BITSTREAM, AVERROR(EAGAIN), "expect more bitstream at output" }, |
|
81 |
+ { MFX_ERR_INCOMPATIBLE_AUDIO_PARAM, AVERROR(EINVAL), "incompatible audio parameters" }, |
|
82 |
+ { MFX_ERR_INVALID_AUDIO_PARAM, AVERROR(EINVAL), "invalid audio parameters" }, |
|
83 |
+ |
|
84 |
+ { MFX_WRN_IN_EXECUTION, 0, "operation in execution" }, |
|
85 |
+ { MFX_WRN_DEVICE_BUSY, 0, "device busy" }, |
|
86 |
+ { MFX_WRN_VIDEO_PARAM_CHANGED, 0, "video parameters changed" }, |
|
87 |
+ { MFX_WRN_PARTIAL_ACCELERATION, 0, "partial acceleration" }, |
|
88 |
+ { MFX_WRN_INCOMPATIBLE_VIDEO_PARAM, 0, "incompatible video parameters" }, |
|
89 |
+ { MFX_WRN_VALUE_NOT_CHANGED, 0, "value is saturated" }, |
|
90 |
+ { MFX_WRN_OUT_OF_RANGE, 0, "value out of range" }, |
|
91 |
+ { MFX_WRN_FILTER_SKIPPED, 0, "filter skipped" }, |
|
92 |
+ { MFX_WRN_INCOMPATIBLE_AUDIO_PARAM, 0, "incompatible audio parameters" }, |
|
93 |
+}; |
|
94 |
+ |
|
95 |
+int ff_qsv_map_error(mfxStatus mfx_err, const char **desc) |
|
58 | 96 |
{ |
59 |
- switch (mfx_err) { |
|
60 |
- case MFX_ERR_NONE: |
|
61 |
- return 0; |
|
62 |
- case MFX_ERR_MEMORY_ALLOC: |
|
63 |
- case MFX_ERR_NOT_ENOUGH_BUFFER: |
|
64 |
- return AVERROR(ENOMEM); |
|
65 |
- case MFX_ERR_INVALID_HANDLE: |
|
66 |
- return AVERROR(EINVAL); |
|
67 |
- case MFX_ERR_DEVICE_FAILED: |
|
68 |
- case MFX_ERR_DEVICE_LOST: |
|
69 |
- case MFX_ERR_LOCK_MEMORY: |
|
70 |
- return AVERROR(EIO); |
|
71 |
- case MFX_ERR_NULL_PTR: |
|
72 |
- case MFX_ERR_UNDEFINED_BEHAVIOR: |
|
73 |
- case MFX_ERR_NOT_INITIALIZED: |
|
74 |
- return AVERROR_BUG; |
|
75 |
- case MFX_ERR_UNSUPPORTED: |
|
76 |
- case MFX_ERR_NOT_FOUND: |
|
77 |
- return AVERROR(ENOSYS); |
|
78 |
- case MFX_ERR_MORE_DATA: |
|
79 |
- case MFX_ERR_MORE_SURFACE: |
|
80 |
- case MFX_ERR_MORE_BITSTREAM: |
|
81 |
- return AVERROR(EAGAIN); |
|
82 |
- case MFX_ERR_INCOMPATIBLE_VIDEO_PARAM: |
|
83 |
- case MFX_ERR_INVALID_VIDEO_PARAM: |
|
84 |
- return AVERROR(EINVAL); |
|
85 |
- case MFX_ERR_ABORTED: |
|
86 |
- case MFX_ERR_UNKNOWN: |
|
87 |
- default: |
|
88 |
- return AVERROR_UNKNOWN; |
|
97 |
+ int i; |
|
98 |
+ for (i = 0; i < FF_ARRAY_ELEMS(qsv_errors); i++) { |
|
99 |
+ if (qsv_errors[i].mfxerr == mfx_err) { |
|
100 |
+ if (desc) |
|
101 |
+ *desc = qsv_errors[i].desc; |
|
102 |
+ return qsv_errors[i].averr; |
|
103 |
+ } |
|
89 | 104 |
} |
105 |
+ if (desc) |
|
106 |
+ *desc = "unknown error"; |
|
107 |
+ return AVERROR_UNKNOWN; |
|
108 |
+} |
|
109 |
+ |
|
110 |
+int ff_qsv_print_error(void *log_ctx, mfxStatus err, |
|
111 |
+ const char *error_string) |
|
112 |
+{ |
|
113 |
+ const char *desc; |
|
114 |
+ int ret; |
|
115 |
+ ret = ff_qsv_map_error(err, &desc); |
|
116 |
+ av_log(log_ctx, AV_LOG_ERROR, "%s: %s (%d)\n", error_string, desc, err); |
|
117 |
+ return ret; |
|
90 | 118 |
} |
91 | 119 |
|
92 | 120 |
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc) |
... | ... |
@@ -138,9 +166,10 @@ static int qsv_load_plugins(mfxSession session, const char *load_plugins, |
138 | 138 |
|
139 | 139 |
ret = MFXVideoUSER_Load(session, &uid, 1); |
140 | 140 |
if (ret < 0) { |
141 |
- av_log(logctx, AV_LOG_ERROR, "Could not load the requested plugin: %s\n", |
|
142 |
- plugin); |
|
143 |
- err = ff_qsv_error(ret); |
|
141 |
+ char errorbuf[128]; |
|
142 |
+ snprintf(errorbuf, sizeof(errorbuf), |
|
143 |
+ "Could not load the requested plugin '%s'", plugin); |
|
144 |
+ err = ff_qsv_print_error(logctx, ret, errorbuf); |
|
144 | 145 |
goto load_plugin_fail; |
145 | 146 |
} |
146 | 147 |
|
... | ... |
@@ -166,10 +195,9 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session, |
166 | 166 |
int ret; |
167 | 167 |
|
168 | 168 |
ret = MFXInit(impl, &ver, session); |
169 |
- if (ret < 0) { |
|
170 |
- av_log(avctx, AV_LOG_ERROR, "Error initializing an internal MFX session\n"); |
|
171 |
- return ff_qsv_error(ret); |
|
172 |
- } |
|
169 |
+ if (ret < 0) |
|
170 |
+ return ff_qsv_print_error(avctx, ret, |
|
171 |
+ "Error initializing an internal MFX session"); |
|
173 | 172 |
|
174 | 173 |
ret = qsv_load_plugins(*session, load_plugins, avctx); |
175 | 174 |
if (ret < 0) { |
... | ... |
@@ -282,10 +310,9 @@ int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, |
282 | 282 |
err = MFXQueryIMPL(parent_session, &impl); |
283 | 283 |
if (err == MFX_ERR_NONE) |
284 | 284 |
err = MFXQueryVersion(parent_session, &ver); |
285 |
- if (err != MFX_ERR_NONE) { |
|
286 |
- av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n"); |
|
287 |
- return ff_qsv_error(err); |
|
288 |
- } |
|
285 |
+ if (err != MFX_ERR_NONE) |
|
286 |
+ return ff_qsv_print_error(avctx, err, |
|
287 |
+ "Error querying the session attributes"); |
|
289 | 288 |
|
290 | 289 |
for (i = 0; i < FF_ARRAY_ELEMS(handle_types); i++) { |
291 | 290 |
err = MFXVideoCORE_GetHandle(parent_session, handle_types[i], &handle); |
... | ... |
@@ -301,18 +328,15 @@ int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, |
301 | 301 |
} |
302 | 302 |
|
303 | 303 |
err = MFXInit(impl, &ver, &session); |
304 |
- if (err != MFX_ERR_NONE) { |
|
305 |
- av_log(avctx, AV_LOG_ERROR, |
|
306 |
- "Error initializing a child MFX session: %d\n", err); |
|
307 |
- return ff_qsv_error(err); |
|
308 |
- } |
|
304 |
+ if (err != MFX_ERR_NONE) |
|
305 |
+ return ff_qsv_print_error(avctx, err, |
|
306 |
+ "Error initializing a child MFX session"); |
|
309 | 307 |
|
310 | 308 |
if (handle) { |
311 | 309 |
err = MFXVideoCORE_SetHandle(session, handle_type, handle); |
312 |
- if (err != MFX_ERR_NONE) { |
|
313 |
- av_log(avctx, AV_LOG_ERROR, "Error setting a HW handle: %d\n", err); |
|
314 |
- return ff_qsv_error(err); |
|
315 |
- } |
|
310 |
+ if (err != MFX_ERR_NONE) |
|
311 |
+ return ff_qsv_print_error(avctx, err, |
|
312 |
+ "Error setting a HW handle"); |
|
316 | 313 |
} |
317 | 314 |
|
318 | 315 |
ret = qsv_load_plugins(session, load_plugins, avctx); |
... | ... |
@@ -334,10 +358,9 @@ int ff_qsv_init_session_hwcontext(AVCodecContext *avctx, mfxSession *psession, |
334 | 334 |
qsv_frames_ctx->mids[i] = frames_hwctx->surfaces[i].Data.MemId; |
335 | 335 |
|
336 | 336 |
err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator); |
337 |
- if (err != MFX_ERR_NONE) { |
|
338 |
- av_log(avctx, AV_LOG_ERROR, "Error setting a frame allocator: %d\n", err); |
|
339 |
- return ff_qsv_error(err); |
|
340 |
- } |
|
337 |
+ if (err != MFX_ERR_NONE) |
|
338 |
+ return ff_qsv_print_error(avctx, err, |
|
339 |
+ "Error setting a frame allocator"); |
|
341 | 340 |
} |
342 | 341 |
|
343 | 342 |
*psession = session; |
... | ... |
@@ -57,7 +57,10 @@ typedef struct QSVFramesContext { |
57 | 57 |
/** |
58 | 58 |
* Convert a libmfx error code into a libav error code. |
59 | 59 |
*/ |
60 |
-int ff_qsv_error(int mfx_err); |
|
60 |
+int ff_qsv_map_error(mfxStatus mfx_err, const char **desc); |
|
61 |
+ |
|
62 |
+int ff_qsv_print_error(void *log_ctx, mfxStatus err, |
|
63 |
+ const char *error_string); |
|
61 | 64 |
|
62 | 65 |
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id); |
63 | 66 |
|
... | ... |
@@ -161,10 +161,9 @@ static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q) |
161 | 161 |
param.NumExtParam = q->nb_ext_buffers; |
162 | 162 |
|
163 | 163 |
ret = MFXVideoDECODE_Init(q->session, ¶m); |
164 |
- if (ret < 0) { |
|
165 |
- av_log(avctx, AV_LOG_ERROR, "Error initializing the MFX video decoder\n"); |
|
166 |
- return ff_qsv_error(ret); |
|
167 |
- } |
|
164 |
+ if (ret < 0) |
|
165 |
+ return ff_qsv_print_error(avctx, ret, |
|
166 |
+ "Error initializing the MFX video decoder"); |
|
168 | 167 |
|
169 | 168 |
q->frame_info = param.mfx.FrameInfo; |
170 | 169 |
|
... | ... |
@@ -298,9 +297,9 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q, |
298 | 298 |
ret != MFX_ERR_MORE_DATA && |
299 | 299 |
ret != MFX_WRN_VIDEO_PARAM_CHANGED && |
300 | 300 |
ret != MFX_ERR_MORE_SURFACE) { |
301 |
- av_log(avctx, AV_LOG_ERROR, "Error during QSV decoding.\n"); |
|
302 | 301 |
av_freep(&sync); |
303 |
- return ff_qsv_error(ret); |
|
302 |
+ return ff_qsv_print_error(avctx, ret, |
|
303 |
+ "Error during QSV decoding."); |
|
304 | 304 |
} |
305 | 305 |
|
306 | 306 |
/* make sure we do not enter an infinite loop if the SDK |
... | ... |
@@ -601,7 +601,8 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) |
601 | 601 |
|
602 | 602 |
ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param); |
603 | 603 |
if (ret < 0) |
604 |
- return ff_qsv_error(ret); |
|
604 |
+ return ff_qsv_print_error(avctx, ret, |
|
605 |
+ "Error calling GetVideoParam"); |
|
605 | 606 |
|
606 | 607 |
q->packet_size = q->param.mfx.BufferSizeInKB * 1000; |
607 | 608 |
|
... | ... |
@@ -750,10 +751,9 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) |
750 | 750 |
return ret; |
751 | 751 |
|
752 | 752 |
ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req); |
753 |
- if (ret < 0) { |
|
754 |
- av_log(avctx, AV_LOG_ERROR, "Error querying the encoding parameters\n"); |
|
755 |
- return ff_qsv_error(ret); |
|
756 |
- } |
|
753 |
+ if (ret < 0) |
|
754 |
+ return ff_qsv_print_error(avctx, ret, |
|
755 |
+ "Error querying the encoding parameters"); |
|
757 | 756 |
|
758 | 757 |
if (opaque_alloc) { |
759 | 758 |
ret = qsv_init_opaque_alloc(avctx, q); |
... | ... |
@@ -791,10 +791,9 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) |
791 | 791 |
} |
792 | 792 |
|
793 | 793 |
ret = MFXVideoENCODE_Init(q->session, &q->param); |
794 |
- if (ret < 0) { |
|
795 |
- av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n"); |
|
796 |
- return ff_qsv_error(ret); |
|
797 |
- } |
|
794 |
+ if (ret < 0) |
|
795 |
+ return ff_qsv_print_error(avctx, ret, |
|
796 |
+ "Error initializing the encoder"); |
|
798 | 797 |
|
799 | 798 |
ret = qsv_retrieve_enc_params(avctx, q); |
800 | 799 |
if (ret < 0) { |
... | ... |
@@ -979,7 +978,8 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, |
979 | 979 |
av_packet_unref(&new_pkt); |
980 | 980 |
av_freep(&bs); |
981 | 981 |
av_freep(&sync); |
982 |
- return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret); |
|
982 |
+ return (ret == MFX_ERR_MORE_DATA) ? |
|
983 |
+ 0 : ff_qsv_print_error(avctx, ret, "Error during encoding"); |
|
983 | 984 |
} |
984 | 985 |
|
985 | 986 |
if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame) |