]> git.sesse.net Git - vlc/blobdiff - modules/demux/gme.cpp
broken avi dialog: notify the effective changes
[vlc] / modules / demux / gme.cpp
index faf06506e6907133771496ac35e0851c192d7bf0..dcd213f73ebece167e5aad257bb6798e2f89542a 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 
 #include "Nsf_Emu.h"
 #include "Gbs_Emu.h"
@@ -47,15 +50,15 @@ using namespace std;
 static int  Open    ( vlc_object_t * );
 static void Close  ( vlc_object_t * );
 
-vlc_module_begin();
-    set_shortname( "GME");
-    set_description( _("GME demuxer (Game_Music_Emu)" ) );
-    set_capability( "demux2", 10 );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_DEMUX );
-    set_callbacks( Open, Close );
-    add_shortcut( "gme" );
-vlc_module_end();
+vlc_module_begin ()
+    set_shortname( "GME")
+    set_description( N_("GME demuxer (Game_Music_Emu)" ) )
+    set_capability( "demux", 10 )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_DEMUX )
+    set_callbacks( Open, Close )
+    add_shortcut( "gme" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -112,13 +115,14 @@ static int Open( vlc_object_t *p_this )
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
     char        *ext;
-    int         i;
+    int         i = 0;
     vlc_value_t val;
-    
     /* We accept file based on extention match */
-    if( strcasecmp( p_demux->psz_demux, "gme" ) )
+    if( !p_demux->b_force )
     {
-        if( ( ext = strrchr( p_demux->psz_path, '.' ) ) == NULL ||
+        if( p_demux->psz_file == NULL
+         || ( ext = strrchr( p_demux->psz_file, '.' ) ) == NULL ||
             stream_Size( p_demux->s ) == 0 ) return VLC_EGENERIC;
 
         ext++;  /* skip . */
@@ -145,10 +149,17 @@ static int Open( vlc_object_t *p_this )
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;
     p_demux->p_sys = p_sys = (demux_sys_t *)malloc( sizeof( demux_sys_t ) );
+    if( unlikely( !p_sys ) )
+        return VLC_ENOMEM;
 
     msg_Dbg( p_demux, "loading complete file (could be long)" );
     p_sys->i_data = stream_Size( p_demux->s );
     p_sys->p_data = (uint8_t *)malloc( p_sys->i_data );
+    if( unlikely( !p_sys->p_data ) )
+    {
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
     p_sys->i_data = stream_Read( p_demux->s, p_sys->p_data, p_sys->i_data );
     if( p_sys->i_data <= 0 )
     {
@@ -159,7 +170,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* Prepare emulator */
-   
 #ifdef HAVE_ZLIB_H
     if (i == 4) /* gzipped vgm */
     {
@@ -167,7 +178,7 @@ static int Open( vlc_object_t *p_this )
         size_t i_outsize;
 
         inflate_gzbuf( p_sys->p_data, p_sys->i_data, &p_outbuffer, &i_outsize );
-        
         if (p_outbuffer == NULL)
         {
             msg_Err( p_demux, "failed to understand the file : unable to inflate vgz file" );
@@ -182,11 +193,11 @@ static int Open( vlc_object_t *p_this )
 
         p_sys->p_data = p_outbuffer;
         p_sys->i_data = i_outsize;
-    }    
+    }
 #endif
 
-    p_sys->p_reader = new Emu_Mem_Reader( p_sys->p_data, p_sys->i_data ); 
-    
+    p_sys->p_reader = new Emu_Mem_Reader( p_sys->p_data, p_sys->i_data );
     switch(i)
     {
         case 0:
@@ -216,15 +227,15 @@ static int Open( vlc_object_t *p_this )
         p_emu->init( 44100 ); \
         p_sys->p_musicemu = p_emu; \
         p_sys->p_reader->read( &header, sizeof(header) ); \
-        p_error = p_emu->load( header, *(p_sys->p_reader) ); 
+        p_error = p_emu->load( header, *(p_sys->p_reader) );
 
     p_sys->p_meta = vlc_meta_New();
 
     char psz_temp[512];
-    
     /// \todo Reinstate meta codec name
     //SET_META( VLC_META_CODEC_NAME, type_str[p_sys->i_type])
-    
     const char * p_error;
 
     switch(p_sys->i_type)
@@ -286,7 +297,7 @@ static int Open( vlc_object_t *p_this )
             }
      }
         break;
-    } 
+    }
 
     if( p_error != NULL )
     {
@@ -299,7 +310,7 @@ static int Open( vlc_object_t *p_this )
     }
 
    /* init time */
-    p_sys->i_time  = 1;
+    p_sys->i_time  = 0;
     p_sys->i_length = 314 * (int64_t)1000;
 
     msg_Dbg( p_demux, "GME loaded type=%s title=%s tracks=%i", type_str[p_sys->i_type],
@@ -316,7 +327,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->fmt.audio.i_channels = 2;
     p_sys->fmt.audio.i_bitspersample = 16;
     p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
-    
     return VLC_SUCCESS;
 }
 
@@ -353,7 +364,7 @@ static int Demux( demux_t *p_demux )
     p_frame = block_New( p_demux, i_buf );
 
     p_sys->p_musicemu->play( i_emubuf, p_emubuf );
-    
     /*
     if( p_error != NULL )
     {
@@ -367,13 +378,13 @@ static int Demux( demux_t *p_demux )
     for (int i = 0; i<i_buf; i++) p_frame->p_buffer[i] = ((uint8_t *)p_emubuf)[i];
 
     /* Set PCR */
-    es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_time );
+    es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_time );
+    p_frame->i_dts = p_frame->i_pts = VLC_TS_0 + p_sys->i_time;
 
     /* We should use p_frame->i_buffer */
     p_sys->i_time += (int64_t)1000000 * p_frame->i_buffer / i_bk / p_sys->fmt.audio.i_rate;
 
     /* Send data */
