]> git.sesse.net Git - vlc/blobdiff - modules/codec/realaudio.c
libvlc: disable audio mute on VolumeUp/Down
[vlc] / modules / codec / realaudio.c
index 90f620ffc8baa3fdb8c9e141ea11fe43981cfdf1..2d0fcca3159cbbcdb38eaf694c22cae64f233784 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include <vlc/vout.h>
-#include <vlc/decoder.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_aout.h>
+#include <vlc_codec.h>
 
 #ifdef LOADER
 /* Need the w32dll loader from mplayer */
@@ -57,27 +61,31 @@ int WINAPI FreeLibrary( void *handle );
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( _("RealAudio library decoder") );
-    set_capability( "decoder", 10 );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("RealAudio library decoder") )
+    set_capability( "decoder", 10 )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
 static int  OpenDll( decoder_t * );
+#ifndef WIN32
 static int  OpenNativeDll( decoder_t *, char *, char * );
+#endif
+#if defined(LOADER) || defined(WIN32)
 static int  OpenWin32Dll( decoder_t *, char *, char * );
+#endif
 static void CloseDll( decoder_t * );
 
 static aout_buffer_t *Decode( decoder_t *, block_t ** );
 
 struct decoder_sys_t
 {
-    audio_date_t end_date;
+    date_t end_date;
 
     /* Output buffer */
     char *p_out;
@@ -85,7 +93,7 @@ struct decoder_sys_t
 
     /* Codec params */
     void *context;
-    int i_codec_flavor;
+    short int i_codec_flavor;
 
     void *dll;
     unsigned long (*raCloseCodec)(void*);
@@ -148,10 +156,12 @@ typedef struct __attribute__((__packed__)) {
     void* extradata;
 } wra_init_t;
 
+#if 0 /* I have no idea what this is doing here */
 void *__builtin_new(unsigned long size) {return malloc(size);}
 void __builtin_delete(void *p) {free(p);}
+#endif
 
-static int pi_channels_maps[7] =
+static const int pi_channels_maps[7] =
 {
     0,
     AOUT_CHAN_CENTER,
@@ -178,27 +188,34 @@ static int Open( vlc_object_t *p_this )
 
     switch( p_dec->fmt_in.i_codec )
     {
-    case VLC_FOURCC('c','o','o','k'):
+    case VLC_CODEC_COOK:
+    case VLC_CODEC_ATRAC3:
+    case VLC_FOURCC('s','i','p','r'):
         break;
 
     default:
         return VLC_EGENERIC;
     }
 
-    p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
-    memset( p_sys, 0, sizeof(decoder_sys_t) );
+    /* Channel detection */
+    if( p_dec->fmt_in.audio.i_channels <= 0 ||
+        p_dec->fmt_in.audio.i_channels > 6 )
+    {
+        msg_Err( p_dec, "invalid number of channels (not between 1 and 6): %i",
+                 p_dec->fmt_in.audio.i_channels );
+        return VLC_EGENERIC;
+    }
+
+    p_dec->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
 
+    /* Flavor for SIPR codecs */
     p_sys->i_codec_flavor = -1;
     if( p_dec->fmt_in.i_codec == VLC_FOURCC('s','i','p','r') )
     {
-        if( p_dec->fmt_in.audio.i_bitspersample > 1531 )
-            p_sys->i_codec_flavor = 3;
-        else if( p_dec->fmt_in.audio.i_bitspersample > 937 )
-            p_sys->i_codec_flavor = 1;
-        else if( p_dec->fmt_in.audio.i_bitspersample > 719 )
-            p_sys->i_codec_flavor = 0;
-        else
-            p_sys->i_codec_flavor = 2;
+        p_sys->i_codec_flavor = p_dec->fmt_in.audio.i_flavor;
+        msg_Dbg( p_dec, "Got sipr flavor %d", p_sys->i_codec_flavor );
     }
 
     if( OpenDll( p_dec ) != VLC_SUCCESS )
@@ -211,7 +228,7 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->win32_dll ) Close( p_this );
 #endif
 
-    es_format_Init( &p_dec->fmt_out, AUDIO_ES, AOUT_FMT_S16_NE );
+    es_format_Init( &p_dec->fmt_out, AUDIO_ES, VLC_CODEC_S16N );
     p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate;
     p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels;
     p_dec->fmt_out.audio.i_bitspersample =
@@ -220,12 +237,17 @@ static int Open( vlc_object_t *p_this )
     p_dec->fmt_out.audio.i_original_channels =
         pi_channels_maps[p_dec->fmt_out.audio.i_channels];
 
-    aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate );
-    aout_DateSet( &p_sys->end_date, 0 );
+    date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
+    date_Set( &p_sys->end_date, 0 );
 
     p_dec->pf_decode_audio = Decode;
 
     p_sys->p_out = malloc( 4096 * 10 );
