|
a/src/httpgate.cpp |
|
b/src/httpgate.cpp |
|
... |
|
... |
287 |
}
|
287 |
}
|
288 |
#endif
|
288 |
#endif
|
289 |
return MHD_YES;
|
289 |
return MHD_YES;
|
290 |
}
|
290 |
}
|
291 |
|
291 |
|
|
|
292 |
|
292 |
void *audioEater(void *cls)
|
293 |
static void *audioEater(void *cls)
|
293 |
{
|
294 |
{
|
294 |
AudioEaterContext *ctxt = (AudioEaterContext*)cls;
|
295 |
AudioEater::Context *ctxt = (AudioEater::Context*)cls;
|
295 |
LOGDEB("Using port " << ctxt->port << " for HTTP" << endl);
|
296 |
|
|
|
297 |
LOGDEB("audioEater: queue " << ctxt->queue << " HTTP port " << ctxt->port
|
|
|
298 |
<< endl);
|
|
|
299 |
|
296 |
struct MHD_Daemon *daemon =
|
300 |
struct MHD_Daemon *daemon =
|
297 |
MHD_start_daemon(
|
301 |
MHD_start_daemon(
|
298 |
MHD_USE_THREAD_PER_CONNECTION,
|
302 |
MHD_USE_THREAD_PER_CONNECTION,
|
299 |
//MHD_USE_SELECT_INTERNALLY,
|
303 |
//MHD_USE_SELECT_INTERNALLY,
|
300 |
ctxt->port,
|
304 |
ctxt->port,
|
|
... |
|
... |
302 |
accept_policy, NULL,
|
306 |
accept_policy, NULL,
|
303 |
/* handler and arg */
|
307 |
/* handler and arg */
|
304 |
&answer_to_connection, NULL,
|
308 |
&answer_to_connection, NULL,
|
305 |
MHD_OPTION_END);
|
309 |
MHD_OPTION_END);
|
306 |
if (NULL == daemon) {
|
310 |
if (NULL == daemon) {
|
307 |
audioqueue.workerExit();
|
311 |
ctxt->queue->workerExit();
|
308 |
return (void *)0;
|
312 |
return (void *)0;
|
309 |
}
|
313 |
}
|
|
|
314 |
|
|
|
315 |
WorkQueue<AudioMessage*> *queue = ctxt->queue;
|
310 |
delete ctxt;
|
316 |
delete ctxt;
|
311 |
while (true) {
|
317 |
while (true) {
|
312 |
AudioMessage *tsk = 0;
|
318 |
AudioMessage *tsk = 0;
|
313 |
size_t qsz;
|
319 |
size_t qsz;
|
314 |
if (!audioqueue.take(&tsk, &qsz)) {
|
320 |
if (!queue->take(&tsk, &qsz)) {
|
315 |
MHD_stop_daemon (daemon);
|
321 |
MHD_stop_daemon (daemon);
|
316 |
audioqueue.workerExit();
|
322 |
queue->workerExit();
|
317 |
return (void*)1;
|
323 |
return (void*)1;
|
318 |
}
|
324 |
}
|
319 |
PTMutexLocker lock(dataqueueLock);
|
325 |
PTMutexLocker lock(dataqueueLock);
|
|
|
326 |
|
320 |
/* limit size of queuing. If there is a client but it is not
|
327 |
/* limit size of queuing. If there is a client but it is not
|
321 |
eating blocks fast enough, there will be audio pops */
|
328 |
eating blocks fast enough, there will be skips */
|
322 |
while (dataqueue.size() > 2) {
|
329 |
while (dataqueue.size() > 2) {
|
323 |
LOGDEB("audioEater: discarding buffer !" << endl);
|
330 |
LOGDEB("audioEater: discarding buffer !" << endl);
|
324 |
delete dataqueue.front();
|
331 |
delete dataqueue.front();
|
325 |
dataqueue.pop();
|
332 |
dataqueue.pop();
|
326 |
}
|
333 |
}
|
|
|
334 |
|
327 |
dataqueue.push(tsk);
|
335 |
dataqueue.push(tsk);
|
328 |
pthread_cond_broadcast(&dataqueueWaitCond);
|
336 |
pthread_cond_broadcast(&dataqueueWaitCond);
|
|
|
337 |
pthread_yield();
|
329 |
}
|
338 |
}
|
330 |
}
|
339 |
}
|
|
|
340 |
|
|
|
341 |
AudioEater httpAudioEater(AudioEater::BO_LSB, &audioEater);
|