diff mbox

[FFmpeg-devel,v4,04/14] avcodec/videotoolbox: print descriptive errors on decode failures

Message ID 20171110214059.84891-4-ffmpeg@tmm1.net
State Accepted
Commit 6515e2834a51e651aa9855d071291eeb8256dbb6
Headers show

Commit Message

Aman Gupta Nov. 10, 2017, 9:40 p.m. UTC
From: Aman Gupta <aman@tmm1.net>

---
 libavcodec/videotoolbox.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index a4a282c33a..9db2e1116b 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -572,9 +572,22 @@  static OSStatus videotoolbox_session_decode_frame(AVCodecContext *avctx)
     return status;
 }
 
+static const char *videotoolbox_error_string(OSStatus status)
+{
+    switch (status) {
+        case kVTVideoDecoderBadDataErr:
+            return "bad data";
+        case kVTVideoDecoderMalfunctionErr:
+            return "decoder malfunction";
+        case kVTInvalidSessionErr:
+            return "invalid session";
+    }
+    return "unknown";
+}
+
 static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
 {
-    int status;
+    OSStatus status;
     AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
     VTContext *vtctx = avctx->internal->hwaccel_priv_data;
 
@@ -582,9 +595,8 @@  static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
         return AVERROR_INVALIDDATA;
 
     status = videotoolbox_session_decode_frame(avctx);
-
-    if (status) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
+    if (status != noErr) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", videotoolbox_error_string(status), (int)status);
         return AVERROR_UNKNOWN;
     }