]> git.sesse.net Git - vlc/blobdiff - modules/misc/dummy/decoder.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / misc / dummy / decoder.c
index 5d14596fac4a88e0ad9db7be8172dd47e85f4404..956cfff459d093294d4a3ddab642946c414ac980 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_codec.h>
+#include <vlc_fs.h>
 
+#include <sys/types.h>
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h> /* write(), close() */
 #elif defined( WIN32 ) && !defined( UNDER_CE )
 #   include <io.h>
 #endif
-#ifdef HAVE_SYS_TYPES_H
-#   include <sys/types.h> /* open() */
-#endif
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
 #ifdef HAVE_FCNTL_H
 #   include <fcntl.h>
 #endif
@@ -67,33 +63,34 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
 /*****************************************************************************
  * OpenDecoder: Open the decoder
  *****************************************************************************/
-int OpenDecoder ( vlc_object_t *p_this )
+static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys;
     char psz_file[ PATH_MAX ];
-    vlc_value_t val;
 
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys =
           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
     {
-        msg_Err( p_dec, "out of memory" );
-        return VLC_EGENERIC;
+        return VLC_ENOMEM;
     }
 
-    sprintf( psz_file, "stream.%i", p_dec->i_object_id );
+    snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec );
 
 #ifndef UNDER_CE
-    var_Create( p_dec, "dummy-save-es", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    var_Get( p_dec, "dummy-save-es", &val );
-    if( val.b_bool )
+    if( !b_force_dump )
+    {
+        b_force_dump = var_CreateGetBool( p_dec, "dummy-save-es" );
+    }
+    if( b_force_dump )
     {
-        p_sys->i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
+        p_sys->i_fd = vlc_open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
 
         if( p_sys->i_fd == -1 )
         {
             msg_Err( p_dec, "cannot create `%s'", psz_file );
+            free( p_sys );
             return VLC_EGENERIC;
         }
 
@@ -113,9 +110,20 @@ int OpenDecoder ( vlc_object_t *p_this )
     p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **))
         DecodeBlock;
 
+    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
+
     return VLC_SUCCESS;
 }
 
+int OpenDecoder( vlc_object_t *p_this )
+{
+    return OpenDecoderCommon( p_this, false );
+}
+int  OpenDecoderDump( vlc_object_t *p_this )
+{
+    return OpenDecoderCommon( p_this, true );
+}
+
 /****************************************************************************
  * RunDecoder: the whole thing
  ****************************************************************************
@@ -129,13 +137,15 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     if( !pp_block || !*pp_block ) return NULL;
     p_block = *pp_block;
 
-    if( p_sys->i_fd >= 0 && p_block->i_buffer )
+    if( p_sys->i_fd >= 0 &&
+        p_block->i_buffer > 0 &&
+        (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) == 0 )
     {
 #ifndef UNDER_CE
         write( p_sys->i_fd, p_block->p_buffer, p_block->i_buffer );
 #endif
 
-        msg_Dbg( p_dec, "dumped %i bytes", p_block->i_buffer );
+        msg_Dbg( p_dec, "dumped %zu bytes", p_block->i_buffer );
     }
 
     block_Release( p_block );
@@ -151,8 +161,10 @@ void CloseDecoder ( vlc_object_t *p_this )
     decoder_sys_t *p_sys = p_dec->p_sys;
 
 #ifndef UNDER_CE
-    if( p_sys->i_fd >= 0 ) close( p_sys->i_fd );
+    if( p_sys->i_fd >= 0 )
+        close( p_sys->i_fd );
 #endif
 
     free( p_sys );
 }
+