]> git.sesse.net Git - vlc/blobdiff - plugins/arts/arts.c
* ALL: the first libvlc commit.
[vlc] / plugins / arts / arts.c
index 915b8f832d5fed2415e65dfaa3d52421ca923571..fd995d9275ec98c297bbb26e8088ab08e8cf30f6 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                              /* strdup() */
+#include <errno.h>                                                 /* ENOMEM */
+#include <fcntl.h>                                       /* open(), O_WRONLY */
+#include <string.h>                                            /* strerror() */
+#include <unistd.h>                                      /* write(), close() */
+#include <stdlib.h>                            /* calloc(), malloc(), free() */
 
-#include <videolan/vlc.h>
+#include <vlc/vlc.h>
+#include <vlc/aout.h>
+
+#include <artsc.h>
+
+/*****************************************************************************
+ * aout_sys_t: arts audio output method descriptor
+ *****************************************************************************
+ * This structure is part of the audio output thread descriptor.
+ * It describes some arts specific variables.
+ *****************************************************************************/
+struct aout_sys_s
+{
+    arts_stream_t stream;
+};
 
 /*****************************************************************************
- * Capabilities defined in the other files.
+ * Local prototypes.
  *****************************************************************************/
-void _M( aout_getfunctions )( function_list_t * p_function_list );
+static void aout_getfunctions ( function_list_t * );
+static int  aout_Open         ( aout_thread_t * );
+static int  aout_SetFormat    ( aout_thread_t * );
+static int  aout_GetBufInfo   ( aout_thread_t *, int );
+static void aout_Play         ( aout_thread_t *, byte_t *, int );
+static void aout_Close        ( aout_thread_t * );
 
 /*****************************************************************************
  * Build configuration tree.
@@ -42,13 +64,102 @@ MODULE_CONFIG_STOP
 MODULE_INIT_START
     SET_DESCRIPTION( _("aRts audio module") )
     ADD_CAPABILITY( AOUT, 50 )
-    ADD_SHORTCUT( "arts" )
 MODULE_INIT_STOP
 
 MODULE_ACTIVATE_START
-    _M( aout_getfunctions )( &p_module->p_functions->aout );
+    aout_getfunctions( &p_module->p_functions->aout );
 MODULE_ACTIVATE_STOP
 
 MODULE_DEACTIVATE_START
 MODULE_DEACTIVATE_STOP
 
+/*****************************************************************************
+ * Functions exported as capabilities. They are declared as static so that
+ * we don't pollute the namespace too much.
+ *****************************************************************************/
+static void aout_getfunctions( function_list_t * p_function_list )
+{
+    p_function_list->functions.aout.pf_open = aout_Open;
+    p_function_list->functions.aout.pf_setformat = aout_SetFormat;
+    p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
+    p_function_list->functions.aout.pf_play = aout_Play;
+    p_function_list->functions.aout.pf_close = aout_Close;
+}
+
+/*****************************************************************************
+ * aout_Open: initialize arts connection to server
+ *****************************************************************************/
+static int aout_Open( aout_thread_t *p_aout )
+{
+    int i_err = 0;
+
+    /* Allocate structure */
+    p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
+    if( p_aout->p_sys == NULL )
+    {
+        msg_Err( p_aout, "out of memory" );
+        return( 1 );
+    }
+
+    i_err = arts_init();
+    
+    if (i_err < 0)
+    {
+        msg_Err( p_aout, "arts_init failed (%s)", arts_error_text(i_err) );
+        free( p_aout->p_sys );
+        return(-1);
+    }
+
+    p_aout->p_sys->stream =
+        arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
+
+    return( 0 );
+}
+
+/*****************************************************************************
+ * aout_SetFormat: set the output format
+ *****************************************************************************/
+static int aout_SetFormat( aout_thread_t *p_aout )
+{
+   /*Not ready*/ 
+/*    p_aout->i_latency = esd_get_latency(i_fd);*/
+    p_aout->i_latency = 0;
+   
+    //msg_Dbg( p_aout, "aout_arts_latency: %d", p_aout->i_latency );
+
+    return( 0 );
+}
+
+/*****************************************************************************
+ * aout_GetBufInfo: buffer status query
+ *****************************************************************************/
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
+{
+    /* arbitrary value that should be changed */
+    return( i_buffer_limit );
+}
+
+/*****************************************************************************
+ * aout_Play: play a sound samples buffer
+ *****************************************************************************
+ * This function writes a buffer of i_length bytes in the socket
+ *****************************************************************************/
+static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
+{
+    int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
+
+    if( i_err < 0 )
+    {
+        msg_Err( p_aout, "arts_write failed (%s)", arts_error_text(i_err) );
+    }
+}
+
+/*****************************************************************************
+ * aout_Close: close the Esound socket
+ *****************************************************************************/
+static void aout_Close( aout_thread_t *p_aout )
+{
+    arts_close_stream( p_aout->p_sys->stream );
+    free( p_aout->p_sys );
+}
+