]> git.sesse.net Git - vlc/blobdiff - modules/codec/realvideo.c
freetype: use var_Inherit.
[vlc] / modules / codec / realvideo.c
index 6285a6a22279c463931e3c821a68141e301a39f2..3e43f56c97134f9a4d1033e55c801517d5ea6bda 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_vout.h>
 #include <vlc_codec.h>
 
 #ifdef LOADER
@@ -128,13 +127,13 @@ static void Close( vlc_object_t * );
 //static int  OpenPacketizer( vlc_object_t * );
 static picture_t *DecodeVideo( decoder_t *, block_t ** );
 
-vlc_module_begin();
-    set_description( N_("RealVideo library decoder") );
-    set_capability( "decoder", 10 );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("RealVideo library decoder") )
+    set_capability( "decoder", 10 )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 
 /*****************************************************************************
@@ -146,15 +145,15 @@ static void * load_syms(decoder_t *p_dec, const char *path)
 {
     void *handle;
 
-    msg_Dbg( p_dec, "opening win32 dll '%s'\n", path);
+    msg_Dbg( p_dec, "opening win32 dll '%s'", path);
 #ifdef LOADER
     Setup_LDT_Keeper();
 #endif
     handle = LoadLibraryA(path);
-    msg_Dbg( p_dec, "win32 real codec handle=%p  \n",handle);
+    msg_Dbg( p_dec, "win32 real codec handle=%p",handle);
     if (!handle)
     {
-        msg_Err( p_dec, "Error loading dll\n");
+        msg_Err( p_dec, "Error loading dll");
         return NULL;
     }
 
@@ -168,7 +167,7 @@ static void * load_syms(decoder_t *p_dec, const char *path)
         dll_type = 1;
         return handle;
     }
-    msg_Err( p_dec, "Error resolving symbols! (version incompatibility?)\n");
+    msg_Err( p_dec, "Error resolving symbols! (version incompatibility?)");
     FreeLibrary(handle);
     return NULL; // error
 }
@@ -177,12 +176,12 @@ static void * load_syms_linux(decoder_t *p_dec, const char *path)
 {
     void *handle;
 
-    msg_Dbg( p_dec, "opening shared obj '%s'\n", path);
+    msg_Dbg( p_dec, "opening shared obj '%s'", path);
 
     handle = dlopen (path, RTLD_LAZY);
     if (!handle) 
     {
-        msg_Err( p_dec,"Error: %s\n",dlerror());
+        msg_Err( p_dec,"Error: %s",dlerror());
         return NULL;
     }
 
@@ -197,24 +196,27 @@ static void * load_syms_linux(decoder_t *p_dec, const char *path)
         return handle;
     }
 
-    msg_Err( p_dec,"Error resolving symbols! (version incompatibility?)\n");
+    msg_Err( p_dec,"Error resolving symbols! (version incompatibility?)");
     dlclose(handle);
     return 0;
 }
 #endif
 
+static vlc_mutex_t rm_mutex = VLC_STATIC_MUTEX;
+
 static int InitVideo(decoder_t *p_dec)
 {
     int result;
     struct rv_init_t init_data;
     char fcc[4];
-    vlc_mutex_t  *lock;
     char *g_decode_path;
 
     int  i_vide = p_dec->fmt_in.i_extra;
     unsigned int *p_vide = p_dec->fmt_in.p_extra;
-    decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
-    memset(p_sys,0,sizeof( decoder_sys_t ) );
+    decoder_sys_t *p_sys = calloc( 1, sizeof( decoder_sys_t ) );
+
+    if( !p_sys )
+        return VLC_ENOMEM;
 
     if( i_vide < 8 )
     {
@@ -222,7 +224,7 @@ static int InitVideo(decoder_t *p_dec)
             free( p_sys );
             return VLC_EGENERIC;
     }
-    if (p_sys->plane) free(p_sys->plane);
+    free( p_sys->plane );
     p_sys->plane = malloc (p_dec->fmt_in.video.i_width*p_dec->fmt_in.video.i_height*3/2 + 1024 );
     if (NULL == p_sys->plane)
     {
@@ -254,46 +256,51 @@ static int InitVideo(decoder_t *p_dec)
     if( (p_sys->rv_handle = load_syms(p_dec, g_decode_path)) )
         b_so_opened = true;
 #else
-    const char *ppsz_path[] =
+    static const char psz_paths[] =
     {
-        "/usr/lib/win32",
-        "/usr/lib/codecs",
-        "/usr/local/RealPlayer8/Codecs",
-        "/usr/RealPlayer8/Codecs",
-        "/usr/lib/RealPlayer8/Codecs",
-        "/opt/RealPlayer8/Codecs",
-        "/usr/lib/RealPlayer9/users/Real/Codecs",
-        "/usr/lib/RealPlayer10/codecs",
-        "/usr/lib/RealPlayer10GOLD/codecs",
-        "/usr/lib/helix/player/codecs",
-        "/usr/lib64/RealPlayer8/Codecs",
-        "/usr/lib64/RealPlayer9/users/Real/Codecs",
-        "/usr/lib64/RealPlayer10/codecs",
-        "/usr/lib64/RealPlayer10GOLD/codecs",
-        "/usr/local/lib/codecs",
-        NULL
+        "/usr/lib/win32\0"
+        "/usr/lib/codecs\0"
+        "/usr/local/RealPlayer8/Codecs\0"
+        "/usr/RealPlayer8/Codecs\0"
+        "/usr/lib/RealPlayer8/Codecs\0"
+        "/opt/RealPlayer8/Codecs\0"
+        "/usr/lib/RealPlayer9/users/Real/Codecs\0"
+        "/usr/lib/RealPlayer10/codecs\0"
+        "/usr/lib/RealPlayer10GOLD/codecs\0"
+        "/usr/lib/helix/player/codecs\0"
+        "/usr/lib64/RealPlayer8/Codecs\0"
+        "/usr/lib64/RealPlayer9/users/Real/Codecs\0"
+        "/usr/lib64/RealPlayer10/codecs\0"
+        "/usr/lib64/RealPlayer10GOLD/codecs\0"
+        "/usr/local/lib/codecs\0"
+        "\0"
     };
 
-    for( int i = 0; ppsz_path[i]; i++ )
+    for( size_t i = 0; psz_paths[i]; i += strlen( psz_paths + i ) + 1 )
     {
-        asprintf( &g_decode_path, "%s/drv4.so.6.0", ppsz_path[i] );
-        if( (p_sys->rv_handle = load_syms_linux(p_dec, g_decode_path)) )
+        if( asprintf( &g_decode_path, "%s/drv4.so.6.0", psz_paths + i ) != -1 )
         {
-            b_so_opened = true;
+            p_sys->rv_handle = load_syms_linux(p_dec, g_decode_path);
             free( g_decode_path );
+        }
+        if( p_sys->rv_handle )
+        {
+            b_so_opened = true;
             break;
         }
 
-        asprintf( &g_decode_path, "%s/drv3.so.6.0", ppsz_path[i] );
-        if( (p_sys->rv_handle = load_syms_linux(p_dec, g_decode_path)) )
+        if( asprintf( &g_decode_path, "%s/drv3.so.6.0", psz_paths + i ) != -1 )
         {
-            b_so_opened = true;
+            p_sys->rv_handle = load_syms_linux(p_dec, g_decode_path);
             free( g_decode_path );
+        }
+        if( p_sys->rv_handle )
+        {
+            b_so_opened = true;
             break;
         }
 
         msg_Dbg( p_dec, "Cannot load real decoder library: %s", g_decode_path);
-        free( g_decode_path );
     }
 #endif
 
@@ -304,9 +311,7 @@ static int InitVideo(decoder_t *p_dec)
         return VLC_EGENERIC;
     }
 
-    lock = var_AcquireMutex( "rm_mutex" );
-    if ( lock == NULL )
-        return VLC_EGENERIC;
+    vlc_mutex_lock( &rm_mutex );
 
     p_sys->handle=NULL;
     #ifdef WIN32
@@ -323,7 +328,7 @@ static int InitVideo(decoder_t *p_dec)
     }
 
     /* setup rv30 codec (codec sub-type and image dimensions): */
