]> git.sesse.net Git - vlc/blob - plugins/arts/aout_arts.c
* aRts audio output courtesy of Emmanuel Blindauer <manu@agat.net>.
[vlc] / plugins / arts / aout_arts.c
1 /*****************************************************************************
2  * aout_arts.c : aRts functions library
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors: Blindauer Emmanuel <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 #define MODULE_NAME arts
24 #include "modules_inner.h"
25
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
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() */
38
39 #include <artsc.h>
40
41 #include "config.h"
42 #include "common.h"                                     /* boolean_t, byte_t */
43 #include "threads.h"
44 #include "mtime.h"
45 #include "tests.h"
46
47 #include "audio_output.h"                                   /* aout_thread_t */
48
49 #include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
50 #include "main.h"
51
52 #include "modules.h"
53 #include "modules_export.h"
54
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
62 {
63     arts_stream_t stream;
64
65 } aout_sys_t;
66
67 /*****************************************************************************
68  * Local prototypes.
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 );
77
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 )
83 {
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;
90 }
91
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 )
99 {
100     if( TestMethod( AOUT_METHOD_VAR, "arts" ) )
101     {
102         return( 999 );
103     }
104
105     /* We don't have to test anything -- if we managed to open this plugin,
106      * it means we have the appropriate libs. */
107     return( 50 );
108 }
109
110 /*****************************************************************************
111  * aout_Open: initialize arts connection to server
112  *****************************************************************************/
113 static int aout_Open( aout_thread_t *p_aout )
114 {
115     int i_err = 0;
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;
119
120
121     i_err = arts_init();
122     
123     if (i_err < 0)
124     {
125         fprintf(stderr, "arts_init error: %s\n", arts_error_text(i_err));
126         return(-1);
127     }
128
129     p_aout->p_sys->stream =
130         arts_play_stream( p_aout->l_rate, 16, p_aout->i_channels, "vlc" );
131
132     return( 0 );
133 }
134
135 /*****************************************************************************
136  * aout_SetFormat: set the output format
137  *****************************************************************************/
138 static int aout_SetFormat( aout_thread_t *p_aout )
139 {
140    /*Not ready*/ 
141 /*    p_aout->i_latency = esd_get_latency(i_fd);*/
142     p_aout->i_latency = 0;
143    
144     intf_WarnMsg(2, "aout_arts_latency: %d",p_aout->i_latency);
145
146     return( 0 );
147 }
148
149 /*****************************************************************************
150  * aout_GetBufInfo: buffer status query
151  *****************************************************************************/
152 static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
153 {
154     /* arbitrary value that should be changed */
155     return( l_buffer_limit );
156 }
157
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 )
164 {
165
166     int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
167
168     if(i_err < 0)
169     {
170         fprintf(stderr, "arts_write error: %s\n", arts_error_text(i_err));
171     }
172
173 }
174
175 /*****************************************************************************
176  * aout_Close: close the Esound socket
177  *****************************************************************************/
178 static void aout_Close( aout_thread_t *p_aout )
179 {
180     arts_close_stream( p_aout->p_sys->stream );
181 }
182