Mercurial > mplayer.hg
annotate libao2/ao_arts.c @ 13009:e50313e4b899
As discussed with Attila, I am now the new maintainer of
vo xv, vo x11 and x11_common.
author | al |
---|---|
date | Thu, 12 Aug 2004 21:48:44 +0000 |
parents | fd60b841a49a |
children | c1955840883d |
rev | line source |
---|---|
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
1 /* |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
2 * ao_arts - aRts audio output driver for MPlayer |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
3 * |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
4 * Michele Balistreri <brain87@gmx.net> |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
5 * |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
6 * This driver is distribuited under terms of GPL |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
7 * |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
8 */ |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
9 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
10 #include <artsc.h> |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
11 #include <stdio.h> |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
12 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
13 #include "audio_out.h" |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
14 #include "audio_out_internal.h" |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
15 #include "afmt.h" |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
16 #include "../config.h" |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
17 #include "../mp_msg.h" |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
18 |
8576
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
19 #define OBTAIN_BITRATE(a) (((a != AFMT_U8) && (a != AFMT_S8)) ? 16 : 8) |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
20 |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
21 /* 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
|
22 #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
|
23 #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
|
24 |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
25 static arts_stream_t stream; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
26 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
27 static ao_info_t info = |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
28 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
29 "aRts audio output", |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
30 "arts", |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
31 "Michele Balistreri <brain87@gmx.net>", |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
32 "" |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
33 }; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
34 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
35 LIBAO_EXTERN(arts) |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
36 |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8576
diff
changeset
|
37 static int control(int cmd, void *arg) |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
38 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
39 return(CONTROL_UNKNOWN); |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
40 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
41 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
42 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
|
43 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
44 int err; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
45 int frag_spec; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
46 |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
6807
diff
changeset
|
47 if( (err=arts_init()) ) { |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
48 mp_msg(MSGT_AO, MSGL_ERR, "AO: [arts] %s\n", arts_error_text(err)); |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
49 return 0; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
50 } |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
51 mp_msg(MSGT_AO, MSGL_INFO, "AO: [arts] Connected to sound server\n"); |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
52 |
8576
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
53 /* |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
54 * 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
|
55 * (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
|
56 * 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
|
57 * |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
58 * 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
|
59 * 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
|
60 */ |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
61 switch (format) { |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
62 case AFMT_U8: |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
63 case AFMT_S8: |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
64 format = AFMT_U8; |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
65 break; |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
66 default: |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
67 format = AFMT_S16_LE; /* artsd always expects little endian?*/ |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
68 break; |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
69 } |
ed132c268686
- Fix 8-bit sound in arts audio driver (logic in OBTAIN_BITRATE macro was
jkeil
parents:
8123
diff
changeset
|
70 |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
71 ao_data.format = format; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
72 ao_data.channels = channels; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
73 ao_data.samplerate = rate_hz; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
74 ao_data.bps = (rate_hz*channels); |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
75 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
76 if(format != AFMT_U8 && format != AFMT_S8) |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
77 ao_data.bps*=2; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
78 |
12984 | 79 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
|
80 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
81 if(stream == NULL) { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
82 mp_msg(MSGT_AO, MSGL_ERR, "AO: [arts] Unable to open a stream\n"); |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
83 arts_free(); |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
84 return 0; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
85 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
86 |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
87 /* 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
|
88 /* 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
|
89 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
|
90 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
|
91 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
|
92 ao_data.buffersize = arts_stream_get(stream, ARTS_P_BUFFER_SIZE); |
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
93 mp_msg(MSGT_AO, MSGL_INFO, "AO: [arts] Stream opened\n"); |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
94 |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
95 mp_msg(MSGT_AO, MSGL_INFO,"AO: [arts] buffer size: %d\n", |
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
96 ao_data.buffersize); |
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
97 mp_msg(MSGT_AO, MSGL_INFO,"AO: [arts] packet size: %d\n", |
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
98 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
|
99 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
100 return 1; |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
101 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
102 |
12145 | 103 static void uninit(int immed) |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
104 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
105 arts_close_stream(stream); |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
106 arts_free(); |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
107 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
108 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
109 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
|
110 { |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
111 return arts_write(stream, data, len); |
6214
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
112 } |
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 static void audio_pause() |
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 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
117 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
118 static void audio_resume() |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
119 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
120 } |
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 static void reset() |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
123 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
124 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
125 |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
126 static int get_space() |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
127 { |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
128 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
|
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 static float get_delay() |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
132 { |
6807
ae2f3cdcb462
Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents:
6214
diff
changeset
|
133 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
|
134 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
|
135 } |
0398cb49fe5e
aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff
changeset
|
136 |