annotate libao2/ao_arts.c @ 7242:8bafdfe945b4

document -vop halfpack
author rfelker
date Mon, 02 Sep 2002 03:21:03 +0000
parents ae2f3cdcb462
children 9fc45fe0d444
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 /*
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
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
19 #define OBTAIN_BITRATE(a) (((a != AFMT_U8) || (a != AFMT_S8)) ? 16 : 8)
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
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
37 static int control(int cmd, int arg)
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
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
47 if(err=arts_init()) {
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
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
53 ao_data.format = format;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
54 ao_data.channels = channels;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
55 ao_data.samplerate = rate_hz;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
56 ao_data.bps = (rate_hz*channels);
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 if(format != AFMT_U8 && format != AFMT_S8)
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
59 ao_data.bps*=2;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
60
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
61 stream=arts_play_stream(rate_hz, OBTAIN_BITRATE(format), channels, "Mplayer");
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
62
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
63 if(stream == NULL) {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
64 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
65 arts_free();
6214
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
66 return 0;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
67 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
68
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
69 /* 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
70 /* 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
71 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
72 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
73 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
74 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
75 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
76
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
77 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
78 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
79 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
80 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
81
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
82 return 1;
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
83 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
84
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
85 static void uninit()
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
86 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
87 arts_close_stream(stream);
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
88 arts_free();
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
89 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
90
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
91 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
92 {
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
93 return arts_write(stream, data, len);
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
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
96 static void audio_pause()
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
97 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
98 }
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 static void audio_resume()
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 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
103
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
104 static void reset()
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
105 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
106 }
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 static int get_space()
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
109 {
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
110 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
111 }
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 static float get_delay()
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
114 {
6807
ae2f3cdcb462 Improved ao_arts delay and buff er handling, patch by Szombathelyi Gy|rgy <gyurco@freemail.hu>
atmos4
parents: 6214
diff changeset
115 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
116 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
117 }
0398cb49fe5e aRts audio out support by Michele Balistreri <brain at email.it>
atmos4
parents:
diff changeset
118