]> git.sesse.net Git - vlc/blobdiff - modules/codec/fake.c
Used VLC_CODEC_* and vlc_fourcc_GetCodec when suitable.
[vlc] / modules / codec / fake.c
index 83c17a7ad8fc013bcfdb9142219c852b115b01fc..b9787851c7bf2428357f81516acb7bcf7a91127c 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_codec.h>
 
 #include <vlc_image.h>
@@ -77,41 +78,41 @@ static int FakeCallback( vlc_object_t *, char const *,
 #define CHROMA_LONGTEXT N_( \
     "Force use of a specific chroma for output. Default is I420." )
 
-static const char *ppsz_deinterlace_type[] =
+static const char *const ppsz_deinterlace_type[] =
 {
     "deinterlace", "ffmpeg-deinterlace"
 };
 
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_shortname( _("Fake") );
-    set_description( _("Fake video decoder") );
-    set_capability( "decoder", 1000 );
-    set_callbacks( OpenDecoder, CloseDecoder );
-    add_shortcut( "fake" );
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
+    set_shortname( N_("Fake") )
+    set_description( N_("Fake video decoder") )
+    set_capability( "decoder", 1000 )
+    set_callbacks( OpenDecoder, CloseDecoder )
+    add_shortcut( "fake" )
 
     add_file( "fake-file", "", NULL, FILE_TEXT,
-                FILE_LONGTEXT, false );
+                FILE_LONGTEXT, false )
     add_integer( "fake-file-reload", 0, NULL, RELOAD_TEXT,
-                RELOAD_LONGTEXT, false );
+                RELOAD_LONGTEXT, false )
     add_integer( "fake-width", 0, NULL, WIDTH_TEXT,
-                 WIDTH_LONGTEXT, true );
+                 WIDTH_LONGTEXT, true )
     add_integer( "fake-height", 0, NULL, HEIGHT_TEXT,
-                 HEIGHT_LONGTEXT, true );
+                 HEIGHT_LONGTEXT, true )
     add_bool( "fake-keep-ar", 0, NULL, KEEP_AR_TEXT, KEEP_AR_LONGTEXT,
-              true );
+              true )
     add_string( "fake-aspect-ratio", "", NULL,
-                ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, true );
+                ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, true )
     add_bool( "fake-deinterlace", 0, NULL, DEINTERLACE_TEXT,
-              DEINTERLACE_LONGTEXT, false );
+              DEINTERLACE_LONGTEXT, false )
     add_string( "fake-deinterlace-module", "deinterlace", NULL,
                 DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,
-                false );
-        change_string_list( ppsz_deinterlace_type, 0, 0 );
+                false )
+        change_string_list( ppsz_deinterlace_type, 0, 0 )
     add_string( "fake-chroma", "I420", NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
-                true );
-vlc_module_end();
+                true )
+vlc_module_end ()
 
 struct decoder_sys_t
 {
@@ -142,17 +143,15 @@ static int OpenDecoder( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    p_dec->p_sys = (decoder_sys_t *)malloc( sizeof( decoder_sys_t ) );
+    p_dec->p_sys = calloc( 1, sizeof( *p_dec->p_sys ) );
     if( !p_dec->p_sys )
-    {
         return VLC_ENOMEM;
-    }
-    memset( p_dec->p_sys, 0, sizeof( decoder_sys_t ) );
 
     psz_file = var_CreateGetNonEmptyStringCommand( p_dec, "fake-file" );
     if( !psz_file )
     {
         msg_Err( p_dec, "specify a file with --fake-file=..." );
+        free( p_dec->p_sys );
         return VLC_EGENERIC;
     }
     var_AddCallback( p_dec, "fake-file", FakeCallback, p_dec );
@@ -167,19 +166,21 @@ static int OpenDecoder( vlc_object_t *p_this )
         p_dec->p_sys->i_reload = (mtime_t)(val.i_int * 1000000);
         p_dec->p_sys->i_next   = (mtime_t)(p_dec->p_sys->i_reload + mdate());
     }
+    var_AddCallback( p_dec, "fake-file-reload", FakeCallback , p_dec );
 
     psz_chroma = var_CreateGetString( p_dec, "fake-chroma" );
     if( strlen( psz_chroma ) != 4 )
     {
         msg_Warn( p_dec, "Invalid chroma (%s). Using I420.", psz_chroma );
-        fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
+        fmt_out.i_chroma = VLC_CODEC_I420;
     }
     else
     {
-        fmt_out.i_chroma = VLC_FOURCC( psz_chroma[0],
-                                       psz_chroma[1],
-                                       psz_chroma[2],
-                                       psz_chroma[3] );
+        fmt_out.i_chroma = vlc_fourcc_GetCodec( VIDEO_ES,
+                                                VLC_FOURCC( psz_chroma[0],
+                                                            psz_chroma[1],
+                                                            psz_chroma[2],
+                                                            psz_chroma[3] ) );
     }
     free( psz_chroma );
 
@@ -221,6 +222,8 @@ static int OpenDecoder( vlc_object_t *p_this )
     if ( p_image == NULL )
     {
         msg_Err( p_dec, "unable to read image file %s", psz_file );
+        free( psz_file );
+        free( p_dec->p_sys );
         return VLC_EGENERIC;
     }
     msg_Dbg( p_dec, "file %s loaded successfully", psz_file );
@@ -276,7 +279,7 @@ static int OpenDecoder( vlc_object_t *p_this )
             }
             else
             {
-                p_old->pf_release( p_old );
+                picture_Release( p_old );
             }
         }
     }
@@ -313,7 +316,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         }
         else
         {
-            p_old->pf_release( p_old );
+            picture_Release( p_old );
         }
     }
 
@@ -326,7 +329,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_dec->pf_decode_video = DecodeBlock;
 
     p_dec->p_sys->p_image = p_image;
-    vlc_mutex_init( p_dec, &p_dec->p_sys->lock );
+    vlc_mutex_init( &p_dec->p_sys->lock );
 
     return VLC_SUCCESS;
 }
@@ -340,7 +343,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     picture_t *p_pic;
 
     if( pp_block == NULL || !*pp_block ) return NULL;
-    p_pic = p_dec->pf_vout_buffer_new( p_dec );
+    p_pic = decoder_NewPicture( p_dec );
     if( p_pic == NULL )
     {
         msg_Err( p_dec, "cannot get picture" );
@@ -354,7 +357,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         p_sys->i_next = (mtime_t)(p_sys->i_reload + mdate());
     }
     vlc_mutex_lock( &p_dec->p_sys->lock );
-    vout_CopyPicture( p_dec, p_pic, p_dec->p_sys->p_image );
+    picture_Copy( p_pic, p_dec->p_sys->p_image );
     vlc_mutex_unlock( &p_dec->p_sys->lock );
 
     p_pic->date = (*pp_block)->i_pts;
@@ -375,7 +378,7 @@ static void CloseDecoder( vlc_object_t *p_this )
     picture_t *p_image = p_dec->p_sys->p_image;
 
     if( p_image != NULL )
-        p_image->pf_release( p_image );
+        picture_Release( p_image );
 
     vlc_mutex_destroy( &p_dec->p_sys->lock );
     free( p_dec->p_sys );
@@ -424,7 +427,7 @@ static int FakeCallback( vlc_object_t *p_this, char const *psz_var,
         }
 
         p_dec->p_sys->p_image = p_new_image;
-        p_image->pf_release( p_image );
+        picture_Release( p_image );
         vlc_mutex_unlock( &p_dec->p_sys->lock );
     }
     else if( !strcmp( psz_var, "fake-file-reload" ) )