annotate libao2/ao_nas.c @ 7710:c97a06ff84cf

stream selection cleanup, fixed -nosound
author arpi
date Thu, 10 Oct 2002 23:24:15 +0000
parents 0761d6ac7ce9
children 328bbac6224c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3336
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
1 /*
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
2 * NAS output plugin for mplayer
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
3 *
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
4 * based on the libaudiooss parts rewritten by me, which were
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
5 * originally based on the NAS output plugin for xmms.
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
6 *
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
7 * xmms plugin by Willem Monsuwe
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
8 * adapted for libaudiooss by Jon Trulson
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
9 * further modified by Erik Inge Bolsų
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
10 * largely rewritten and used for this
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
11 * plugin by Tobias Diedrich
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
12 *
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
13 * Theory of operation:
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
14 *
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
15 * The NAS consists of two parts, a server daemon and a client.
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
16 * We setup the server to use a buffer of size NAS_BUFFER_SIZE
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
17 * with a low watermark of NAS_BUFFER_SIZE - NAS_FRAG_SIZE.
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
18 * Upon starting the flow the server will generate a buffer underrun
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
19 * event and the event handler will fill the buffer for the first time.
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
20 * Now the server will generate a lowwater event when the server buffer
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
21 * falls below the low watermark value. The event handler gets called
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
22 * again and refills the buffer by the number of bytes requested by the
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
23 * server (usually a multiple of 4096). To prevent stuttering on
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
24 * startup (start of playing, seeks, unpausing) the client buffer should
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
25 * be bigger than the server buffer. (For debugging we also do some
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
26 * accounting of what we think how much of the server buffer is filled)
3336
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
27 */
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
28
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
29 #include <stdio.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
30 #include <stdlib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
31 #include <pthread.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
32 #include <audio/audiolib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
33
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
34 #include "../mp_msg.h"
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
35
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
36 #include "audio_out.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
37 #include "audio_out_internal.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
38 #include "afmt.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
39
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
40 #define NAS_FRAG_SIZE 4096
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
41 #define NAS_FRAG_COUNT 8
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
42 #define NAS_BUFFER_SIZE NAS_FRAG_SIZE * NAS_FRAG_COUNT
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
43
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
44 static char *nas_event_types[] = {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
45 "Undefined",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
46 "Undefined",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
47 "ElementNotify",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
48 "GrabNotify",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
49 "MonitorNotify",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
50 "BucketNotify",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
51 "DeviceNotify"
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
52 };
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
53
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
54 static char *nas_elementnotify_kinds[] = {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
55 "LowWater",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
56 "HighWater",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
57 "State",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
58 "Unknown"
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
59 };
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
60
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
61 static char *nas_states[] = {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
62 "Stop",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
63 "Start",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
64 "Pause",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
65 "Any"
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
66 };
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
67
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
68 static char *nas_reasons[] = {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
69 "User",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
70 "Underrun",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
71 "Overrun",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
72 "EOF",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
73 "Watermark",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
74 "Hardware",
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
75 "Any"
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
76 };
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
77
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
78 static char* nas_reason(unsigned int reason)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
79 {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
80 if (reason > 6) reason = 6;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
81 return nas_reasons[reason];
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
82 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
83
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
84 static char* nas_elementnotify_kind(unsigned int kind)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
85 {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
86 if (kind > 2) kind = 3;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
87 return nas_elementnotify_kinds[kind];
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
88 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
89
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
90 static char* nas_event_type(unsigned int type) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
91 if (type > 6) type = 0;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
92 return nas_event_types[type];
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
93 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
94
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
95 static char* nas_state(unsigned int state) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
96 if (state>3) state = 3;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
97 return nas_states[state];
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
98 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
99
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
100 static ao_info_t info =
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
101 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
102 "NAS audio output",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
103 "nas",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
104 "Tobias Diedrich",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
105 ""
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
106 };
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
107
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
108 struct ao_nas_data {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
109 AuServer *aud;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
110 AuFlowID flow;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
111 AuDeviceID dev;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
112
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
113 int flow_stopped;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
114 int flow_paused;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
115 int expect_underrun;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
116
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
117 void *client_buffer;
7449
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
118 void *server_buffer;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
119 int client_buffer_size;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
120 int client_buffer_used;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
121 int server_buffer_size;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
122 int server_buffer_used;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
123 pthread_mutex_t buffer_mutex;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
124
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
125 pthread_t event_thread;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
126 int stop_thread;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
127 };
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
128
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
129 static struct ao_nas_data *nas_data;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
130
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
131 LIBAO_EXTERN(nas)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
132
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
133 static void nas_print_error(AuServer *aud, char *prefix, AuStatus as)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
134 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
135 char s[100];
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
136 AuGetErrorText(aud, as, s, 100);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
137 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
138 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
139
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
140 static int nas_readBuffer(struct ao_nas_data *nas_data, int num)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
141 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
142 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
143
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
144 pthread_mutex_lock(&nas_data->buffer_mutex);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
145 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n",
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
146 num,
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
147 nas_data->client_buffer_used, nas_data->client_buffer_size,
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
148 nas_data->server_buffer_used, nas_data->server_buffer_size);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
149
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
150 if (nas_data->client_buffer_used == 0) {
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
151 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: buffer is empty, nothing read.\n");
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
152 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
153 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
154 }
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
155 if (nas_data->client_buffer_used < num)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
156 num = nas_data->client_buffer_used;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
157
7449
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
158 /*
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
159 * It is not appropriate to call AuWriteElement() here because the
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
160 * buffer is locked and delays writing to the network will cause
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
161 * other threads to block waiting for buffer_mutex. Instead the
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
162 * data is copied to "server_buffer" and written it to the network
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
163 * outside of the locked section of code.
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
164 *
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
165 * (Note: Rather than these two buffers, a single circular buffer
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
166 * could eliminate the memcpy/memmove steps.)
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
167 */
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
168 memcpy(nas_data->server_buffer, nas_data->client_buffer, num);
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
169
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
170 nas_data->client_buffer_used -= num;
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
171 nas_data->server_buffer_used += num;
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
172 memmove(nas_data->client_buffer, nas_data->client_buffer + num, nas_data->client_buffer_used);
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
173 pthread_mutex_unlock(&nas_data->buffer_mutex);
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
174
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
175 /*
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
176 * Now write the new buffer to the network.
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
177 */
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
178 AuWriteElement(nas_data->aud, nas_data->flow, 0, num, nas_data->server_buffer, AuFalse, &as);
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
179 if (as != AuSuccess)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
180 nas_print_error(nas_data->aud, "nas_readBuffer(): AuWriteElement", as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
181
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
182 if (nas_data->flow_paused) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
183 AuPauseFlow(nas_data->aud, nas_data->flow, &as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
184 if (as != AuSuccess)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
185 nas_print_error(nas_data->aud, "nas_readBuffer(): AuPauseFlow", as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
186 }
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
187
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
188 return num;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
189 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
190
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
191 static void nas_writeBuffer(struct ao_nas_data *nas_data, void *data, int len)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
192 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
193 pthread_mutex_lock(&nas_data->buffer_mutex);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
194 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_writeBuffer(): len=%d client=%d/%d server=%d/%d\n",
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
195 len, nas_data->client_buffer_used, nas_data->client_buffer_size,
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
196 nas_data->server_buffer_used, nas_data->server_buffer_size);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
197
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
198 memcpy(nas_data->client_buffer + nas_data->client_buffer_used, data, len);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
199 nas_data->client_buffer_used += len;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
200
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
201 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
202 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
203
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
204 static int nas_empty_event_queue(struct ao_nas_data *nas_data)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
205 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
206 AuEvent ev;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
207 int result = 0;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
208
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
209 while (AuScanForTypedEvent(nas_data->aud, AuEventsQueuedAfterFlush,
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
210 AuTrue, AuEventTypeElementNotify, &ev)) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
211 AuDispatchEvent(nas_data->aud, &ev);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
212 result = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
213 }
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
214 return result;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
215 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
216
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
217 static void *nas_event_thread_start(void *data)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
218 {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
219 struct ao_nas_data *nas_data = data;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
220 AuEvent ev;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
221 AuBool result;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
222
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
223 do {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
224 nas_empty_event_queue(nas_data);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
225 usleep(10000);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
226 } while (!nas_data->stop_thread);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
227 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
228
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
229 static AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
230 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
231 char s[100];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
232 AuGetErrorText(aud, ev->error_code, s, 100);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
233 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: error [%s]\n"
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
234 "error_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
235 "request_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
236 "minor_code: %d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
237 s,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
238 ev->error_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
239 ev->request_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
240 ev->minor_code);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
241
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
242 return AuTrue;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
243 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
244
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
245 static AuBool nas_event_handler(AuServer *aud, AuEvent *ev, AuEventHandlerRec *hnd)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
246 {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
247 AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
248 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
249 struct ao_nas_data *nas_data = hnd->data;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
250
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
251 switch (ev->type) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
252 case AuEventTypeElementNotify:
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
253 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: event_handler(): kind %s state %s->%s reason %s numbytes %d expect_underrun %d\n",
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
254 nas_elementnotify_kind(event->kind),
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
255 nas_state(event->prev_state),
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
256 nas_state(event->cur_state),
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
257 nas_reason(event->reason),
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
258 event->num_bytes,
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
259 nas_data->expect_underrun);
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
260
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
261 nas_data->server_buffer_used -= event->num_bytes;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
262 if (nas_data->server_buffer_used < 0)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
263 nas_data->server_buffer_used = 0;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
264
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
265 switch (event->kind) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
266 case AuElementNotifyKindLowWater:
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
267 nas_readBuffer(nas_data, event->num_bytes);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
268 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
269 case AuElementNotifyKindState:
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
270 if (event->cur_state == AuStatePause) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
271 switch (event->reason) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
272 case AuReasonUnderrun:
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
273 // buffer underrun -> refill buffer
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
274 if (nas_data->expect_underrun)
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
275 nas_data->expect_underrun = 0;
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
276 else {
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
277 mp_msg(MSGT_AO, MSGL_WARN, "ao_nas: Buffer underrun.\n");
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
278 mp_msg(MSGT_AO, MSGL_HINT, "Possible reasons are network congestion or your NAS server is too slow.\n"
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
279 "Try renicing your nasd to e.g. -15.\n");
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
280 }
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
281 nas_data->server_buffer_used = 0;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
282 if (nas_readBuffer(nas_data, nas_data->server_buffer_size - nas_data->server_buffer_used) == 0)
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
283 nas_data->flow_stopped = 1;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
284 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
285 default:
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
286 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
287 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
288 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
289 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
290 default: // silently ignored
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
291 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
292 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
293 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
294 default:
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
295 mp_msg(MSGT_AO, MSGL_WARN, "ao_nas: nas_event_handler(): unhandled event type %d\n", ev->type);
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
296 break;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
297 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
298 return AuTrue;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
299 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
300
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
301 static AuDeviceID nas_find_device(AuServer *aud, int nch)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
302 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
303 int i;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
304 for (i = 0; i < AuServerNumDevices(aud); i++) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
305 AuDeviceAttributes *dev = AuServerDevice(aud, i);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
306 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) &&
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
307 AuDeviceNumTracks(dev) == nch) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
308 return AuDeviceIdentifier(dev);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
309 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
310 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
311 return AuNone;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
312 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
313
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
314 static unsigned int nas_aformat_to_auformat(unsigned int format)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
315 {
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
316 unsigned int res=format << 8;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
317 switch (format) {
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
318 case AFMT_U8:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
319 return res + AuFormatLinearUnsigned8;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
320 case AFMT_S8:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
321 return res + AuFormatLinearSigned8;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
322 case AFMT_U16_LE:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
323 return res + AuFormatLinearUnsigned16LSB;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
324 case AFMT_U16_BE:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
325 return res + AuFormatLinearUnsigned16MSB;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 4775
diff changeset
326 #ifndef WORDS_BIGENDIAN
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
327 default:
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 4775
diff changeset
328 #endif
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
329 case AFMT_S16_LE:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
330 return (AFMT_S16_LE << 8) + AuFormatLinearSigned16LSB;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 4775
diff changeset
331 #ifdef WORDS_BIGENDIAN
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
332 default:
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 4775
diff changeset
333 #endif
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
334 case AFMT_S16_BE:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
335 return (AFMT_S16_BE << 8) + AuFormatLinearSigned16MSB;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
336 case AFMT_MU_LAW:
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
337 return res + AuFormatULAW8;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
338 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
339 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
340
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
341 // to set/get/query special features/parameters
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
342 static int control(int cmd,int arg){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
343 return -1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
344 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
345
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
346 // open & setup audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
347 // return: 1=success 0=fail
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
348 static int init(int rate,int channels,int format,int flags)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
349 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
350 AuElement elms[3];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
351 AuStatus as;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
352 unsigned char auformat = nas_aformat_to_auformat(format);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
353 int bytes_per_sample = channels * AuSizeofFormat(auformat);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
354 char *server;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
355
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
356 nas_data=malloc(sizeof(struct ao_nas_data));
6114
34d5c9a67b94 Patch by Tobias Diedrich <td@informatik.uni-hannover.de>:
pl
parents: 5790
diff changeset
357 memset(nas_data, 0, sizeof(struct ao_nas_data));
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
358
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
359 mp_msg(MSGT_AO, MSGL_V, "ao2: %d Hz %d chans %s\n",rate,channels,
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
360 audio_out_format_name(format));
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
361
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
362 nas_data->client_buffer_size = NAS_BUFFER_SIZE*2;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
363 nas_data->client_buffer = malloc(nas_data->client_buffer_size);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
364 nas_data->server_buffer_size = NAS_BUFFER_SIZE;
7449
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
365 nas_data->server_buffer = malloc(nas_data->server_buffer_size);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
366
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
367 ao_data.format = auformat >> 8;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
368 ao_data.samplerate = rate;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
369 ao_data.channels = channels;
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
370 ao_data.buffersize = NAS_BUFFER_SIZE * 2;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
371 ao_data.outburst = NAS_FRAG_SIZE;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
372 ao_data.bps = rate * bytes_per_sample;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
373
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
374 if (!bytes_per_sample) {
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
375 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Zero bytes per sample -> nosound\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
376 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
377 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
378
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
379 if (!(server = getenv("AUDIOSERVER")) &&
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
380 !(server = getenv("DISPLAY"))) {
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
381 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): AUDIOSERVER environment variable not set -> nosound\n");
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
382 return 0;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
383 }
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
384
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
385 mp_msg(MSGT_AO, MSGL_V, "ao_nas: init(): Using audioserver %s\n", server);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
386
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
387 nas_data->aud = AuOpenServer(server, 0, NULL, 0, NULL, NULL);
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
388 if (!nas_data->aud) {
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
389 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't open nas audio server -> nosound\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
390 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
391 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
392
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
393 while (channels>1) {
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
394 nas_data->dev = nas_find_device(nas_data->aud, channels);
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
395 if (nas_data->dev != AuNone &&
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
396 (nas_data->flow = AuCreateFlow(nas_data->aud, NULL) != 0))
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
397 break;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
398 channels--;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
399 }
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
400
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
401 if (nas_data->flow == 0) {
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
402 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't find a suitable output device -> nosound\n");
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
403 AuCloseServer(nas_data->aud);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
404 nas_data->aud = 0;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
405 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
406 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
407
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
408 AuMakeElementImportClient(elms, rate, auformat & 0xff, channels, AuTrue,
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
409 NAS_BUFFER_SIZE / bytes_per_sample,
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
410 (NAS_BUFFER_SIZE - NAS_FRAG_SIZE) / bytes_per_sample,
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
411 0, NULL);
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
412 AuMakeElementExportDevice(elms+1, 0, nas_data->dev, rate,
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
413 AuUnlimitedSamples, 0, NULL);
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
414 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, 2, elms, &as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
415 if (as != AuSuccess)
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
416 nas_print_error(nas_data->aud, "init(): AuSetElements", as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
417 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask |
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
418 AuEventHandlerTypeMask,
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
419 AuEventTypeElementNotify, nas_data->flow,
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
420 nas_event_handler, (AuPointer) nas_data);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
421 AuSetErrorHandler(nas_data->aud, nas_error_handler);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
422 nas_data->flow_stopped=1;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
423 nas_data->expect_underrun=0;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
424
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
425 pthread_mutex_init(&nas_data->buffer_mutex, NULL);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
426 pthread_create(&nas_data->event_thread, NULL, &nas_event_thread_start, nas_data);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
427
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
428 return 1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
429 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
430
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
431 // close audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
432 static void uninit(){
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
433 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
434
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
435 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: uninit()\n");
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
436
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
437 nas_data->stop_thread = 1;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
438 pthread_join(nas_data->event_thread, NULL);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
439 if (!nas_data->flow_stopped) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
440 AuStopFlow(nas_data->aud, nas_data->flow, &as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
441 if (as != AuSuccess)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
442 nas_print_error(nas_data->aud, "uninit(): AuStopFlow", as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
443 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
444 AuCloseServer(nas_data->aud);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
445 nas_data->aud = 0;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
446 free(nas_data->client_buffer);
7449
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
447 free(nas_data->server_buffer);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
448 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
449
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
450 // stop playing and empty buffers (for seeking/pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
451 static void reset(){
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
452 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
453
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
454 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: reset()\n");
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
455
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
456 pthread_mutex_lock(&nas_data->buffer_mutex);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
457 nas_data->client_buffer_used = 0;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
458 if (!nas_data->flow_stopped) {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
459 AuStopFlow(nas_data->aud, nas_data->flow, &as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
460 if (as != AuSuccess)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
461 nas_print_error(nas_data->aud, "reset(): AuStopFlow", as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
462 nas_data->flow_stopped = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
463 }
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
464 nas_data->server_buffer_used = 0;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
465 AuSync(nas_data->aud, AuTrue);
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
466 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
467 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
468
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
469 // stop playing, keep buffers (for pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
470 static void audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
471 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
472 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
473
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
474 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: audio_pause()\n");
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
475
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
476 nas_data->flow_paused = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
477 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
478
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
479 // resume playing, after audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
480 static void audio_resume()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
481 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
482 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
483 AuEvent ev;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
484
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
485 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: audio_resume()\n");
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
486
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
487 nas_data->flow_stopped = 0;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
488 nas_data->flow_paused = 0;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
489 nas_data->expect_underrun = 1;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
490 AuStartFlow(nas_data->aud, nas_data->flow, &as);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
491 if (as != AuSuccess)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
492 nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
493 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
494
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
495
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
496 // return: how many bytes can be played without blocking
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
497 static int get_space()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
498 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
499 int result;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
500
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
501 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: get_space()\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
502
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
503 pthread_mutex_lock(&nas_data->buffer_mutex);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
504 result = nas_data->client_buffer_size - nas_data->client_buffer_used;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
505 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
506
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
507 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
508 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
509
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
510 // plays 'len' bytes of 'data'
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
511 // it should round it down to outburst*n
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
512 // return: number of bytes played
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
513 static int play(void* data,int len,int flags)
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
514 {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
515 int maxbursts, playbursts, writelen;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
516 AuStatus as;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
517
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
518 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play()\n");
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
519
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
520 pthread_mutex_lock(&nas_data->buffer_mutex);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
521 maxbursts = (nas_data->client_buffer_size -
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
522 nas_data->client_buffer_used) / ao_data.outburst;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
523 playbursts = len / ao_data.outburst;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
524 writelen = (playbursts > maxbursts ? maxbursts : playbursts) *
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
525 ao_data.outburst;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
526 pthread_mutex_unlock(&nas_data->buffer_mutex);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
527
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
528 nas_writeBuffer(nas_data, data, writelen);
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
529
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
530 if (nas_data->flow_stopped) {
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
531 AuEvent ev;
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
532
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
533 nas_data->expect_underrun = 1;
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
534 AuStartFlow(nas_data->aud, nas_data->flow, &as);
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
535 if (as != AuSuccess)
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
536 nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
537 nas_data->flow_stopped = 0;
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
538 }
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
539
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
540 return writelen;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
541 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
542
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
543 // return: delay in seconds between first and last sample in buffer
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
544 static float get_delay()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
545 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
546 float result;
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
547
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
548 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: get_delay()\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
549
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
550 pthread_mutex_lock(&nas_data->buffer_mutex);
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
551 result = ((float)(nas_data->client_buffer_used +
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
552 nas_data->server_buffer_used)) /
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
553 (float)ao_data.bps;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
554 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
555
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
556 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
557 }