annotate libao2/ao_nas.c @ 5336:3cc26c4e662b

no native support for I420 in G200
author arpi
date Mon, 25 Mar 2002 16:22:15 +0000
parents 080cf3df3e4e
children d141f1e9cc36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3336
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
1 /*
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
2 * NAS output plugin for mplayer
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
3 *
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
4 * based on the libaudiooss parts rewritten by me, which were
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
5 * originally based on the NAS output plugin for xmms.
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
6 *
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
7 * xmms plugin by Willem Monsuwe
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
8 * adapted for libaudiooss by Jon Trulson
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
9 * further modified by Erik Inge Bolsų
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
10 * largely rewritten and used for this
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
11 * plugin by Tobias Diedrich
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
12 *
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
15 #include <stdio.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
16 #include <stdlib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
17 #include <pthread.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
18 #include <audio/audiolib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
19
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
20 #include "audio_out.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
21 #include "audio_out_internal.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
22 #include "afmt.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
27
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
28 #define NAS_DEBUG 0
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
29
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
88 #define DPRINTF(format, args...) fprintf(stderr, format, ## args); \
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
89 fflush(stderr)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
90 #else
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
91 #define DPRINTF(format, args...)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
92 #endif
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
93
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
94 static ao_info_t info =
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
95 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
96 "NAS audio output",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
97 "nas",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
98 "Tobias Diedrich",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
99 ""
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
100 };
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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;
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
112 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
113 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
114 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
115 pthread_mutex_t buffer_mutex;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
116
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
117 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
118 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
119 };
080cf3df3e4e improved event handling, implemented working pause that does not 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 static struct ao_nas_data *nas_data;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
122
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
123 LIBAO_EXTERN(nas)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
124
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
125 static void nas_print_error(AuServer *aud, char *prefix, AuStatus as)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
126 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
128 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
129 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
130 fflush(stderr);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
131 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
132
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
133 static int nas_readBuffer(struct ao_nas_data *nas_data, int num)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
134 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
135 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
136
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
138 DPRINTF("ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n",
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
139 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
140 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
141 nas_data->server_buffer_used, nas_data->server_buffer_size);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
142
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
143 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
144 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
145 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
146 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
147 }
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
148 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
149 num = nas_data->client_buffer_used;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
150
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
151 AuWriteElement(nas_data->aud, nas_data->flow, 0, num, nas_data->client_buffer, AuFalse, &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
152 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
153 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
154 else {
080cf3df3e4e improved event handling, implemented working pause that does not 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 nas_data->client_buffer_used -= num;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
156 nas_data->server_buffer_used += num;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
157 memmove(nas_data->client_buffer, nas_data->client_buffer + num, 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
158 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
159 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
160
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
161 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
162 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
163 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
164 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
165 }
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
166
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
167 return num;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
168 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
169
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
170 static void nas_writeBuffer(struct ao_nas_data *nas_data, void *data, int len)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
171 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
172 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
173 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
174 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
175 nas_data->server_buffer_used, nas_data->server_buffer_size);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
176
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
178 nas_data->client_buffer_used += len;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
179
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
181 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
182 nas_readBuffer(nas_data, nas_data->server_buffer_size - nas_data->server_buffer_used);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
183 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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 int nas_empty_event_queue(struct ao_nas_data *nas_data)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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 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
188 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
189
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
191 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
192 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
193 result = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
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 return result;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
196 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
197
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
198 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
199 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
201 AuEvent ev;
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
202 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
203
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
204 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
205 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
206 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
207 } 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
208 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
209
080cf3df3e4e improved event handling, implemented working pause that does not 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 AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
211 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
212 char s[100];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
213 AuGetErrorText(aud, ev->error_code, s, 100);
3336
8818c12743a8 patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents: 3276
diff changeset
214 fprintf(stderr,"ao_nas: error [%s]\n"
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
215 "error_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
216 "request_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
217 "minor_code: %d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
218 s,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
219 ev->error_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
220 ev->request_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
221 ev->minor_code);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
222 fflush(stderr);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
223
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
224 return AuTrue;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
225 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
226
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
227 static AuBool nas_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
228 {
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
229 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
230 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
231 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
232
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
233 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
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
243 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
244 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
245
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 // 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
255 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
256 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
257 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
258 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
259 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
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 }
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
263 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
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 }
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
267 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
268 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
269 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
270 }
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
272 }
080cf3df3e4e improved event handling, implemented working pause that does not 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
080cf3df3e4e improved event handling, implemented working pause that does not 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 static AuDeviceID nas_find_device(AuServer *aud, int nch)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
275 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
276 int i;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
277 for (i = 0; i < AuServerNumDevices(aud); i++) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
278 AuDeviceAttributes *dev = AuServerDevice(aud, i);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
279 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) &&
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
280 AuDeviceNumTracks(dev) == nch) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
281 return AuDeviceIdentifier(dev);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
282 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
283 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
284 return AuNone;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
285 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
286
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 static unsigned char nas_aformat_to_auformat(unsigned int format)
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
288 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
289 switch (format) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
290 case AFMT_U8: return AuFormatLinearUnsigned8;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
291 case AFMT_S8: return AuFormatLinearSigned8;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
292 case AFMT_U16_LE: return AuFormatLinearUnsigned16LSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
293 case AFMT_U16_BE: return AuFormatLinearUnsigned16MSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
294 case AFMT_S16_LE: return AuFormatLinearSigned16LSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
295 case AFMT_S16_BE: return AuFormatLinearSigned16MSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
296 case AFMT_MU_LAW: return AuFormatULAW8;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
297 default: return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
298 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
299 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
300
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
301 // to set/get/query special features/parameters
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
302 static int control(int cmd,int arg){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
303 return -1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
304 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
305
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
306 // open & setup audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
307 // return: 1=success 0=fail
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
308 static int init(int rate,int channels,int format,int flags)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
309 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
310 AuElement elms[3];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
311 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
312 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
313 int bytes_per_sample = channels * AuSizeofFormat(auformat);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
314 char *server;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
315
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
316 nas_data=malloc(sizeof(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
317
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
318 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
319 audio_out_format_name(format));
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
320
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
321 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
322 printf("ao_nas: init(): Unsupported format -> nosound\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
323 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
324 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
325
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
326 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
327 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
328 nas_data->server_buffer_size = NAS_BUFFER_SIZE;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
329
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
330 ao_data.samplerate = rate;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
331 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
332 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
333 ao_data.outburst = NAS_FRAG_SIZE;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
334 ao_data.bps = rate * bytes_per_sample;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
335
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
336 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
337 printf("ao_nas: init(): Zero bytes per sample -> nosound\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
338 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
339 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
340
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
341 if (!(server = getenv("AUDIOSERVER")))
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
342 server = getenv("DISPLAY");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
343
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
344 if (!server) // default to tcp/localhost:8000
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
345 server = "tcp/localhost:8000";
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
346
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
347 printf("ao_nas: init(): Using audioserver %s\n", server);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
348
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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->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
350 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
351 printf("ao_nas: init(): Can't open nas audio server -> nosound\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
352 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
353 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
354
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
356 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
357 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
358 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
359 nas_data->aud = 0;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
360 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
361 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
362
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
363 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
364 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
365 (NAS_BUFFER_SIZE - NAS_FRAG_SIZE) / bytes_per_sample,
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
366 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
367 AuMakeElementExportDevice(elms+1, 0, nas_data->dev, rate,
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
368 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
369 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, 2, elms, &as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
370 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
371 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
372 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask |
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
373 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
374 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
375 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
376 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
377 nas_data->flow_stopped=1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
378
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
380 pthread_create(&nas_data->event_thread, NULL, &nas_event_thread_start, nas_data);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
381
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
382 return 1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
383 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
384
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
385 // close audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
386 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
387 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
388
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
389 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
390 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
391 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
392 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
393 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
394 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
395 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
396 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
397 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
398 free(nas_data->client_buffer);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
399 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
400
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
401 // stop playing and empty buffers (for seeking/pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
402 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
403 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
404
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
406 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
407 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
408 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
409 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
410 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
411 nas_data->flow_stopped = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
412 }
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
414 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
415 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
416
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
417 // stop playing, keep buffers (for pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
418 static void audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
419 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
421
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
422 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
423
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
424 nas_data->flow_paused = 1;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
425 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
426
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
427 // resume playing, after audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
428 static void audio_resume()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
429 {
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
431 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
432
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
434
080cf3df3e4e improved event handling, implemented working pause that does not 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 = 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
436 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
437 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
438 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
439 nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
440 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
441
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
442
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
443 // return: how many bytes can be played without blocking
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
444 static int get_space()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
445 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
446 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
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 DPRINTF("ao_nas: get_space()\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
449
4775
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
450 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
451 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
452 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
453
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
454 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
455 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
456
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
457 // plays 'len' bytes of 'data'
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
458 // it should round it down to outburst*n
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
459 // 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
460 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
461 {
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
463 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
464
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
466
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
468 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
469
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
470 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
471 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
472 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
473 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
474 while (!nas_empty_event_queue(nas_data)); // wait for first buffer underrun event
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
475 }
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
476
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
477 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
478 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
479 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
480 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
481 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
482 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
483 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
484
080cf3df3e4e improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents: 3336
diff changeset
485 nas_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
486 return writelen;
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
487 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
488
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
489 // return: delay in seconds between first and last sample in buffer
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
490 static float get_delay()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
491 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
492 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
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 DPRINTF("ao_nas: get_delay()\n");
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
495
4775
080cf3df3e4e improved event handling, implemented working pause that does not 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 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
497 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
498 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
499 (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
500 pthread_mutex_unlock(&nas_data->buffer_mutex);
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
501
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
502 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
503 }