]> git.sesse.net Git - vlc/blobdiff - modules/access/jack.c
Used VLC_CODEC_* and vlc_fourcc_GetCodec when suitable.
[vlc] / modules / access / jack.c
index 858a0e296cb8109c35847efa49254c7924f60314..ed87e881d39e751d7aa0d5f202e73f09ebc62406 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * jack.c: JACK audio input module
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * Copyright (C) 2007 Société des arts technologiques
  * Copyright (C) 2007 Savoir-faire Linux
  *
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_demux.h>
 #include <vlc_vout.h>
@@ -56,7 +61,7 @@ static void Close( vlc_object_t * );
 
 #define CACHING_TEXT N_("Caching value in ms")
 #define CACHING_LONGTEXT N_( \
-    "Make VLC buffer audio data capturer from jack for the specified " \
+    "Make VLC buffer audio data captured from jack for the specified " \
     "length in milliseconds." )
 #define PACE_TEXT N_( "Pace" )
 #define PACE_LONGTEXT N_( \
@@ -65,23 +70,23 @@ static void Close( vlc_object_t * );
 #define AUTO_CONNECT_LONGTEXT N_( \
     "Automatically connect VLC input ports to available output ports." )
 
-vlc_module_begin();
-     set_description( _("JACK audio input") );
-     set_capability( "access_demux", 0 );
-     set_shortname( _( "JACK Input" ) );
-     set_category( CAT_INPUT );
-     set_subcategory( SUBCAT_INPUT_ACCESS );
+vlc_module_begin ()
+     set_description( N_("JACK audio input") )
+     set_capability( "access_demux", 0 )
+     set_shortname( N_( "JACK Input" ) )
+     set_category( CAT_INPUT )
+     set_subcategory( SUBCAT_INPUT_ACCESS )
 
      add_integer( "jack-input-caching", DEFAULT_PTS_DELAY / 1000, NULL,
-         CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
-     add_bool( "jack-input-use-vlc-pace", VLC_FALSE, NULL,
-         PACE_TEXT, PACE_LONGTEXT, VLC_TRUE );
-     add_bool( "jack-input-auto-connect", VLC_FALSE, NULL,
-         PACE_TEXT, PACE_LONGTEXT, VLC_TRUE );
+         CACHING_TEXT, CACHING_LONGTEXT, true )
+     add_bool( "jack-input-use-vlc-pace", false, NULL,
+         PACE_TEXT, PACE_LONGTEXT, true )
+     add_bool( "jack-input-auto-connect", false, NULL,
+         AUTO_CONNECT_TEXT, AUTO_CONNECT_LONGTEXT, true )
 
-     add_shortcut( "jack" );
-     set_callbacks( Open, Close );
-vlc_module_end();
+     add_shortcut( "jack" )
+     set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -137,12 +142,8 @@ static int Open( vlc_object_t *p_this )
 
     /* Allocate structure */
     p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
-    if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory, cannot allocate structure" );
+    if( !p_sys )
         return VLC_ENOMEM;
-    }
-    memset( p_sys, 0, sizeof( demux_sys_t ) );
 
     /* Parse MRL */
     Parse( p_demux );
