annotate libao2/ao_nas.c @ 3289:6582188b79d8

-cache added as default (8192)
author gabucino
date Mon, 03 Dec 2001 17:10:02 +0000
parents e279cc05f189
children 8818c12743a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3276
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
1 #include <stdio.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
2 #include <stdlib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
3 #include <pthread.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
4 #include <audio/audiolib.h>
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
5
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
6 #include "audio_out.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
7 #include "audio_out_internal.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
8 #include "afmt.h"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
9
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
10 #define FRAG_SIZE 4096
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
11 #define FRAG_COUNT 8
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
12 #define BUFFER_SIZE FRAG_SIZE * FRAG_COUNT
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
13
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
14 #define NAS_DEBUG 0
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
15
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
16 #if NAS_DEBUG == 1
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
17 #define DPRINTF(format, args...) fprintf(stderr, format, ## args); \
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
18 fflush(stderr)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
19 #else
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
20 #define DPRINTF(format, args...)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
21 #endif
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
22
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
23 static ao_info_t info =
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
24 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
25 "NAS audio output",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
26 "nas",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
27 "Tobias Diedrich",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
28 ""
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
31 static AuServer* aud;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
32 static AuFlowID flow;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
33 static AuDeviceID dev;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
34
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
35 static void *client_buffer;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
36 static int client_buffer_size = BUFFER_SIZE;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
37 static int client_buffer_used;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
38 static int server_buffer_size = BUFFER_SIZE;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
39 static int server_buffer_used;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
40 static pthread_mutex_t buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
41
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
42 pthread_t event_thread;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
43 static int stop_thread;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
44
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
45 LIBAO_EXTERN(nas)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
46
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
47 static void wait_for_event()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
48 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
49 AuEvent ev;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
50
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
51 AuNextEvent(aud, AuTrue, &ev);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
52 AuDispatchEvent(aud, &ev);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
53 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
54
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
55 static int readBuffer(int num)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
56 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
57 pthread_mutex_lock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
58 DPRINTF("readBuffer(): num=%d client=%d/%d server=%d/%d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
59 num,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
60 client_buffer_used, client_buffer_size,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
61 server_buffer_used, server_buffer_size);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
62
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
63 if (client_buffer_used == 0) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
64 DPRINTF("buffer is empty, nothing read.\n");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
65 pthread_mutex_unlock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
66 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
67 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
68 if (client_buffer_used < num)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
69 num = client_buffer_used;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
70
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
71 AuWriteElement(aud, flow, 0, num, client_buffer, AuFalse, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
72 client_buffer_used -= num;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
73 server_buffer_used += num;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
74 memmove(client_buffer, client_buffer + num, client_buffer_used);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
75 pthread_mutex_unlock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
76
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
77 return num;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
78 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
79
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
80 static void writeBuffer(void *data, int len)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
81 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
82 pthread_mutex_lock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
83 DPRINTF("writeBuffer(): len=%d client=%d/%d server=%d/%d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
84 len, client_buffer_used, client_buffer_size,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
85 server_buffer_used, server_buffer_size);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
86
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
87 memcpy(client_buffer + client_buffer_used, data, len);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
88 client_buffer_used += len;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
89
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
90 pthread_mutex_unlock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
91 if (server_buffer_used < server_buffer_size)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
92 readBuffer(server_buffer_size - server_buffer_used);
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
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 static void *event_thread_start(void *data)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
97 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
98 while (!stop_thread) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
99 wait_for_event();
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 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
102
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
103 static AuBool event_handler(AuServer *aud, AuEvent *ev, AuEventHandlerRec *hnd)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
104 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
105 switch (ev->type) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
106 case AuEventTypeElementNotify: {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
107 AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
108 DPRINTF("event_handler(): kind %d state %d->%d reason %d numbytes %d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
109 event->kind,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
110 event->prev_state,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
111 event->cur_state,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
112 event->reason,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
113 event->num_bytes);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
114
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
115 switch (event->kind) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
116 case AuElementNotifyKindLowWater:
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
117 server_buffer_used -= event->num_bytes;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
118 readBuffer(event->num_bytes);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
119 break;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
120 case AuElementNotifyKindState:
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
121 if ((event->cur_state == AuStatePause) &&
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
122 (event->reason != AuReasonUser)) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
123 // buffer underrun -> refill buffer
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
124 server_buffer_used = 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
125 readBuffer(server_buffer_size - server_buffer_used);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
126 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
127 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
128 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
129 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
130 return AuTrue;
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
133 static AuBool error_handler(AuServer* aud, AuErrorEvent* ev)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
134 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
135 char s[100];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
136 AuGetErrorText(aud, ev->error_code, s, 100);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
137 fprintf(stderr,"libaudiooss: error [%s]\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
138 "error_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
139 "request_code: %d\n"
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
140 "minor_code: %d\n",
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
141 s,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
142 ev->error_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
143 ev->request_code,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
144 ev->minor_code);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
145 fflush(stderr);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
146
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
147 return AuTrue;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
148 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
149
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
150 static AuDeviceID find_device(int nch)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
151 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
152 int i;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
153 for (i = 0; i < AuServerNumDevices(aud); i++) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
154 AuDeviceAttributes *dev = AuServerDevice(aud, i);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
155 if ((AuDeviceKind(dev) == AuComponentKindPhysicalOutput) &&
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
156 AuDeviceNumTracks(dev) == nch) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
157 return AuDeviceIdentifier(dev);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
158 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
159 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
160 return AuNone;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
161 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
162
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
163 static unsigned char aformat_to_auformat(unsigned int format)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
164 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
165 switch (format) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
166 case AFMT_U8: return AuFormatLinearUnsigned8;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
167 case AFMT_S8: return AuFormatLinearSigned8;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
168 case AFMT_U16_LE: return AuFormatLinearUnsigned16LSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
169 case AFMT_U16_BE: return AuFormatLinearUnsigned16MSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
170 case AFMT_S16_LE: return AuFormatLinearSigned16LSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
171 case AFMT_S16_BE: return AuFormatLinearSigned16MSB;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
172 case AFMT_MU_LAW: return AuFormatULAW8;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
173 default: return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
174 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
175 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
176
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
177 // to set/get/query special features/parameters
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
178 static int control(int cmd,int arg){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
179 return -1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
180 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
181
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
182 // open & setup audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
183 // return: 1=success 0=fail
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
184 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
185 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
186 AuElement elms[3];
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
187 AuStatus as;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
188 unsigned char auformat = aformat_to_auformat(format);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
189 int bytes_per_sample;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
190 char *server;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
191
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
192 printf("ao2: %d Hz %d chans %s\n",rate,channels,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
193 audio_out_format_name(format));
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
194
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
195 if (!auformat) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
196 printf("Unsupported format -> nosound\n");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
197 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
198 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
199
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
200 client_buffer = malloc(BUFFER_SIZE);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
201 bytes_per_sample = channels * AuSizeofFormat(auformat);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
202
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
203 ao_data.samplerate = rate;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
204 ao_data.channels = channels;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
205 ao_data.buffersize = BUFFER_SIZE * 2;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
206 ao_data.outburst = FRAG_SIZE;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
207 ao_data.bps = rate * bytes_per_sample;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
208
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
209 if (!bytes_per_sample) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
210 printf("Zero bytes per sample -> nosound\n");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
211 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
212 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
213
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
214 if (!(server = getenv("AUDIOSERVER")))
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
215 server = getenv("DISPLAY");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
216
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
217 if (!server) // default to tcp/localhost:8000
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
218 server = "tcp/localhost:8000";
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
219
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
220 printf("Using audioserver %s\n", server);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
221
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
222 aud = AuOpenServer(server, 0, NULL, 0, NULL, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
223 if (!aud){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
224 printf("Can't open nas audio server -> nosound\n");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
225 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
226 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
227
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
228 dev = find_device(channels);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
229 if ((dev == AuNone) || (!(flow = AuCreateFlow(aud, NULL)))) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
230 printf("Can't find a device serving that many channels -> nosound\n");
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
231 AuCloseServer(aud);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
232 aud = 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
233 return 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
234 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
235
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
236 AuMakeElementImportClient(elms, rate, auformat, channels, AuTrue,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
237 BUFFER_SIZE / bytes_per_sample,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
238 (BUFFER_SIZE - FRAG_SIZE) / bytes_per_sample,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
239 0, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
240 AuMakeElementExportDevice(elms+1, 0, dev, rate,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
241 AuUnlimitedSamples, 0, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
242 AuSetElements(aud, flow, AuTrue, 2, elms, &as);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
243 if (as != AuSuccess)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
244 printf("AuSetElements returned status %d!\n", as);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
245 AuRegisterEventHandler(aud, AuEventHandlerIDMask |
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
246 AuEventHandlerTypeMask,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
247 AuEventTypeElementNotify, flow,
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
248 event_handler, (AuPointer) NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
249 AuSetErrorHandler(aud, error_handler);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
250 AuStartFlow(aud, flow, &as);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
251 if (as != AuSuccess)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
252 printf("AuSetElements returned status %d!\n", as);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
253
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
254 /*
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
255 * Wait for first buffer underrun event
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
256 *
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
257 * For some weird reason we get a buffer underrun event if we
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
258 * don't fill the server buffer fast enough after staring the
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
259 * flow. So we just wait for it to happen to be in a sane state.
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
260 */
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
261 wait_for_event();
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
262
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
263 pthread_create(&event_thread, NULL, &event_thread_start, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
264
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
265 return 1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
266 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
267
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
268 // close audio device
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
269 static void uninit(){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
270 stop_thread = 1;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
271 pthread_join(event_thread, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
272 AuStopFlow(aud, flow, NULL);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
273 AuCloseServer(aud);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
274 aud = 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
275 free(client_buffer);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
276 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
277
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
278 // stop playing and empty buffers (for seeking/pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
279 static void reset(){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
280 pthread_mutex_lock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
281 client_buffer_used = 0;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
282 pthread_mutex_unlock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
283 while (server_buffer_used > 0) {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
284 usleep(1000);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
285 // DPRINTF("used=%d\n", server_buffer_used);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
286 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
287 }
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 // stop playing, keep buffers (for pause)
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
290 static void audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
291 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
292 // for now, just call reset();
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
293 reset();
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
294 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
295
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
296 // resume playing, after audio_pause()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
297 static void audio_resume()
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 // return: how many bytes can be played without blocking
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
302 static int get_space()
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
303 {
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
304 int result;
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 pthread_mutex_lock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
307 result = client_buffer_size - client_buffer_used;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
308 pthread_mutex_unlock(&buffer_mutex);
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 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
311 }
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
312
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
313 // plays 'len' bytes of 'data'
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
314 // it should round it down to outburst*n
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
315 // return: number of bytes played
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
316 static int play(void* data,int len,int flags){
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
317 writeBuffer(data, len);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
318 // printf("ao_nas: wrote %d bytes of audio data\n", len);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
319 return len;
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
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
322 // 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
323 static float get_delay()
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 float result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
326
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
327 pthread_mutex_lock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
328 result = ((float)(client_buffer_used + server_buffer_used)) /
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
329 (float)ao_data.bps;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
330 pthread_mutex_unlock(&buffer_mutex);
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
331
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
332 return result;
e279cc05f189 -ao NAS support by Tobias Diedrich <ranma@gmx.at>
arpi
parents:
diff changeset
333 }