annotate libao2/ao_nas.c @ 14742:76d461a061df

Unified colorkey code for vo xv and vo xvmc. Made the code also more flexible. Colorkey drawing is now by default done as proposed by Marko Macek. Patch also approved by iive.
author al
date Sun, 20 Feb 2005 22:43:25 +0000
parents 1d3cc596069d
children d313f591d1a4
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.
7732
arpi
parents: 7646
diff changeset
16 * We setup the server to use a buffer of size bytes_per_second
arpi
parents: 7646
diff changeset
17 * with a low watermark of buffer_size - NAS_FRAG_SIZE.
7626
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
7732
arpi
parents: 7646
diff changeset
29 #include <unistd.h>
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
30 #include <stdio.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
31 #include <stdlib.h>
7732
arpi
parents: 7646
diff changeset
32 #include <string.h>
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
33 #include <pthread.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
34 #include <audio/audiolib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
35
14480
1d3cc596069d actually mp_msg.h includes config.h, but for consistency better include it
reimar
parents: 14479
diff changeset
36 #include "config.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 12145
diff changeset
37 #include "mp_msg.h"
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
38
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
39 #include "audio_out.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
40 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
41 #include "libaf/af_format.h"
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
42
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
43 #define NAS_FRAG_SIZE 4096
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
44
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
45 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
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 "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
48 "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
49 "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
50 "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
51 "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
52 "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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
56 "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
57 "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
58 "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
59 "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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
63 "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
64 "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
65 "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
66 "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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
70 "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
71 "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
72 "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
73 "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
74 "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
75 "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
76 "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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
80 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
82 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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
86 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
88 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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
92 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
93 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
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
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
97 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
98 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
99 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
100
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
101 static ao_info_t info =
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
102 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
103 "NAS audio output",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
104 "nas",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
105 "Tobias Diedrich",
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 };
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
108
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
109 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
110 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
111 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
112 AuDeviceID dev;
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
113 AuFixedPoint gain;
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
114
7732
arpi
parents: 7646
diff changeset
115 unsigned int state;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
116 int expect_underrun;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
117
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
118 void *client_buffer;
7449
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
119 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
120 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
121 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
122 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
123 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
124 pthread_mutex_t buffer_mutex;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
125
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
126 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
127 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
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
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
130 static struct ao_nas_data *nas_data;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
131
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
132 LIBAO_EXTERN(nas)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
133
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
134 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
135 {
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
136 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
137 AuGetErrorText(aud, as, s, 100);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
138 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
139 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
140
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
141 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
142 {
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
143 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
144
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
145 pthread_mutex_lock(&nas_data->buffer_mutex);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
146 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
147 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
148 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
149 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
150
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
151 if (nas_data->client_buffer_used == 0) {
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
152 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
153 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
154 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
155 }
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
156 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
157 num = nas_data->client_buffer_used;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
158
7449
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
159 /*
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
160 * 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
161 * 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
162 * 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
163 * 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
164 * 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
165 *
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
166 * (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
167 * 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
168 */
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
169 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
170
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
171 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
172 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
173 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
174 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
175
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
176 /*
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
177 * 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
178 */
28785e6e6900 "One can cause a permanent hang on a seek, and the other just causes
arpi
parents: 6114
diff changeset
179 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
180 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
181 nas_print_error(nas_data->aud, "nas_readBuffer(): AuWriteElement", as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
182
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
183 return num;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
184 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
185
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
186 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
187 {
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
188 pthread_mutex_lock(&nas_data->buffer_mutex);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
189 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
190 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
191 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
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 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
194 nas_data->client_buffer_used += len;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
195
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
196 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
197 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
198
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
199 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
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 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
202 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
203
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
205 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
206 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
207 result = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
208 }
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
209 return result;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
210 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
211
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
212 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
213 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
215
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
216 do {
7732
arpi
parents: 7646
diff changeset
217 mp_msg(MSGT_AO, MSGL_DBG2,
arpi
parents: 7646
diff changeset
218 "ao_nas: event thread heartbeat (state=%s)\n",
arpi
parents: 7646
diff changeset
219 nas_state(nas_data->state));
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
220 nas_empty_event_queue(nas_data);
7732
arpi
parents: 7646
diff changeset
221 usleep(1000);
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
222 } while (!nas_data->stop_thread);
7732
arpi
parents: 7646
diff changeset
223
arpi
parents: 7646
diff changeset
224 return 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
225 }
080cf3df3e4e improved event handling, implemented working pause that does not 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
080cf3df3e4e improved event handling, implemented working pause that does not 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 static AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
228 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
229 char s[100];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
230 AuGetErrorText(aud, ev->error_code, s, 100);
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
231 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
232 "error_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
233 "request_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
234 "minor_code: %d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
235 s,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
236 ev->error_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
237 ev->request_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
238 ev->minor_code);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
239
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
240 return AuTrue;
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
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
243 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
244 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
246 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
247
7732
arpi
parents: 7646
diff changeset
248 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: event_handler(): type %s kind %s state %s->%s reason %s numbytes %d expect_underrun %d\n",
arpi
parents: 7646
diff changeset
249 nas_event_type(event->type),
arpi
parents: 7646
diff changeset
250 nas_elementnotify_kind(event->kind),
arpi
parents: 7646
diff changeset
251 nas_state(event->prev_state),
arpi
parents: 7646
diff changeset
252 nas_state(event->cur_state),
arpi
parents: 7646
diff changeset
253 nas_reason(event->reason),
arpi
parents: 7646
diff changeset
254 event->num_bytes,
arpi
parents: 7646
diff changeset
255 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
256
7732
arpi
parents: 7646
diff changeset
257 nas_data->server_buffer_used -= event->num_bytes;
arpi
parents: 7646
diff changeset
258 if (nas_data->server_buffer_used < 0)
arpi
parents: 7646
diff changeset
259 nas_data->server_buffer_used = 0;
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
7732
arpi
parents: 7646
diff changeset
261 switch (event->reason) {
arpi
parents: 7646
diff changeset
262 case AuReasonWatermark:
arpi
parents: 7646
diff changeset
263 nas_readBuffer(nas_data, event->num_bytes);
arpi
parents: 7646
diff changeset
264 break;
arpi
parents: 7646
diff changeset
265 case AuReasonUnderrun:
arpi
parents: 7646
diff changeset
266 // buffer underrun -> refill buffer
arpi
parents: 7646
diff changeset
267 nas_data->server_buffer_used = 0;
arpi
parents: 7646
diff changeset
268 if (nas_data->expect_underrun) {
arpi
parents: 7646
diff changeset
269 nas_data->expect_underrun = 0;
arpi
parents: 7646
diff changeset
270 } else {
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
271 static int hint = 1;
7732
arpi
parents: 7646
diff changeset
272 mp_msg(MSGT_AO, MSGL_WARN,
arpi
parents: 7646
diff changeset
273 "ao_nas: Buffer underrun.\n");
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
274 if (hint) {
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
275 hint = 0;
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
276 mp_msg(MSGT_AO, MSGL_HINT,
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
277 "Possible reasons are:\n"
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
278 "1) Network congestion.\n"
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
279 "2) Your NAS server is too slow.\n"
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
280 "Try renicing your nasd to e.g. -15.\n");
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
281 }
7732
arpi
parents: 7646
diff changeset
282 }
arpi
parents: 7646
diff changeset
283 if (nas_readBuffer(nas_data,
arpi
parents: 7646
diff changeset
284 nas_data->server_buffer_size -
arpi
parents: 7646
diff changeset
285 nas_data->server_buffer_used) != 0) {
arpi
parents: 7646
diff changeset
286 event->cur_state = AuStateStart;
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
287 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
288 }
7732
arpi
parents: 7646
diff changeset
289 mp_msg(MSGT_AO, MSGL_DBG2,
arpi
parents: 7646
diff changeset
290 "ao_nas: Can't refill buffer, stopping flow.\n");
arpi
parents: 7646
diff changeset
291 AuStopFlow(nas_data->aud, nas_data->flow, 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
292 break;
7732
arpi
parents: 7646
diff changeset
293 default:
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
294 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
295 }
7732
arpi
parents: 7646
diff changeset
296 nas_data->state=event->cur_state;
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
297 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
298 }
080cf3df3e4e improved event handling, implemented working pause that does not 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 static AuDeviceID nas_find_device(AuServer *aud, int nch)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
301 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
302 int i;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
303 for (i = 0; i < AuServerNumDevices(aud); i++) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
304 AuDeviceAttributes *dev = AuServerDevice(aud, i);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
305 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) &&
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
306 AuDeviceNumTracks(dev) == nch) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
307 return AuDeviceIdentifier(dev);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
308 }
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 return AuNone;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
311 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
312
7732
arpi
parents: 7646
diff changeset
313 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
314 {
7732
arpi
parents: 7646
diff changeset
315 switch (*format) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
316 case AF_FORMAT_U8:
7732
arpi
parents: 7646
diff changeset
317 return AuFormatLinearUnsigned8;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
318 case AF_FORMAT_S8:
7732
arpi
parents: 7646
diff changeset
319 return AuFormatLinearSigned8;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
320 case AF_FORMAT_U16_LE:
7732
arpi
parents: 7646
diff changeset
321 return AuFormatLinearUnsigned16LSB;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
322 case AF_FORMAT_U16_BE:
7732
arpi
parents: 7646
diff changeset
323 return AuFormatLinearUnsigned16MSB;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
324 case AF_FORMAT_S16_LE:
7732
arpi
parents: 7646
diff changeset
325 return AuFormatLinearSigned16LSB;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
326 case AF_FORMAT_S16_BE:
7732
arpi
parents: 7646
diff changeset
327 return AuFormatLinearSigned16MSB;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
328 case AF_FORMAT_MU_LAW:
7732
arpi
parents: 7646
diff changeset
329 return AuFormatULAW8;
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
330 default:
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
331 *format=AF_FORMAT_S16_NE;
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
332 return nas_aformat_to_auformat(format);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
333 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
334 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
335
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
336 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 9583
diff changeset
337 static int control(int cmd, void *arg)
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
338 {
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
339 AuElementParameters aep;
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
340 AuStatus as;
9583
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
341 int retval = CONTROL_UNKNOWN;
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
342
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
343 ao_control_vol_t *vol = (ao_control_vol_t *)arg;
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
344
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
345 switch (cmd) {
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
346 case AOCONTROL_GET_VOLUME:
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
347
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
348 vol->right = (float)nas_data->gain/AU_FIXED_POINT_SCALE*50;
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
349 vol->left = vol->right;
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
350
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
351 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_GET_VOLUME: %08x\n", nas_data->gain);
9583
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
352 retval = CONTROL_OK;
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
353 break;
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
354
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
355 case AOCONTROL_SET_VOLUME:
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
356 /*
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
357 * kn: we should have vol->left == vol->right but i don't
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
358 * know if something can change it outside of ao_nas
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
359 * so i take the mean of both values.
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
360 */
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
361 nas_data->gain = AU_FIXED_POINT_SCALE*((vol->left+vol->right)/2)/50;
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
362 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_SET_VOLUME: %08x\n", nas_data->gain);
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
363
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
364 aep.parameters[AuParmsMultiplyConstantConstant]=nas_data->gain;
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
365 aep.flow = nas_data->flow;
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
366 aep.element_num = 1;
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
367 aep.num_parameters = AuParmsMultiplyConstant;
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
368
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
369 AuSetElementParameters(nas_data->aud, 1, &aep, &as);
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
370 if (as != AuSuccess) {
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
371 nas_print_error(nas_data->aud,
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
372 "control(): AuSetElementParameters", as);
9583
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
373 retval = CONTROL_ERROR;
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
374 } else retval = CONTROL_OK;
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
375 break;
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
376 };
8272
b1c5460a8105 Implement volume setting functionality,
ranma
parents: 7732
diff changeset
377
9583
e442209e6241 Fix small memleak in control().
ranma
parents: 8272
diff changeset
378 return retval;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
379 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
380
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
381 // open & setup audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
382 // return: 1=success 0=fail
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
383 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
384 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
385 AuElement elms[3];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
386 AuStatus as;
7732
arpi
parents: 7646
diff changeset
387 unsigned char auformat = nas_aformat_to_auformat(&format);
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
388 int bytes_per_sample = channels * AuSizeofFormat(auformat);
7732
arpi
parents: 7646
diff changeset
389 int buffer_size;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
390 char *server;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
391
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
392 nas_data=malloc(sizeof(struct ao_nas_data));
6114
34d5c9a67b94 Patch by Tobias Diedrich <td@informatik.uni-hannover.de>:
pl
parents: 5790
diff changeset
393 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
394
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
395 mp_msg(MSGT_AO, MSGL_V, "ao2: %d Hz %d chans %s\n",rate,channels,
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14255
diff changeset
396 af_fmt2str_short(format));
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
397
7732
arpi
parents: 7646
diff changeset
398 ao_data.format = format;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
399 ao_data.samplerate = rate;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
400 ao_data.channels = 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
401 ao_data.outburst = NAS_FRAG_SIZE;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
402 ao_data.bps = rate * bytes_per_sample;
7732
arpi
parents: 7646
diff changeset
403 buffer_size = ao_data.bps; /* buffer 1 second */
arpi
parents: 7646
diff changeset
404 /*
arpi
parents: 7646
diff changeset
405 * round up to multiple of NAS_FRAG_SIZE
arpi
parents: 7646
diff changeset
406 * divide by 3 first because of 2:1 split
arpi
parents: 7646
diff changeset
407 */
arpi
parents: 7646
diff changeset
408 buffer_size = (buffer_size/3 + NAS_FRAG_SIZE-1) & ~(NAS_FRAG_SIZE-1);
arpi
parents: 7646
diff changeset
409 ao_data.buffersize = buffer_size*3;
arpi
parents: 7646
diff changeset
410
arpi
parents: 7646
diff changeset
411 nas_data->client_buffer_size = buffer_size*2;
arpi
parents: 7646
diff changeset
412 nas_data->client_buffer = malloc(nas_data->client_buffer_size);
arpi
parents: 7646
diff changeset
413 nas_data->server_buffer_size = buffer_size;
arpi
parents: 7646
diff changeset
414 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
415
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
416 if (!bytes_per_sample) {
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
417 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
418 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
419 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
420
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
421 if (!(server = getenv("AUDIOSERVER")) &&
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
422 !(server = getenv("DISPLAY"))) {
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
423 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
424 return 0;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
425 }
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
426
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
427 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
428
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
429 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
430 if (!nas_data->aud) {
7627
382b28368402 DPRINTF -> mp_msg()
arpi
parents: 7626
diff changeset
431 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
432 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
433 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
434
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
435 while (channels>1) {
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
436 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
437 if (nas_data->dev != AuNone &&
7732
arpi
parents: 7646
diff changeset
438 ((nas_data->flow = AuCreateFlow(nas_data->aud, NULL)) != 0))
7646
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
439 break;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
440 channels--;
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
441 }
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
442
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
443 if (nas_data->flow == 0) {
0761d6ac7ce9 libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents: 7627
diff changeset
444 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
445 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
446 nas_data->aud = 0;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
447 return 0;
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
7732
arpi
parents: 7646
diff changeset
450 AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue,
arpi
parents: 7646
diff changeset
451 buffer_size / bytes_per_sample,
arpi
parents: 7646
diff changeset
452 (buffer_size - NAS_FRAG_SIZE) /
arpi
parents: 7646
diff changeset
453 bytes_per_sample, 0, NULL);
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
454 nas_data->gain = AuFixedPointFromFraction(1, 1);
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
455 AuMakeElementMultiplyConstant(elms+1, 0, nas_data->gain);
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
456 AuMakeElementExportDevice(elms+2, 1, nas_data->dev, rate,
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
457 AuUnlimitedSamples, 0, NULL);
12022
293141b57c01 Use MultiplyElement to control volume.
ranma
parents: 9633
diff changeset
458 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, sizeof(elms)/sizeof(*elms), elms, &as);
7732
arpi
parents: 7646
diff changeset
459 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
460 nas_print_error(nas_data->aud, "init(): AuSetElements", as);
7732
arpi
parents: 7646
diff changeset
461 AuCloseServer(nas_data->aud);
arpi
parents: 7646
diff changeset
462 nas_data->aud = 0;
arpi
parents: 7646
diff changeset
463 return 0;
arpi
parents: 7646
diff changeset
464 }
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
465 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask |
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
466 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
467 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
468 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
469 AuSetErrorHandler(nas_data->aud, nas_error_handler);
7732
arpi
parents: 7646
diff changeset
470 nas_data->state=AuStateStop;
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
471 nas_data->expect_underrun=0;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
472
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
473 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
474 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
475
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
476 return 1;
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 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 12022
diff changeset
480 static void uninit(int immed){
7732
arpi
parents: 7646
diff changeset
481
arpi
parents: 7646
diff changeset
482 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: uninit()\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
483
7732
arpi
parents: 7646
diff changeset
484 nas_data->expect_underrun = 1;
arpi
parents: 7646
diff changeset
485 while (nas_data->state != AuStateStop) usleep(1000);
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 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
487 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
488 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
489 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
490 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
491 free(nas_data->server_buffer);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
492 }
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 // stop playing and empty buffers (for seeking/pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
495 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
496 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
497
7732
arpi
parents: 7646
diff changeset
498 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: reset()\n");
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
499
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 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
501 nas_data->client_buffer_used = 0;
7732
arpi
parents: 7646
diff changeset
502 pthread_mutex_unlock(&nas_data->buffer_mutex);
arpi
parents: 7646
diff changeset
503 while (nas_data->state != AuStateStop) {
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
504 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
505 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
506 nas_print_error(nas_data->aud, "reset(): AuStopFlow", as);
7732
arpi
parents: 7646
diff changeset
507 usleep(1000);
3276
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
511 // stop playing, keep buffers (for pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
512 static void audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
513 {
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
514 AuStatus as;
7732
arpi
parents: 7646
diff changeset
515 mp_msg(MSGT_AO, MSGL_DBG3, "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
516
7732
arpi
parents: 7646
diff changeset
517 AuStopFlow(nas_data->aud, nas_data->flow, &as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
518 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
519
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
520 // resume playing, after audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
521 static void audio_resume()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
522 {
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
523 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
524
7732
arpi
parents: 7646
diff changeset
525 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: audio_resume()\n");
arpi
parents: 7646
diff changeset
526
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
527 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
528 if (as != AuSuccess)
7732
arpi
parents: 7646
diff changeset
529 nas_print_error(nas_data->aud,
arpi
parents: 7646
diff changeset
530 "play(): AuStartFlow", as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
531 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
532
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
533
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
534 // return: how many bytes can be played without blocking
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
535 static int get_space()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
536 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
537 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
538
7732
arpi
parents: 7646
diff changeset
539 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_space()\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
540
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
541 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
542 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
543 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
544
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
545 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
546 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
547
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
548 // plays 'len' bytes of 'data'
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
549 // it should round it down to outburst*n
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
550 // 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
551 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
552 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
554 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
555
7732
arpi
parents: 7646
diff changeset
556 mp_msg(MSGT_AO, MSGL_DBG3,
arpi
parents: 7646
diff changeset
557 "ao_nas: play(%p, %d, %d)\n",
arpi
parents: 7646
diff changeset
558 data, len, flags);
arpi
parents: 7646
diff changeset
559
arpi
parents: 7646
diff changeset
560 if (len == 0)
arpi
parents: 7646
diff changeset
561 return 0;
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
562
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
563 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
564 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
565 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
566 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
567 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
568 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
569 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
570
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
571 nas_writeBuffer(nas_data, data, writelen);
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
572
7732
arpi
parents: 7646
diff changeset
573 if (nas_data->state != AuStateStart &&
arpi
parents: 7646
diff changeset
574 maxbursts == playbursts) {
arpi
parents: 7646
diff changeset
575 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n");
7626
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
576 nas_data->expect_underrun = 1;
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
577 AuStartFlow(nas_data->aud, nas_data->flow, &as);
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
578 if (as != AuSuccess)
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
579 nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
580 }
09ccf6147d76 Small error, the buffer size got set incorrectly.
arpi
parents: 7449
diff changeset
581
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
582 return writelen;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
583 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
584
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
585 // 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
586 static float get_delay()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
587 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
588 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
589
7732
arpi
parents: 7646
diff changeset
590 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_delay()\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
591
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
592 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
593 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
594 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
595 (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
596 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
597
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
598 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
599 }