]> git.sesse.net Git - vlc/blobdiff - modules/codec/crystalhd.c
sftp: implement directory listing
[vlc] / modules / codec / crystalhd.c
index ff60509d521041485685d71742e014cc7e390414..b8e39afa8625860e79879f75661097d0eff5b52c 100644 (file)
@@ -1,18 +1,20 @@
 /*****************************************************************************
+ * crystalhd.c: CrystalHD decoder
+ *****************************************************************************
  * Copyright © 2010-2011 VideoLAN
  *
  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
  *          Narendra Sankar <nsankar@broadcom.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
  * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this program; if not, write to the Free Software Foundation,
@@ -37,6 +39,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
+#include "h264_nal.h"
 
 /* Workaround for some versions of libcrystalHD */
 #if !defined(_WIN32) && !defined(__APPLE__)
@@ -197,7 +200,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     };
     for( int i = 0; i < PATHS_NB; i++ )
     {
-        HINSTANCE p_bcm_dll = LoadLibrary( psz_paths[i] );
+        HINSTANCE p_bcm_dll = LoadLibraryA( psz_paths[i] );
         if( p_bcm_dll )
         {
             p_sys->p_bcm_dll = p_bcm_dll;
@@ -211,7 +214,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     }
 
 #define LOAD_SYM( a ) \
-    BC_FUNC( a )  = (void *)GetProcAddress( p_sys->p_bcm_dll, TEXT( #a ) ); \
+    BC_FUNC( a )  = (void *)GetProcAddress( p_sys->p_bcm_dll, ( #a ) ); \
     if( !BC_FUNC( a ) ) { \
         msg_Err( p_dec, "missing symbol " # a ); return VLC_EGENERIC; }
 
@@ -578,7 +581,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             break;
     }
     if( p_pic )
-        decoder_DeletePicture( p_dec, p_pic );
+        picture_Release( p_pic );
     return NULL;
 }
 
@@ -596,7 +599,7 @@ static void crystal_CopyPicture ( picture_t *p_pic, BC_DTS_PROC_OUT* p_out )
     p_dst_end     = p_dst  + (i_dst_stride * p_out->PicInfo.height);
 
     for( ; p_dst < p_dst_end; p_dst += i_dst_stride, p_src += (p_out->PicInfo.width * 2))
-        vlc_memcpy( p_dst, p_src, p_out->PicInfo.width * 2); // Copy in bytes
+        memcpy( p_dst, p_src, p_out->PicInfo.width * 2); // Copy in bytes
 }
 #endif
 
@@ -606,9 +609,7 @@ static int crystal_insert_sps_pps( decoder_t *p_dec,
                                    uint32_t i_buf_size)
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    int i_profile;
-    uint32_t i_data_size = i_buf_size, i_nal_size;
-    unsigned int i_loop_end;
+    int ret;
 
     p_sys->i_sps_pps_size = 0;
 
@@ -616,68 +617,14 @@ static int crystal_insert_sps_pps( decoder_t *p_dec,
     if( !p_sys->p_sps_pps_buf )
         return VLC_ENOMEM;
 
-    /* */
-    if( i_data_size < 7 )
-    {
-        msg_Err( p_dec, "Input Metadata too small" );
-        goto error;
-    }
-
-    /* Read infos in first 6 bytes */
-    i_profile         = (p_buf[1] << 16) | (p_buf[2] << 8) | p_buf[3];
-    p_sys->i_nal_size = (p_buf[4] & 0x03) + 1;
-    p_buf            += 5;
-    i_data_size      -= 5;
-
-    for ( unsigned int j = 0; j < 2; j++ )
-    {
-        /* First time is SPS, Second is PPS */
-        if( i_data_size < 1 )
-        {
-            msg_Err( p_dec, "PPS too small after processing SPS/PPS %u",
-                    i_data_size );
-            goto error;
-        }
-        i_loop_end = p_buf[0] & (j == 0 ? 0x1f : 0xff);
-        p_buf++; i_data_size--;
-
-        for ( unsigned int i = 0; i < i_loop_end; i++)
-        {
-            if( i_data_size < 2 )
-            {
-                msg_Err( p_dec, "SPS is too small %u", i_data_size );
-                goto error;
-            }
-
-            i_nal_size = (p_buf[0] << 8) | p_buf[1];
-            p_buf += 2;
-            i_data_size -= 2;
-
-            if( i_data_size < i_nal_size )
-            {
-                msg_Err( p_dec, "SPS size does not match NAL specified size %u",
-                        i_data_size );
-                goto error;
-            }
-
-            p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 0;
-            p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 0;
-            p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 0;
-            p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 1;
+    ret = convert_sps_pps( p_dec, p_buf, i_buf_size, p_sys->p_sps_pps_buf,
+                           p_dec->fmt_in.i_extra * 2, &p_sys->i_sps_pps_size,
+                           &p_sys->i_nal_size );
+    if( !ret )
+        return ret;
 
-            memcpy( p_sys->p_sps_pps_buf + p_sys->i_sps_pps_size, p_buf, i_nal_size );
-            p_sys->i_sps_pps_size += i_nal_size;
-
-            p_buf += i_nal_size;
-            i_data_size -= i_nal_size;
-        }
-    }
-
-    return VLC_SUCCESS;
-
-error:
     free( p_sys->p_sps_pps_buf );
     p_sys->p_sps_pps_buf = NULL;
-    return VLC_ENOMEM;
+    return ret;
 }