-    p_frame->i_dts = p_frame->i_pts = p_sys->i_time;
     es_out_Send( p_demux->out, p_sys->es, p_frame );
 
     return 1;
@@ -416,8 +427,7 @@ switch( i_query )
             if( i64 >= 0 && i64 <= p_sys->i_length )
             {
                 ModPlug_Seek( p_sys->f, i64 / 1000 );
-                p_sys->i_time = i64 + 1;
-                es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
+                p_sys->i_time = i64;
 
                 return VLC_SUCCESS;
             }
@@ -439,8 +449,7 @@ switch( i_query )
             if( i64 >= 0 && i64 <= p_sys->i_length )
             {
                 ModPlug_Seek( p_sys->f, i64 / 1000 );
-                p_sys->i_time = i64 + 1;
-                es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
+                p_sys->i_time = i64;
 
                 return VLC_SUCCESS;
             }
@@ -453,7 +462,7 @@ switch( i_query )
                 int *pi_int    = (int*)va_arg( args, int* );
 
                 *pi_int = p_sys->i_tracks;
-                *ppp_title = (input_title_t**)malloc( sizeof( input_title_t**) * p_sys->i_tracks );
+                *ppp_title = (input_title_t**)xmalloc( sizeof( input_title_t**) * p_sys->i_tracks );
 
                 for( int i = 0; i < p_sys->i_tracks; i++ )
                 {
@@ -470,7 +479,7 @@ switch( i_query )
 
         case DEMUX_SET_TITLE:
             i_idx = (int)va_arg( args, int );
-            p_sys->p_musicemu->start_track( i_idx );    
+            p_sys->p_musicemu->start_track( i_idx );
             p_demux->info.i_title = i_idx;
             p_demux->info.i_update = INPUT_UPDATE_TITLE;
             msg_Dbg( p_demux, "set title %i", i_idx);
@@ -497,7 +506,7 @@ static void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuff
     memset(&z_str, 0, sizeof(z_str));
 
     out_size = i_size * 2;
-    out_buffer = (uint8_t*)malloc(out_size);
+    out_buffer = (uint8_t*)xmalloc(out_size);
 
     z_str.next_in   = (unsigned char*)p_buffer;
     z_str.avail_in  = i_size;
@@ -519,7 +528,7 @@ static void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuff
         case Z_BUF_ERROR:
             offset = z_str.next_out - out_buffer;
             out_size *= 2;
-            out_buffer = (uint8_t *)realloc(out_buffer, out_size);
+            out_buffer = (uint8_t *)xrealloc(out_buffer, out_size);
             z_str.next_out  = out_buffer + offset;
             z_str.avail_out = out_size - offset;
             break;
@@ -533,8 +542,8 @@ static void inflate_gzbuf(uint8_t * p_buffer, size_t i_size, uint8_t ** pp_obuff
     (*pi_osize) = out_size - z_str.avail_out;
 
     inflateEnd(&z_str);
-    
-    out_buffer = (uint8_t *)realloc(out_buffer, *pi_osize); 
+    out_buffer = (uint8_t *)xrealloc(out_buffer, *pi_osize);
     (*pp_obuffer) = out_buffer;
 }
 #endif