]> git.sesse.net Git - vlc/blobdiff - modules/demux/mpc.c
Add missing shortnames.
[vlc] / modules / demux / mpc.c
index c201ed8fa2cfe77926ee129abcd5f56f692e4ac7..b02e4cdf51610470676a4a793e07d4d6edc8ab15 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_demux.h>
 #include <vlc_input.h>
 #include <vlc_codec.h>
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define REPLAYGAIN_TYPE_TEXT N_("Replay Gain type" )
-#define REPLAYGAIN_TYPE_LONGTEXT N_( "Musepack can have a title-specific " \
-              "replay gain (volume control) or an album-specific one. "  \
-              "Choose which type you want to use" )
-
 static int  Open  ( vlc_object_t * );
 static void Close ( vlc_object_t * );
 
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_DEMUX );
-    set_description( _("MusePack demuxer") );
-    set_capability( "demux2", 145 );
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_DEMUX )
+    set_description( N_("MusePack demuxer") )
+    set_capability( "demux", 145 )
 
-    set_callbacks( Open, Close );
-    add_shortcut( "mpc" );
-vlc_module_end();
+    set_callbacks( Open, Close )
+    add_shortcut( "mpc" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -71,7 +71,7 @@ static int Control( demux_t *, int, va_list );
 struct demux_sys_t
 {
     /* */
-    es_out_id_t *p_es;
+    es_out_id_t   *p_es;
 
     /* */
     mpc_decoder    decoder;
@@ -79,15 +79,14 @@ struct demux_sys_t
     mpc_streaminfo info;
 
     /* */
-    vlc_meta_t     *p_meta;
     int64_t        i_position;
 };
 
-mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size );
-mpc_bool_t  ReaderSeek( void *p_private, mpc_int32_t i_offset );
-mpc_int32_t ReaderTell( void *p_private);
-mpc_int32_t ReaderGetSize( void *p_private );
-mpc_bool_t  ReaderCanSeek( void *p_private );
+static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size );
+static mpc_bool_t  ReaderSeek( void *p_private, mpc_int32_t i_offset );
+static mpc_int32_t ReaderTell( void *p_private);
+static mpc_int32_t ReaderGetSize( void *p_private );
+static mpc_bool_t  ReaderCanSeek( void *p_private );
 
 /*****************************************************************************
  * Open: initializes ES structures
@@ -98,7 +97,6 @@ static int Open( vlc_object_t * p_this )
     demux_sys_t *p_sys;
     es_format_t fmt;
     const uint8_t *p_peek;
-    module_t    *p_id3;
 
     if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
         return VLC_EGENERIC;
@@ -114,16 +112,17 @@ static int Open( vlc_object_t * p_this )
         if( !p_demux->b_force )
         {
             /* Check file name extension */
-            if( !demux2_IsPathExtension( p_demux, ".mpc" ) &&
-                !demux2_IsPathExtension( p_demux, ".mp+" ) &&
-                !demux2_IsPathExtension( p_demux, ".mpp" ) )
+            if( !demux_IsPathExtension( p_demux, ".mpc" ) &&
+                !demux_IsPathExtension( p_demux, ".mp+" ) &&
+                !demux_IsPathExtension( p_demux, ".mpp" ) )
                 return VLC_EGENERIC;
         }
     }
 
     /* */
