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 int Open ( vlc_object_t * );
52 static void Close ( vlc_object_t * );
54 static int SetFormat ( aout_thread_t * );
55 static int GetBufInfo ( aout_thread_t *, int );
56 static void Play ( aout_thread_t *, byte_t *, int );
58 /*****************************************************************************
60 *****************************************************************************/
62 set_description( _("aRts audio module") );
63 set_capability( "audio output", 50 );
64 set_callbacks( Open, Close );
67 /*****************************************************************************
68 * Open: initialize arts connection to server
69 *****************************************************************************/
70 static int Open( vlc_object_t *p_this )
72 aout_thread_t *p_aout = (aout_thread_t *)p_this;
75 /* Allocate structure */
76 p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
77 if( p_aout->p_sys == NULL )
79 msg_Err( p_aout, "out of memory" );
87 msg_Err( p_aout, "arts_init failed (%s)", arts_error_text(i_err) );
88 free( p_aout->p_sys );
92 p_aout->pf_setformat = SetFormat;
93 p_aout->pf_getbufinfo = GetBufInfo;
94 p_aout->pf_play = Play;
96 p_aout->p_sys->stream =
97 arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
102 /*****************************************************************************
103 * SetFormat: set the output format
104 *****************************************************************************/
105 static int SetFormat( aout_thread_t *p_aout )
108 /* p_aout->i_latency = esd_get_latency(i_fd);*/
109 p_aout->i_latency = 0;
111 //msg_Dbg( p_aout, "aout_arts_latency: %d", p_aout->i_latency );
116 /*****************************************************************************
117 * GetBufInfo: buffer status query
118 *****************************************************************************/
119 static int GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
121 /* arbitrary value that should be changed */
122 return( i_buffer_limit );
125 /*****************************************************************************
126 * Play: play a sound samples buffer
127 *****************************************************************************
128 * This function writes a buffer of i_length bytes in the socket
129 *****************************************************************************/
130 static void Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
132 int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
136 msg_Err( p_aout, "arts_write failed (%s)", arts_error_text(i_err) );
140 /*****************************************************************************
141 * Close: close the Esound socket
142 *****************************************************************************/
143 static void Close( vlc_object_t *p_this )
145 aout_thread_t *p_aout = (aout_thread_t *)p_this;
147 arts_close_stream( p_aout->p_sys->stream );
148 free( p_aout->p_sys );