annotate libao2/ao_arts.c @ 31194:b2bb87b92146

stream_check_interrupt should sleep even if no callback is set.
author reimar
date Fri, 28 May 2010 18:49:02 +0000
parents 32725ca88fed
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
1 /*
27509
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
2 * aRts audio output driver for MPlayer
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
3 *
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
4 * copyright (c) 2002 Michele Balistreri <brain87@gmx.net>
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
5 *
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
6 * This file is part of MPlayer.
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
7 *
27509
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
9 * it under the terms of the GNU General Public License as published by
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
11 * (at your option) any later version.
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
12 *
27509
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
16 * GNU General Public License for more details.
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
17 *
27509
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
18 * You should have received a copy of the GNU General Public License along
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 26757
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
21 */
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
22
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
23 #include <artsc.h>
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
24 #include <stdio.h>
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
25
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14245
diff changeset
26 #include "config.h"
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
27 #include "audio_out.h"
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
28 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
29 #include "libaf/af_format.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
30 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
31 #include "help_mp.h"
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
32
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
33 #define OBTAIN_BITRATE(a) (((a != AF_FORMAT_U8) && (a != AF_FORMAT_S8)) ? 16 : 8)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
34
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
35 /* Feel free to experiment with the following values: */
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
36 #define ARTS_PACKETS 10 /* Number of audio packets */
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
37 #define ARTS_PACKET_SIZE_LOG2 11 /* Log2 of audio packet size */
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
38
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
39 static arts_stream_t stream;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
40
28823
9a5b8c2ed6de Make ao_info_t structs const.
reimar
parents: 27509
diff changeset
41 static const ao_info_t info =
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
42 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
43 "aRts audio output",
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
44 "arts",
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
45 "Michele Balistreri <brain87@gmx.net>",
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
46 ""
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
47 };
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
48
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
49 LIBAO_EXTERN(arts)
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
50
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 8576
diff changeset
51 static int control(int cmd, void *arg)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
52 {
26757
0fdf04b07ecb cosmetics: Remove pointless parentheses from return statements.
diego
parents: 17566
diff changeset
53 return CONTROL_UNKNOWN;
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
54 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
55
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
56 static int init(int rate_hz, int channels, int format, int flags)
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
57 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
58 int err;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
59 int frag_spec;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
60
8123
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 6807
diff changeset
61 if( (err=arts_init()) ) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12984
diff changeset
62 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantInit, arts_error_text(err));
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
63 return 0;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
64 }
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12984
diff changeset
65 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_ServerConnect);
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
66
8576
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
67 /*
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
68 * arts supports 8bit unsigned and 16bit signed sample formats
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
69 * (16bit apparently in little endian format, even in the case
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
70 * when artsd runs on a big endian cpu).
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
71 *
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
72 * Unsupported formats are translated to one of these two formats
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
73 * using mplayer's audio filters.
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
74 */
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
75 switch (format) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
76 case AF_FORMAT_U8:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
77 case AF_FORMAT_S8:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
78 format = AF_FORMAT_U8;
8576
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
79 break;
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
80 default:
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
81 format = AF_FORMAT_S16_LE; /* artsd always expects little endian?*/
8576
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
82 break;
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
83 }
ed132c268686 - Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents: 8123
diff changeset
84
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
85 ao_data.format = format;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
86 ao_data.channels = channels;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
87 ao_data.samplerate = rate_hz;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
88 ao_data.bps = (rate_hz*channels);
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
89
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
90 if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
91 ao_data.bps*=2;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
92
12984
fd60b841a49a embarassing typo
diego
parents: 12145
diff changeset
93 stream=arts_play_stream(rate_hz, OBTAIN_BITRATE(format), channels, "MPlayer");
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
94
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
95 if(stream == NULL) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12984
diff changeset
96 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantOpenStream);
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
97 arts_free();
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
98 return 0;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
99 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
100
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
101 /* Set the stream to blocking: it will not block anyway, but it seems */
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
102 /* to be working better */
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
103 arts_stream_set(stream, ARTS_P_BLOCKING, 1);
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
104 frag_spec = ARTS_PACKET_SIZE_LOG2 | ARTS_PACKETS << 16;
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
105 arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
106 ao_data.buffersize = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12984
diff changeset
107 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_StreamOpen);
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
108
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12984
diff changeset
109 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
110 ao_data.buffersize);
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12984
diff changeset
111 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
112 arts_stream_get(stream, ARTS_P_PACKET_SIZE));
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
113
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
114 return 1;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
115 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
116
12145
99798c3cdb93 uninit immed flag
alex
parents: 9633
diff changeset
117 static void uninit(int immed)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
118 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
119 arts_close_stream(stream);
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
120 arts_free();
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
121 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
122
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
123 static int play(void* data,int len,int flags)
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
124 {
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
125 return arts_write(stream, data, len);
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
126 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
127
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
128 static void audio_pause(void)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
129 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
130 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
131
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
132 static void audio_resume(void)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
133 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
134 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
135
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
136 static void reset(void)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
137 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
138 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
139
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
140 static int get_space(void)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
141 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
142 return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
143 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
144
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 14479
diff changeset
145 static float get_delay(void)
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
146 {
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
147 return ((float) (ao_data.buffersize - arts_stream_get(stream,
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
148 ARTS_P_BUFFER_SPACE))) / ((float) ao_data.bps);
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
149 }