void swd::storage::process_next() { boost::unique_lock<boost::mutex> consumer_lock(consumer_mutex_); while (!stop_) { /* Wait for a new request in the queue. */ while (1) { /* Do not wait if there are still elements in the queue. */ { boost::unique_lock<boost::mutex> queue_lock(queue_mutex_); if (!queue_.empty()) { break; } } cond_.wait(consumer_lock); } /* Move oldest element of queue to request. */ swd::request_ptr request; { boost::unique_lock<boost::mutex> queue_lock(queue_mutex_); request = queue_.front(); queue_.pop(); } /* Saving is the time-consuming part, do outside of mutex. */ this->save(request); } }
void player_set_soft_volume(int l, int r) { consumer_lock(); soft_vol_l = l; soft_vol_r = r; consumer_unlock(); }
void player_set_soft_vol(int soft) { consumer_lock(); /* don't mess with scale_pos if soft_vol or replaygain is already enabled */ if (!soft_vol && !replaygain) scale_pos = consumer_pos; soft_vol = soft; consumer_unlock(); }
static void *consumer_loop(void *arg) { while (1) { int rc, space; int size; char *rpos; consumer_lock(); if (!consumer_running) break; if (consumer_status == CS_PAUSED || consumer_status == CS_STOPPED) { pthread_cond_wait(&consumer_playing, &consumer_mutex); consumer_unlock(); continue; } space = op_buffer_space(); if (space < 0) { d_print("op_buffer_space returned %d %s\n", space, space == -1 ? strerror(errno) : ""); /* try to reopen */ op_close(); __consumer_status_update(CS_STOPPED); __consumer_play(); consumer_unlock(); continue; } /* d_print("BS: %6d %3d\n", space, space * 1000 / (44100 * 2 * 2)); */ while (1) { if (space == 0) { __consumer_position_update(); consumer_unlock(); ms_sleep(25); break; } size = buffer_get_rpos(&rpos); if (size == 0) { producer_lock(); if (producer_status != PS_PLAYING) { producer_unlock(); consumer_unlock(); break; } /* must recheck rpos */ size = buffer_get_rpos(&rpos); if (size == 0) { /* OK. now it's safe to check if we are at EOF */ if (ip_eof(ip)) { /* EOF */ __consumer_handle_eof(); producer_unlock(); consumer_unlock(); break; } else { /* possible underrun */ producer_unlock(); __consumer_position_update(); consumer_unlock(); /* d_print("possible underrun\n"); */ ms_sleep(10); break; } } /* player_buffer and ip.eof were inconsistent */ producer_unlock(); } if (size > space) size = space; if (soft_vol || replaygain) scale_samples(rpos, (unsigned int *)&size); rc = op_write(rpos, size); if (rc < 0) { d_print("op_write returned %d %s\n", rc, rc == -1 ? strerror(errno) : ""); /* try to reopen */ op_close(); __consumer_status_update(CS_STOPPED); __consumer_play(); consumer_unlock(); break; } buffer_consume(rc); consumer_pos += rc; space -= rc; } } __consumer_stop(); consumer_unlock(); return NULL; }