]> git.sesse.net Git - vlc/blob - plugins/arts/aout_arts.c
4e02122aaaa1cd2105deb294f5f2da5e4b16bf27
[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_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 );
60
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 )
66 {
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;
72 }
73
74 /*****************************************************************************
75  * aout_Open: initialize arts connection to server
76  *****************************************************************************/
77 static int aout_Open( aout_thread_t *p_aout )
78 {
79     int i_err = 0;
80
81     /* Allocate structure */
82     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
83     if( p_aout->p_sys == NULL )
84     {
85         intf_ErrMsg("error: %s", strerror(ENOMEM) );
86         return( 1 );
87     }
88
89     i_err = arts_init();
90     
91     if (i_err < 0)
92     {
93         intf_ErrMsg( "aout error: arts_init (%s)", arts_error_text(i_err) );
94         free( p_aout->p_sys );
95         return(-1);
96     }
97
98     p_aout->p_sys->stream =
99         arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
100
101     return( 0 );
102 }
103
104 /*****************************************************************************
105  * aout_SetFormat: set the output format
106  *****************************************************************************/
107 static int aout_SetFormat( aout_thread_t *p_aout )
108 {
109    /*Not ready*/ 
110 /*    p_aout->i_latency = esd_get_latency(i_fd);*/
111     p_aout->i_latency = 0;
112    
113     //intf_WarnMsg( 5, "aout_arts_latency: %d",p_aout->i_latency);
114
115     return( 0 );
116 }
117
118 /*****************************************************************************
119  * aout_GetBufInfo: buffer status query
120  *****************************************************************************/
121 static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
122 {
123     /* arbitrary value that should be changed */
124     return( i_buffer_limit );
125 }
126
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 )
133 {
134
135     int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
136
137     if( i_err < 0 )
138     {
139         intf_ErrMsg( "aout error: arts_write (%s)", arts_error_text(i_err) );
140     }
141
142 }
143
144 /*****************************************************************************
145  * aout_Close: close the Esound socket
146  *****************************************************************************/
147 static void aout_Close( aout_thread_t *p_aout )
148 {
149     arts_close_stream( p_aout->p_sys->stream );
150     free( p_aout->p_sys );
151 }
152