1
/*****************************************************************************
2
* aout_esd.c : Esound functions library
3
*****************************************************************************
4
* Copyright (C) 2000-2001 VideoLAN
5
* $Id: aout_esd.c,v 1.16 2001/12/07 18:33:07 sam Exp $
7
* Authors: Samuel Hocevar <sam@zoy.org>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22
*****************************************************************************/
24
#define MODULE_NAME esd
25
#include "modules_inner.h"
29
* - use the libesd function to get latency when it's not buggy anymore
33
/*****************************************************************************
35
*****************************************************************************/
38
#include <errno.h> /* ENOMEM */
39
#include <fcntl.h> /* open(), O_WRONLY */
40
#include <string.h> /* strerror() */
41
#include <unistd.h> /* write(), close() */
42
#include <stdio.h> /* "intf_msg.h" */
43
#include <stdlib.h> /* calloc(), malloc(), free() */
47
#include "common.h" /* boolean_t, byte_t */
48
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
53
#include "audio_output.h" /* aout_thread_t */
56
#include "modules_export.h"
58
/*****************************************************************************
59
* aout_sys_t: esd audio output method descriptor
60
*****************************************************************************
61
* This structure is part of the audio output thread descriptor.
62
* It describes some esd specific variables.
63
*****************************************************************************/
64
typedef struct aout_sys_s
66
esd_format_t esd_format;
70
/*****************************************************************************
72
*****************************************************************************/
73
static int aout_Probe ( probedata_t *p_data );
74
static int aout_Open ( aout_thread_t *p_aout );
75
static int aout_SetFormat ( aout_thread_t *p_aout );
76
static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
77
static void aout_Play ( aout_thread_t *p_aout,
78
byte_t *buffer, int i_size );
79
static void aout_Close ( aout_thread_t *p_aout );
81
/*****************************************************************************
82
* Functions exported as capabilities. They are declared as static so that
83
* we don't pollute the namespace too much.
84
*****************************************************************************/
85
void _M( aout_getfunctions )( function_list_t * p_function_list )
87
p_function_list->pf_probe = aout_Probe;
88
p_function_list->functions.aout.pf_open = aout_Open;
89
p_function_list->functions.aout.pf_setformat = aout_SetFormat;
90
p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
91
p_function_list->functions.aout.pf_play = aout_Play;
92
p_function_list->functions.aout.pf_close = aout_Close;
95
/*****************************************************************************
96
* aout_Probe: probes the audio device and return a score
97
*****************************************************************************
98
* This function tries to open the dps and returns a score to the plugin
99
* manager so that it can
100
*****************************************************************************/
101
static int aout_Probe( probedata_t *p_data )
103
if( TestMethod( AOUT_METHOD_VAR, "esd" ) )
108
/* We don't have to test anything -- if we managed to open this plugin,
109
* it means we have the appropriate libs. */
113
/*****************************************************************************
114
* aout_Open: open an esd socket
115
*****************************************************************************/
116
static int aout_Open( aout_thread_t *p_aout )
118
/* mpg123 does it this way */
119
int i_bits = ESD_BITS16;
120
int i_mode = ESD_STREAM;
121
int i_func = ESD_PLAY;
123
/* Allocate structure */
124
p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
125
if( p_aout->p_sys == NULL )
127
intf_ErrMsg("error: %s", strerror(ENOMEM) );
131
/* Initialize some variables */
132
p_aout->i_format = AOUT_FORMAT_DEFAULT;
133
p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
134
p_aout->l_rate = esd_audio_rate; /* We use actual esd rate value, not AOUT_RATE_DEFAULT */
139
p_aout->p_sys->esd_format = (i_bits | i_mode | i_func) & (~ESD_MASK_CHAN);
141
if( p_aout->i_channels == 1 )
143
p_aout->p_sys->esd_format |= ESD_MONO;
147
p_aout->p_sys->esd_format |= ESD_STEREO;
150
/* open a socket for playing a stream
151
* and try to open /dev/dsp if there's no EsounD */
153
= esd_play_stream_fallback(p_aout->p_sys->esd_format,
154
p_aout->l_rate, NULL, "vlc")) < 0 )
156
intf_ErrMsg( "aout error: can't open esound socket"
157
" (format 0x%08x at %ld Hz)",
158
p_aout->p_sys->esd_format, p_aout->l_rate );
165
/*****************************************************************************
166
* aout_SetFormat: set the output format
167
*****************************************************************************/
168
static int aout_SetFormat( aout_thread_t *p_aout )
172
i_fd = esd_open_sound(NULL);
173
p_aout->i_latency = esd_get_latency(i_fd);
175
intf_WarnMsg(2, "aout_esd_latency: %d",p_aout->i_latency);
180
/*****************************************************************************
181
* aout_GetBufInfo: buffer status query
182
*****************************************************************************/
183
static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
185
/* arbitrary value that should be changed */
186
return( l_buffer_limit );
189
/*****************************************************************************
190
* aout_Play: play a sound samples buffer
191
*****************************************************************************
192
* This function writes a buffer of i_length bytes in the socket
193
*****************************************************************************/
194
static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
198
if (p_aout->p_sys->esd_format & ESD_STEREO)
200
if (p_aout->p_sys->esd_format & ESD_BITS16)
202
i_amount = (44100 * (ESD_BUF_SIZE + 64)) / p_aout->l_rate;
206
i_amount = (44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
211
if (p_aout->p_sys->esd_format & ESD_BITS16)
213
i_amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
217
i_amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / p_aout->l_rate;
221
write( p_aout->i_fd, buffer, i_size );
224
/*****************************************************************************
225
* aout_Close: close the Esound socket
226
*****************************************************************************/
227
static void aout_Close( aout_thread_t *p_aout )
229
close( p_aout->i_fd );