-    /*if ( p_dec->fmt_in.i_codec == VLC_FOURCC('R','V','3','0') )*/
+    /*if ( p_dec->fmt_in.i_codec == VLC_CODEC_RV30 )*/
     if (p_vide[1]>=0x20200002)
     {
         int i, cmsg_cnt;
@@ -343,17 +348,18 @@ static int InitVideo(decoder_t *p_dec)
             (*rvyuv_custom_message)(&cmsg_data,p_sys->handle);
     }
     /*
-    es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC( 'Y','V','1','2' ));
-    es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC( 'Y','U','Y','2' ));
+    es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_YV12);
+    es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_YUYV);
      */
-    es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC( 'I', '4', '2', '0'));
+    es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_I420);
      
     p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
     p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
-    p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
+    p_dec->fmt_out.video.i_sar_num = 1;
+    p_dec->fmt_out.video.i_sar_den = 1;
     p_sys->inited = 0;
 
-    vlc_mutex_unlock( lock );
+    vlc_mutex_unlock( &rm_mutex );
     return VLC_SUCCESS;
 }
 
@@ -367,15 +373,12 @@ static int Open( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
 
-    /* create a mutex */
-    var_Create( p_this->p_libvlc, "rm_mutex", VLC_VAR_MUTEX );
-
     switch ( p_dec->fmt_in.i_codec )
     {
-    case VLC_FOURCC('R','V','1','0')
-    case VLC_FOURCC('R','V','2','0')
-    case VLC_FOURCC('R','V','3','0'):
-    case VLC_FOURCC('R','V','4','0')
+    case VLC_CODEC_RV10
+    case VLC_CODEC_RV20
+    case VLC_CODEC_RV30:
+    case VLC_CODEC_RV40
         p_dec->p_sys = NULL;
         p_dec->pf_decode_video = DecodeVideo;
         return InitVideo(p_dec);
@@ -392,10 +395,9 @@ static void Close( vlc_object_t *p_this )
 {
     decoder_t     *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys = p_dec->p_sys;
-    vlc_mutex_t   *lock;
 
     /* get lock, avoid segfault */
-    lock = var_AcquireMutex( "rm_mutex" );
+    vlc_mutex_lock( &rm_mutex );
 
     #ifdef WIN32
     if (dll_type == 1)
@@ -417,11 +419,8 @@ static void Close( vlc_object_t *p_this )
 #endif
         p_sys->rv_handle=NULL;
 
-    if (p_sys->plane)
-    {
-        free(p_sys->plane);
-        p_sys->plane = NULL;
-    }
+    free( p_sys->plane );
+    p_sys->plane = NULL;
 
     msg_Dbg( p_dec, "FreeLibrary ok." );
 #ifdef LOADER
@@ -430,11 +429,9 @@ static void Close( vlc_object_t *p_this )
 #endif
     p_sys->inited = 0;
 
-    if ( lock )
-    vlc_mutex_unlock( lock );
+    vlc_mutex_unlock( &rm_mutex );
 
-    if ( p_sys )
-        free( p_sys );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -443,7 +440,6 @@ static void Close( vlc_object_t *p_this )
 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    vlc_mutex_t   *lock;
     block_t       *p_block;
     picture_t     *p_pic;
     mtime_t       i_pts;
@@ -458,13 +454,11 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
     p_block = *pp_block;
     *pp_block = NULL;
 
-    i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
+    i_pts = (p_block->i_pts > VLC_TS_INVALID) ? p_block->i_pts : p_block->i_dts;
 
-    lock = var_AcquireMutex( "rm_mutex" );
-    if ( lock == NULL )
-        return NULL;
+    vlc_mutex_lock( &rm_mutex );
 
-    p_pic = p_dec->pf_vout_buffer_new( p_dec );
+    p_pic = decoder_NewPicture( p_dec );
 
     if ( p_pic )
     {
@@ -515,7 +509,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
              || p_dec->fmt_in.video.i_height  != transform_out[4] )
             {
                 msg_Warn(p_dec, "Warning, Real's Header give a wrong "
-                         "information about media's width and height!\n"
+                         "information about media's width and height!"
                          "\tRealHeader: \t %d X %d  \t %d X %d",
                          p_dec->fmt_in.video.i_width,
                          p_dec->fmt_in.video.i_height,
@@ -531,7 +525,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
                     p_dec->fmt_out.video.i_visible_height = 
                     p_dec->fmt_in.video.i_height= transform_out[4];
 
-                    p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
+                    p_dec->fmt_out.video.i_sar_num = 1;
+                    p_dec->fmt_out.video.i_sar_den = 1;
                 }
                 else
                 {
@@ -554,7 +549,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         p_pic->b_force = 1;
     }
 
-    vlc_mutex_unlock( lock );
+    vlc_mutex_unlock( &rm_mutex );
 
     block_Release( p_block );
     return p_pic;