static AuBool event_handler(AuServer* aud, AuEvent* ev, AuEventHandlerRec* hnd) { WINE_WAVEOUT *wwo = hnd->data; switch (ev->type) { case AuEventTypeElementNotify: { AuElementNotifyEvent* event = (AuElementNotifyEvent *)ev; switch (event->kind) { case AuElementNotifyKindLowWater: wwo->freeBytes += event->num_bytes; if (wwo->writeBytes > 0) wwo->sendBytes += event->num_bytes; if (wwo->freeBytes && wwo->BufferUsed) nas_send_buffer(wwo); break; case AuElementNotifyKindState: TRACE("ev: kind %s state %s->%s reason %s numbytes %ld freeB %u\n", nas_elementnotify_kind(event->kind), nas_state(event->prev_state), nas_state(event->cur_state), nas_reason(event->reason), event->num_bytes, wwo->freeBytes); if (event->cur_state == AuStatePause && event->reason != AuReasonUser) { wwo->freeBytes += event->num_bytes; if (wwo->writeBytes > 0) wwo->sendBytes += event->num_bytes; if (wwo->sendBytes > wwo->writeBytes) wwo->sendBytes = wwo->writeBytes; if (wwo->freeBytes && wwo->BufferUsed) nas_send_buffer(wwo); } break; } } } return AuTrue; }
static AuBool nas_event_handler(AuServer *aud, AuEvent *ev, AuEventHandlerRec *hnd) { AuElementNotifyEvent *event = (AuElementNotifyEvent*)ev; audio_job_t aj = hnd->data; snsd_t *snsd = audio_job_device_data(aj); NAS_DEBUG_EV("event_handler(): " "type %s kind %s state %s->%s reason %s " "numbytes %u\n", nas_event_type(event->type), nas_elementnotify_kind(event->kind), nas_state(event->prev_state), nas_state(event->cur_state), nas_reason(event->reason), (uint32_t)event->num_bytes); if (event->num_bytes > INT_MAX) { NAS_CRITICAL("num_bytes > 2GB, server buggy?\n"); } switch (event->reason) { case AuReasonWatermark: nas_read(aj, event->num_bytes); break; case AuReasonUnderrun: /* buffer underrun -> refill buffer */ if (nas_read(aj, event->num_bytes) != 0) { event->cur_state = AuStateStart; NAS_DEBUG_EV("restarting\n"); break; } NAS_DEBUG_S("Can't refill buffer, stopping flow.\n"); AuStopFlow(aud, snsd->flow, NULL); aj->play_state = MTPSTATE_STOP; break; default: break; } return AuTrue; }