2 * aRts audio output driver for MPlayer
4 * copyright (c) 2002 Michele Balistreri <brain87@gmx.net>
6 * This file is part of MPlayer.
8 * MPlayer 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.
13 * MPlayer 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.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "audio_out.h"
28 #include "audio_out_internal.h"
29 #include "libaf/af_format.h"
33 #define OBTAIN_BITRATE(a) (((a != AF_FORMAT_U8) && (a != AF_FORMAT_S8)) ? 16 : 8)
35 /* Feel free to experiment with the following values: */
36 #define ARTS_PACKETS 10 /* Number of audio packets */
37 #define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
39 static arts_stream_t stream
;
41 static const ao_info_t info
=
45 "Michele Balistreri <brain87@gmx.net>",
51 static int control(int cmd
, void *arg
)
53 return CONTROL_UNKNOWN
;
56 static int init(int rate_hz
, int channels
, int format
, int flags
)
61 if( (err
=arts_init()) ) {
62 mp_msg(MSGT_AO
, MSGL_ERR
, MSGTR_AO_ARTS_CantInit
, arts_error_text(err
));
65 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_ServerConnect
);
68 * arts supports 8bit unsigned and 16bit signed sample formats
69 * (16bit apparently in little endian format, even in the case
70 * when artsd runs on a big endian cpu).
72 * Unsupported formats are translated to one of these two formats
73 * using mplayer's audio filters.
78 format
= AF_FORMAT_U8
;
81 format
= AF_FORMAT_S16_LE
; /* artsd always expects little endian?*/
85 ao_data
.format
= format
;
86 ao_data
.channels
= channels
;
87 ao_data
.samplerate
= rate_hz
;
88 ao_data
.bps
= (rate_hz
*channels
);
90 if(format
!= AF_FORMAT_U8
&& format
!= AF_FORMAT_S8
)
93 stream
=arts_play_stream(rate_hz
, OBTAIN_BITRATE(format
), channels
, "MPlayer");
96 mp_msg(MSGT_AO
, MSGL_ERR
, MSGTR_AO_ARTS_CantOpenStream
);
101 /* Set the stream to blocking: it will not block anyway, but it seems */
102 /* to be working better */
103 arts_stream_set(stream
, ARTS_P_BLOCKING
, 1);
104 frag_spec
= ARTS_PACKET_SIZE_LOG2
| ARTS_PACKETS
<< 16;
105 arts_stream_set(stream
, ARTS_P_PACKET_SETTINGS
, frag_spec
);
106 ao_data
.buffersize
= arts_stream_get(stream
, ARTS_P_BUFFER_SIZE
);
107 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_StreamOpen
);
109 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_BufferSize
,
111 mp_msg(MSGT_AO
, MSGL_INFO
, MSGTR_AO_ARTS_BufferSize
,
112 arts_stream_get(stream
, ARTS_P_PACKET_SIZE
));
117 static void uninit(int immed
)
119 arts_close_stream(stream
);
123 static int play(void* data
,int len
,int flags
)
125 return arts_write(stream
, data
, len
);
128 static void audio_pause(void)
132 static void audio_resume(void)
136 static void reset(void)
140 static int get_space(void)
142 return arts_stream_get(stream
, ARTS_P_BUFFER_SPACE
);
145 static float get_delay(void)
147 return ((float) (ao_data
.buffersize
- arts_stream_get(stream
,
148 ARTS_P_BUFFER_SPACE
))) / ((float) ao_data
.bps
);