Add a comment that explains why this header has no multiple inclusion guards.
[mplayer/greg.git] / libao2 / ao_arts.c
blob96379560a0b17cc51353a5f65794ca9fef9ce4c9
1 /*
2 * ao_arts - aRts audio output driver for MPlayer
4 * Michele Balistreri <brain87@gmx.net>
6 * This driver is distribuited under terms of GPL
8 */
10 #include <artsc.h>
11 #include <stdio.h>
13 #include "config.h"
14 #include "audio_out.h"
15 #include "audio_out_internal.h"
16 #include "libaf/af_format.h"
17 #include "mp_msg.h"
18 #include "help_mp.h"
20 #define OBTAIN_BITRATE(a) (((a != AF_FORMAT_U8) && (a != AF_FORMAT_S8)) ? 16 : 8)
22 /* Feel free to experiment with the following values: */
23 #define ARTS_PACKETS 10 /* Number of audio packets */
24 #define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
26 static arts_stream_t stream;
28 static ao_info_t info =
30 "aRts audio output",
31 "arts",
32 "Michele Balistreri <brain87@gmx.net>",
36 LIBAO_EXTERN(arts)
38 static int control(int cmd, void *arg)
40 return(CONTROL_UNKNOWN);
43 static int init(int rate_hz, int channels, int format, int flags)
45 int err;
46 int frag_spec;
48 if( (err=arts_init()) ) {
49 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantInit, arts_error_text(err));
50 return 0;
52 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_ServerConnect);
55 * arts supports 8bit unsigned and 16bit signed sample formats
56 * (16bit apparently in little endian format, even in the case
57 * when artsd runs on a big endian cpu).
59 * Unsupported formats are translated to one of these two formats
60 * using mplayer's audio filters.
62 switch (format) {
63 case AF_FORMAT_U8:
64 case AF_FORMAT_S8:
65 format = AF_FORMAT_U8;
66 break;
67 default:
68 format = AF_FORMAT_S16_LE; /* artsd always expects little endian?*/
69 break;
72 ao_data.format = format;
73 ao_data.channels = channels;
74 ao_data.samplerate = rate_hz;
75 ao_data.bps = (rate_hz*channels);
77 if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8)
78 ao_data.bps*=2;
80 stream=arts_play_stream(rate_hz, OBTAIN_BITRATE(format), channels, "MPlayer");
82 if(stream == NULL) {
83 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantOpenStream);
84 arts_free();
85 return 0;
88 /* Set the stream to blocking: it will not block anyway, but it seems */
89 /* to be working better */
90 arts_stream_set(stream, ARTS_P_BLOCKING, 1);
91 frag_spec = ARTS_PACKET_SIZE_LOG2 | ARTS_PACKETS << 16;
92 arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
93 ao_data.buffersize = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
94 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_StreamOpen);
96 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
97 ao_data.buffersize);
98 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
99 arts_stream_get(stream, ARTS_P_PACKET_SIZE));
101 return 1;
104 static void uninit(int immed)
106 arts_close_stream(stream);
107 arts_free();
110 static int play(void* data,int len,int flags)
112 return arts_write(stream, data, len);
115 static void audio_pause(void)
119 static void audio_resume(void)
123 static void reset(void)
127 static int get_space(void)
129 return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
132 static float get_delay(void)
134 return ((float) (ao_data.buffersize - arts_stream_get(stream,
135 ARTS_P_BUFFER_SPACE))) / ((float) ao_data.bps);