1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
6 * Authors: Emmanuel Blindauer <manu@agat.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
26 #include <errno.h> /* ENOMEM */
27 #include <fcntl.h> /* open(), O_WRONLY */
28 #include <string.h> /* strerror() */
29 #include <unistd.h> /* write(), close() */
30 #include <stdlib.h> /* calloc(), malloc(), free() */
37 /*****************************************************************************
38 * aout_sys_t: arts audio output method descriptor
39 *****************************************************************************
40 * This structure is part of the audio output thread descriptor.
41 * It describes some arts specific variables.
42 *****************************************************************************/
48 /*****************************************************************************
50 *****************************************************************************/
51 static void aout_getfunctions ( function_list_t * );
52 static int aout_Open ( aout_thread_t * );
53 static int aout_SetFormat ( aout_thread_t * );
54 static int aout_GetBufInfo ( aout_thread_t *, int );
55 static void aout_Play ( aout_thread_t *, byte_t *, int );
56 static void aout_Close ( aout_thread_t * );
58 /*****************************************************************************
59 * Build configuration tree.
60 *****************************************************************************/
65 SET_DESCRIPTION( _("aRts audio module") )
66 ADD_CAPABILITY( AOUT, 50 )
70 aout_getfunctions( &p_module->p_functions->aout );
73 MODULE_DEACTIVATE_START
74 MODULE_DEACTIVATE_STOP
76 /*****************************************************************************
77 * Functions exported as capabilities. They are declared as static so that
78 * we don't pollute the namespace too much.
79 *****************************************************************************/
80 static void aout_getfunctions( function_list_t * p_function_list )
82 p_function_list->functions.aout.pf_open = aout_Open;
83 p_function_list->functions.aout.pf_setformat = aout_SetFormat;
84 p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
85 p_function_list->functions.aout.pf_play = aout_Play;
86 p_function_list->functions.aout.pf_close = aout_Close;
89 /*****************************************************************************
90 * aout_Open: initialize arts connection to server
91 *****************************************************************************/
92 static int aout_Open( aout_thread_t *p_aout )
96 /* Allocate structure */
97 p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
98 if( p_aout->p_sys == NULL )
100 msg_Err( p_aout, "out of memory" );
108 msg_Err( p_aout, "arts_init failed (%s)", arts_error_text(i_err) );
109 free( p_aout->p_sys );
113 p_aout->p_sys->stream =
114 arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
119 /*****************************************************************************
120 * aout_SetFormat: set the output format
121 *****************************************************************************/
122 static int aout_SetFormat( aout_thread_t *p_aout )
125 /* p_aout->i_latency = esd_get_latency(i_fd);*/
126 p_aout->i_latency = 0;
128 //msg_Dbg( p_aout, "aout_arts_latency: %d", p_aout->i_latency );
133 /*****************************************************************************
134 * aout_GetBufInfo: buffer status query
135 *****************************************************************************/
136 static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
138 /* arbitrary value that should be changed */
139 return( i_buffer_limit );
142 /*****************************************************************************
143 * aout_Play: play a sound samples buffer
144 *****************************************************************************
145 * This function writes a buffer of i_length bytes in the socket
146 *****************************************************************************/
147 static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
149 int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
153 msg_Err( p_aout, "arts_write failed (%s)", arts_error_text(i_err) );
157 /*****************************************************************************
158 * aout_Close: close the Esound socket
159 *****************************************************************************/
160 static void aout_Close( aout_thread_t *p_aout )
162 arts_close_stream( p_aout->p_sys->stream );
163 free( p_aout->p_sys );