]> git.sesse.net Git - vlc/blobdiff - modules/codec/avcodec/vda.c
vda: minor cleanup
[vlc] / modules / codec / avcodec / vda.c
index 403ab57bf3c06c9c6981ca15b7c00afc580d5152..e2bbd88700fa3a4a957577396e6dec7aacd02e07 100644 (file)
@@ -52,7 +52,6 @@ vlc_module_begin ()
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_VCODEC )
     set_callbacks( Open, Close )
-    add_shortcut ( "vdadecoder" )
     add_integer ( "avcodec-vda-pix-fmt", 0, VDA_PIX_FMT_TEXT,
                   VDA_PIX_FMT_LONGTEXT, false)
         change_integer_list( nvda_pix_fmt_list, nvda_pix_fmt_list_text )
@@ -92,6 +91,9 @@ static void vda_Copy420YpCbCr8Planar( picture_t *p_pic,
     uint8_t *pp_plane[3];
     size_t  pi_pitch[3];
 
+    if (!buffer)
+        return;
+
     CVPixelBufferLockBaseAddress( buffer, 0 );
 
     for( int i = 0; i < 3; i++ )
@@ -104,6 +106,7 @@ static void vda_Copy420YpCbCr8Planar( picture_t *p_pic,
                   i_width, i_height, cache );
 
     CVPixelBufferUnlockBaseAddress( buffer, 0 );
+    CVPixelBufferRelease( buffer );
 }
 
 /*****************************************************************************
@@ -134,13 +137,13 @@ static void vda_Copy422YpCbCr8( picture_t *p_pic,
     }
 
     CVPixelBufferUnlockBaseAddress( buffer, 0 );
+    CVPixelBufferRelease( buffer );
 }
 
-static int Setup( vlc_va_t *p_external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
+static int Setup( vlc_va_t *external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
                   int i_width, int i_height )
 {
-
-    vlc_va_vda_t *p_va = vlc_va_vda_Get( p_external );
+    vlc_va_vda_t *p_va = vlc_va_vda_Get( external );
 
     if( p_va->hw_ctx.width == i_width
         && p_va->hw_ctx.height == i_height
@@ -169,12 +172,14 @@ static int Setup( vlc_va_t *p_external, void **pp_hw_ctx, vlc_fourcc_t *pi_chrom
         case 1 :
             p_va->hw_ctx.cv_pix_fmt_type = kCVPixelFormatType_422YpCbCr8;
             p_va->i_chroma = VLC_CODEC_UYVY;
+            msg_Dbg(p_va->p_log, "using pixel format 422YpCbCr8");
             break;
         case 0 :
         default :
             p_va->hw_ctx.cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8Planar;
             p_va->i_chroma = VLC_CODEC_I420;
             CopyInitCache( &p_va->image_cache, i_width );
+            msg_Dbg(p_va->p_log, "using pixel format 420YpCbCr8Planar");
     }
 
 ok:
@@ -188,16 +193,19 @@ ok:
                                         p_va->i_extradata );
     if( status )
     {
-        msg_Err( p_va->p_log, "Failed to create the decoder : %i", status );
+        msg_Err( p_va->p_log, "Failed to create decoder: %i", status );
         return VLC_EGENERIC;
     }
+    else
+        msg_Dbg( p_va->p_log, "VDA decoder created");
 
     return VLC_SUCCESS;
 }
 
-static int Get( vlc_va_t *p_external, AVFrame *p_ff )
+static int Get( vlc_va_t *external, AVFrame *p_ff )
 {
-    VLC_UNUSED( p_external );
+    msg_Dbg(external, "Get");
+    VLC_UNUSED( external );
 
     /* */
     for( int i = 0; i < 4; i++ )
@@ -212,9 +220,9 @@ static int Get( vlc_va_t *p_external, AVFrame *p_ff )
     return VLC_SUCCESS;
 }
 
-static int Extract( vlc_va_t *p_external, picture_t *p_picture, AVFrame *p_ff )
+static int Extract( vlc_va_t *external, picture_t *p_picture, AVFrame *p_ff )
 {
-    vlc_va_vda_t *p_va = vlc_va_vda_Get( p_external );
+    vlc_va_vda_t *p_va = vlc_va_vda_Get( external );
     CVPixelBufferRef cv_buffer = ( CVPixelBufferRef )p_ff->data[3];
 
     if( !cv_buffer )
@@ -225,8 +233,10 @@ static int Extract( vlc_va_t *p_external, picture_t *p_picture, AVFrame *p_ff )
 
     if( p_va->hw_ctx.cv_pix_fmt_type == kCVPixelFormatType_420YpCbCr8Planar )
     {
-        if( !p_va->image_cache.buffer )
+        if( !p_va->image_cache.buffer ) {
+            CVPixelBufferRelease( cv_buffer );
             return VLC_EGENERIC;
+        }
 
         vda_Copy420YpCbCr8Planar( p_picture,
                                   cv_buffer,
@@ -240,18 +250,20 @@ static int Extract( vlc_va_t *p_external, picture_t *p_picture, AVFrame *p_ff )
     return VLC_SUCCESS;
 }
 
-static void Release( vlc_va_t *p_external, AVFrame *p_ff )
+static void Release( vlc_va_t *external, AVFrame *p_ff )
 {
-    VLC_UNUSED( p_external );
+    VLC_UNUSED( external );
     CVPixelBufferRef cv_buffer = ( CVPixelBufferRef )p_ff->data[3];
 
     if ( cv_buffer )
-        CFRelease( cv_buffer );
+        CVPixelBufferRelease( cv_buffer );
 }
 
-static void Close( vlc_va_t *p_external )
+static void Close( vlc_va_t *external )
 {
-    vlc_va_vda_t *p_va = vlc_va_vda_Get( p_external );
+    vlc_va_vda_t *p_va = vlc_va_vda_Get( external );
+
+    msg_Dbg(p_va->p_log, "destroying VDA decoder");
 
     ff_vda_destroy_decoder( &p_va->hw_ctx ) ;
 
@@ -263,8 +275,12 @@ static void Close( vlc_va_t *p_external )
 
 static int Open( vlc_va_t *external, int i_codec_id, const es_format_t *fmt )
 {
+    msg_Dbg( external, "opening VDA module" );
     if( i_codec_id != AV_CODEC_ID_H264 )
+    {
+        msg_Warn( external, "input codec isn't H264, canceling VDA decoding" );
         return VLC_EGENERIC;
+    }
 
     if( fmt->p_extra == NULL || fmt->i_extra < 7 )
     {