Skip to content

Commit

Permalink
Close audio output when stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
bebac committed Aug 19, 2017
1 parent b7e52d5 commit b3ab205
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/player/audio_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void audio_output::dispatch(message& m)
handle(m.open_req);
break;
case message::close_req_id:
handle(m.open_req);
handle(m.close_req);
break;
case message::stream_begin_id:
handle(m.stream_begin);
Expand Down
26 changes: 26 additions & 0 deletions source/player/player_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ namespace musciteer
session_->done();
session_.reset();

audio_output_close();

state_ = stopped;

player_state_notify();
Expand Down Expand Up @@ -686,4 +688,28 @@ namespace musciteer
return false;
}
}

bool player_task::audio_output_close()
{
message_channel ch;
message m(message::close_req_id);

m.close_req.reply = ch;

audio_output_->send(std::move(m));

auto r = ch.recv(this);

if ( r.open_res.error_code == 0 )
{
std::cout << "audio output " << audio_output_device_ << " closed ok" << std::endl;
return true;
}
else
{
std::cout << "audio output close response error_code=" << r.open_res.error_code << ", error_message=" << r.open_res.error_message << std::endl;
// TODO: Send some sort of notification.
return false;
}
}
}
1 change: 1 addition & 0 deletions source/player/player_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace musciteer
void audio_output_subscribe(message_channel&);
void audio_output_unsubscribe(message_channel&);
bool audio_output_open();
bool audio_output_close();
private:
state state_;
private:
Expand Down

0 comments on commit b3ab205

Please sign in to comment.