Mercurial > mplayer.hg
annotate libao2/ao_nas.c @ 33466:45d8bfbd27bc
Define "gmplayer" as symbolic constant.
This defines a hardcoded value at one single point.
author | ib |
---|---|
date | Fri, 03 Jun 2011 15:43:38 +0000 |
parents | 0f1b5b68af32 |
children |
rev | line source |
---|---|
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
1 /* |
28343 | 2 * NAS audio output driver |
3 * | |
4 * copyright (c) 2001 Tobias Diedrich <ranma@gmx.at> | |
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
5 * |
28343 | 6 * Based on the libaudiooss parts rewritten by me, which were |
7 * originally based on the NAS output plugin for XMMS. | |
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
8 * |
28343 | 9 * XMMS plugin by Willem Monsuwe |
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
10 * adapted for libaudiooss by Jon Trulson |
23734 | 11 * further modified by Erik Inge Bolsø |
28343 | 12 * largely rewritten and used for this ao driver by Tobias Diedrich |
13 * | |
14 * This file is part of MPlayer. | |
15 * | |
16 * MPlayer is free software; you can redistribute it and/or modify | |
17 * it under the terms of the GNU General Public License as published by | |
18 * the Free Software Foundation; either version 2 of the License, or | |
19 * (at your option) any later version. | |
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
20 * |
28343 | 21 * MPlayer is distributed in the hope that it will be useful, |
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 * GNU General Public License for more details. | |
25 * | |
26 * You should have received a copy of the GNU General Public License along | |
27 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
28 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
29 */ | |
30 | |
31 /* | |
7626 | 32 * Theory of operation: |
33 * | |
34 * The NAS consists of two parts, a server daemon and a client. | |
7732 | 35 * We setup the server to use a buffer of size bytes_per_second |
36 * with a low watermark of buffer_size - NAS_FRAG_SIZE. | |
7626 | 37 * Upon starting the flow the server will generate a buffer underrun |
38 * event and the event handler will fill the buffer for the first time. | |
39 * Now the server will generate a lowwater event when the server buffer | |
40 * falls below the low watermark value. The event handler gets called | |
41 * again and refills the buffer by the number of bytes requested by the | |
42 * server (usually a multiple of 4096). To prevent stuttering on | |
43 * startup (start of playing, seeks, unpausing) the client buffer should | |
44 * be bigger than the server buffer. (For debugging we also do some | |
45 * accounting of what we think how much of the server buffer is filled) | |
3336
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
46 */ |
8818c12743a8
patch by Tobias Diedrich <td@informatik.uni-hannover.de>
pl
parents:
3276
diff
changeset
|
47 |
7732 | 48 #include <unistd.h> |
3276 | 49 #include <stdio.h> |
50 #include <stdlib.h> | |
7732 | 51 #include <string.h> |
3276 | 52 #include <pthread.h> |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
53 #include <limits.h> |
3276 | 54 #include <audio/audiolib.h> |
55 | |
14480
1d3cc596069d
actually mp_msg.h includes config.h, but for consistency better include it
reimar
parents:
14479
diff
changeset
|
56 #include "config.h" |
14123 | 57 #include "mp_msg.h" |
7627 | 58 |
3276 | 59 #include "audio_out.h" |
60 #include "audio_out_internal.h" | |
14245 | 61 #include "libaf/af_format.h" |
3276 | 62 |
27449 | 63 /* NAS_FRAG_SIZE must be a power-of-two value */ |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 #define NAS_FRAG_SIZE 4096 |
3276 | 65 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
66 static const char * const nas_event_types[] = { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 "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
|
68 "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
|
69 "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
|
70 "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
|
71 "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
|
72 "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
|
73 "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
|
74 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
76 static const char * const nas_elementnotify_kinds[] = { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 "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
|
78 "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
|
79 "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
|
80 "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
|
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 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
83 static const char * const nas_states[] = { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 "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
|
85 "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
|
86 "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
|
87 "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
|
88 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
89 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
90 static const char * const nas_reasons[] = { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
91 "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
|
92 "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
|
93 "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
|
94 "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
|
95 "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
|
96 "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
|
97 "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
|
98 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
99 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
100 static const char* nas_reason(unsigned int reason) |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
101 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
103 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
|
104 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
106 static const char* nas_elementnotify_kind(unsigned int kind) |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 { |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
109 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
|
110 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
112 static const char* nas_event_type(unsigned int type) { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
114 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
|
115 } |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
116 |
28192
bc49998d5745
Move several of the ao_nas int-to-string maps into .rodata
reimar
parents:
27449
diff
changeset
|
117 static const char* nas_state(unsigned int state) { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
118 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
|
119 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
|
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 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
122 static const ao_info_t info = |
3276 | 123 { |
124 "NAS audio output", | |
125 "nas", | |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
126 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>", |
3276 | 127 "" |
128 }; | |
129 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
131 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
|
132 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
|
133 AuDeviceID dev; |
12022 | 134 AuFixedPoint gain; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
135 |
7732 | 136 unsigned int state; |
7626 | 137 int expect_underrun; |
3276 | 138 |
27446 | 139 char *client_buffer; |
140 char *server_buffer; | |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
141 unsigned int client_buffer_size; |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
142 unsigned int client_buffer_used; |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
143 unsigned int server_buffer_size; |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
144 unsigned int server_buffer_used; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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_t buffer_mutex; |
3276 | 146 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
147 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
|
148 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
|
149 }; |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
150 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static struct ao_nas_data *nas_data; |
3276 | 152 |
153 LIBAO_EXTERN(nas) | |
154 | |
18965
24ae1f262dc2
make prefix const. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
17566
diff
changeset
|
155 static void nas_print_error(AuServer *aud, const char *prefix, AuStatus as) |
3276 | 156 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
158 AuGetErrorText(aud, as, s, 100); |
7627 | 159 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: %s: returned status %d (%s)\n", prefix, as, s); |
3276 | 160 } |
161 | |
27446 | 162 static int nas_readBuffer(struct ao_nas_data *nas_data, unsigned int num) |
3276 | 163 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
165 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
166 pthread_mutex_lock(&nas_data->buffer_mutex); |
7627 | 167 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_readBuffer(): num=%d client=%d/%d server=%d/%d\n", |
3276 | 168 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
|
169 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
|
170 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 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 if (nas_data->client_buffer_used == 0) { |
7627 | 173 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: buffer is empty, nothing read.\n"); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
174 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 175 return 0; |
176 } | |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
177 if (num > nas_data->client_buffer_used) |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 num = nas_data->client_buffer_used; |
3276 | 179 |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
180 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
181 * It is not appropriate to call AuWriteElement() here because the |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
182 * buffer is locked and delays writing to the network will cause |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
183 * other threads to block waiting for buffer_mutex. Instead the |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
184 * data is copied to "server_buffer" and written to the network |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
185 * outside of the locked section of code. |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
186 * |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
187 * (Note: Rather than these two buffers, a single circular buffer |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
188 * could eliminate the memcpy/memmove steps.) |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
189 */ |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
190 /* make sure we don't overflow the buffer */ |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
191 if (num > nas_data->server_buffer_size) |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
192 num = nas_data->server_buffer_size; |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
193 memcpy(nas_data->server_buffer, nas_data->client_buffer, num); |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
194 |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
195 nas_data->client_buffer_used -= num; |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
196 nas_data->server_buffer_used += num; |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
197 memmove(nas_data->client_buffer, nas_data->client_buffer + num, nas_data->client_buffer_used); |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
198 pthread_mutex_unlock(&nas_data->buffer_mutex); |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
199 |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
200 /* |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
201 * Now write the new buffer to the network. |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
202 */ |
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
203 AuWriteElement(nas_data->aud, nas_data->flow, 0, num, nas_data->server_buffer, AuFalse, &as); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
204 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
|
205 nas_print_error(nas_data->aud, "nas_readBuffer(): AuWriteElement", as); |
3276 | 206 |
207 return num; | |
208 } | |
209 | |
27446 | 210 static int nas_writeBuffer(struct ao_nas_data *nas_data, void *data, unsigned int len) |
3276 | 211 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
212 pthread_mutex_lock(&nas_data->buffer_mutex); |
7627 | 213 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: nas_writeBuffer(): len=%d client=%d/%d server=%d/%d\n", |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
214 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
|
215 nas_data->server_buffer_used, nas_data->server_buffer_size); |
3276 | 216 |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
217 /* make sure we don't overflow the buffer */ |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
218 if (len > nas_data->client_buffer_size - nas_data->client_buffer_used) |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
219 len = nas_data->client_buffer_size - nas_data->client_buffer_used; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
220 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
|
221 nas_data->client_buffer_used += len; |
3276 | 222 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
223 pthread_mutex_unlock(&nas_data->buffer_mutex); |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
224 |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
225 return len; |
3276 | 226 } |
227 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static int nas_empty_event_queue(struct ao_nas_data *nas_data) |
3276 | 229 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
231 int result = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
232 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
234 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
|
235 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
|
236 result = 1; |
3276 | 237 } |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 return result; |
3276 | 239 } |
240 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
241 static 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
|
242 { |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
243 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
|
244 |
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
245 do { |
7732 | 246 mp_msg(MSGT_AO, MSGL_DBG2, |
247 "ao_nas: event thread heartbeat (state=%s)\n", | |
248 nas_state(nas_data->state)); | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
249 nas_empty_event_queue(nas_data); |
7732 | 250 usleep(1000); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
251 } while (!nas_data->stop_thread); |
7732 | 252 |
253 return NULL; | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
254 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static AuBool nas_error_handler(AuServer* aud, AuErrorEvent* ev) |
3276 | 257 { |
258 char s[100]; | |
259 AuGetErrorText(aud, ev->error_code, s, 100); | |
7627 | 260 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: error [%s]\n" |
3276 | 261 "error_code: %d\n" |
262 "request_code: %d\n" | |
263 "minor_code: %d\n", | |
264 s, | |
265 ev->error_code, | |
266 ev->request_code, | |
267 ev->minor_code); | |
268 | |
269 return AuTrue; | |
270 } | |
271 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not 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 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
|
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 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
|
275 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
|
276 |
7732 | 277 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: event_handler(): type %s kind %s state %s->%s reason %s numbytes %d expect_underrun %d\n", |
278 nas_event_type(event->type), | |
279 nas_elementnotify_kind(event->kind), | |
280 nas_state(event->prev_state), | |
281 nas_state(event->cur_state), | |
282 nas_reason(event->reason), | |
27446 | 283 (int)event->num_bytes, |
7732 | 284 nas_data->expect_underrun); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
285 |
15741
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
286 if (event->num_bytes > INT_MAX) { |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
287 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: num_bytes > 2GB, server buggy?\n"); |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
288 } |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
289 |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
290 if (event->num_bytes > nas_data->server_buffer_used) |
2beb7a7cdac1
Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald for noticing this problem
ranma
parents:
14849
diff
changeset
|
291 event->num_bytes = nas_data->server_buffer_used; |
7732 | 292 nas_data->server_buffer_used -= event->num_bytes; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
293 |
7732 | 294 switch (event->reason) { |
295 case AuReasonWatermark: | |
296 nas_readBuffer(nas_data, event->num_bytes); | |
297 break; | |
298 case AuReasonUnderrun: | |
299 // buffer underrun -> refill buffer | |
300 nas_data->server_buffer_used = 0; | |
301 if (nas_data->expect_underrun) { | |
302 nas_data->expect_underrun = 0; | |
303 } else { | |
12022 | 304 static int hint = 1; |
7732 | 305 mp_msg(MSGT_AO, MSGL_WARN, |
306 "ao_nas: Buffer underrun.\n"); | |
12022 | 307 if (hint) { |
308 hint = 0; | |
309 mp_msg(MSGT_AO, MSGL_HINT, | |
310 "Possible reasons are:\n" | |
311 "1) Network congestion.\n" | |
312 "2) Your NAS server is too slow.\n" | |
313 "Try renicing your nasd to e.g. -15.\n"); | |
314 } | |
7732 | 315 } |
316 if (nas_readBuffer(nas_data, | |
317 nas_data->server_buffer_size - | |
318 nas_data->server_buffer_used) != 0) { | |
319 event->cur_state = AuStateStart; | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
320 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
|
321 } |
7732 | 322 mp_msg(MSGT_AO, MSGL_DBG2, |
323 "ao_nas: Can't refill buffer, stopping flow.\n"); | |
27446 | 324 AuStopFlow(aud, nas_data->flow, NULL); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
325 break; |
7732 | 326 default: |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
327 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
|
328 } |
7732 | 329 nas_data->state=event->cur_state; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
330 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
|
331 } |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 |
080cf3df3e4e
improved event handling, implemented working pause that does not 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 static AuDeviceID nas_find_device(AuServer *aud, int nch) |
3276 | 334 { |
335 int i; | |
336 for (i = 0; i < AuServerNumDevices(aud); i++) { | |
337 AuDeviceAttributes *dev = AuServerDevice(aud, i); | |
338 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) && | |
339 AuDeviceNumTracks(dev) == nch) { | |
340 return AuDeviceIdentifier(dev); | |
341 } | |
342 } | |
343 return AuNone; | |
344 } | |
345 | |
7732 | 346 static unsigned int nas_aformat_to_auformat(unsigned int *format) |
3276 | 347 { |
7732 | 348 switch (*format) { |
14245 | 349 case AF_FORMAT_U8: |
7732 | 350 return AuFormatLinearUnsigned8; |
14245 | 351 case AF_FORMAT_S8: |
7732 | 352 return AuFormatLinearSigned8; |
14245 | 353 case AF_FORMAT_U16_LE: |
7732 | 354 return AuFormatLinearUnsigned16LSB; |
14245 | 355 case AF_FORMAT_U16_BE: |
7732 | 356 return AuFormatLinearUnsigned16MSB; |
14245 | 357 case AF_FORMAT_S16_LE: |
7732 | 358 return AuFormatLinearSigned16LSB; |
14245 | 359 case AF_FORMAT_S16_BE: |
7732 | 360 return AuFormatLinearSigned16MSB; |
14245 | 361 case AF_FORMAT_MU_LAW: |
7732 | 362 return AuFormatULAW8; |
12022 | 363 default: |
14245 | 364 *format=AF_FORMAT_S16_NE; |
12022 | 365 return nas_aformat_to_auformat(format); |
3276 | 366 } |
367 } | |
368 | |
369 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9583
diff
changeset
|
370 static int control(int cmd, void *arg) |
8272 | 371 { |
12022 | 372 AuElementParameters aep; |
8272 | 373 AuStatus as; |
9583 | 374 int retval = CONTROL_UNKNOWN; |
375 | |
8272 | 376 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
377 | |
378 switch (cmd) { | |
379 case AOCONTROL_GET_VOLUME: | |
380 | |
12022 | 381 vol->right = (float)nas_data->gain/AU_FIXED_POINT_SCALE*50; |
8272 | 382 vol->left = vol->right; |
383 | |
27446 | 384 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_GET_VOLUME: %.2f\n", vol->right); |
9583 | 385 retval = CONTROL_OK; |
386 break; | |
8272 | 387 |
388 case AOCONTROL_SET_VOLUME: | |
389 /* | |
390 * kn: we should have vol->left == vol->right but i don't | |
391 * know if something can change it outside of ao_nas | |
392 * so i take the mean of both values. | |
393 */ | |
12022 | 394 nas_data->gain = AU_FIXED_POINT_SCALE*((vol->left+vol->right)/2)/50; |
27446 | 395 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: AOCONTROL_SET_VOLUME: %.2f\n", (vol->left+vol->right)/2); |
8272 | 396 |
12022 | 397 aep.parameters[AuParmsMultiplyConstantConstant]=nas_data->gain; |
398 aep.flow = nas_data->flow; | |
399 aep.element_num = 1; | |
400 aep.num_parameters = AuParmsMultiplyConstant; | |
401 | |
402 AuSetElementParameters(nas_data->aud, 1, &aep, &as); | |
8272 | 403 if (as != AuSuccess) { |
404 nas_print_error(nas_data->aud, | |
12022 | 405 "control(): AuSetElementParameters", as); |
9583 | 406 retval = CONTROL_ERROR; |
407 } else retval = CONTROL_OK; | |
408 break; | |
409 }; | |
8272 | 410 |
9583 | 411 return retval; |
3276 | 412 } |
413 | |
414 // open & setup audio device | |
415 // return: 1=success 0=fail | |
416 static int init(int rate,int channels,int format,int flags) | |
417 { | |
418 AuElement elms[3]; | |
419 AuStatus as; | |
7732 | 420 unsigned char auformat = nas_aformat_to_auformat(&format); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
421 int bytes_per_sample = channels * AuSizeofFormat(auformat); |
7732 | 422 int buffer_size; |
3276 | 423 char *server; |
424 | |
27446 | 425 (void)flags; /* shut up 'unused parameter' warning */ |
426 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
427 nas_data=malloc(sizeof(struct ao_nas_data)); |
6114
34d5c9a67b94
Patch by Tobias Diedrich <td@informatik.uni-hannover.de>:
pl
parents:
5790
diff
changeset
|
428 memset(nas_data, 0, sizeof(struct ao_nas_data)); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
429 |
7627 | 430 mp_msg(MSGT_AO, MSGL_V, "ao2: %d Hz %d chans %s\n",rate,channels, |
14264 | 431 af_fmt2str_short(format)); |
3276 | 432 |
7732 | 433 ao_data.format = format; |
3276 | 434 ao_data.samplerate = rate; |
435 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
|
436 ao_data.outburst = NAS_FRAG_SIZE; |
3276 | 437 ao_data.bps = rate * bytes_per_sample; |
7732 | 438 buffer_size = ao_data.bps; /* buffer 1 second */ |
439 /* | |
440 * round up to multiple of NAS_FRAG_SIZE | |
441 * divide by 3 first because of 2:1 split | |
442 */ | |
443 buffer_size = (buffer_size/3 + NAS_FRAG_SIZE-1) & ~(NAS_FRAG_SIZE-1); | |
444 ao_data.buffersize = buffer_size*3; | |
445 | |
446 nas_data->client_buffer_size = buffer_size*2; | |
447 nas_data->client_buffer = malloc(nas_data->client_buffer_size); | |
448 nas_data->server_buffer_size = buffer_size; | |
449 nas_data->server_buffer = malloc(nas_data->server_buffer_size); | |
3276 | 450 |
451 if (!bytes_per_sample) { | |
7627 | 452 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Zero bytes per sample -> nosound\n"); |
3276 | 453 return 0; |
454 } | |
455 | |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
456 if (!(server = getenv("AUDIOSERVER")) && |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
457 !(server = getenv("DISPLAY"))) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
458 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): AUDIOSERVER environment variable not set -> nosound\n"); |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
459 return 0; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
460 } |
3276 | 461 |
7627 | 462 mp_msg(MSGT_AO, MSGL_V, "ao_nas: init(): Using audioserver %s\n", server); |
3276 | 463 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
464 nas_data->aud = AuOpenServer(server, 0, NULL, 0, NULL, NULL); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
465 if (!nas_data->aud) { |
7627 | 466 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't open nas audio server -> nosound\n"); |
3276 | 467 return 0; |
468 } | |
469 | |
23006 | 470 while (channels>0) { |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
471 nas_data->dev = nas_find_device(nas_data->aud, channels); |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
472 if (nas_data->dev != AuNone && |
7732 | 473 ((nas_data->flow = AuCreateFlow(nas_data->aud, NULL)) != 0)) |
7646
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
474 break; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
475 channels--; |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
476 } |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
477 |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
478 if (nas_data->flow == 0) { |
0761d6ac7ce9
libaf compliance (ao_data) fix by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7627
diff
changeset
|
479 mp_msg(MSGT_AO, MSGL_ERR, "ao_nas: init(): Can't find a suitable output device -> nosound\n"); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
480 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
|
481 nas_data->aud = 0; |
3276 | 482 return 0; |
483 } | |
484 | |
7732 | 485 AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue, |
486 buffer_size / bytes_per_sample, | |
487 (buffer_size - NAS_FRAG_SIZE) / | |
488 bytes_per_sample, 0, NULL); | |
12022 | 489 nas_data->gain = AuFixedPointFromFraction(1, 1); |
490 AuMakeElementMultiplyConstant(elms+1, 0, nas_data->gain); | |
491 AuMakeElementExportDevice(elms+2, 1, nas_data->dev, rate, | |
3276 | 492 AuUnlimitedSamples, 0, NULL); |
12022 | 493 AuSetElements(nas_data->aud, nas_data->flow, AuTrue, sizeof(elms)/sizeof(*elms), elms, &as); |
7732 | 494 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
|
495 nas_print_error(nas_data->aud, "init(): AuSetElements", as); |
7732 | 496 AuCloseServer(nas_data->aud); |
497 nas_data->aud = 0; | |
498 return 0; | |
499 } | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
500 AuRegisterEventHandler(nas_data->aud, AuEventHandlerIDMask | |
3276 | 501 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
|
502 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
|
503 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
|
504 AuSetErrorHandler(nas_data->aud, nas_error_handler); |
7732 | 505 nas_data->state=AuStateStop; |
7626 | 506 nas_data->expect_underrun=0; |
3276 | 507 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
508 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
|
509 pthread_create(&nas_data->event_thread, NULL, &nas_event_thread_start, nas_data); |
3276 | 510 |
511 return 1; | |
512 } | |
513 | |
514 // close audio device | |
12145 | 515 static void uninit(int immed){ |
7732 | 516 |
517 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: uninit()\n"); | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
518 |
7732 | 519 nas_data->expect_underrun = 1; |
14849
d313f591d1a4
aos should respect the immed uninit flag (quit immediatly vs waiting till file
reimar
parents:
14480
diff
changeset
|
520 if (!immed) |
7732 | 521 while (nas_data->state != AuStateStop) usleep(1000); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 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
|
526 free(nas_data->client_buffer); |
7449
28785e6e6900
"One can cause a permanent hang on a seek, and the other just causes
arpi
parents:
6114
diff
changeset
|
527 free(nas_data->server_buffer); |
3276 | 528 } |
529 | |
530 // stop playing and empty buffers (for seeking/pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15741
diff
changeset
|
531 static void reset(void){ |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
532 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
|
533 |
7732 | 534 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: reset()\n"); |
7626 | 535 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
536 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
|
537 nas_data->client_buffer_used = 0; |
7732 | 538 pthread_mutex_unlock(&nas_data->buffer_mutex); |
539 while (nas_data->state != AuStateStop) { | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
540 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
|
541 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
|
542 nas_print_error(nas_data->aud, "reset(): AuStopFlow", as); |
7732 | 543 usleep(1000); |
3276 | 544 } |
545 } | |
546 | |
547 // stop playing, keep buffers (for pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15741
diff
changeset
|
548 static void audio_pause(void) |
3276 | 549 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
550 AuStatus as; |
7732 | 551 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: audio_pause()\n"); |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
552 |
7732 | 553 AuStopFlow(nas_data->aud, nas_data->flow, &as); |
3276 | 554 } |
555 | |
556 // resume playing, after audio_pause() | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15741
diff
changeset
|
557 static void audio_resume(void) |
3276 | 558 { |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
559 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
|
560 |
7732 | 561 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: audio_resume()\n"); |
562 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
563 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
|
564 if (as != AuSuccess) |
7732 | 565 nas_print_error(nas_data->aud, |
566 "play(): AuStartFlow", as); | |
3276 | 567 } |
568 | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
569 |
3276 | 570 // return: how many bytes can be played without blocking |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15741
diff
changeset
|
571 static int get_space(void) |
3276 | 572 { |
573 int result; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
574 |
7732 | 575 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_space()\n"); |
3276 | 576 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
577 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
|
578 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
|
579 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 580 |
581 return result; | |
582 } | |
583 | |
584 // plays 'len' bytes of 'data' | |
585 // it should round it down to outburst*n | |
586 // 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
|
587 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
|
588 { |
27449 | 589 int written, maxbursts = 0, playbursts = 0; |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
590 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
|
591 |
7732 | 592 mp_msg(MSGT_AO, MSGL_DBG3, |
593 "ao_nas: play(%p, %d, %d)\n", | |
594 data, len, flags); | |
595 | |
596 if (len == 0) | |
597 return 0; | |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
598 |
27449 | 599 if (!(flags & AOPLAY_FINAL_CHUNK)) { |
600 pthread_mutex_lock(&nas_data->buffer_mutex); | |
601 maxbursts = (nas_data->client_buffer_size - | |
602 nas_data->client_buffer_used) / ao_data.outburst; | |
603 playbursts = len / ao_data.outburst; | |
604 len = (playbursts > maxbursts ? maxbursts : playbursts) * | |
605 ao_data.outburst; | |
606 pthread_mutex_unlock(&nas_data->buffer_mutex); | |
27435
f3cd247a4aa3
Work correctly with very small files where less than outburst is to be played.
diego
parents:
23734
diff
changeset
|
607 } |
f3cd247a4aa3
Work correctly with very small files where less than outburst is to be played.
diego
parents:
23734
diff
changeset
|
608 |
27449 | 609 /* |
610 * If AOPLAY_FINAL_CHUNK is set, we did not actually check len fits | |
611 * into the available buffer space, but mplayer.c shouldn't give us | |
612 * more to play than we report to it by get_space(), so this should be | |
613 * fine. | |
614 */ | |
615 written = nas_writeBuffer(nas_data, data, len); | |
7626 | 616 |
7732 | 617 if (nas_data->state != AuStateStart && |
27449 | 618 (maxbursts == playbursts || |
619 flags & AOPLAY_FINAL_CHUNK)) { | |
7732 | 620 mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n"); |
7626 | 621 nas_data->expect_underrun = 1; |
622 AuStartFlow(nas_data->aud, nas_data->flow, &as); | |
623 if (as != AuSuccess) | |
624 nas_print_error(nas_data->aud, "play(): AuStartFlow", as); | |
625 } | |
626 | |
27449 | 627 return written; |
3276 | 628 } |
629 | |
630 // return: delay in seconds between first and last sample in buffer | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15741
diff
changeset
|
631 static float get_delay(void) |
3276 | 632 { |
633 float result; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
634 |
7732 | 635 mp_msg(MSGT_AO, MSGL_DBG3, "ao_nas: get_delay()\n"); |
3276 | 636 |
4775
080cf3df3e4e
improved event handling, implemented working pause that does not flush all buffers, work around a deadlock in the new threadsafe version 1.5 of libaudio by Tobias Diedrich
atmos4
parents:
3336
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 (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
|
641 pthread_mutex_unlock(&nas_data->buffer_mutex); |
3276 | 642 |
643 return result; | |
644 } |