]> git.sesse.net Git - vlc/blob - plugins/arts/arts.c
* ALL: the first libvlc commit.
[vlc] / plugins / arts / arts.c
1 /*****************************************************************************
2  * arts.c : aRts module
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  *
6  * Authors: Emmanuel Blindauer <manu@agat.net>
7  *
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.
12  * 
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.
17  *
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  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
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() */
31
32 #include <vlc/vlc.h>
33 #include <vlc/aout.h>
34
35 #include <artsc.h>
36
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  *****************************************************************************/
43 struct aout_sys_s
44 {
45     arts_stream_t stream;
46 };
47
48 /*****************************************************************************
49  * Local prototypes.
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 * );
57
58 /*****************************************************************************
59  * Build configuration tree.
60  *****************************************************************************/
61 MODULE_CONFIG_START
62 MODULE_CONFIG_STOP
63
64 MODULE_INIT_START
65     SET_DESCRIPTION( _("aRts audio module") )
66     ADD_CAPABILITY( AOUT, 50 )
67 MODULE_INIT_STOP
68
69 MODULE_ACTIVATE_START
70     aout_getfunctions( &p_module->p_functions->aout );
71 MODULE_ACTIVATE_STOP
72
73 MODULE_DEACTIVATE_START
74 MODULE_DEACTIVATE_STOP
75
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 )
81 {
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;
87 }
88
89 /*****************************************************************************
90  * aout_Open: initialize arts connection to server
91  *****************************************************************************/
92 static int aout_Open( aout_thread_t *p_aout )
93 {
94     int i_err = 0;
95
96     /* Allocate structure */
97     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
98     if( p_aout->p_sys == NULL )
99     {
100         msg_Err( p_aout, "out of memory" );
101         return( 1 );
102     }
103
104     i_err = arts_init();
105     
106     if (i_err < 0)
107     {
108         msg_Err( p_aout, "arts_init failed (%s)", arts_error_text(i_err) );
109         free( p_aout->p_sys );
110         return(-1);
111     }
112
113     p_aout->p_sys->stream =
114         arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
115
116     return( 0 );
117 }
118
119 /*****************************************************************************
120  * aout_SetFormat: set the output format
121  *****************************************************************************/
122 static int aout_SetFormat( aout_thread_t *p_aout )
123 {
124    /*Not ready*/ 
125 /*    p_aout->i_latency = esd_get_latency(i_fd);*/
126     p_aout->i_latency = 0;
127    
128     //msg_Dbg( p_aout, "aout_arts_latency: %d", p_aout->i_latency );
129
130     return( 0 );
131 }
132
133 /*****************************************************************************
134  * aout_GetBufInfo: buffer status query
135  *****************************************************************************/
136 static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
137 {
138     /* arbitrary value that should be changed */
139     return( i_buffer_limit );
140 }
141
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 )
148 {
149     int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
150
151     if( i_err < 0 )
152     {
153         msg_Err( p_aout, "arts_write failed (%s)", arts_error_text(i_err) );
154     }
155 }
156
157 /*****************************************************************************
158  * aout_Close: close the Esound socket
159  *****************************************************************************/
160 static void aout_Close( aout_thread_t *p_aout )
161 {
162     arts_close_stream( p_aout->p_sys->stream );
163     free( p_aout->p_sys );
164 }
165