@@ -168,7 +169,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* find some specifics ports if user entered a regexp */
-    if( p_sys->psz_ports)
+    if( p_sys->psz_ports )
     {
         Port_finder( p_demux );
         if( p_sys->i_channels == 0 )
@@ -183,7 +184,8 @@ static int Open( vlc_object_t *p_this )
         p_sys->i_channels * sizeof( jack_port_t* ) );
     if( p_sys->pp_jack_port_input == NULL )
     {
-        msg_Err( p_demux, "out of memory, cannot allocate input ports" );
+        jack_client_close( p_sys->p_jack_client );
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
@@ -195,7 +197,9 @@ static int Open( vlc_object_t *p_this )
          * sizeof( jack_default_audio_sample_t ) );
     if( p_sys->p_jack_ringbuffer == NULL )
     {
-        msg_Err( p_demux, "out of memory, cannot allocate ringbuffer" );
+        free( p_sys->pp_jack_port_input );
+        jack_client_close( p_sys->p_jack_client );
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
@@ -210,10 +214,9 @@ static int Open( vlc_object_t *p_this )
         if( p_sys->pp_jack_port_input[i] == NULL )
         {
             msg_Err( p_demux, "failed to register a JACK port" );
-            if( p_sys->p_jack_client) jack_client_close( p_sys->p_jack_client );
-            if( p_sys->pp_jack_port_input ) free( p_sys->pp_jack_port_input );
-            if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
-            if( p_sys->pp_jack_buffer ) free( p_sys->pp_jack_buffer );
+            jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+            free( p_sys->pp_jack_port_input );
+            jack_client_close( p_sys->p_jack_client );
             free( p_sys );
             return VLC_EGENERIC;
         }
@@ -224,7 +227,12 @@ static int Open( vlc_object_t *p_this )
         * sizeof( jack_default_audio_sample_t * ) );
     if( p_sys->pp_jack_buffer == NULL )
     {
-        msg_Err( p_demux, "out of memory, cannot allocate input buffer" );
+        for( i = 0; i < p_sys->i_channels; i++ )
+            jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] );
+        jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+        free( p_sys->pp_jack_port_input );
+        jack_client_close( p_sys->p_jack_client );
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
@@ -235,10 +243,12 @@ static int Open( vlc_object_t *p_this )
     if ( jack_activate( p_sys->p_jack_client ) )
     {
         msg_Err( p_demux, "failed to activate JACK client" );
-        if( p_sys->p_jack_client) jack_client_close( p_sys->p_jack_client );
-        if( p_sys->pp_jack_port_input ) free( p_sys->pp_jack_port_input );
-        if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
-        if( p_sys->pp_jack_buffer ) free( p_sys->pp_jack_buffer );
+        free( p_sys->pp_jack_buffer );
+        for( i = 0; i < p_sys->i_channels; i++ )
+            jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] );
+        jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+        free( p_sys->pp_jack_port_input );
+        jack_client_close( p_sys->p_jack_client );
         free( p_sys );
         return VLC_EGENERIC;
     }
@@ -249,8 +259,8 @@ static int Open( vlc_object_t *p_this )
     {
         int        i_input_ports;
         int        j;
-        
-       if( p_sys->i_match_ports > 0 )
+    if( p_sys->i_match_ports > 0 )
         {
             for( j = 0; j < p_sys->i_match_ports; j++ )
             {
@@ -283,7 +293,7 @@ static int Open( vlc_object_t *p_this )
                     jack_port_name( p_sys->pp_jack_port_input[i_input_ports] ) );
             }
         }
-       if( pp_jack_port_output ) free( pp_jack_port_output );
+        free( pp_jack_port_output );
     }
 
     /* info about jack server */
@@ -295,7 +305,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->jack_sample_size = sizeof( jack_default_audio_sample_t );
 
     /* Define output format */
-    es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'f','l','3','2' ) );
+    es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_FL32 );
     fmt.audio.i_channels =  p_sys->i_channels;
     fmt.audio.i_rate =  p_sys->jack_sample_rate;
     fmt.audio.i_bitspersample =  p_sys->jack_sample_size * 8;
@@ -323,9 +333,9 @@ static void Close( vlc_object_t *p_this )
     if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio );
     if( p_sys->p_jack_client ) jack_client_close( p_sys->p_jack_client );
     if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
-    if( p_sys->pp_jack_port_input ) free( p_sys->pp_jack_port_input );
-    if( p_sys->pp_jack_buffer ) free( p_sys->pp_jack_buffer );
-    if( p_sys->pp_jack_port_table ) free( p_sys->pp_jack_port_table );
+    free( p_sys->pp_jack_port_input );
+    free( p_sys->pp_jack_buffer );
+    free( p_sys->pp_jack_port_table );
     free( p_sys );
 }
 