+    if( !p_sys->p_out )
+    {
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
     p_sys->i_out = 0;
 
     return VLC_SUCCESS;
@@ -239,7 +261,7 @@ static void Close( vlc_object_t *p_this )
     decoder_t *p_dec = (decoder_t*)p_this;
 
     CloseDll( p_dec );
-    if( p_dec->p_sys->p_out ) free( p_dec->p_sys->p_out );
+    free( p_dec->p_sys->p_out );
     free( p_dec->p_sys );
 }
 
@@ -251,7 +273,8 @@ static int OpenDll( decoder_t *p_dec )
     char *psz_dll;
     int i, i_result;
 
-    char *ppsz_path[] =
+    /** Find the good path for the dlls.**/
+    const char *ppsz_path[] =
     {
       ".",
 #ifndef WIN32
@@ -260,9 +283,16 @@ static int OpenDll( decoder_t *p_dec )
       "/usr/lib/RealPlayer8/Codecs",
       "/opt/RealPlayer8/Codecs",
       "/usr/lib/RealPlayer9/users/Real/Codecs",
+      "/usr/lib/RealPlayer10/codecs",
+      "/usr/lib/RealPlayer10GOLD/codecs",
+      "/usr/lib/helix/player/codecs",
       "/usr/lib64/RealPlayer8/Codecs",
       "/usr/lib64/RealPlayer9/users/Real/Codecs",
+      "/usr/lib64/RealPlayer10/codecs",
+      "/usr/lib64/RealPlayer10GOLD/codecs",
       "/usr/lib/win32",
+      "/usr/lib/codecs",
+      "/usr/local/lib/codecs",
 #endif
       NULL,
       NULL,
@@ -272,18 +302,7 @@ static int OpenDll( decoder_t *p_dec )
 #ifdef WIN32
     char psz_win32_real_codecs[MAX_PATH + 1];
     char psz_win32_helix_codecs[MAX_PATH + 1];
-#endif
 
-    for( i = 0; ppsz_path[i]; i++ )
-    {
-        asprintf( &psz_dll, "%s/%4.4s.so.6.0", ppsz_path[i],
-                  (char *)&p_dec->fmt_in.i_codec );
-        i_result = OpenNativeDll( p_dec, ppsz_path[i], psz_dll );
-        free( psz_dll );
-        if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
-    }
-
-#ifdef WIN32
     {
         HKEY h_key;
         DWORD i_type, i_data = MAX_PATH + 1, i_index = 1;
@@ -325,26 +344,59 @@ static int OpenDll( decoder_t *p_dec )
     }
 #endif
 
+
+    /** Try the native libraries first **/
+#ifndef WIN32
+    for( i = 0; ppsz_path[i]; i++ )
+    {
+        /* Old format */
+        if( asprintf( &psz_dll, "%s/%4.4s.so.6.0", ppsz_path[i],
+                  (char *)&p_dec->fmt_in.i_codec ) != -1 )
+        {
+            i_result = OpenNativeDll( p_dec, (char *)ppsz_path[i], psz_dll );
+            free( psz_dll );
+            if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+        }
+
+        /* New format */
+        if( asprintf( &psz_dll, "%s/%4.4s.so", ppsz_path[i],
+                  (char *)&p_dec->fmt_in.i_codec ) != -1 )
+        {
+            i_result = OpenNativeDll( p_dec, (char *)ppsz_path[i], psz_dll );
+            free( psz_dll );
+            if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+        }
+    }
+#endif
+
+    /** Or use the WIN32 dlls **/
+#if defined(LOADER) || defined(WIN32)
     for( i = 0; ppsz_path[i]; i++ )
     {
         /* New format */
-        asprintf( &psz_dll, "%s\\%4.4s.dll", ppsz_path[i],
-                  (char *)&p_dec->fmt_in.i_codec );
-        i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
-        free( psz_dll );
-        if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+        if( asprintf( &psz_dll, "%s\\%4.4s.dll", ppsz_path[i],
+                  (char *)&p_dec->fmt_in.i_codec ) != -1 )
+        {
+            i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
+            free( psz_dll );
+            if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+        }
 
         /* Old format */
-        asprintf( &psz_dll, "%s\\%4.4s3260.dll", ppsz_path[i],
-                  (char *)&p_dec->fmt_in.i_codec );
-        i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
-        free( psz_dll );
-        if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+        if( asprintf( &psz_dll, "%s\\%4.4s3260.dll", ppsz_path[i],
+                  (char *)&p_dec->fmt_in.i_codec ) != -1 )
+        {
+            i_result = OpenWin32Dll( p_dec, ppsz_path[i], psz_dll );
+            free( psz_dll );
+            if( i_result == VLC_SUCCESS ) return VLC_SUCCESS;
+        }
     }
+#endif
 
     return VLC_EGENERIC;
 }
 
