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 #define MODULE_NAME arts
24 #include "modules_inner.h"
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
33 #include <fcntl.h> /* open(), O_WRONLY */
34 #include <string.h> /* strerror() */
35 #include <unistd.h> /* write(), close() */
36 #include <stdio.h> /* "intf_msg.h" */
37 #include <stdlib.h> /* calloc(), malloc(), free() */
42 #include "common.h" /* boolean_t, byte_t */
48 #include "audio_output.h" /* aout_thread_t */
53 #include "modules_export.h"
55 /*****************************************************************************
56 * aout_sys_t: arts audio output method descriptor
57 *****************************************************************************
58 * This structure is part of the audio output thread descriptor.
59 * It describes some arts specific variables.
60 *****************************************************************************/
61 typedef struct aout_sys_s
67 /*****************************************************************************
69 *****************************************************************************/
70 static int aout_Probe ( probedata_t *p_data );
71 static int aout_Open ( aout_thread_t *p_aout );
72 static int aout_SetFormat ( aout_thread_t *p_aout );
73 static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
74 static void aout_Play ( aout_thread_t *p_aout,
75 byte_t *buffer, int i_size );
76 static void aout_Close ( aout_thread_t *p_aout );
78 /*****************************************************************************
79 * Functions exported as capabilities. They are declared as static so that
80 * we don't pollute the namespace too much.
81 *****************************************************************************/
82 void _M( aout_getfunctions )( function_list_t * p_function_list )
84 p_function_list->pf_probe = aout_Probe;
85 p_function_list->functions.aout.pf_open = aout_Open;
86 p_function_list->functions.aout.pf_setformat = aout_SetFormat;
87 p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
88 p_function_list->functions.aout.pf_play = aout_Play;
89 p_function_list->functions.aout.pf_close = aout_Close;
92 /*****************************************************************************
93 * aout_Probe: probes the audio device and return a score
94 *****************************************************************************
95 * This function tries to open the dps and returns a score to the plugin
96 * manager so that it can
97 *****************************************************************************/
98 static int aout_Probe( probedata_t *p_data )
100 if( TestMethod( AOUT_METHOD_VAR, "arts" ) )
105 /* We don't have to test anything -- if we managed to open this plugin,
106 * it means we have the appropriate libs. */
110 /*****************************************************************************
111 * aout_Open: initialize arts connection to server
112 *****************************************************************************/
113 static int aout_Open( aout_thread_t *p_aout )
116 p_aout->i_format = AOUT_FORMAT_DEFAULT;
117 p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
118 p_aout->l_rate = AOUT_RATE_DEFAULT;
125 fprintf(stderr, "arts_init error: %s\n", arts_error_text(i_err));
129 p_aout->p_sys->stream =
130 arts_play_stream( p_aout->l_rate, 16, p_aout->i_channels, "vlc" );
135 /*****************************************************************************
136 * aout_SetFormat: set the output format
137 *****************************************************************************/
138 static int aout_SetFormat( aout_thread_t *p_aout )
141 /* p_aout->i_latency = esd_get_latency(i_fd);*/
142 p_aout->i_latency = 0;
144 intf_WarnMsg(2, "aout_arts_latency: %d",p_aout->i_latency);
149 /*****************************************************************************
150 * aout_GetBufInfo: buffer status query
151 *****************************************************************************/
152 static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
154 /* arbitrary value that should be changed */
155 return( l_buffer_limit );
158 /*****************************************************************************
159 * aout_Play: play a sound samples buffer
160 *****************************************************************************
161 * This function writes a buffer of i_length bytes in the socket
162 *****************************************************************************/
163 static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
166 int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
170 fprintf(stderr, "arts_write error: %s\n", arts_error_text(i_err));
175 /*****************************************************************************
176 * aout_Close: close the Esound socket
177 *****************************************************************************/
178 static void aout_Close( aout_thread_t *p_aout )
180 arts_close_stream( p_aout->p_sys->stream );