diff mbox

[FFmpeg-devel,5/9] avcodec/videotoolbox: print descriptive errors on decode failures

Message ID 20170926003631.55571-5-ffmpeg@tmm1.net
State Superseded
Headers show

Commit Message

Aman Gupta Sept. 26, 2017, 12:36 a.m. UTC
From: Aman Gupta <aman@tmm1.net>

---
 libavcodec/videotoolbox.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

wm4 Sept. 26, 2017, 12:20 p.m. UTC | #1
On Mon, 25 Sep 2017 17:36:27 -0700
Aman Gupta <ffmpeg@tmm1.net> wrote:

> From: Aman Gupta <aman@tmm1.net>
> 
> ---
>  libavcodec/videotoolbox.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> index 1de556f3e8..f56ab1f8c9 100644
> --- a/libavcodec/videotoolbox.c
> +++ b/libavcodec/videotoolbox.c
> @@ -425,7 +425,22 @@ static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
>      status = videotoolbox_session_decode_frame(avctx);
>  
>      if (status) {
> -        av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
> +        const char *error = NULL;
> +        switch (status) {
> +            case kVTVideoDecoderBadDataErr:
> +                error = "bad data";
> +                break;
> +            case kVTVideoDecoderMalfunctionErr:
> +                error = "decoder malfunction";
> +                break;
> +            case kVTInvalidSessionErr:
> +                error = "invalid session";
> +                break;
> +            default:
> +                error = "unknown";
> +                break;
> +        }
> +        av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", error, status);
>          return AVERROR_UNKNOWN;
>      }
>  

Is status really an int? If not, it should be casted (the safest way to
deal with "opaque" typedefs).

Bonus points for moving the error status->string switch mapping to a
separate function.
diff mbox

Patch

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1de556f3e8..f56ab1f8c9 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -425,7 +425,22 @@  static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
     status = videotoolbox_session_decode_frame(avctx);
 
     if (status) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
+        const char *error = NULL;
+        switch (status) {
+            case kVTVideoDecoderBadDataErr:
+                error = "bad data";
+                break;
+            case kVTVideoDecoderMalfunctionErr:
+                error = "decoder malfunction";
+                break;
+            case kVTInvalidSessionErr:
+                error = "invalid session";
+                break;
+            default:
+                error = "unknown";
+                break;
+        }
+        av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", error, status);
         return AVERROR_UNKNOWN;
     }