Mercurial > mplayer.hg
annotate libao2/ao_nas.c @ 7575:3a6d7933a6ad
flickering fix, patch by Fredrik Noring <noring@nocrew.org>
author | arpi |
---|---|
date | Tue, 01 Oct 2002 21:47:32 +0000 |
parents | 28785e6e6900 |
children | 09ccf6147d76 |
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 * |
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
13 */ |
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
14 |
3276 | 15 #include <stdio.h> |
16 #include <stdlib.h> | |
17 #include <pthread.h> | |
18 #include <audio/audiolib.h> | |
19 | |
20 #include "audio_out.h" | |
21 #include "audio_out_internal.h" | |
22 #include "afmt.h" | |
23 | |
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
|
24 #define NAS_FRAG_SIZE 4096 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
25 #define NAS_FRAG_COUNT 8 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
26 #define NAS_BUFFER_SIZE NAS_FRAG_SIZE * NAS_FRAG_COUNT |
3276 | 27 |
28 #define NAS_DEBUG 0 | |
29 | |
30 #if NAS_DEBUG == 1 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
31 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
32 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
|
33 "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
|
34 "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
|
35 "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
|
36 "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
|
37 "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
|
38 "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
|
39 "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
|
40 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
41 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
43 "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
|
44 "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
|
45 "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
|
46 "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
|
47 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
50 "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
|
51 "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
|
52 "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
|
53 "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
|
54 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
55 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
57 "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
|
58 "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
|
59 "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
|
60 "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
|
61 "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
|
62 "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
|
63 "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
|
64 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
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 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
|
69 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
|
70 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
73 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
75 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
|
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_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
|
79 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
|
80 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
|
81 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
84 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
|
85 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
|
86 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
87 |
3276 | 88 #define DPRINTF(format, args...) fprintf(stderr, format, ## args); \ |
89 fflush(stderr) | |
90 #else | |
91 #define DPRINTF(format, args...) | |
92 #endif | |
93 | |
94 static ao_info_t info = | |
95 { | |
96 "NAS audio output", | |
97 "nas", | |
98 "Tobias Diedrich", | |
99 "" | |
100 }; | |
101 | |
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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
107 int flow_stopped; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
108 int flow_paused; |
3276 | 109 |
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
|
110 void *client_buffer; |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 pthread_mutex_t buffer_mutex; |
3276 | 117 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
118 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
|
119 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
|
120 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static struct ao_nas_data *nas_data; |
3276 | 123 |
124 LIBAO_EXTERN(nas) | |
125 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
126 static void nas_print_error(AuServer *aud, char *prefix, AuStatus as) |
3276 | 127 { |
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
|
128 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
|
129 AuGetErrorText(aud, as, 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
|
130 fprintf(stderr, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
131 fflush(stderr); |
3276 | 132 } |
133 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
134 static int nas_readBuffer(struct ao_nas_data *nas_data, int num) |
3276 | 135 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
136 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
|
137 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
138 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
|
139 DPRINTF("ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n", |
3276 | 140 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
|
141 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
|
142 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 143 |
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
|
144 if (nas_data->client_buffer_used == 0) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
145 DPRINTF("ao_nas: buffer is empty, nothing read.\n"); |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 147 return 0; |
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 < 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
|
150 num = nas_data->client_buffer_used; |
3276 | 151 |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
152 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
153 * 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
|
154 * 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
|
155 * 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
|
156 * 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
|
157 * 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
|
158 * |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
159 * (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
|
160 * 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
|
161 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
162 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
|
163 |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 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
|
168 |
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 * 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
|
171 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
172 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
|
173 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
|
174 nas_print_error(nas_data->aud, "nas_readBuffer(): AuWriteElement", as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
175 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
176 if (nas_data->flow_paused) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
177 AuPauseFlow(nas_data->aud, nas_data->flow, &as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
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(): AuPauseFlow", as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
180 } |
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); |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 DPRINTF("ao_nas: nas_writeBuffer(): len=%d client=%d/%d server=%d/%d\n", |
080cf3df3e4e
improved event handling, implemented working pause that does not 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); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
196 if (nas_data->server_buffer_used < nas_data->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
|
197 nas_readBuffer(nas_data, nas_data->server_buffer_size - nas_data->server_buffer_used); |
3276 | 198 } |
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 static int nas_empty_event_queue(struct ao_nas_data *nas_data) |
3276 | 201 { |
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
|
202 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
|
203 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
|
204 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
206 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
|
207 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
|
208 result = 1; |
3276 | 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 return result; |
3276 | 211 } |
212 | |
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
|
213 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
|
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 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
|
216 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
|
217 AuBool result; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
218 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
219 do { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
220 nas_empty_event_queue(nas_data); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
221 usleep(10000); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
222 } while (!nas_data->stop_thread); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
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); | |
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
229 fprintf(stderr,"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 fflush(stderr); | |
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 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
|
246 struct ao_nas_data *nas_data = hnd->data; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
247 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
248 switch (ev->type) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
249 case AuEventTypeElementNotify: |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
250 DPRINTF("ao_nas: event_handler(): kind %s state %s->%s reason %s numbytes %d\n", |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
251 nas_elementnotify_kind(event->kind), |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
252 nas_state(event->prev_state), |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
253 nas_state(event->cur_state), |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
254 nas_reason(event->reason), |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
255 event->num_bytes); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
256 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
257 nas_data->server_buffer_used -= event->num_bytes; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
258 if (nas_data->server_buffer_used < 0) |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
259 nas_data->server_buffer_used = 0; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
260 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
261 switch (event->kind) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
262 case AuElementNotifyKindLowWater: |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
263 nas_readBuffer(nas_data, event->num_bytes); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
264 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
|
265 case AuElementNotifyKindState: |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
266 if (event->cur_state == AuStatePause) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
267 switch (event->reason) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
268 case AuReasonUnderrun: |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
269 // buffer underrun -> refill buffer |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
270 nas_data->server_buffer_used = 0; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
271 nas_readBuffer(nas_data, nas_data->server_buffer_size - 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
|
272 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
|
273 default: |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
274 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
|
275 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
276 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
277 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
|
278 default: // silently ignored |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
279 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
|
280 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 default: |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
283 printf("ao_nas: nas_event_handler(): unhandled event type %d\n", ev->type); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
284 break; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
285 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
287 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
288 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
289 static AuDeviceID nas_find_device(AuServer *aud, int nch) |
3276 | 290 { |
291 int i; | |
292 for (i = 0; i < AuServerNumDevices(aud); i++) { | |
293 AuDeviceAttributes *dev = AuServerDevice(aud, i); | |
294 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) && | |
295 AuDeviceNumTracks(dev) == nch) { | |
296 return AuDeviceIdentifier(dev); | |
297 } | |
298 } | |
299 return AuNone; | |
300 } | |
301 | |
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
|
302 static unsigned char nas_aformat_to_auformat(unsigned int format) |
3276 | 303 { |
304 switch (format) { | |
305 case AFMT_U8: return AuFormatLinearUnsigned8; | |
306 case AFMT_S8: return AuFormatLinearSigned8; | |
307 case AFMT_U16_LE: return AuFormatLinearUnsigned16LSB; | |
308 case AFMT_U16_BE: return AuFormatLinearUnsigned16MSB; | |
5790 | 309 #ifndef WORDS_BIGENDIAN |
310 case AFMT_AC3: | |
311 #endif | |
3276 | 312 case AFMT_S16_LE: return AuFormatLinearSigned16LSB; |
5790 | 313 #ifdef WORDS_BIGENDIAN |
314 case AFMT_AC3: | |
315 #endif | |
3276 | 316 case AFMT_S16_BE: return AuFormatLinearSigned16MSB; |
317 case AFMT_MU_LAW: return AuFormatULAW8; | |
318 default: return 0; | |
319 } | |
320 } | |
321 | |
322 // to set/get/query special features/parameters | |
323 static int control(int cmd,int arg){ | |
324 return -1; | |
325 } | |
326 | |
327 // open & setup audio device | |
328 // return: 1=success 0=fail | |
329 static int init(int rate,int channels,int format,int flags) | |
330 { | |
331 AuElement elms[3]; | |
332 AuStatus as; | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
333 unsigned char auformat = nas_aformat_to_auformat(format); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
334 int bytes_per_sample = channels * AuSizeofFormat(auformat); |
3276 | 335 char *server; |
336 | |
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
|
337 nas_data=malloc(sizeof(struct ao_nas_data)); |
6114
34d5c9a67b94
Patch by Tobias Diedrich <td@informatik.uni-hannover.de>:
pl
parents:
5790
diff
changeset
|
338 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
|
339 |
3276 | 340 printf("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
|
341 audio_out_format_name(format)); |
3276 | 342 |
343 if (!auformat) { | |
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
|
344 printf("ao_nas: init(): Unsupported format -> nosound\n"); |
3276 | 345 return 0; |
346 } | |
347 | |
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
|
348 nas_data->client_buffer_size = NAS_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
|
349 nas_data->client_buffer = malloc(nas_data->client_buffer_size); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
350 nas_data->server_buffer_size = NAS_BUFFER_SIZE; |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
351 nas_data->server_buffer = malloc(nas_data->server_buffer_size); |
3276 | 352 |
353 ao_data.samplerate = rate; | |
354 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
|
355 ao_data.buffersize = NAS_BUFFER_SIZE * 2; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
356 ao_data.outburst = NAS_FRAG_SIZE; |
3276 | 357 ao_data.bps = rate * bytes_per_sample; |
358 | |
359 if (!bytes_per_sample) { | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
360 printf("ao_nas: init(): Zero bytes per sample -> nosound\n"); |
3276 | 361 return 0; |
362 } | |
363 | |
364 if (!(server = getenv("AUDIOSERVER"))) | |
365 server = getenv("DISPLAY"); | |
366 | |
367 if (!server) // default to tcp/localhost:8000 | |
368 server = "tcp/localhost:8000"; | |
369 | |
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
|
370 printf("ao_nas: init(): Using audioserver %s\n", server); |
3276 | 371 |
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
|
372 nas_data->aud = AuOpenServer(server, 0, NULL, 0, NULL, 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
|
373 if (!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
|
374 printf("ao_nas: init(): Can't open nas audio server -> nosound\n"); |
3276 | 375 return 0; |
376 } | |
377 | |
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
|
378 nas_data->dev = nas_find_device(nas_data->aud, channels); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
379 if ((nas_data->dev == AuNone) || (!(nas_data->flow = AuCreateFlow(nas_data->aud, 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
|
380 printf("ao_nas: init(): Can't find a device serving that many channels -> nosound\n"); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
381 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
|
382 nas_data->aud = 0; |
3276 | 383 return 0; |
384 } | |
385 | |
386 AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue, | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
387 NAS_BUFFER_SIZE / bytes_per_sample, |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
388 (NAS_BUFFER_SIZE - NAS_FRAG_SIZE) / bytes_per_sample, |
3276 | 389 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
|
390 AuMakeElementExportDevice(elms+1, 0, nas_data->dev, rate, |
3276 | 391 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
|
392 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, 2, elms, &as); |
3276 | 393 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
|
394 nas_print_error(nas_data->aud, "init(): AuSetElements", as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
395 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask | |
3276 | 396 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
|
397 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
|
398 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
|
399 AuSetErrorHandler(nas_data->aud, nas_error_handler); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
400 nas_data->flow_stopped=1; |
3276 | 401 |
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
|
402 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
|
403 pthread_create(&nas_data->event_thread, NULL, &nas_event_thread_start, nas_data); |
3276 | 404 |
405 return 1; | |
406 } | |
407 | |
408 // close audio device | |
409 static void uninit(){ | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
410 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
|
411 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
412 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
|
413 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
|
414 if (!nas_data->flow_stopped) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
415 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
|
416 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
|
417 nas_print_error(nas_data->aud, "uninit(): AuStopFlow", as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
418 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
419 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
|
420 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
|
421 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
|
422 free(nas_data->server_buffer); |
3276 | 423 } |
424 | |
425 // stop playing and empty buffers (for seeking/pause) | |
426 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
|
427 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
|
428 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
429 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
|
430 nas_data->client_buffer_used = 0; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
431 if (!nas_data->flow_stopped) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
432 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
|
433 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
|
434 nas_print_error(nas_data->aud, "reset(): AuStopFlow", as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
435 nas_data->flow_stopped = 1; |
3276 | 436 } |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
437 nas_data->server_buffer_used = 0; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
438 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 439 } |
440 | |
441 // stop playing, keep buffers (for pause) | |
442 static void audio_pause() | |
443 { | |
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 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
|
445 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
446 DPRINTF("ao_nas: audio_pause()\n"); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
447 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
448 nas_data->flow_paused = 1; |
3276 | 449 } |
450 | |
451 // resume playing, after audio_pause() | |
452 static void audio_resume() | |
453 { | |
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 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
|
455 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
|
456 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
457 DPRINTF("ao_nas: audio_resume()\n"); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
458 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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_data->flow_stopped = 0; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
460 nas_data->flow_paused = 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
|
461 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
|
462 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
|
463 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); |
3276 | 464 } |
465 | |
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 |
3276 | 467 // return: how many bytes can be played without blocking |
468 static int get_space() | |
469 { | |
470 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
|
471 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 DPRINTF("ao_nas: get_space()\n"); |
3276 | 473 |
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 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
|
475 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
|
476 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 477 |
478 return result; | |
479 } | |
480 | |
481 // plays 'len' bytes of 'data' | |
482 // it should round it down to outburst*n | |
483 // 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
|
484 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
|
485 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
487 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
|
488 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 DPRINTF("ao_nas: play()\n"); |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
491 if (nas_data->flow_stopped) { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
492 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
|
493 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
495 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
|
496 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
497 nas_data->flow_stopped = 0; |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
498 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
499 * Do not continue to wait if there is nothing in the server |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
500 * buffer. (The event never happens and mplayer can freeze.) |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
501 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
502 while (nas_data->server_buffer_used > 0 && |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
503 !nas_empty_event_queue(nas_data)); // wait for first buffer underrun event |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
504 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
514 nas_writeBuffer(nas_data, data, 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
|
515 return writelen; |
3276 | 516 } |
517 | |
518 // return: delay in seconds between first and last sample in buffer | |
519 static float get_delay() | |
520 { | |
521 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
|
522 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 DPRINTF("ao_nas: get_delay()\n"); |
3276 | 524 |
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
|
525 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
|
526 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
|
527 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
|
528 (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
|
529 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 530 |
531 return result; | |
532 } |