+#ifndef WIN32
 static int OpenNativeDll( decoder_t *p_dec, char *psz_path, char *psz_dll )
 {
 #if defined(HAVE_DL_DLOPEN)
@@ -445,14 +497,19 @@ static int OpenNativeDll( decoder_t *p_dec, char *psz_path, char *psz_dll )
     if( context ) p_sys->raFreeDecoder( context );
     if( context ) p_sys->raCloseCodec( context );
     dlclose( handle );
+#else
+    VLC_UNUSED( p_dec );
+    VLC_UNUSED( psz_path);
+    VLC_UNUSED( psz_dll );
 #endif
 
     return VLC_EGENERIC;
 }
+#endif /* Win32 */
 
+#if defined(LOADER) || defined(WIN32)
 static int OpenWin32Dll( decoder_t *p_dec, char *psz_path, char *psz_dll )
 {
-#if defined(LOADER) || defined(WIN32)
     decoder_sys_t *p_sys = p_dec->p_sys;
     void *handle = 0, *context = 0;
     unsigned int i_result;
@@ -557,10 +614,10 @@ static int OpenWin32Dll( decoder_t *p_dec, char *psz_path, char *psz_dll )
     if( context ) p_sys->wraFreeDecoder( context );
     if( context ) p_sys->wraCloseCodec( context );
     FreeLibrary( handle );
-#endif
 
     return VLC_EGENERIC;
 }
+#endif
 
 /*****************************************************************************
  * CloseDll:
@@ -618,7 +675,7 @@ static aout_buffer_t *Decode( decoder_t *p_dec, block_t **pp_block )
         if( OpenDll( p_dec ) != VLC_SUCCESS )
         {
             /* Fatal */
-            p_dec->b_error = VLC_TRUE;
+            p_dec->b_error = true;
             return NULL;
         }
     }
@@ -643,13 +700,13 @@ static aout_buffer_t *Decode( decoder_t *p_dec, block_t **pp_block )
 #endif
 
     /* Date management */
-    if( p_block->i_pts > 0 &&
-        p_block->i_pts != aout_DateGet( &p_sys->end_date ) )
+    if( p_block->i_pts > VLC_TS_INVALID &&
+        p_block->i_pts != date_Get( &p_sys->end_date ) )
     {
-        aout_DateSet( &p_sys->end_date, p_block->i_pts );
+        date_Set( &p_sys->end_date, p_block->i_pts );
     }
 
-    if( !aout_DateGet( &p_sys->end_date ) )
+    if( !date_Get( &p_sys->end_date ) )
     {
         /* We've just started the stream, wait for the first PTS. */
         if( p_block ) block_Release( p_block );
@@ -660,15 +717,15 @@ static aout_buffer_t *Decode( decoder_t *p_dec, block_t **pp_block )
         p_dec->fmt_out.audio.i_bitspersample /p_dec->fmt_out.audio.i_channels;
 
     p_aout_buffer =
-        p_dec->pf_aout_buffer_new( p_dec, i_samples );
+        decoder_NewAudioBuffer( p_dec, i_samples );
     if( p_aout_buffer )
     {
         memcpy( p_aout_buffer->p_buffer, p_sys->p_out, p_sys->i_out );
 
         /* Date management */
-        p_aout_buffer->start_date = aout_DateGet( &p_sys->end_date );
-        p_aout_buffer->end_date =
-            aout_DateIncrement( &p_sys->end_date, i_samples );
+        p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
+        p_aout_buffer->i_length = date_Increment( &p_sys->end_date, i_samples )
+                                  - p_aout_buffer->i_pts;
     }
 
     block_Release( p_block );