Fixed a crazy bug in Player.cpp that should have been crashing every time in Linux.

This commit is contained in:
casey 2016-06-06 21:11:06 -07:00
parent 301985a335
commit 85dca8aa10
2 changed files with 22 additions and 13 deletions

View File

@ -151,10 +151,13 @@ void Player::ThreadLoop() {
this->output->Stop(); /* flush all buffers */ this->output->Stop(); /* flush all buffers */
this->output->Resume(); /* start it back up */ this->output->Resume(); /* start it back up */
while (this->lockedBuffers.size() > 0) { {
boost::mutex::scoped_lock lock(this->mutex); boost::mutex::scoped_lock lock(this->mutex);
while (this->lockedBuffers.size() > 0) {
writeToOutputCondition.wait(this->mutex); writeToOutputCondition.wait(this->mutex);
} }
}
this->stream->SetPosition(this->setPosition); this->stream->SetPosition(this->setPosition);
@ -267,21 +270,25 @@ bool Player::Exited() {
void Player::OnBufferProcessed(IBuffer *buffer) { void Player::OnBufferProcessed(IBuffer *buffer) {
bool started = false; bool started = false;
bool found = false;
{ {
boost::mutex::scoped_lock lock(this->mutex); boost::mutex::scoped_lock lock(this->mutex);
/* removes the specified buffer from the list of locked buffers, and also /* removes the specified buffer from the list of locked buffers, and also
lets the stream know it can be recycled. */ lets the stream know it can be recycled. */
BufferList::iterator it = this->lockedBuffers.begin(); BufferList::iterator it = this->lockedBuffers.begin();
for ( ; it != this->lockedBuffers.end(); ++it) { while (it != this->lockedBuffers.end() && !found) {
if (it->get() == buffer) { if (it->get() == buffer) {
found = true;
if (this->stream) { if (this->stream) {
this->stream->OnBufferProcessedByPlayer(*it); this->stream->OnBufferProcessedByPlayer(*it);
} }
this->lockedBuffers.erase(it); it = this->lockedBuffers.erase(it);
/* this sets the current time in the stream. it does this by grabbing
the time at the next buffer in the queue */
if (!this->lockedBuffers.empty()) { if (!this->lockedBuffers.empty()) {
this->currentPosition = this->lockedBuffers.front()->Position(); this->currentPosition = this->lockedBuffers.front()->Position();
} }
@ -290,8 +297,9 @@ void Player::OnBufferProcessed(IBuffer *buffer) {
accepting new samples. now that a buffer has been processed, we can accepting new samples. now that a buffer has been processed, we can
try to enqueue another sample. the thread loop blocks on this condition */ try to enqueue another sample. the thread loop blocks on this condition */
this->writeToOutputCondition.notify_all(); this->writeToOutputCondition.notify_all();
}
it = this->lockedBuffers.end(); /* bail out of the loop */ else {
++it;
} }
} }

View File

@ -137,23 +137,24 @@ void CommandWindow::Help() {
int64 s = -1; int64 s = -1;
this->output->WriteLine("help:\n", s); this->output->WriteLine("help:\n", s);
this->output->WriteLine(" <tab> to switch between windows", s); this->output->WriteLine(" <tab> to switch between windows", s);
this->output->WriteLine(" <F1> console view", s); this->output->WriteLine(" ALT+Q console view", s);
this->output->WriteLine(" <F2> library view", s); this->output->WriteLine(" ALT+W library view", s);
this->output->WriteLine("\n", s); this->output->WriteLine("", s);
this->output->WriteLine(" addir <dir>: add a music directory", s); this->output->WriteLine(" addir <dir>: add a music directory", s);
this->output->WriteLine(" rmdir <dir>: remove a music directory", s); this->output->WriteLine(" rmdir <dir>: remove a music directory", s);
this->output->WriteLine(" lsdirs: list scanned directories", s); this->output->WriteLine(" lsdirs: list scanned directories", s);
this->output->WriteLine(" rescan: rescan paths for new metadata", s); this->output->WriteLine(" rescan: rescan paths for new metadata", s);
this->output->WriteLine("\n", s); this->output->WriteLine("", s);
this->output->WriteLine(" play <uri>: play audio at <uri>", s); this->output->WriteLine(" play <uri>: play audio at <uri>", s);
this->output->WriteLine(" pause: pause/resume", s); this->output->WriteLine(" pause: pause/resume", s);
this->output->WriteLine(" stop: stop and clean up everything", s); this->output->WriteLine(" stop: stop and clean up everything", s);
this->output->WriteLine(" volume: <0 - 100>: set % volume", s); this->output->WriteLine(" volume: <0 - 100>: set % volume", s);
this->output->WriteLine(" clear: clear the log window", s); this->output->WriteLine(" clear: clear the log window", s);
this->output->WriteLine(" seek <seconds>: seek to <seconds> into track", s); this->output->WriteLine(" seek <seconds>: seek to <seconds> into track", s);
this->output->WriteLine("\n", s); this->output->WriteLine("", s);
this->output->WriteLine(" plugins: list loaded plugins", s); this->output->WriteLine(" plugins: list loaded plugins", s);
this->output->WriteLine("\n <ctrl+d>: quit\n", s); this->output->WriteLine("", s);
this->output->WriteLine(" <ctrl+d>: quit\n", s);
} }
bool CommandWindow::ProcessCommand(const std::string& cmd) { bool CommandWindow::ProcessCommand(const std::string& cmd) {