static void* thread_loop(void* arg) { struct despotify_session* ds = arg; struct ds_pcm_data pcm; pthread_mutex_init(&thread_mutex, NULL); pthread_cond_init(&thread_cond, NULL); bool loop = true; while (loop) { switch (play_state) { case PAUSE: pthread_mutex_lock(&thread_mutex); log_append("thread_loop(): PAUSE, sleeping"); pthread_cond_wait(&thread_cond, &thread_mutex); log_append("thread_loop(): PAUSE, woke up"); pthread_mutex_unlock(&thread_mutex); break; case PLAY: { int rc = despotify_get_pcm(ds, &pcm); if (rc == 0) audio_play_pcm(audio_device, &pcm); else { log_append("despotify_get_pcm() failed"); //wrapper_wprintf(L"despotify_get_pcm() returned error %d\n", rc); } break; } case EXIT: loop = false; break; } } pthread_cond_destroy(&thread_cond); pthread_mutex_destroy(&thread_mutex); return NULL; }
static void refill_buffer(struct input_despotify *ctx) { /* Wait until there is data */ while (1) { int rc = despotify_get_pcm(ctx->session, &ctx->pcm); if (rc == 0 && ctx->pcm.len) { ctx->len_available = ctx->pcm.len; break; } if (ctx->eof == true) break; if (rc < 0) { g_debug("despotify_get_pcm error\n"); ctx->eof = true; break; } /* Wait a while until next iteration */ usleep(50 * 1000); } }