@@ -335,7 +345,7 @@ static void Close( vlc_object_t *p_this )
  *****************************************************************************/
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
-    vlc_bool_t  *pb;
+    bool  *pb;
     int64_t     *pi64;
     demux_sys_t *p_sys = p_demux->p_sys;
 
@@ -343,10 +353,15 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     {
     /* Special for access_demux */
     case DEMUX_CAN_PAUSE:
+    case DEMUX_CAN_SEEK:
+        pb = (bool *)va_arg( args, bool * );
+        *pb = true;
+        return VLC_SUCCESS;
+
     case DEMUX_SET_PAUSE_STATE:
         return VLC_SUCCESS;
     case DEMUX_CAN_CONTROL_PACE:
-        pb = ( vlc_bool_t* )va_arg( args, vlc_bool_t * );
+        pb = ( bool* )va_arg( args, bool * );
         *pb = var_GetBool( p_demux, "jack-input-use-vlc-pace" );
         return VLC_SUCCESS;
 
@@ -403,7 +418,7 @@ int Process( jack_nframes_t i_frames, void *p_arg )
     demux_sys_t        *p_sys = p_demux->p_sys;
     unsigned int        i, j;
     size_t              i_write;
-    
     /* Get and interlace buffers */
     for ( i = 0; i < p_sys->i_channels ; i++ )
     {
@@ -416,13 +431,13 @@ int Process( jack_nframes_t i_frames, void *p_arg )
     {
         for( i = 0; i <p_sys->i_channels; i++ )
         {
-            if( jack_ringbuffer_write_space( p_sys->p_jack_ringbuffer ) < 
+            if( jack_ringbuffer_write_space( p_sys->p_jack_ringbuffer ) <
                 p_sys->jack_sample_size ) {
                 msg_Err( p_demux, "buffer overflow");
                 return 0; // buffer overflow
             }
-            i_write = jack_ringbuffer_write( p_sys->p_jack_ringbuffer, 
-                                             ( char * ) (p_sys->pp_jack_buffer[i]+j), 
+            i_write = jack_ringbuffer_write( p_sys->p_jack_ringbuffer,
+                                             ( char * ) (p_sys->pp_jack_buffer[i]+j),
                                              p_sys->jack_sample_size );
             if (i_write != p_sys->jack_sample_size ) {
                 msg_Warn( p_demux, "error writing on ring buffer");
@@ -465,7 +480,7 @@ static block_t *GrabJack( demux_t *p_demux )
         msg_Warn( p_demux, "cannot get block" );
         return 0;
     }
-    
     //Find the previous power of 2, this algo assumes size_t has the same size on all arch
     i_read >>= 1;
     i_read--;
@@ -475,22 +490,22 @@ static block_t *GrabJack( demux_t *p_demux )
     i_read |= i_read >> 8;
     i_read |= i_read >> 16;
     i_read++;
-    
     i_read = jack_ringbuffer_read( p_sys->p_jack_ringbuffer, ( char * ) p_block->p_buffer, i_read );
-      
     p_block->i_dts = p_block->i_pts =    date_Increment( &p_sys->pts,
          i_read/(p_sys->i_channels * p_sys->jack_sample_size) );
 
     p_sys->p_block_audio = p_block;
     p_block->i_buffer = i_read;
     p_sys->p_block_audio = 0;
-    
     return p_block;
 }
 
 
 /*****************************************************************************
- * Port_finder: compare ports with the regexp entered 
+ * Port_finder: compare ports with the regexp entered
  *****************************************************************************/
 static void Port_finder( demux_t *p_demux )
 {
@@ -537,7 +552,7 @@ static void Port_finder( demux_t *p_demux )
         }
     }
 
-    if( pp_jack_port_output ) free( pp_jack_port_output );
+    free( pp_jack_port_output );
     p_sys->i_match_ports = i_total_out_ports;
 }