]> git.sesse.net Git - vlc/blob - plugins/arts/aout_arts.c
* ./plugins/beos/*: BeOS fixes from Rudolf Cornelissen.
[vlc] / plugins / arts / aout_arts.c
1 /*****************************************************************************
2  * aout_arts.c : aRts functions library
3  *****************************************************************************
4  * Copyright (C) 2001 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 /*****************************************************************************
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 <stdio.h>                                           /* "intf_msg.h" */
31 #include <stdlib.h>                            /* calloc(), malloc(), free() */
32
33 #include <artsc.h>
34
35 #include <videolan/vlc.h>
36
37 #include "audio_output.h"                                   /* aout_thread_t */
38
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
46 {
47     arts_stream_t stream;
48
49 } aout_sys_t;
50
51 /*****************************************************************************
52  * Local prototypes.
53  *****************************************************************************/
54 static int     aout_Probe       ( probedata_t *p_data );
55 static int     aout_Open        ( aout_thread_t *p_aout );
56 static int     aout_SetFormat   ( aout_thread_t *p_aout );
57 static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
58 static void    aout_Play        ( aout_thread_t *p_aout,
59                                   byte_t *buffer, int i_size );
60 static void    aout_Close       ( aout_thread_t *p_aout );
61
62 /*****************************************************************************
63  * Functions exported as capabilities. They are declared as static so that
64  * we don't pollute the namespace too much.
65  *****************************************************************************/
66 void _M( aout_getfunctions )( function_list_t * p_function_list )
67 {
68     p_function_list->pf_probe = aout_Probe;
69     p_function_list->functions.aout.pf_open = aout_Open;
70     p_function_list->functions.aout.pf_setformat = aout_SetFormat;
71     p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
72     p_function_list->functions.aout.pf_play = aout_Play;
73     p_function_list->functions.aout.pf_close = aout_Close;
74 }
75
76 /*****************************************************************************
77  * aout_Probe: probes the audio device and return a score
78  *****************************************************************************
79  * This function tries to open the dps and returns a score to the plugin
80  * manager so that it can 
81  *****************************************************************************/
82 static int aout_Probe( probedata_t *p_data )
83 {
84     /* We don't have to test anything -- if we managed to open this plugin,
85      * it means we have the appropriate libs. */
86     return( 50 );
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     p_aout->i_format = AOUT_FORMAT_DEFAULT;
96     p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
97     p_aout->l_rate = AOUT_RATE_DEFAULT;
98
99     /* Allocate structure */
100     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
101     if( p_aout->p_sys == NULL )
102     {
103         intf_ErrMsg("error: %s", strerror(ENOMEM) );
104         return( 1 );
105     }
106
107     i_err = arts_init();
108     
109     if (i_err < 0)
110     {
111         intf_ErrMsg( "aout error: arts_init (%s)", arts_error_text(i_err) );
112         free( p_aout->p_sys );
113         return(-1);
114     }
115
116     p_aout->p_sys->stream =
117         arts_play_stream( p_aout->l_rate, 16, p_aout->i_channels, "vlc" );
118
119     return( 0 );
120 }
121
122 /*****************************************************************************
123  * aout_SetFormat: set the output format
124  *****************************************************************************/
125 static int aout_SetFormat( aout_thread_t *p_aout )
126 {
127    /*Not ready*/ 
128 /*    p_aout->i_latency = esd_get_latency(i_fd);*/
129     p_aout->i_latency = 0;
130    
131     //intf_WarnMsg( 5, "aout_arts_latency: %d",p_aout->i_latency);
132
133     return( 0 );
134 }
135
136 /*****************************************************************************
137  * aout_GetBufInfo: buffer status query
138  *****************************************************************************/
139 static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
140 {
141     /* arbitrary value that should be changed */
142     return( l_buffer_limit );
143 }
144
145 /*****************************************************************************
146  * aout_Play: play a sound samples buffer
147  *****************************************************************************
148  * This function writes a buffer of i_length bytes in the socket
149  *****************************************************************************/
150 static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
151 {
152
153     int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
154
155     if( i_err < 0 )
156     {
157         intf_ErrMsg( "aout error: arts_write (%s)", arts_error_text(i_err) );
158     }
159
160 }
161
162 /*****************************************************************************
163  * aout_Close: close the Esound socket
164  *****************************************************************************/
165 static void aout_Close( aout_thread_t *p_aout )
166 {
167     arts_close_stream( p_aout->p_sys->stream );
168     free( p_aout->p_sys );
169 }
170