2002-05-28 01:52:40 +00:00
|
|
|
/*
|
|
|
|
* ao_arts - aRts audio output driver for MPlayer
|
|
|
|
*
|
|
|
|
* Michele Balistreri <brain87@gmx.net>
|
|
|
|
*
|
|
|
|
* This driver is distribuited under terms of GPL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <artsc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-01-12 22:00:02 +00:00
|
|
|
#include "config.h"
|
2002-05-28 01:52:40 +00:00
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
2004-12-27 17:30:15 +00:00
|
|
|
#include "libaf/af_format.h"
|
2004-12-07 02:24:15 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
2002-05-28 01:52:40 +00:00
|
|
|
|
2004-12-27 17:30:15 +00:00
|
|
|
#define OBTAIN_BITRATE(a) (((a != AF_FORMAT_U8) && (a != AF_FORMAT_S8)) ? 16 : 8)
|
2002-05-28 01:52:40 +00:00
|
|
|
|
2002-07-26 00:02:31 +00:00
|
|
|
/* Feel free to experiment with the following values: */
|
|
|
|
#define ARTS_PACKETS 10 /* Number of audio packets */
|
|
|
|
#define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
|
|
|
|
|
2002-05-28 01:52:40 +00:00
|
|
|
static arts_stream_t stream;
|
|
|
|
|
|
|
|
static ao_info_t info =
|
|
|
|
{
|
|
|
|
"aRts audio output",
|
|
|
|
"arts",
|
|
|
|
"Michele Balistreri <brain87@gmx.net>",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBAO_EXTERN(arts)
|
|
|
|
|
2003-03-21 16:42:50 +00:00
|
|
|
static int control(int cmd, void *arg)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
|
|
|
return(CONTROL_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init(int rate_hz, int channels, int format, int flags)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int frag_spec;
|
|
|
|
|
2002-11-06 23:54:29 +00:00
|
|
|
if( (err=arts_init()) ) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantInit, arts_error_text(err));
|
2002-05-28 01:52:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_ServerConnect);
|
2002-05-28 01:52:40 +00:00
|
|
|
|
2002-12-27 16:35:29 +00:00
|
|
|
/*
|
|
|
|
* arts supports 8bit unsigned and 16bit signed sample formats
|
|
|
|
* (16bit apparently in little endian format, even in the case
|
|
|
|
* when artsd runs on a big endian cpu).
|
|
|
|
*
|
|
|
|
* Unsupported formats are translated to one of these two formats
|
|
|
|
* using mplayer's audio filters.
|
|
|
|
*/
|
|
|
|
switch (format) {
|
2004-12-27 17:30:15 +00:00
|
|
|
case AF_FORMAT_U8:
|
|
|
|
case AF_FORMAT_S8:
|
|
|
|
format = AF_FORMAT_U8;
|
2002-12-27 16:35:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-12-27 17:30:15 +00:00
|
|
|
format = AF_FORMAT_S16_LE; /* artsd always expects little endian?*/
|
2002-12-27 16:35:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-05-28 01:52:40 +00:00
|
|
|
ao_data.format = format;
|
|
|
|
ao_data.channels = channels;
|
|
|
|
ao_data.samplerate = rate_hz;
|
|
|
|
ao_data.bps = (rate_hz*channels);
|
|
|
|
|
2004-12-27 17:30:15 +00:00
|
|
|
if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8)
|
2002-05-28 01:52:40 +00:00
|
|
|
ao_data.bps*=2;
|
|
|
|
|
2004-08-09 23:53:37 +00:00
|
|
|
stream=arts_play_stream(rate_hz, OBTAIN_BITRATE(format), channels, "MPlayer");
|
2002-05-28 01:52:40 +00:00
|
|
|
|
|
|
|
if(stream == NULL) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantOpenStream);
|
2002-07-26 00:02:31 +00:00
|
|
|
arts_free();
|
2002-05-28 01:52:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-26 00:02:31 +00:00
|
|
|
/* Set the stream to blocking: it will not block anyway, but it seems */
|
|
|
|
/* to be working better */
|
|
|
|
arts_stream_set(stream, ARTS_P_BLOCKING, 1);
|
|
|
|
frag_spec = ARTS_PACKET_SIZE_LOG2 | ARTS_PACKETS << 16;
|
|
|
|
arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
|
|
|
|
ao_data.buffersize = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_StreamOpen);
|
2002-05-28 01:52:40 +00:00
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
|
2002-07-26 00:02:31 +00:00
|
|
|
ao_data.buffersize);
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
|
2002-07-26 00:02:31 +00:00
|
|
|
arts_stream_get(stream, ARTS_P_PACKET_SIZE));
|
2002-05-28 01:52:40 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-04-06 17:55:36 +00:00
|
|
|
static void uninit(int immed)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
|
|
|
arts_close_stream(stream);
|
|
|
|
arts_free();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int play(void* data,int len,int flags)
|
|
|
|
{
|
2002-07-26 00:02:31 +00:00
|
|
|
return arts_write(stream, data, len);
|
2002-05-28 01:52:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static void audio_pause(void)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static void audio_resume(void)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static void reset(void)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static int get_space(void)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
|
|
|
return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
|
|
|
|
}
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static float get_delay(void)
|
2002-05-28 01:52:40 +00:00
|
|
|
{
|
2002-07-26 00:02:31 +00:00
|
|
|
return ((float) (ao_data.buffersize - arts_stream_get(stream,
|
|
|
|
ARTS_P_BUFFER_SPACE))) / ((float) ao_data.bps);
|
2002-05-28 01:52:40 +00:00
|
|
|
}
|
|
|
|
|