]> git.sesse.net Git - vlc/blob - plugins/esd/aout_esd.c
. rajout de l'option -Winline
[vlc] / plugins / esd / aout_esd.c
1 /*****************************************************************************
2  * aout_esd.c : Esound functions library
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors:
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 /* TODO:
24  *
25  * - use the libesd function to get latency when it's not buggy anymore
26  *
27  */
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include "defs.h"
33
34 #include <errno.h>                                                 /* ENOMEM */
35 #include <fcntl.h>                                       /* open(), O_WRONLY */
36 #include <string.h>                                            /* strerror() */
37 #include <unistd.h>                                      /* write(), close() */
38 #include <stdio.h>                                           /* "intf_msg.h" */
39 #include <stdlib.h>                            /* calloc(), malloc(), free() */
40
41 #include <esd.h>
42
43 #include "config.h"
44 #include "common.h"                                     /* boolean_t, byte_t */
45 #include "threads.h"
46 #include "mtime.h"
47 #include "plugins.h"
48
49 #include "audio_output.h"                                   /* aout_thread_t */
50
51 #include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
52 #include "main.h"
53
54 /*****************************************************************************
55  * aout_sys_t: esd audio output method descriptor
56  *****************************************************************************
57  * This structure is part of the audio output thread descriptor.
58  * It describes some esd specific variables.
59  *****************************************************************************/
60 typedef struct aout_sys_s
61 {
62     esd_format_t esd_format;
63
64 } aout_sys_t;
65
66 /*****************************************************************************
67  * aout_EsdOpen: opens an esd socket
68  *****************************************************************************/
69 int aout_EsdOpen( aout_thread_t *p_aout )
70 {
71     /* mpg123 does it this way */
72     int i_bits = ESD_BITS16;
73     int i_mode = ESD_STREAM;
74     int i_func = ESD_PLAY;
75
76     /* Allocate structure */
77     p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
78     if( p_aout->p_sys == NULL )
79     {
80         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
81         return( 1 );
82     }
83
84     /* Initialize some variables */
85     p_aout->i_format = AOUT_DEFAULT_FORMAT;
86     p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
87     p_aout->l_rate     = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
88
89     i_bits = ESD_BITS16;
90     i_mode = ESD_STREAM;
91     i_func = ESD_PLAY;
92     p_aout->p_sys->esd_format = (i_bits | i_mode | i_func) & (~ESD_MASK_CHAN);
93
94     if( p_aout->i_channels == 1 )
95         p_aout->p_sys->esd_format |= ESD_MONO;
96     else
97         p_aout->p_sys->esd_format |= ESD_STEREO;
98
99     /* open a socket for playing a stream
100      * and try to open /dev/dsp if there's no EsounD */
101     if ( (p_aout->i_fd
102             = esd_play_stream_fallback(p_aout->p_sys->esd_format,
103                 p_aout->l_rate, NULL, "vlc")) < 0 )
104     {
105         intf_ErrMsg( "aout error: can't open esound socket"
106                      " (format 0x%08x at %ld Hz)\n",
107                      p_aout->p_sys->esd_format, p_aout->l_rate );
108         return( -1 );
109     }
110
111     return( 0 );
112 }
113
114 /*****************************************************************************
115  * aout_EsdReset: resets the dsp
116  *****************************************************************************/
117 int aout_EsdReset( aout_thread_t *p_aout )
118 {
119     return( 0 );
120 }
121
122 /*****************************************************************************
123  * aout_EsdSetFormat: sets the dsp output format
124  *****************************************************************************/
125 int aout_EsdSetFormat( aout_thread_t *p_aout )
126 {
127     return( 0 );
128 }
129
130 /*****************************************************************************
131  * aout_EsdSetChannels: sets the dsp's stereo or mono mode
132  *****************************************************************************/
133 int aout_EsdSetChannels( aout_thread_t *p_aout )
134 {
135     return( 0 );
136 }
137
138 /*****************************************************************************
139  * aout_EsdSetRate: sets the dsp's audio output rate
140  *****************************************************************************/
141 int aout_EsdSetRate( aout_thread_t *p_aout )
142 {
143     return( 0 );
144 }
145
146 /*****************************************************************************
147  * aout_EsdGetBufInfo: buffer status query
148  *****************************************************************************/
149 long aout_EsdGetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
150 {
151     /* arbitrary value that should be changed */
152     return( l_buffer_limit );
153 }
154
155 /*****************************************************************************
156  * aout_EsdPlaySamples: plays a sound samples buffer
157  *****************************************************************************
158  * This function writes a buffer of i_length bytes in the dsp
159  *****************************************************************************/
160 void aout_EsdPlaySamples( aout_thread_t *p_aout, byte_t *buffer, int i_size )
161 {
162     int amount;
163
164     if (p_aout->p_sys->esd_format & ESD_STEREO)
165     {
166         if (p_aout->p_sys->esd_format & ESD_BITS16)
167             amount = (44100 * (ESD_BUF_SIZE + 64)) / p_aout->l_rate;
168         else
169             amount = (44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
170     }
171     else
172     {
173         if (p_aout->p_sys->esd_format & ESD_BITS16)
174             amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
175         else
176             amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / p_aout->l_rate;
177     }
178
179     intf_DbgMsg( "aout: latency is %i\n", amount );
180
181     write( p_aout->i_fd, buffer, i_size );
182 }
183
184 /*****************************************************************************
185  * aout_EsdClose: closes the dsp audio device
186  *****************************************************************************/
187 void aout_EsdClose( aout_thread_t *p_aout )
188 {
189     close( p_aout->i_fd );
190 }
191