2001-06-04 17:42:09 +00:00
|
|
|
/*
|
2009-01-26 15:06:44 +00:00
|
|
|
* ALSA 0.5.x audio output driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Alex Beregszaszi
|
|
|
|
*
|
|
|
|
* Thanks to Arpi for helping me ;)
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/asoundlib.h>
|
|
|
|
|
2004-12-07 02:24:15 +00:00
|
|
|
#include "config.h"
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
2004-12-27 17:30:15 +00:00
|
|
|
#include "libaf/af_format.h"
|
2001-06-04 17:42:09 +00:00
|
|
|
|
2004-12-07 02:24:15 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
2002-04-29 16:53:38 +00:00
|
|
|
|
2001-06-04 17:42:09 +00:00
|
|
|
static ao_info_t info =
|
|
|
|
{
|
|
|
|
"ALSA-0.5.x audio output",
|
|
|
|
"alsa5",
|
2003-07-03 20:07:54 +00:00
|
|
|
"Alex Beregszaszi",
|
2001-06-04 17:42:09 +00:00
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBAO_EXTERN(alsa5)
|
|
|
|
|
|
|
|
static snd_pcm_t *alsa_handler;
|
|
|
|
static snd_pcm_format_t alsa_format;
|
|
|
|
static int alsa_rate = SND_PCM_RATE_CONTINUOUS;
|
|
|
|
|
|
|
|
/* to set/get/query special features/parameters */
|
2003-03-21 16:42:50 +00:00
|
|
|
static int control(int cmd, void *arg)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
2008-05-16 09:31:55 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
open & setup audio device
|
|
|
|
return: 1=success 0=fail
|
|
|
|
*/
|
|
|
|
static int init(int rate_hz, int channels, int format, int flags)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int cards = -1;
|
|
|
|
snd_pcm_channel_params_t params;
|
|
|
|
snd_pcm_channel_setup_t setup;
|
|
|
|
snd_pcm_info_t info;
|
|
|
|
snd_pcm_channel_info_t chninfo;
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ALSA5_InitInfo, rate_hz,
|
2004-12-28 19:11:14 +00:00
|
|
|
channels, af_fmt2str_short(format));
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
alsa_handler = NULL;
|
|
|
|
|
2002-04-29 16:53:38 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_V, "alsa-init: compiled for ALSA-%s (%d)\n", SND_LIB_VERSION_STR,
|
|
|
|
SND_LIB_VERSION);
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
if ((cards = snd_cards()) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_SoundCardNotFound);
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.format = format;
|
2002-10-07 19:56:26 +00:00
|
|
|
ao_data.channels = channels;
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.samplerate = rate_hz;
|
2002-10-07 19:56:26 +00:00
|
|
|
ao_data.bps = ao_data.samplerate*ao_data.channels;
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.outburst = OUTBURST;
|
|
|
|
ao_data.buffersize = 16384;
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
memset(&alsa_format, 0, sizeof(alsa_format));
|
|
|
|
switch (format)
|
|
|
|
{
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_S8:
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.format = SND_PCM_SFMT_S8;
|
|
|
|
break;
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_U8:
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.format = SND_PCM_SFMT_U8;
|
|
|
|
break;
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_U16_LE:
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.format = SND_PCM_SFMT_U16_LE;
|
|
|
|
break;
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_U16_BE:
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.format = SND_PCM_SFMT_U16_BE;
|
|
|
|
break;
|
2002-04-22 22:33:06 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_AC3:
|
2002-04-22 22:33:06 +00:00
|
|
|
#endif
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_S16_LE:
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.format = SND_PCM_SFMT_S16_LE;
|
|
|
|
break;
|
2002-04-22 22:33:06 +00:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_AC3:
|
2002-04-22 22:33:06 +00:00
|
|
|
#endif
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_S16_BE:
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.format = SND_PCM_SFMT_S16_BE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
alsa_format.format = SND_PCM_SFMT_MPEG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(alsa_format.format)
|
|
|
|
{
|
|
|
|
case SND_PCM_SFMT_S16_LE:
|
|
|
|
case SND_PCM_SFMT_U16_LE:
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.bps *= 2;
|
2001-06-04 17:42:09 +00:00
|
|
|
break;
|
|
|
|
case -1:
|
2004-12-28 19:11:14 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_InvalidFormatReq,af_fmt2str_short(format));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-12 14:13:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(rate_hz)
|
|
|
|
{
|
|
|
|
case 8000:
|
|
|
|
alsa_rate = SND_PCM_RATE_8000;
|
|
|
|
break;
|
|
|
|
case 11025:
|
|
|
|
alsa_rate = SND_PCM_RATE_11025;
|
|
|
|
break;
|
|
|
|
case 16000:
|
|
|
|
alsa_rate = SND_PCM_RATE_16000;
|
|
|
|
break;
|
|
|
|
case 22050:
|
|
|
|
alsa_rate = SND_PCM_RATE_22050;
|
|
|
|
break;
|
|
|
|
case 32000:
|
|
|
|
alsa_rate = SND_PCM_RATE_32000;
|
|
|
|
break;
|
|
|
|
case 44100:
|
|
|
|
alsa_rate = SND_PCM_RATE_44100;
|
|
|
|
break;
|
|
|
|
case 48000:
|
|
|
|
alsa_rate = SND_PCM_RATE_48000;
|
|
|
|
break;
|
|
|
|
case 88200:
|
|
|
|
alsa_rate = SND_PCM_RATE_88200;
|
|
|
|
break;
|
|
|
|
case 96000:
|
|
|
|
alsa_rate = SND_PCM_RATE_96000;
|
|
|
|
break;
|
|
|
|
case 176400:
|
|
|
|
alsa_rate = SND_PCM_RATE_176400;
|
|
|
|
break;
|
|
|
|
case 192000:
|
|
|
|
alsa_rate = SND_PCM_RATE_192000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
alsa_rate = SND_PCM_RATE_CONTINUOUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
alsa_format.rate = ao_data.samplerate;
|
2003-03-23 18:19:08 +00:00
|
|
|
alsa_format.voices = ao_data.channels;
|
2001-06-04 17:42:09 +00:00
|
|
|
alsa_format.interleave = 1;
|
|
|
|
|
|
|
|
if ((err = snd_pcm_open(&alsa_handler, 0, 0, SND_PCM_OPEN_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PlayBackError, snd_strerror(err));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_info(alsa_handler, &info)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PcmInfoError, snd_strerror(err));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ALSA5_SoundcardsFound,
|
2002-04-29 16:53:38 +00:00
|
|
|
cards, info.name);
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
if (info.flags & SND_PCM_INFO_PLAYBACK)
|
|
|
|
{
|
2001-12-24 10:35:43 +00:00
|
|
|
memset(&chninfo, 0, sizeof(chninfo));
|
2001-06-04 17:42:09 +00:00
|
|
|
chninfo.channel = SND_PCM_CHANNEL_PLAYBACK;
|
|
|
|
if ((err = snd_pcm_channel_info(alsa_handler, &chninfo)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PcmChanInfoError, snd_strerror(err));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
2001-11-24 05:21:22 +00:00
|
|
|
|
2001-11-23 16:35:51 +00:00
|
|
|
#ifndef __QNX__
|
2001-06-04 17:42:09 +00:00
|
|
|
if (chninfo.buffer_size)
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.buffersize = chninfo.buffer_size;
|
2001-11-23 16:35:51 +00:00
|
|
|
#endif
|
2001-11-24 05:21:22 +00:00
|
|
|
|
2002-04-29 16:53:38 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_V, "alsa-init: setting preferred buffer size from driver: %d bytes\n",
|
|
|
|
ao_data.buffersize);
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
params.channel = SND_PCM_CHANNEL_PLAYBACK;
|
|
|
|
params.mode = SND_PCM_MODE_STREAM;
|
|
|
|
params.format = alsa_format;
|
|
|
|
params.start_mode = SND_PCM_START_DATA;
|
|
|
|
params.stop_mode = SND_PCM_STOP_ROLLOVER;
|
2001-11-24 05:21:22 +00:00
|
|
|
params.buf.stream.queue_size = ao_data.buffersize;
|
2001-06-04 17:42:09 +00:00
|
|
|
params.buf.stream.fill = SND_PCM_FILL_NONE;
|
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_params(alsa_handler, ¶ms)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_CantSetParms, snd_strerror(err));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&setup, 0, sizeof(setup));
|
|
|
|
setup.channel = SND_PCM_CHANNEL_PLAYBACK;
|
|
|
|
setup.mode = SND_PCM_MODE_STREAM;
|
|
|
|
setup.format = alsa_format;
|
2001-11-24 05:21:22 +00:00
|
|
|
setup.buf.stream.queue_size = ao_data.buffersize;
|
|
|
|
setup.msbits_per_sample = ao_data.bps;
|
2001-06-04 17:42:09 +00:00
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_setup(alsa_handler, &setup)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_CantSetChan, snd_strerror(err));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ChanPrepareError, snd_strerror(err));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
2002-04-29 16:53:38 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, "AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n",
|
2002-10-07 19:56:26 +00:00
|
|
|
ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize,
|
2001-06-04 17:42:09 +00:00
|
|
|
snd_pcm_get_format_name(alsa_format.format));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 1;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* close audio device */
|
2004-04-06 17:55:36 +00:00
|
|
|
static void uninit(int immed)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
2001-06-08 13:35:24 +00:00
|
|
|
int err;
|
|
|
|
|
2001-06-07 13:03:17 +00:00
|
|
|
if ((err = snd_pcm_playback_drain(alsa_handler)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_DrainError, snd_strerror(err));
|
2001-06-07 13:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_FlushError, snd_strerror(err));
|
2001-06-07 13:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_close(alsa_handler)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PcmCloseError, snd_strerror(err));
|
2001-06-07 13:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stop playing and empty buffers (for seeking/pause) */
|
2006-07-06 04:30:19 +00:00
|
|
|
static void reset(void)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if ((err = snd_pcm_playback_drain(alsa_handler)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetDrainError, snd_strerror(err));
|
2001-06-04 17:42:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetFlushError, snd_strerror(err));
|
2001-06-04 17:42:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResetChanPrepareError, snd_strerror(err));
|
2001-06-04 17:42:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
/* stop playing, keep buffers (for pause) */
|
2006-07-06 04:30:19 +00:00
|
|
|
static void audio_pause(void)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
2001-06-07 13:03:17 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if ((err = snd_pcm_playback_drain(alsa_handler)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PauseDrainError, snd_strerror(err));
|
2001-06-07 13:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = snd_pcm_channel_flush(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PauseFlushError, snd_strerror(err));
|
2001-06-07 13:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-05 18:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* resume playing, after audio_pause() */
|
2006-07-06 04:30:19 +00:00
|
|
|
static void audio_resume(void)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
2001-06-08 13:35:24 +00:00
|
|
|
int err;
|
2001-06-07 13:03:17 +00:00
|
|
|
if ((err = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_ResumePrepareError, snd_strerror(err));
|
2001-06-07 13:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-05 18:40:44 +00:00
|
|
|
}
|
|
|
|
|
2001-06-04 17:42:09 +00:00
|
|
|
/*
|
|
|
|
plays 'len' bytes of 'data'
|
|
|
|
returns: number of bytes played
|
|
|
|
*/
|
|
|
|
static int play(void* data, int len, int flags)
|
|
|
|
{
|
2002-04-29 16:53:38 +00:00
|
|
|
int got_len;
|
|
|
|
|
|
|
|
if (!len)
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2002-04-29 16:53:38 +00:00
|
|
|
|
|
|
|
if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
2002-04-29 16:53:38 +00:00
|
|
|
if (got_len == -EPIPE) /* underrun? */
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_Underrun);
|
2002-04-29 16:53:38 +00:00
|
|
|
if ((got_len = snd_pcm_channel_prepare(alsa_handler, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_PlaybackPrepareError, snd_strerror(got_len));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
2002-04-29 16:53:38 +00:00
|
|
|
if ((got_len = snd_pcm_write(alsa_handler, data, len)) < 0)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_WriteErrorAfterReset,
|
2002-04-29 16:53:38 +00:00
|
|
|
snd_strerror(got_len));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
2008-05-16 09:31:55 +00:00
|
|
|
return got_len; /* 2nd write was ok */
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ALSA5_OutPutError, snd_strerror(got_len));
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
2008-05-16 09:31:55 +00:00
|
|
|
return got_len;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* how many byes are free in the buffer */
|
2006-07-06 04:30:19 +00:00
|
|
|
static int get_space(void)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
|
|
|
snd_pcm_channel_status_t ch_stat;
|
|
|
|
|
|
|
|
ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK;
|
|
|
|
|
|
|
|
if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0)
|
2008-05-16 09:31:55 +00:00
|
|
|
return 0; /* error occurred */
|
2001-06-04 17:42:09 +00:00
|
|
|
else
|
2008-05-16 09:31:55 +00:00
|
|
|
return ch_stat.free;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
/* delay in seconds between first and last sample in buffer */
|
2006-07-06 04:30:19 +00:00
|
|
|
static float get_delay(void)
|
2001-06-04 17:42:09 +00:00
|
|
|
{
|
|
|
|
snd_pcm_channel_status_t ch_stat;
|
|
|
|
|
|
|
|
ch_stat.channel = SND_PCM_CHANNEL_PLAYBACK;
|
|
|
|
|
|
|
|
if (snd_pcm_channel_status(alsa_handler, &ch_stat) < 0)
|
2008-05-16 09:31:55 +00:00
|
|
|
return (float)ao_data.buffersize/(float)ao_data.bps; /* error occurred */
|
2001-06-04 17:42:09 +00:00
|
|
|
else
|
2008-05-16 09:31:55 +00:00
|
|
|
return (float)ch_stat.count/(float)ao_data.bps;
|
2001-06-04 17:42:09 +00:00
|
|
|
}
|