[PATCH] new generic still image demuxer (implemented as a =

Joseph Tulou brezhoneg1 at yahoo.fr
Sun Jan 4 16:31:08 CET 2009


submodule of fake access_demux)=0A=
=0A=
---=0A=
 modules/access/fake.c |  117 =
++++++++++++++++++++++++++++++++++++++++++-------=0A=
 src/input/demux.c     |   20 ++++++++=0A=
 2 files changed, 121 insertions(+), 16 deletions(-)=0A=
=0A=
diff --git a/modules/access/fake.c b/modules/access/fake.c=0A=
index 2e0d990..32fd155 100644=0A=
--- a/modules/access/fake.c=0A=
+++ b/modules/access/fake.c=0A=
@@ -33,11 +33,13 @@=0A=
 #include <vlc_plugin.h>=0A=
 #include <vlc_access.h>=0A=
 #include <vlc_demux.h>=0A=
+#include <vlc_image.h>=0A=
 =0A=
 =
/************************************************************************=
*****=0A=
  * Module descriptior=0A=
  =
*************************************************************************=
****/=0A=
 static int  Open ( vlc_object_t * );=0A=
+static int  ImageOpen ( vlc_object_t * );=0A=
 static void Close( vlc_object_t * );=0A=
 =0A=
 #define CACHING_TEXT N_("Caching value in ms")=0A=
@@ -72,11 +74,19 @@ vlc_module_begin ()=0A=
     add_shortcut( "fake" )=0A=
     set_capability( "access_demux", 0 )=0A=
     set_callbacks( Open, Close )=0A=
+=0A=
+    add_submodule ()=0A=
+    set_description( N_("Still image generic demux") )=0A=
+    add_shortcut( "image" )=0A=
+    set_capability( "demux", 0 )=0A=
+    set_callbacks( ImageOpen, Close )=0A=
+=0A=
 vlc_module_end ()=0A=
 =0A=
 =
/************************************************************************=
*****=0A=
  * Access: local prototypes=0A=
  =
*************************************************************************=
****/=0A=
+static int fakeOpen ( demux_t *, vlc_fourcc_t );=0A=
 static int Demux  ( demux_t * );=0A=
 static int Control( demux_t *, int, va_list );=0A=
 =0A=
@@ -85,6 +95,10 @@ struct demux_sys_t=0A=
     float f_fps;=0A=
     mtime_t i_last_pts, i_duration, i_first_pts, i_end_pts, i_pause_pts;=0A=
 =0A=
+    vlc_fourcc_t  i_codec;=0A=
+    int           i_size;=0A=
+    char          *p_image;=0A=
+=0A=
     es_out_id_t  *p_es_video;=0A=
 };=0A=
 =0A=
@@ -94,25 +108,94 @@ struct demux_sys_t=0A=
 static int Open( vlc_object_t *p_this )=0A=
 {=0A=
     demux_t     *p_demux =3D (demux_t*)p_this;=0A=
-    demux_sys_t *p_sys;=0A=
-    es_format_t fmt;=0A=
 =0A=
     /* Only when selected */=0A=
     if( *p_demux->psz_access =3D=3D '\0' )=0A=
         return VLC_EGENERIC;=0A=
 =0A=
+    return fakeOpen( p_demux, VLC_FOURCC('f','a','k','e') );=0A=
+}=0A=
+=0A=
+/***********************************************************************=
******=0A=
+ * Close: close device, free resources=0A=
+ =
*************************************************************************=
****/=0A=
+static void Close( vlc_object_t *p_this )=0A=
+{=0A=
+    demux_t     *p_demux =3D (demux_t *)p_this;=0A=
+    demux_sys_t *p_sys   =3D p_demux->p_sys;=0A=
+=0A=
+    if( p_sys->p_image )=0A=
+        free( p_sys->p_image );=0A=
+    free( p_sys );=0A=
+}=0A=
+=0A=
+/***********************************************************************=
******=0A=
+ * ImageOpen: opens a generic image demux=0A=
+ =
*************************************************************************=
****/=0A=
+static int ImageOpen( vlc_object_t *p_this )=0A=
+{=0A=
+    demux_t     *p_demux =3D (demux_t*)p_this;=0A=
+    demux_sys_t *p_sys;=0A=
+=0A=
+    if( !p_demux->psz_path || !*(p_demux->psz_path) )=0A=
+        return VLC_EGENERIC;=0A=
+=0A=
+    vlc_fourcc_t i_codec =3D image_Ext2Fourcc( p_demux->psz_path );=0A=
+    if( !i_codec )=0A=
+        return VLC_EGENERIC;=0A=
+=0A=
+    char* p_codec =3D (char*) &i_codec;=0A=
+    msg_Dbg( p_demux, "still image detected with codec format %c%c%c%c",=0A=
+               p_codec[0], p_codec[1], p_codec[2], p_codec[3] ); =0A=
+=0A=
+    int ret =3D fakeOpen( p_demux, i_codec );=0A=
+    if( ret !=3D VLC_SUCCESS )=0A=
+        return ret;=0A=
+=0A=
+    /* keep local copy of still image to be used later on */=0A=
+=0A=
+    p_sys =3D p_demux->p_sys;=0A=
+=0A=
+    p_sys->i_size =3D stream_Size( p_demux->s );=0A=
+    if( !p_sys->i_size )=0A=
+    {=0A=
+        free( p_sys );=0A=
+        return VLC_EGENERIC;=0A=
+    }=0A=
+=0A=
+    p_sys->p_image =3D malloc( p_sys->i_size );=0A=
+    if( !p_sys->p_image )=0A=
+    {=0A=
+        free( p_sys );=0A=
+        return VLC_ENOMEM;=0A=
+    }=0A=
+    stream_Read( p_demux->s, p_sys->p_image, p_sys->i_size );=0A=
+=0A=
+    return VLC_SUCCESS;=0A=
+}=0A=
+=0A=
+/***********************************************************************=
******=0A=
+ * fakeOpen : set up a fake demux for both capabilities=0A=
+ =
*************************************************************************=
****/=0A=
+static int fakeOpen( demux_t *p_demux, vlc_fourcc_t i_codec )=0A=
+{=0A=
+    demux_sys_t *p_sys;=0A=
+    es_format_t fmt;=0A=
+=0A=
     /* Set up p_demux */=0A=
     DEMUX_INIT_COMMON(); p_sys =3D p_demux->p_sys;=0A=
     p_demux->info.i_update =3D 0;=0A=
     p_demux->info.i_title =3D 0;=0A=
     p_demux->info.i_seekpoint =3D 0;=0A=
 =0A=
+    p_sys->i_codec =3D i_codec;=0A=
+=0A=
     p_sys->i_duration =3D=0A=
         (mtime_t)var_CreateGetInteger( p_demux, "fake-duration" ) * =
1000;=0A=
     p_sys->f_fps =3D var_CreateGetFloat( p_demux, "fake-fps" );=0A=
 =0A=
     /* Declare the elementary stream */=0A=
-    es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC('f','a','k','e') );=0A=
+    es_format_Init( &fmt, VIDEO_ES, i_codec );=0A=
     fmt.i_id =3D var_CreateGetInteger( p_demux, "fake-id" );=0A=
     p_sys->p_es_video =3D es_out_Add( p_demux->out, &fmt );=0A=
 =0A=