-    p_sys = malloc( sizeof( demux_sys_t ) );
-    memset( p_sys, 0, sizeof(demux_sys_t) );
+    p_sys = calloc( 1, sizeof( *p_sys ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
 
     p_sys->i_position = 0;
 
@@ -137,20 +136,12 @@ static int Open( vlc_object_t * p_this )
     /* Load info */
     mpc_streaminfo_init( &p_sys->info );
     if( mpc_streaminfo_read( &p_sys->info, &p_sys->reader ) != ERROR_CODE_OK )
-    {
-        /* invalid file */
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
+        goto error;
 
     /* */
     mpc_decoder_setup( &p_sys->decoder, &p_sys->reader );
     if( !mpc_decoder_initialize( &p_sys->decoder, &p_sys->info ) )
-    {
-        /* */
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
+        goto error;
 
     /* Fill p_demux fields */
     p_demux->pf_demux = Demux;
@@ -175,54 +166,28 @@ static int Open( vlc_object_t * p_this )
                     fmt.audio.i_bitspersample;
     if( p_sys->info.peak_title > 0 )
     {
-        fmt.audio_replay_gain.pb_peak[AUDIO_REPLAY_GAIN_TRACK] = VLC_TRUE;
+        fmt.audio_replay_gain.pb_peak[AUDIO_REPLAY_GAIN_TRACK] = true;
         fmt.audio_replay_gain.pf_peak[AUDIO_REPLAY_GAIN_TRACK] = (float)p_sys->info.peak_title / 32767.0;
-        fmt.audio_replay_gain.pb_gain[AUDIO_REPLAY_GAIN_TRACK] = VLC_TRUE;
+        fmt.audio_replay_gain.pb_gain[AUDIO_REPLAY_GAIN_TRACK] = true;
         fmt.audio_replay_gain.pf_gain[AUDIO_REPLAY_GAIN_TRACK] = (float)p_sys->info.gain_title / 100.0;
     }
     if( p_sys->info.peak_album > 0 )
     {
-        fmt.audio_replay_gain.pb_peak[AUDIO_REPLAY_GAIN_ALBUM] = VLC_TRUE;
+        fmt.audio_replay_gain.pb_peak[AUDIO_REPLAY_GAIN_ALBUM] = true;
         fmt.audio_replay_gain.pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = (float)p_sys->info.peak_album / 32767.0;
-        fmt.audio_replay_gain.pb_gain[AUDIO_REPLAY_GAIN_ALBUM] = VLC_TRUE;
+        fmt.audio_replay_gain.pb_gain[AUDIO_REPLAY_GAIN_ALBUM] = true;
         fmt.audio_replay_gain.pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = (float)p_sys->info.gain_album / 100.0;
     }
 
-    /* Parse possible id3 header */
-    input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT, FIND_PARENT );
-    if( p_input )
-    {
-        if( !( input_GetItem( p_input )->p_meta->i_status & ITEM_PREPARSED ) )
-        {
-            p_demux->p_private = malloc( sizeof( demux_meta_t ) );
-            if( !p_demux->p_private )
-            {
-                vlc_object_release( p_input );
-                return VLC_ENOMEM;
-            }
-            if( ( p_id3 = module_Need( p_demux, "meta reader", NULL, 0 ) ) )
-            {
-                demux_meta_t *p_demux_meta = (demux_meta_t *)p_demux->p_private;
-                p_sys->p_meta = p_demux_meta->p_meta;
-                module_Unneed( p_demux, p_id3 );
-                int i;
-                for( i = 0; i < p_demux_meta->i_attachments; i++ )
-                    free( p_demux_meta->attachments[i] );
-                TAB_CLEAN( p_demux_meta->i_attachments,
-                            p_demux_meta->attachments );
-            }
-            free( p_demux->p_private );
-        }
-        vlc_object_release( p_input );
-    }
-
-    if( !p_sys->p_meta )
-        p_sys->p_meta = vlc_meta_New();
-
-    vlc_audio_replay_gain_MergeFromMeta( &fmt.audio_replay_gain, p_sys->p_meta );
     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
+    if( !p_sys->p_es )
+        goto error;
 
     return VLC_SUCCESS;
+
+error:
+    free( p_sys );
+    return VLC_EGENERIC;
 }
 
 /*****************************************************************************
@@ -249,9 +214,12 @@ static int Demux( demux_t *p_demux )
 
     p_data = block_New( p_demux,
                         MPC_DECODER_BUFFER_LENGTH*sizeof(MPC_SAMPLE_FORMAT) );
+    if( !p_data )
+        return -1;
+
     i_ret = mpc_decoder_decode( &p_sys->decoder,
-                               (MPC_SAMPLE_FORMAT*)p_data->p_buffer,
-                               NULL, NULL );
+                                (MPC_SAMPLE_FORMAT*)p_data->p_buffer,
+                                NULL, NULL );
     if( i_ret <= 0 )
     {
         block_Release( p_data );
@@ -261,7 +229,7 @@ static int Demux( demux_t *p_demux )
     /* */
     p_data->i_buffer = i_ret * sizeof(MPC_SAMPLE_FORMAT) * p_sys->info.channels;
     p_data->i_dts = p_data->i_pts =
-            1 + I64C(1000000) * p_sys->i_position / p_sys->info.sample_freq;
+            1 + INT64_C(1000000) * p_sys->i_position / p_sys->info.sample_freq;
 
     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_data->i_dts );
 
@@ -281,21 +249,18 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     demux_sys_t *p_sys = p_demux->p_sys;
     double   f, *pf;
     int64_t i64, *pi64;
-    vlc_meta_t *p_meta;
+    bool *pb_bool;
 
     switch( i_query )
     {
-        case DEMUX_GET_META:
-            p_meta = (vlc_meta_t *)va_arg( args, vlc_meta_t* );
-            if( p_sys->p_meta )
-                vlc_meta_Merge( p_meta, p_sys->p_meta );
-            else
-                p_meta = NULL;
+        case DEMUX_HAS_UNSUPPORTED_META:
+            pb_bool = (bool*)va_arg( args, bool* );
+            *pb_bool = true;
             return VLC_SUCCESS;
 
         case DEMUX_GET_LENGTH:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = I64C(1000000) * p_sys->info.pcm_samples /
+            *pi64 = INT64_C(1000000) * p_sys->info.pcm_samples /
                         p_sys->info.sample_freq;
             return VLC_SUCCESS;
 
@@ -310,7 +275,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_TIME:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = I64C(1000000) * p_sys->i_position /
+            *pi64 = INT64_C(1000000) * p_sys->i_position /
                         p_sys->info.sample_freq;
             return VLC_SUCCESS;
 
@@ -338,34 +303,34 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     }
 }
 
-mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size )
+static mpc_int32_t ReaderRead( void *p_private, void *dst, mpc_int32_t i_size )
 {
     demux_t *p_demux = (demux_t*)p_private;
     return stream_Read( p_demux->s, dst, i_size );
 }
 
-mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset )
+static mpc_bool_t ReaderSeek( void *p_private, mpc_int32_t i_offset )
 {
     demux_t *p_demux = (demux_t*)p_private;
     return !stream_Seek( p_demux->s, i_offset );
 }
 
-mpc_int32_t ReaderTell( void *p_private)
+static mpc_int32_t ReaderTell( void *p_private)
 {
     demux_t *p_demux = (demux_t*)p_private;
     return stream_Tell( p_demux->s );
 }
 
-mpc_int32_t ReaderGetSize( void *p_private )
+static mpc_int32_t ReaderGetSize( void *p_private )
 {
     demux_t *p_demux = (demux_t*)p_private;
     return stream_Size( p_demux->s );
 }
 
-mpc_bool_t ReaderCanSeek( void *p_private )
+static mpc_bool_t ReaderCanSeek( void *p_private )
 {
     demux_t *p_demux = (demux_t*)p_private;
-    vlc_bool_t b_canseek;
+    bool b_canseek;
 
     stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_canseek );
     return b_canseek;