]> git.sesse.net Git - vlc/blob - plugins/arts/arts.c
* ALL: new module API. Makes a few things a lot simpler, and we gain
[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_t
44 {
45     arts_stream_t stream;
46 };
47
48 /*****************************************************************************
49  * Local prototypes
50  *****************************************************************************/
51 static int  Open         ( vlc_object_t * );
52 static void Close        ( vlc_object_t * );
53
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 );
57
58 /*****************************************************************************
59  * Module descriptor
60  *****************************************************************************/
61 vlc_module_begin();
62    set_description( _("aRts audio module") );
63    set_capability( "audio output", 50 );
64    set_callbacks( Open, Close );
65 vlc_module_end();
66
67 /*****************************************************************************
68  * Open: initialize arts connection to server
69  *****************************************************************************/
70 static int Open( vlc_object_t *p_this )
71 {
72     aout_thread_t *p_aout = (aout_thread_t *)p_this;
73     int i_err = 0;
74
75     /* Allocate structure */
76     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
77     if( p_aout->p_sys == NULL )
78     {
79         msg_Err( p_aout, "out of memory" );
80         return( 1 );
81     }
82
83     i_err = arts_init();
84     
85     if (i_err < 0)
86     {
87         msg_Err( p_aout, "arts_init failed (%s)", arts_error_text(i_err) );
88         free( p_aout->p_sys );
89         return(-1);
90     }
91
92     p_aout->pf_setformat = SetFormat;
93     p_aout->pf_getbufinfo = GetBufInfo;
94     p_aout->pf_play = Play;
95
96     p_aout->p_sys->stream =
97         arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
98
99     return( 0 );
100 }
101
102 /*****************************************************************************
103  * SetFormat: set the output format
104  *****************************************************************************/
105 static int SetFormat( aout_thread_t *p_aout )
106 {
107    /*Not ready*/ 
108 /*    p_aout->i_latency = esd_get_latency(i_fd);*/
109     p_aout->i_latency = 0;
110    
111     //msg_Dbg( p_aout, "aout_arts_latency: %d", p_aout->i_latency );
112
113     return( 0 );
114 }
115
116 /*****************************************************************************
117  * GetBufInfo: buffer status query
118  *****************************************************************************/
119 static int GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
120 {
121     /* arbitrary value that should be changed */
122     return( i_buffer_limit );
123 }
124
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 )
131 {
132     int i_err = arts_write( p_aout->p_sys->stream, buffer, i_size );
133
134     if( i_err < 0 )
135     {
136         msg_Err( p_aout, "arts_write failed (%s)", arts_error_text(i_err) );
137     }
138 }
139
140 /*****************************************************************************
141  * Close: close the Esound socket
142  *****************************************************************************/
143 static void Close( vlc_object_t *p_this )
144 {
145     aout_thread_t *p_aout = (aout_thread_t *)p_this;
146
147     arts_close_stream( p_aout->p_sys->stream );
148     free( p_aout->p_sys );
149 }
150