@@ -121,18 +204,6 @@ static int Open( vlc_object_t *p_this )=0A=
 =0A=
     return VLC_SUCCESS;=0A=
 }=0A=
-=0A=
-/***********************************************************************=
******=0A=
- * Close: close device, free resources=0A=
- =
*************************************************************************=
****/=0A=
-static void Close( vlc_object_t *p_this )=0A=
-{=0A=
-    demux_t     *p_demux =3D (demux_t *)p_this;=0A=
-    demux_sys_t *p_sys   =3D p_demux->p_sys;=0A=
-=0A=
-    free( p_sys );=0A=
-}=0A=
-=0A=
 =
/************************************************************************=
*****=0A=
  * Control:=0A=
  =
*************************************************************************=
****/=0A=
@@ -228,6 +299,7 @@ static int Control( demux_t *p_demux, int i_query, =
va_list args )=0A=
 static int Demux( demux_t *p_demux )=0A=
 {=0A=
     demux_sys_t *p_sys =3D p_demux->p_sys;=0A=
+    block_t *p_block;=0A=
 =0A=
     if ( !p_sys->i_last_pts )=0A=
     {=0A=
@@ -243,7 +315,20 @@ static int Demux( demux_t *p_demux )=0A=
         mwait( p_sys->i_last_pts );=0A=
     }=0A=
 =0A=
-    block_t *p_block =3D block_New( p_demux, 1 );=0A=
+    if( p_sys->p_image )=0A=
+    {=0A=
+        p_block =3D block_New( p_demux, p_sys->i_size );=0A=
+        if( !p_block )=0A=
+            return VLC_ENOMEM;=0A=
+        memcpy( p_block->p_buffer, p_sys->p_image, p_sys->i_size );=0A=
+    }=0A=
+    else=0A=
+    {=0A=
+        p_block =3D block_New( p_demux, 1 );=0A=
+        if( !p_block )=0A=
+            return VLC_ENOMEM;=0A=
+    }=0A=
+=0A=
     p_block->i_flags |=3D BLOCK_FLAG_TYPE_I;=0A=
     p_block->i_dts =3D p_block->i_pts =3D p_sys->i_last_pts;=0A=
 =0A=
diff --git a/src/input/demux.c b/src/input/demux.c=0A=
index 026ad4b..35eca52 100644=0A=
--- a/src/input/demux.c=0A=
+++ b/src/input/demux.c=0A=
@@ -111,6 +111,26 @@ demux_t *__demux_New( vlc_object_t *p_obj,=0A=
             { "voc",  "voc" },=0A=
             { "mid",  "smf" },=0A=
             { "rmi",  "smf" },=0A=
+=0A=
+            { "jpeg", "image" },=0A=
+            { "jpg",  "image" },=0A=
+            { "ljpg", "image" },=0A=
+            { "png",  "image" },=0A=
+            { "pgm",  "image" },=0A=
+            { "pgmyuv", "image" },=0A=
+            { "pbm",  "image" },=0A=
+            { "pam",  "image" },=0A=
+            { "tga",  "image" },=0A=
+            { "bmp",  "image" },=0A=
+            { "pnm",  "image" },=0A=
+            { "xpm",  "image" },=0A=
+            { "xcf",  "image" },=0A=
+            { "pcx",  "image" },=0A=
+            { "gif",  "image" },=0A=
+            { "tif",  "image" },=0A=
+            { "tiff", "image" },=0A=
+            { "lbm",  "image" },=0A=
+=0A=
             { "",  "" },=0A=
         };=0A=
         /* Here, we don't mind if it does not work, it must be quick */=0A=
-- =0A=
1.5.2.5=0A=
=0A=

------=_NextPart_000_0001_01C96E92.FB7C7CD0
Content-Type: application/octet-stream;
	name="0001-minor-changes-to-png-and-sdl_image-decoders-to-suppo.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="0001-minor-changes-to-png-and-sdl_image-decoders-to-suppo.patch"



More information about the vlc-devel mailing list