1 /*****************************************************************************
2 * aout_arts.c : aRts functions library
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
6 * Authors: Blindauer Emmanuel <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 <stdio.h> /* "intf_msg.h" */
31 #include <stdlib.h> /* calloc(), malloc(), free() */
35 #include <videolan/vlc.h>
37 #include "audio_output.h" /* aout_thread_t */
39 /*****************************************************************************
40 * aout_sys_t: arts audio output method descriptor
41 *****************************************************************************
42 * This structure is part of the audio output thread descriptor.
43 * It describes some arts specific variables.
44 *****************************************************************************/
45 typedef struct aout_sys_s
51 /*****************************************************************************
53 *****************************************************************************/
54 static int aout_Probe ( probedata_t *p_data );
55 static int aout_Open ( aout_thread_t *p_aout );
56 static int aout_SetFormat ( aout_thread_t *p_aout );
57 static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
58 static void aout_Play ( aout_thread_t *p_aout,
59 byte_t *buffer, int i_size );
60 static void aout_Close ( aout_thread_t *p_aout );
62 /*****************************************************************************
63 * Functions exported as capabilities. They are declared as static so that
64 * we don't pollute the namespace too much.
65 *****************************************************************************/
66 void _M( aout_getfunctions )( function_list_t * p_function_list )
68 p_function_list->pf_probe = aout_Probe;
69 p_function_list->functions.aout.pf_open = aout_Open;
70 p_function_list->functions.aout.pf_setformat = aout_SetFormat;
71 p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
72 p_function_list->functions.aout.pf_play = aout_Play;
73 p_function_list->functions.aout.pf_close = aout_Close;
76 /*****************************************************************************
77 * aout_Probe: probes the audio device and return a score
78 *****************************************************************************
79 * This function tries to open the dps and returns a score to the plugin
80 * manager so that it can
81 *****************************************************************************/
82 static int aout_Probe( probedata_t *p_data )
84 /* We don't have to test anything -- if we managed to open this plugin,
85 * it means we have the appropriate libs. */
89 /*****************************************************************************
90 * aout_Open: initialize arts connection to server
91 *****************************************************************************/
92 static int aout_Open( aout_thread_t *p_aout )
95 p_aout->i_format = AOUT_FORMAT_DEFAULT;
96 p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
97 p_aout->l_rate = AOUT_RATE_DEFAULT;
99 /* Allocate structure */
100 p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
101 if( p_aout->p_sys == NULL )
103 intf_ErrMsg("error: %s", strerror(ENOMEM) );
111 intf_ErrMsg( "aout error: arts_init (%s)", arts_error_text(i_err) );
112 free( p_aout->p_sys );
116 p_aout->p_sys->stream =
117 arts_play_stream( p_aout->l_rate, 16, p_aout->i_channels, "vlc" );
122 /*****************************************************************************
123 * aout_SetFormat: set the output format
124 *****************************************************************************/
125 static int aout_SetFormat( aout_thread_t *p_aout )
128 /* p_aout->i_latency = esd_get_latency(i_fd);*/
129 p_aout->i_latency = 0;
131 //intf_WarnMsg( 5, "aout_arts_latency: %d",p_aout->i_latency);
136 /*****************************************************************************
137 * aout_GetBufInfo: buffer status query
138 *****************************************************************************/
139 static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
141 /* arbitrary value that should be changed */
142 return( l_buffer_limit );
145 /*****************************************************************************
146 * aout_Play: play a sound samples buffer
147 *****************************************************************************
148 * This function writes a buffer of i_length bytes in the socket
149 *****************************************************************************/
150 static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
153 int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
157 intf_ErrMsg( "aout error: arts_write (%s)", arts_error_text(i_err) );
162 /*****************************************************************************
163 * aout_Close: close the Esound socket
164 *****************************************************************************/
165 static void aout_Close( aout_thread_t *p_aout )
167 arts_close_stream( p_aout->p_sys->stream );
168 free( p_aout->p_sys );