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_Open ( aout_thread_t *p_aout );
55 static int aout_SetFormat ( aout_thread_t *p_aout );
56 static int aout_GetBufInfo ( aout_thread_t *p_aout, int i_buffer_info );
57 static void aout_Play ( aout_thread_t *p_aout,
58 byte_t *buffer, int i_size );
59 static void aout_Close ( aout_thread_t *p_aout );
61 /*****************************************************************************
62 * Functions exported as capabilities. They are declared as static so that
63 * we don't pollute the namespace too much.
64 *****************************************************************************/
65 void _M( aout_getfunctions )( function_list_t * p_function_list )
67 p_function_list->functions.aout.pf_open = aout_Open;
68 p_function_list->functions.aout.pf_setformat = aout_SetFormat;
69 p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
70 p_function_list->functions.aout.pf_play = aout_Play;
71 p_function_list->functions.aout.pf_close = aout_Close;
74 /*****************************************************************************
75 * aout_Open: initialize arts connection to server
76 *****************************************************************************/
77 static int aout_Open( aout_thread_t *p_aout )
81 /* Allocate structure */
82 p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
83 if( p_aout->p_sys == NULL )
85 intf_ErrMsg("error: %s", strerror(ENOMEM) );
93 intf_ErrMsg( "aout error: arts_init (%s)", arts_error_text(i_err) );
94 free( p_aout->p_sys );
98 p_aout->p_sys->stream =
99 arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
104 /*****************************************************************************
105 * aout_SetFormat: set the output format
106 *****************************************************************************/
107 static int aout_SetFormat( aout_thread_t *p_aout )
110 /* p_aout->i_latency = esd_get_latency(i_fd);*/
111 p_aout->i_latency = 0;
113 //intf_WarnMsg( 5, "aout_arts_latency: %d",p_aout->i_latency);
118 /*****************************************************************************
119 * aout_GetBufInfo: buffer status query
120 *****************************************************************************/
121 static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
123 /* arbitrary value that should be changed */
124 return( i_buffer_limit );
127 /*****************************************************************************
128 * aout_Play: play a sound samples buffer
129 *****************************************************************************
130 * This function writes a buffer of i_length bytes in the socket
131 *****************************************************************************/
132 static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
135 int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
139 intf_ErrMsg( "aout error: arts_write (%s)", arts_error_text(i_err) );
144 /*****************************************************************************
145 * aout_Close: close the Esound socket
146 *****************************************************************************/
147 static void aout_Close( aout_thread_t *p_aout )
149 arts_close_stream( p_aout->p_sys->stream );
150 free( p_aout->p_sys );