Mercurial > mplayer.hg
annotate libao2/ao_nas.c @ 9920:cf5ae3f6175c
ffindeo3 (diff from mplayerxp-cvslog) untested
author | michael |
---|---|
date | Tue, 15 Apr 2003 20:40:11 +0000 |
parents | 12b1790038b0 |
children | 293141b57c01 |
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; |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
7732 | 113 unsigned int state; |
7626 | 114 int expect_underrun; |
3276 | 115 |
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
|
116 void *client_buffer; |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 pthread_mutex_t buffer_mutex; |
3276 | 123 |
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
|
124 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
|
125 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
|
126 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static struct ao_nas_data *nas_data; |
3276 | 129 |
130 LIBAO_EXTERN(nas) | |
131 | |
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
|
132 static void nas_print_error(AuServer *aud, char *prefix, AuStatus as) |
3276 | 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 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
|
135 AuGetErrorText(aud, as, s, 100); |
7627 | 136 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s); |
3276 | 137 } |
138 | |
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
|
139 static int nas_readBuffer(struct ao_nas_data *nas_data, int num) |
3276 | 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 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
|
142 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 pthread_mutex_lock(&nas_data->buffer_mutex); |
7627 | 144 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n", |
3276 | 145 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
|
146 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
|
147 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 148 |
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
|
149 if (nas_data->client_buffer_used == 0) { |
7627 | 150 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
|
151 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 152 return 0; |
153 } | |
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
|
154 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
|
155 num = nas_data->client_buffer_used; |
3276 | 156 |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
157 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
158 * 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
|
159 * 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
|
160 * 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
|
161 * 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
|
162 * 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
|
163 * |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
164 * (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
|
165 * 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
|
166 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
167 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
|
168 |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 |
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 * 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
|
176 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
177 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
|
178 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
|
179 nas_print_error(nas_data->aud, "nas_readBuffer(): AuWriteElement", as); |
3276 | 180 |
181 return num; | |
182 } | |
183 | |
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
|
184 static void nas_writeBuffer(struct ao_nas_data *nas_data, void *data, int len) |
3276 | 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 pthread_mutex_lock(&nas_data->buffer_mutex); |
7627 | 187 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
|
188 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
|
189 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 190 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
191 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
|
192 nas_data->client_buffer_used += len; |
3276 | 193 |
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
|
194 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 195 } |
196 | |
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
|
197 static int nas_empty_event_queue(struct ao_nas_data *nas_data) |
3276 | 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 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
|
200 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
|
201 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
203 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
|
204 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
|
205 result = 1; |
3276 | 206 } |
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
|
207 return result; |
3276 | 208 } |
209 | |
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
|
210 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
|
211 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
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 do { |
7732 | 215 mp_msg(MSGT_AO, MSGL_DBG2, |
216 "ao_nas: event thread heartbeat (state=%s)\n", | |
217 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
|
218 nas_empty_event_queue(nas_data); |
7732 | 219 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
|
220 } while (!nas_data->stop_thread); |
7732 | 221 |
222 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
|
223 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev) |
3276 | 226 { |
227 char s[100]; | |
228 AuGetErrorText(aud, ev->error_code, s, 100); | |
7627 | 229 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: error [%s]\n" |
3276 | 230 "error_code: %d\n" |
231 "request_code: %d\n" | |
232 "minor_code: %d\n", | |
233 s, | |
234 ev->error_code, | |
235 ev->request_code, | |
236 ev->minor_code); | |
237 | |
238 return AuTrue; | |
239 } | |
240 | |
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
|
241 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
|
242 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
244 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
|
245 |
7732 | 246 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", |
247 nas_event_type(event->type), | |
248 nas_elementnotify_kind(event->kind), | |
249 nas_state(event->prev_state), | |
250 nas_state(event->cur_state), | |
251 nas_reason(event->reason), | |
252 event->num_bytes, | |
253 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
|
254 |
7732 | 255 nas_data->server_buffer_used -= event->num_bytes; |
256 if (nas_data->server_buffer_used < 0) | |
257 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
|
258 |
7732 | 259 switch (event->reason) { |
260 case AuReasonWatermark: | |
261 nas_readBuffer(nas_data, event->num_bytes); | |
262 break; | |
263 case AuReasonUnderrun: | |
264 // buffer underrun -> refill buffer | |
265 nas_data->server_buffer_used = 0; | |
266 if (nas_data->expect_underrun) { | |
267 nas_data->expect_underrun = 0; | |
268 } else { | |
269 mp_msg(MSGT_AO, MSGL_WARN, | |
270 "ao_nas: Buffer underrun.\n"); | |
271 mp_msg(MSGT_AO, MSGL_HINT, | |
272 "Possible reasons are:" | |
273 "1) Network congestion." | |
274 "2) Your NAS server is too slow." | |
275 "Try renicing your nasd to e.g. -15.\n"); | |
276 } | |
277 if (nas_readBuffer(nas_data, | |
278 nas_data->server_buffer_size - | |
279 nas_data->server_buffer_used) != 0) { | |
280 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
|
281 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
|
282 } |
7732 | 283 mp_msg(MSGT_AO, MSGL_DBG2, |
284 "ao_nas: Can't refill buffer, stopping flow.\n"); | |
285 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
|
286 break; |
7732 | 287 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
|
288 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
|
289 } |
7732 | 290 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
|
291 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
|
292 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
293 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static AuDeviceID nas_find_device(AuServer *aud, int nch) |
3276 | 295 { |
296 int i; | |
297 for (i = 0; i < AuServerNumDevices(aud); i++) { | |
298 AuDeviceAttributes *dev = AuServerDevice(aud, i); | |
299 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) && | |
300 AuDeviceNumTracks(dev) == nch) { | |
301 return AuDeviceIdentifier(dev); | |
302 } | |
303 } | |
304 return AuNone; | |
305 } | |
306 | |
7732 | 307 static unsigned int nas_aformat_to_auformat(unsigned int *format) |
3276 | 308 { |
7732 | 309 switch (*format) { |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
310 case AFMT_U8: |
7732 | 311 return AuFormatLinearUnsigned8; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
312 case AFMT_S8: |
7732 | 313 return AuFormatLinearSigned8; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
314 case AFMT_U16_LE: |
7732 | 315 return AuFormatLinearUnsigned16LSB; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
316 case AFMT_U16_BE: |
7732 | 317 return AuFormatLinearUnsigned16MSB; |
5790 | 318 #ifndef WORDS_BIGENDIAN |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
319 default: |
7732 | 320 *format=AFMT_S16_LE; |
5790 | 321 #endif |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
322 case AFMT_S16_LE: |
7732 | 323 return AuFormatLinearSigned16LSB; |
5790 | 324 #ifdef WORDS_BIGENDIAN |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
325 default: |
7732 | 326 *format=AFMT_S16_BE; |
5790 | 327 #endif |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
328 case AFMT_S16_BE: |
7732 | 329 return AuFormatLinearSigned16MSB; |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
330 case AFMT_MU_LAW: |
7732 | 331 return AuFormatULAW8; |
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 { |
338 AuDeviceAttributes *dattr; | |
339 AuFixedPoint fpgain; | |
340 AuStatus as; | |
341 int gain; | |
9583 | 342 int retval = CONTROL_UNKNOWN; |
343 | |
8272 | 344 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
345 | |
346 dattr = AuGetDeviceAttributes(nas_data->aud, nas_data->dev, &as); | |
347 if (as != AuSuccess) { | |
348 nas_print_error(nas_data->aud, | |
349 "control(): AuGetDeviceAttributes", as); | |
350 return CONTROL_ERROR; | |
351 } | |
352 gain = AuFixedPointRoundDown(AuDeviceGain(dattr)); | |
353 // kn: 0 <= gain <= 100 | |
354 | |
355 switch (cmd) { | |
356 case AOCONTROL_GET_VOLUME: | |
357 | |
358 vol->right = (float) gain; | |
359 vol->left = vol->right; | |
360 | |
9583 | 361 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_GET_VOLUME: %d\n", gain); |
362 retval = CONTROL_OK; | |
363 break; | |
8272 | 364 |
365 case AOCONTROL_SET_VOLUME: | |
366 /* | |
367 * kn: we should have vol->left == vol->right but i don't | |
368 * know if something can change it outside of ao_nas | |
369 * so i take the mean of both values. | |
370 */ | |
371 gain = (int) ((vol->left+vol->right)/2); | |
9583 | 372 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_SET_VOLUME: %d\n", gain); |
8272 | 373 |
374 fpgain = AuFixedPointFromSum(gain, 0); | |
375 AuDeviceGain(dattr) = fpgain; | |
376 AuSetDeviceAttributes(nas_data->aud, nas_data->dev, | |
377 AuCompDeviceGainMask, dattr, &as); | |
378 if (as != AuSuccess) { | |
379 nas_print_error(nas_data->aud, | |
380 "control(): AuSetDeviceAttributes", as); | |
9583 | 381 retval = CONTROL_ERROR; |
382 } else retval = CONTROL_OK; | |
383 break; | |
384 }; | |
8272 | 385 |
9583 | 386 AuFreeDeviceAttributes(nas_data->aud, 1, dattr); |
387 return retval; | |
3276 | 388 } |
389 | |
390 // open & setup audio device | |
391 // return: 1=success 0=fail | |
392 static int init(int rate,int channels,int format,int flags) | |
393 { | |
394 AuElement elms[3]; | |
395 AuStatus as; | |
7732 | 396 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
|
397 int bytes_per_sample = channels * AuSizeofFormat(auformat); |
7732 | 398 int buffer_size; |
3276 | 399 char *server; |
400 | |
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 nas_data=malloc(sizeof(struct ao_nas_data)); |
6114
34d5c9a67b94
Patch by Tobias Diedrich <td@informatik.uni-hannover.de>:
pl
parents:
5790
diff
changeset
|
402 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
|
403 |
7627 | 404 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
|
405 audio_out_format_name(format)); |
3276 | 406 |
7732 | 407 ao_data.format = format; |
3276 | 408 ao_data.samplerate = rate; |
409 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
|
410 ao_data.outburst = NAS_FRAG_SIZE; |
3276 | 411 ao_data.bps = rate * bytes_per_sample; |
7732 | 412 buffer_size = ao_data.bps; /* buffer 1 second */ |
413 /* | |
414 * round up to multiple of NAS_FRAG_SIZE | |
415 * divide by 3 first because of 2:1 split | |
416 */ | |
417 buffer_size = (buffer_size/3 + NAS_FRAG_SIZE-1) & ~(NAS_FRAG_SIZE-1); | |
418 ao_data.buffersize = buffer_size*3; | |
419 | |
420 nas_data->client_buffer_size = buffer_size*2; | |
421 nas_data->client_buffer = malloc(nas_data->client_buffer_size); | |
422 nas_data->server_buffer_size = buffer_size; | |
423 nas_data->server_buffer = malloc(nas_data->server_buffer_size); | |
3276 | 424 |
425 if (!bytes_per_sample) { | |
7627 | 426 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Zero bytes per sample -> nosound\n"); |
3276 | 427 return 0; |
428 } | |
429 | |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
430 if (!(server = getenv("AUDIOSERVER")) && |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
431 !(server = getenv("DISPLAY"))) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
432 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
|
433 return 0; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
434 } |
3276 | 435 |
7627 | 436 mp_msg(MSGT_AO, MSGL_V, "ao_nas: init(): Using audioserver %s\n", server); |
3276 | 437 |
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
|
438 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
|
439 if (!nas_data->aud) { |
7627 | 440 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't open nas audio server -> nosound\n"); |
3276 | 441 return 0; |
442 } | |
443 | |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
444 while (channels>1) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
445 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
|
446 if (nas_data->dev != AuNone && |
7732 | 447 ((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
|
448 break; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
449 channels--; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
450 } |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
451 |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
452 if (nas_data->flow == 0) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
453 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
|
454 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
|
455 nas_data->aud = 0; |
3276 | 456 return 0; |
457 } | |
458 | |
7732 | 459 AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue, |
460 buffer_size / bytes_per_sample, | |
461 (buffer_size - NAS_FRAG_SIZE) / | |
462 bytes_per_sample, 0, NULL); | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
463 AuMakeElementExportDevice(elms+1, 0, nas_data->dev, rate, |
3276 | 464 AuUnlimitedSamples, 0, NULL); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
465 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, 2, elms, &as); |
7732 | 466 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
|
467 nas_print_error(nas_data->aud, "init(): AuSetElements", as); |
7732 | 468 AuCloseServer(nas_data->aud); |
469 nas_data->aud = 0; | |
470 return 0; | |
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 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask | |
3276 | 473 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
|
474 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
|
475 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
|
476 AuSetErrorHandler(nas_data->aud, nas_error_handler); |
7732 | 477 nas_data->state=AuStateStop; |
7626 | 478 nas_data->expect_underrun=0; |
3276 | 479 |
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
|
480 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
|
481 pthread_create(&nas_data->event_thread, NULL, &nas_event_thread_start, nas_data); |
3276 | 482 |
483 return 1; | |
484 } | |
485 | |
486 // close audio device | |
487 static void uninit(){ | |
7732 | 488 |
489 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
|
490 |
7732 | 491 nas_data->expect_underrun = 1; |
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 free(nas_data->server_buffer); |
3276 | 499 } |
500 | |
501 // stop playing and empty buffers (for seeking/pause) | |
502 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
|
503 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
|
504 |
7732 | 505 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: reset()\n"); |
7626 | 506 |
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
|
507 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
|
508 nas_data->client_buffer_used = 0; |
7732 | 509 pthread_mutex_unlock(&nas_data->buffer_mutex); |
510 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
|
511 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
|
512 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
|
513 nas_print_error(nas_data->aud, "reset(): AuStopFlow", as); |
7732 | 514 usleep(1000); |
3276 | 515 } |
516 } | |
517 | |
518 // stop playing, keep buffers (for pause) | |
519 static void audio_pause() | |
520 { | |
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
|
521 AuStatus as; |
7732 | 522 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
|
523 |
7732 | 524 AuStopFlow(nas_data->aud, nas_data->flow, &as); |
3276 | 525 } |
526 | |
527 // resume playing, after audio_pause() | |
528 static void audio_resume() | |
529 { | |
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
|
530 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
|
531 |
7732 | 532 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: audio_resume()\n"); |
533 | |
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
|
534 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
|
535 if (as != AuSuccess) |
7732 | 536 nas_print_error(nas_data->aud, |
537 "play(): AuStartFlow", as); | |
3276 | 538 } |
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 |
3276 | 541 // return: how many bytes can be played without blocking |
542 static int get_space() | |
543 { | |
544 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
|
545 |
7732 | 546 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_space()\n"); |
3276 | 547 |
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
|
548 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
|
549 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
|
550 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 551 |
552 return result; | |
553 } | |
554 | |
555 // plays 'len' bytes of 'data' | |
556 // it should round it down to outburst*n | |
557 // 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
|
558 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
|
559 { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
560 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
|
561 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
|
562 |
7732 | 563 mp_msg(MSGT_AO, MSGL_DBG3, |
564 "ao_nas: play(%p, %d, %d)\n", | |
565 data, len, flags); | |
566 | |
567 if (len == 0) | |
568 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
|
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 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
578 nas_writeBuffer(nas_data, data, writelen); |
7626 | 579 |
7732 | 580 if (nas_data->state != AuStateStart && |
581 maxbursts == playbursts) { | |
582 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n"); | |
7626 | 583 nas_data->expect_underrun = 1; |
584 AuStartFlow(nas_data->aud, nas_data->flow, &as); | |
585 if (as != AuSuccess) | |
586 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); | |
587 } | |
588 | |
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 return writelen; |
3276 | 590 } |
591 | |
592 // return: delay in seconds between first and last sample in buffer | |
593 static float get_delay() | |
594 { | |
595 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
|
596 |
7732 | 597 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_delay()\n"); |
3276 | 598 |
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
|
599 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
|
600 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
|
601 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
|
602 (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
|
603 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 604 |
605 return result; | |
606 } |