diff mbox

[FFmpeg-devel,9/9] avcodec/videotoolbox: create avcC even when h264 extradata is missing

Message ID 20170926003631.55571-9-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>

Removes the avctx->extradata_size requirement when creating avcC, since
avctx->extradata is only used in the esds code path.

This fixes an issue where the VideoToolbox decoder would not work unless
avformat_find_stream_info() was called.
---
 libavcodec/videotoolbox.c | 65 +++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 33 deletions(-)

Comments

Carl Eugen Hoyos Sept. 26, 2017, 11:25 a.m. UTC | #1
2017-09-26 2:36 GMT+02:00 Aman Gupta <ffmpeg@tmm1.net>:

> Removes the avctx->extradata_size requirement when
> creating avcC, since avctx->extradata is only used in the
> esds code path.

Please split the patch in a functional and a cosmetic change.

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

> From: Aman Gupta <aman@tmm1.net>
> 
> Removes the avctx->extradata_size requirement when creating avcC, since
> avctx->extradata is only used in the esds code path.
> 
> This fixes an issue where the VideoToolbox decoder would not work unless
> avformat_find_stream_info() was called.
> ---
>  libavcodec/videotoolbox.c | 65 +++++++++++++++++++++++------------------------
>  1 file changed, 32 insertions(+), 33 deletions(-)
> 
> diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
> index 6c8477c2ce..de51b9a7c4 100644
> --- a/libavcodec/videotoolbox.c
> +++ b/libavcodec/videotoolbox.c
> @@ -538,46 +538,45 @@ static CFDictionaryRef videotoolbox_decoder_config_create(CMVideoCodecType codec
>                           kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
>                           kCFBooleanTrue);
>  
> -    if (avctx->extradata_size) {
> -        CFMutableDictionaryRef avc_info;
> -        CFDataRef data = NULL;
> +    CFMutableDictionaryRef avc_info;
> +    CFDataRef data = NULL;
>  
> -        avc_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
> -                                             1,
> -                                             &kCFTypeDictionaryKeyCallBacks,
> -                                             &kCFTypeDictionaryValueCallBacks);
> +    avc_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
> +                                         1,
> +                                         &kCFTypeDictionaryKeyCallBacks,
> +                                         &kCFTypeDictionaryValueCallBacks);
>  
> -        switch (codec_type) {
> -        case kCMVideoCodecType_MPEG4Video :
> +    switch (codec_type) {
> +    case kCMVideoCodecType_MPEG4Video:
> +        if (avctx->extradata_size)
>              data = videotoolbox_esds_extradata_create(avctx);
> -            if (data)
> -                CFDictionarySetValue(avc_info, CFSTR("esds"), data);
> -            break;
> -        case kCMVideoCodecType_H264 : {
> -            H264Context *h = avctx->priv_data;
> -            if (TARGET_OS_IPHONE && h->ps.sps->frame_mbs_only_flag == 0) {
> -                av_log(avctx, AV_LOG_ERROR, "VideoToolbox cannot decode interlaced fields on iOS\n");
> -                CFRelease(avc_info);
> -                goto fail;
> -            }
> -            data = ff_videotoolbox_avcc_extradata_create(avctx);
> -            if (data)
> -                CFDictionarySetValue(avc_info, CFSTR("avcC"), data);
> -            break;
> -        }
> -        default:
> -            break;
> +        if (data)
> +            CFDictionarySetValue(avc_info, CFSTR("esds"), data);
> +        break;
> +    case kCMVideoCodecType_H264: {
> +        H264Context *h = avctx->priv_data;
> +        if (TARGET_OS_IPHONE && h->ps.sps->frame_mbs_only_flag == 0) {
> +            av_log(avctx, AV_LOG_ERROR, "VideoToolbox cannot decode interlaced fields on iOS\n");
> +            CFRelease(avc_info);
> +            goto fail;
>          }
> +        data = ff_videotoolbox_avcc_extradata_create(avctx);
> +        if (data)
> +            CFDictionarySetValue(avc_info, CFSTR("avcC"), data);
> +        break;
> +    }
> +    default:
> +        break;
> +    }
>  
> -        CFDictionarySetValue(config_info,
> -                kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
> -                avc_info);
> +    CFDictionarySetValue(config_info,
> +            kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
> +            avc_info);
>  
> -        if (data)
> -            CFRelease(data);
> +    if (data)
> +        CFRelease(data);
>  
> -        CFRelease(avc_info);
> -    }
> +    CFRelease(avc_info);
>      return config_info;
>  
>  fail:

LGTM.
diff mbox

Patch

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 6c8477c2ce..de51b9a7c4 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -538,46 +538,45 @@  static CFDictionaryRef videotoolbox_decoder_config_create(CMVideoCodecType codec
                          kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
                          kCFBooleanTrue);
 
-    if (avctx->extradata_size) {
-        CFMutableDictionaryRef avc_info;
-        CFDataRef data = NULL;
+    CFMutableDictionaryRef avc_info;
+    CFDataRef data = NULL;
 
-        avc_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
-                                             1,
-                                             &kCFTypeDictionaryKeyCallBacks,
-                                             &kCFTypeDictionaryValueCallBacks);
+    avc_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
+                                         1,
+                                         &kCFTypeDictionaryKeyCallBacks,
+                                         &kCFTypeDictionaryValueCallBacks);
 
-        switch (codec_type) {
-        case kCMVideoCodecType_MPEG4Video :
+    switch (codec_type) {
+    case kCMVideoCodecType_MPEG4Video:
+        if (avctx->extradata_size)
             data = videotoolbox_esds_extradata_create(avctx);
-            if (data)
-                CFDictionarySetValue(avc_info, CFSTR("esds"), data);
-            break;
-        case kCMVideoCodecType_H264 : {
-            H264Context *h = avctx->priv_data;
-            if (TARGET_OS_IPHONE && h->ps.sps->frame_mbs_only_flag == 0) {
-                av_log(avctx, AV_LOG_ERROR, "VideoToolbox cannot decode interlaced fields on iOS\n");
-                CFRelease(avc_info);
-                goto fail;
-            }
-            data = ff_videotoolbox_avcc_extradata_create(avctx);
-            if (data)
-                CFDictionarySetValue(avc_info, CFSTR("avcC"), data);
-            break;
-        }
-        default:
-            break;
+        if (data)
+            CFDictionarySetValue(avc_info, CFSTR("esds"), data);
+        break;
+    case kCMVideoCodecType_H264: {
+        H264Context *h = avctx->priv_data;
+        if (TARGET_OS_IPHONE && h->ps.sps->frame_mbs_only_flag == 0) {
+            av_log(avctx, AV_LOG_ERROR, "VideoToolbox cannot decode interlaced fields on iOS\n");
+            CFRelease(avc_info);
+            goto fail;
         }
+        data = ff_videotoolbox_avcc_extradata_create(avctx);
+        if (data)
+            CFDictionarySetValue(avc_info, CFSTR("avcC"), data);
+        break;
+    }
+    default:
+        break;
+    }
 
-        CFDictionarySetValue(config_info,
-                kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
-                avc_info);
+    CFDictionarySetValue(config_info,
+            kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
+            avc_info);
 
-        if (data)
-            CFRelease(data);
+    if (data)
+        CFRelease(data);
 
-        CFRelease(avc_info);
-    }
+    CFRelease(avc_info);
     return config_info;
 
 fail: