if (amount == 0) {
amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index)); memcpy(buf, &s->buffer[s->output_index], amount); s->output_index += amount; if (s->output_index >= AUDIO_BUFFER_SIZE) { s->output_index %= AUDIO_BUFFER_SIZE; memcpy(buf + amount, &s->buffer[s->output_index], len - amount); s->output_index += len-amount; s->output_index %= AUDIO_BUFFER_SIZE; } release_sem_etc(s->input_sem, len, 0); #else len = read(s->pipefd, buf, bufferSize); #endif #ifdef PERF_CHECK t = system_time() - t; s->starve_time = MAX(s->starve_time, t); #endif #ifndef USE_RING_BUFFER if (len < B_OK) { puts("EPIPE"); s->player->SetHasData(false);
static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format){    AudioData *s;    size_t amount;    unsigned char *buf = (unsigned char *)buffer;    s = (AudioData *)cookie;    if (s->has_quit)        return;    while (bufferSize > 0) {        if ((amount = read(s->pipefd, buf, bufferSize)) < B_OK) {            puts("EPIPE");            snooze(100000);            s->player->SetHasData(false);            return;        }        if (amount == 0) {            snooze(100000);            s->player->SetHasData(false);            return;        }        buf += amount;        bufferSize -= amount;    }}