Mercurial > mplayer.hg
annotate libao2/ao_nas.c @ 12835:4235ae5a2d60
cache min fill adjustment, based on patch by Jeremy Huddleston
author | iive |
---|---|
date | Fri, 16 Jul 2004 20:31:17 +0000 |
parents | 99798c3cdb93 |
children | a92101a7eb49 |
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 | 13 * Theory of operation: |
14 * | |
15 * The NAS consists of two parts, a server daemon and a client. | |
7732 | 16 * We setup the server to use a buffer of size bytes_per_second |
17 * with a low watermark of buffer_size - NAS_FRAG_SIZE. | |
7626 | 18 * Upon starting the flow the server will generate a buffer underrun |
19 * event and the event handler will fill the buffer for the first time. | |
20 * Now the server will generate a lowwater event when the server buffer | |
21 * falls below the low watermark value. The event handler gets called | |
22 * again and refills the buffer by the number of bytes requested by the | |
23 * server (usually a multiple of 4096). To prevent stuttering on | |
24 * startup (start of playing, seeks, unpausing) the client buffer should | |
25 * be bigger than the server buffer. (For debugging we also do some | |
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 | 29 #include <unistd.h> |
3276 | 30 #include <stdio.h> |
31 #include <stdlib.h> | |
7732 | 32 #include <string.h> |
3276 | 33 #include <pthread.h> |
34 #include <audio/audiolib.h> | |
35 | |
7627 | 36 #include "../mp_msg.h" |
37 | |
3276 | 38 #include "audio_out.h" |
39 #include "audio_out_internal.h" | |
40 #include "afmt.h" | |
41 | |
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
|
42 #define NAS_FRAG_SIZE 4096 |
3276 | 43 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
44 static char *nas_event_types[] = { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
45 "Undefined", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
46 "Undefined", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
47 "ElementNotify", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
48 "GrabNotify", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
49 "MonitorNotify", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
50 "BucketNotify", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
51 "DeviceNotify" |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
52 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
53 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
54 static char *nas_elementnotify_kinds[] = { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
55 "LowWater", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
56 "HighWater", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
57 "State", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
58 "Unknown" |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
59 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
60 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
61 static char *nas_states[] = { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
62 "Stop", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
63 "Start", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
64 "Pause", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
65 "Any" |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
66 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
67 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
68 static char *nas_reasons[] = { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
69 "User", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
70 "Underrun", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
71 "Overrun", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
72 "EOF", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
73 "Watermark", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
74 "Hardware", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
75 "Any" |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
76 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
77 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
78 static char* nas_reason(unsigned int reason) |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
79 { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
80 if (reason > 6) reason = 6; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
81 return nas_reasons[reason]; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
82 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
83 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
84 static char* nas_elementnotify_kind(unsigned int kind) |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
85 { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
86 if (kind > 2) kind = 3; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
87 return nas_elementnotify_kinds[kind]; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
88 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
89 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
90 static char* nas_event_type(unsigned int type) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
91 if (type > 6) type = 0; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
92 return nas_event_types[type]; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
93 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
94 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
95 static char* nas_state(unsigned int state) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
96 if (state>3) state = 3; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
97 return nas_states[state]; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
98 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
99 |
3276 | 100 static ao_info_t info = |
101 { | |
102 "NAS audio output", | |
103 "nas", | |
104 "Tobias Diedrich", | |
105 "" | |
106 }; | |
107 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
108 struct ao_nas_data { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
109 AuServer *aud; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
110 AuFlowID flow; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
111 AuDeviceID dev; |
12022 | 112 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
|
113 |
7732 | 114 unsigned int state; |
7626 | 115 int expect_underrun; |
3276 | 116 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
117 void *client_buffer; |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
118 void *server_buffer; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
119 int client_buffer_size; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
120 int client_buffer_used; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
121 int server_buffer_size; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
122 int server_buffer_used; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
123 pthread_mutex_t buffer_mutex; |
3276 | 124 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
125 pthread_t event_thread; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
126 int stop_thread; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
127 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
128 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
129 static struct ao_nas_data *nas_data; |
3276 | 130 |
131 LIBAO_EXTERN(nas) | |
132 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
133 static void nas_print_error(AuServer *aud, char *prefix, AuStatus as) |
3276 | 134 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
135 char s[100]; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
136 AuGetErrorText(aud, as, s, 100); |
7627 | 137 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s); |
3276 | 138 } |
139 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
140 static int nas_readBuffer(struct ao_nas_data *nas_data, int num) |
3276 | 141 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
142 AuStatus as; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
143 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
144 pthread_mutex_lock(&nas_data->buffer_mutex); |
7627 | 145 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n", |
3276 | 146 num, |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
147 nas_data->client_buffer_used, nas_data->client_buffer_size, |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
148 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 149 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
150 if (nas_data->client_buffer_used == 0) { |
7627 | 151 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: buffer is empty, nothing read.\n"); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
152 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 153 return 0; |
154 } | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
155 if (nas_data->client_buffer_used < num) |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
156 num = nas_data->client_buffer_used; |
3276 | 157 |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
158 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
159 * It is not appropriate to call AuWriteElement() here because the |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
160 * buffer is locked and delays writing to the network will cause |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
161 * other threads to block waiting for buffer_mutex. Instead the |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
162 * data is copied to "server_buffer" and written it to the network |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
163 * outside of the locked section of code. |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
164 * |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
165 * (Note: Rather than these two buffers, a single circular buffer |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
166 * could eliminate the memcpy/memmove steps.) |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
167 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
168 memcpy(nas_data->server_buffer, nas_data->client_buffer, num); |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
169 |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
170 nas_data->client_buffer_used -= num; |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
171 nas_data->server_buffer_used += num; |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
172 memmove(nas_data->client_buffer, nas_data->client_buffer + num, nas_data->client_buffer_used); |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
173 pthread_mutex_unlock(&nas_data->buffer_mutex); |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
174 |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
175 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
176 * Now write the new buffer to the network. |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
177 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
178 AuWriteElement(nas_data->aud, nas_data->flow, 0, num, nas_data->server_buffer, AuFalse, &as); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
179 if (as != AuSuccess) |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
180 nas_print_error(nas_data->aud, "nas_readBuffer(): AuWriteElement", as); |
3276 | 181 |
182 return num; | |
183 } | |
184 | |
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
|
185 static void nas_writeBuffer(struct ao_nas_data *nas_data, void *data, int len) |
3276 | 186 { |
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
|
187 pthread_mutex_lock(&nas_data->buffer_mutex); |
7627 | 188 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
|
189 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
|
190 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 191 |
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
|
192 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
|
193 nas_data->client_buffer_used += len; |
3276 | 194 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
195 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 196 } |
197 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
198 static int nas_empty_event_queue(struct ao_nas_data *nas_data) |
3276 | 199 { |
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
|
200 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
|
201 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
|
202 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
204 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
|
205 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
|
206 result = 1; |
3276 | 207 } |
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
|
208 return result; |
3276 | 209 } |
210 | |
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
|
211 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
|
212 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
214 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 do { |
7732 | 216 mp_msg(MSGT_AO, MSGL_DBG2, |
217 "ao_nas: event thread heartbeat (state=%s)\n", | |
218 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
|
219 nas_empty_event_queue(nas_data); |
7732 | 220 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
|
221 } while (!nas_data->stop_thread); |
7732 | 222 |
223 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
|
224 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev) |
3276 | 227 { |
228 char s[100]; | |
229 AuGetErrorText(aud, ev->error_code, s, 100); | |
7627 | 230 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: error [%s]\n" |
3276 | 231 "error_code: %d\n" |
232 "request_code: %d\n" | |
233 "minor_code: %d\n", | |
234 s, | |
235 ev->error_code, | |
236 ev->request_code, | |
237 ev->minor_code); | |
238 | |
239 return AuTrue; | |
240 } | |
241 | |
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
|
242 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
|
243 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
245 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
|
246 |
7732 | 247 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", |
248 nas_event_type(event->type), | |
249 nas_elementnotify_kind(event->kind), | |
250 nas_state(event->prev_state), | |
251 nas_state(event->cur_state), | |
252 nas_reason(event->reason), | |
253 event->num_bytes, | |
254 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
|
255 |
7732 | 256 nas_data->server_buffer_used -= event->num_bytes; |
257 if (nas_data->server_buffer_used < 0) | |
258 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
|
259 |
7732 | 260 switch (event->reason) { |
261 case AuReasonWatermark: | |
262 nas_readBuffer(nas_data, event->num_bytes); | |
263 break; | |
264 case AuReasonUnderrun: | |
265 // buffer underrun -> refill buffer | |
266 nas_data->server_buffer_used = 0; | |
267 if (nas_data->expect_underrun) { | |
268 nas_data->expect_underrun = 0; | |
269 } else { | |
12022 | 270 static int hint = 1; |
7732 | 271 mp_msg(MSGT_AO, MSGL_WARN, |
272 "ao_nas: Buffer underrun.\n"); | |
12022 | 273 if (hint) { |
274 hint = 0; | |
275 mp_msg(MSGT_AO, MSGL_HINT, | |
276 "Possible reasons are:\n" | |
277 "1) Network congestion.\n" | |
278 "2) Your NAS server is too slow.\n" | |
279 "Try renicing your nasd to e.g. -15.\n"); | |
280 } | |
7732 | 281 } |
282 if (nas_readBuffer(nas_data, | |
283 nas_data->server_buffer_size - | |
284 nas_data->server_buffer_used) != 0) { | |
285 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
|
286 break; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
287 } |
7732 | 288 mp_msg(MSGT_AO, MSGL_DBG2, |
289 "ao_nas: Can't refill buffer, stopping flow.\n"); | |
290 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
|
291 break; |
7732 | 292 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
|
293 break; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
294 } |
7732 | 295 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
|
296 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
|
297 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
298 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static AuDeviceID nas_find_device(AuServer *aud, int nch) |
3276 | 300 { |
301 int i; | |
302 for (i = 0; i < AuServerNumDevices(aud); i++) { | |
303 AuDeviceAttributes *dev = AuServerDevice(aud, i); | |
304 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) && | |
305 AuDeviceNumTracks(dev) == nch) { | |
306 return AuDeviceIdentifier(dev); | |
307 } | |
308 } | |
309 return AuNone; | |
310 } | |
311 | |
7732 | 312 static unsigned int nas_aformat_to_auformat(unsigned int *format) |
3276 | 313 { |
7732 | 314 switch (*format) { |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
315 case AFMT_U8: |
7732 | 316 return AuFormatLinearUnsigned8; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
317 case AFMT_S8: |
7732 | 318 return AuFormatLinearSigned8; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
319 case AFMT_U16_LE: |
7732 | 320 return AuFormatLinearUnsigned16LSB; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
321 case AFMT_U16_BE: |
7732 | 322 return AuFormatLinearUnsigned16MSB; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
323 case AFMT_S16_LE: |
7732 | 324 return AuFormatLinearSigned16LSB; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
325 case AFMT_S16_BE: |
7732 | 326 return AuFormatLinearSigned16MSB; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
327 case AFMT_MU_LAW: |
7732 | 328 return AuFormatULAW8; |
12022 | 329 default: |
330 *format=AFMT_S16_NE; | |
331 return nas_aformat_to_auformat(format); | |
3276 | 332 } |
333 } | |
334 | |
335 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9583
diff
changeset
|
336 static int control(int cmd, void *arg) |
8272 | 337 { |
12022 | 338 AuElementParameters aep; |
8272 | 339 AuStatus as; |
9583 | 340 int retval = CONTROL_UNKNOWN; |
341 | |
8272 | 342 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
343 | |
344 switch (cmd) { | |
345 case AOCONTROL_GET_VOLUME: | |
346 | |
12022 | 347 vol->right = (float)nas_data->gain/AU_FIXED_POINT_SCALE*50; |
8272 | 348 vol->left = vol->right; |
349 | |
12022 | 350 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_GET_VOLUME: %08x\n", nas_data->gain); |
9583 | 351 retval = CONTROL_OK; |
352 break; | |
8272 | 353 |
354 case AOCONTROL_SET_VOLUME: | |
355 /* | |
356 * kn: we should have vol->left == vol->right but i don't | |
357 * know if something can change it outside of ao_nas | |
358 * so i take the mean of both values. | |
359 */ | |
12022 | 360 nas_data->gain = AU_FIXED_POINT_SCALE*((vol->left+vol->right)/2)/50; |
361 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_SET_VOLUME: %08x\n", nas_data->gain); | |
8272 | 362 |
12022 | 363 aep.parameters[AuParmsMultiplyConstantConstant]=nas_data->gain; |
364 aep.flow = nas_data->flow; | |
365 aep.element_num = 1; | |
366 aep.num_parameters = AuParmsMultiplyConstant; | |
367 | |
368 AuSetElementParameters(nas_data->aud, 1, &aep, &as); | |
8272 | 369 if (as != AuSuccess) { |
370 nas_print_error(nas_data->aud, | |
12022 | 371 "control(): AuSetElementParameters", as); |
9583 | 372 retval = CONTROL_ERROR; |
373 } else retval = CONTROL_OK; | |
374 break; | |
375 }; | |
8272 | 376 |
9583 | 377 return retval; |
3276 | 378 } |
379 | |
380 // open & setup audio device | |
381 // return: 1=success 0=fail | |
382 static int init(int rate,int channels,int format,int flags) | |
383 { | |
384 AuElement elms[3]; | |
385 AuStatus as; | |
7732 | 386 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
|
387 int bytes_per_sample = channels * AuSizeofFormat(auformat); |
7732 | 388 int buffer_size; |
3276 | 389 char *server; |
390 | |
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
|
391 nas_data=malloc(sizeof(struct ao_nas_data)); |
6114
34d5c9a67b94
Patch by Tobias Diedrich <td@informatik.uni-hannover.de>:
pl
parents:
5790
diff
changeset
|
392 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
|
393 |
7627 | 394 mp_msg(MSGT_AO, MSGL_V, "ao2: %d Hz %d chans %s\n",rate,channels, |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
395 audio_out_format_name(format)); |
3276 | 396 |
7732 | 397 ao_data.format = format; |
3276 | 398 ao_data.samplerate = rate; |
399 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
|
400 ao_data.outburst = NAS_FRAG_SIZE; |
3276 | 401 ao_data.bps = rate * bytes_per_sample; |
7732 | 402 buffer_size = ao_data.bps; /* buffer 1 second */ |
403 /* | |
404 * round up to multiple of NAS_FRAG_SIZE | |
405 * divide by 3 first because of 2:1 split | |
406 */ | |
407 buffer_size = (buffer_size/3 + NAS_FRAG_SIZE-1) & ~(NAS_FRAG_SIZE-1); | |
408 ao_data.buffersize = buffer_size*3; | |
409 | |
410 nas_data->client_buffer_size = buffer_size*2; | |
411 nas_data->client_buffer = malloc(nas_data->client_buffer_size); | |
412 nas_data->server_buffer_size = buffer_size; | |
413 nas_data->server_buffer = malloc(nas_data->server_buffer_size); | |
3276 | 414 |
415 if (!bytes_per_sample) { | |
7627 | 416 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Zero bytes per sample -> nosound\n"); |
3276 | 417 return 0; |
418 } | |
419 | |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
420 if (!(server = getenv("AUDIOSERVER")) && |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
421 !(server = getenv("DISPLAY"))) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
422 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
|
423 return 0; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
424 } |
3276 | 425 |
7627 | 426 mp_msg(MSGT_AO, MSGL_V, "ao_nas: init(): Using audioserver %s\n", server); |
3276 | 427 |
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
|
428 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
|
429 if (!nas_data->aud) { |
7627 | 430 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't open nas audio server -> nosound\n"); |
3276 | 431 return 0; |
432 } | |
433 | |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
434 while (channels>1) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
435 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
|
436 if (nas_data->dev != AuNone && |
7732 | 437 ((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
|
438 break; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
439 channels--; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
440 } |
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 if (nas_data->flow == 0) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
443 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
|
444 AuCloseServer(nas_data->aud); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
445 nas_data->aud = 0; |
3276 | 446 return 0; |
447 } | |
448 | |
7732 | 449 AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue, |
450 buffer_size / bytes_per_sample, | |
451 (buffer_size - NAS_FRAG_SIZE) / | |
452 bytes_per_sample, 0, NULL); | |
12022 | 453 nas_data->gain = AuFixedPointFromFraction(1, 1); |
454 AuMakeElementMultiplyConstant(elms+1, 0, nas_data->gain); | |
455 AuMakeElementExportDevice(elms+2, 1, nas_data->dev, rate, | |
3276 | 456 AuUnlimitedSamples, 0, NULL); |
12022 | 457 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, sizeof(elms)/sizeof(*elms), elms, &as); |
7732 | 458 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
|
459 nas_print_error(nas_data->aud, "init(): AuSetElements", as); |
7732 | 460 AuCloseServer(nas_data->aud); |
461 nas_data->aud = 0; | |
462 return 0; | |
463 } | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
464 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask | |
3276 | 465 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
|
466 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
|
467 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
|
468 AuSetErrorHandler(nas_data->aud, nas_error_handler); |
7732 | 469 nas_data->state=AuStateStop; |
7626 | 470 nas_data->expect_underrun=0; |
3276 | 471 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
472 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
|
473 pthread_create(&nas_data->event_thread, NULL, &nas_event_thread_start, nas_data); |
3276 | 474 |
475 return 1; | |
476 } | |
477 | |
478 // close audio device | |
12145 | 479 static void uninit(int immed){ |
7732 | 480 |
481 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
|
482 |
7732 | 483 nas_data->expect_underrun = 1; |
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 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
|
490 free(nas_data->server_buffer); |
3276 | 491 } |
492 | |
493 // stop playing and empty buffers (for seeking/pause) | |
494 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
|
495 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
|
496 |
7732 | 497 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: reset()\n"); |
7626 | 498 |
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
|
499 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
|
500 nas_data->client_buffer_used = 0; |
7732 | 501 pthread_mutex_unlock(&nas_data->buffer_mutex); |
502 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
|
503 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
|
504 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
|
505 nas_print_error(nas_data->aud, "reset(): AuStopFlow", as); |
7732 | 506 usleep(1000); |
3276 | 507 } |
508 } | |
509 | |
510 // stop playing, keep buffers (for pause) | |
511 static void audio_pause() | |
512 { | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
513 AuStatus as; |
7732 | 514 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
|
515 |
7732 | 516 AuStopFlow(nas_data->aud, nas_data->flow, &as); |
3276 | 517 } |
518 | |
519 // resume playing, after audio_pause() | |
520 static void audio_resume() | |
521 { | |
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
|
522 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
|
523 |
7732 | 524 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: audio_resume()\n"); |
525 | |
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
|
526 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
|
527 if (as != AuSuccess) |
7732 | 528 nas_print_error(nas_data->aud, |
529 "play(): AuStartFlow", as); | |
3276 | 530 } |
531 | |
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
|
532 |
3276 | 533 // return: how many bytes can be played without blocking |
534 static int get_space() | |
535 { | |
536 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
|
537 |
7732 | 538 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_space()\n"); |
3276 | 539 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
540 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
|
541 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
|
542 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 543 |
544 return result; | |
545 } | |
546 | |
547 // plays 'len' bytes of 'data' | |
548 // it should round it down to outburst*n | |
549 // 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
|
550 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
|
551 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
553 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
|
554 |
7732 | 555 mp_msg(MSGT_AO, MSGL_DBG3, |
556 "ao_nas: play(%p, %d, %d)\n", | |
557 data, len, flags); | |
558 | |
559 if (len == 0) | |
560 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
|
561 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 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
|
569 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 nas_writeBuffer(nas_data, data, writelen); |
7626 | 571 |
7732 | 572 if (nas_data->state != AuStateStart && |
573 maxbursts == playbursts) { | |
574 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n"); | |
7626 | 575 nas_data->expect_underrun = 1; |
576 AuStartFlow(nas_data->aud, nas_data->flow, &as); | |
577 if (as != AuSuccess) | |
578 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); | |
579 } | |
580 | |
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
|
581 return writelen; |
3276 | 582 } |
583 | |
584 // return: delay in seconds between first and last sample in buffer | |
585 static float get_delay() | |
586 { | |
587 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
|
588 |
7732 | 589 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_delay()\n"); |
3276 | 590 |
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
|
591 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
|
592 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
|
593 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
|
594 (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
|
595 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 596 |
597 return result; | |
598 } |