mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Properly implemented play/pause semantics in output plugins (only WaveOut
was doing it properly!)
This commit is contained in:
parent
a6372b3c92
commit
5cd3a8de10
@ -79,6 +79,7 @@ AlsaOut::AlsaOut()
|
||||
, rate(44100)
|
||||
, volume(1.0)
|
||||
, quit(false)
|
||||
, paused(false)
|
||||
, initialized(false) {
|
||||
std::cerr << "AlsaOut::AlsaOut() called" << std::endl;
|
||||
this->writeThread.reset(new boost::thread(boost::bind(&AlsaOut::WriteLoop, this)));
|
||||
@ -198,6 +199,7 @@ void AlsaOut::Pause() {
|
||||
|
||||
if (this->pcmHandle) {
|
||||
snd_pcm_pause(this->pcmHandle, 1);
|
||||
this->paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +208,7 @@ void AlsaOut::Resume() {
|
||||
|
||||
if (this->pcmHandle) {
|
||||
snd_pcm_pause(this->pcmHandle, 0);
|
||||
this->paused = false;
|
||||
NOTIFY();
|
||||
}
|
||||
}
|
||||
@ -282,6 +285,10 @@ bool AlsaOut::Play(IBuffer *buffer, IBufferProvider* provider) {
|
||||
{
|
||||
LOCK("play");
|
||||
|
||||
if (this->paused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->CountBuffersWithProvider(provider) >= BUFFER_COUNT) {
|
||||
return false;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class AlsaOut : public musik::core::sdk::IOutput {
|
||||
size_t channels;
|
||||
size_t rate;
|
||||
double volume;
|
||||
volatile bool quit, initialized;
|
||||
volatile bool quit, paused, initialized;
|
||||
|
||||
std::unique_ptr<boost::thread> writeThread;
|
||||
boost::recursive_mutex stateMutex;
|
||||
|
@ -91,6 +91,7 @@ void CoreAudioOut::NotifyBufferCompleted(BufferContext *context) {
|
||||
|
||||
CoreAudioOut::CoreAudioOut() {
|
||||
this->quit = false;
|
||||
this->paused = false;
|
||||
this->volume = 1.0f;
|
||||
|
||||
this->audioFormat = (AudioStreamBasicDescription) { 0 };
|
||||
@ -113,6 +114,10 @@ CoreAudioOut::CoreAudioOut() {
|
||||
bool CoreAudioOut::Play(IBuffer *buffer, IBufferProvider *provider) {
|
||||
boost::recursive_mutex::scoped_lock lock(this->mutex);
|
||||
|
||||
if (this->paused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (countBuffersWithProvider(this->buffers, provider) >= BUFFER_COUNT) {
|
||||
/* enough buffers are already in the queue. bail, we'll notify the
|
||||
caller when there's more data available */
|
||||
@ -206,6 +211,7 @@ void CoreAudioOut::Pause() {
|
||||
|
||||
if (this->audioQueue) {
|
||||
AudioQueuePause(this->audioQueue);
|
||||
this->paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,6 +220,7 @@ void CoreAudioOut::Resume() {
|
||||
|
||||
if (this->audioQueue) {
|
||||
AudioQueueStart(this->audioQueue, NULL);
|
||||
this->paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,4 +81,5 @@ class CoreAudioOut : public musik::core::sdk::IOutput {
|
||||
boost::thread thread;
|
||||
boost::recursive_mutex mutex;
|
||||
bool quit;
|
||||
bool paused;
|
||||
};
|
||||
|
@ -155,6 +155,10 @@ bool DirectSoundOut::Play(IBuffer *buffer, IBufferProvider *provider) {
|
||||
{
|
||||
Lock lock(this->stateMutex);
|
||||
|
||||
if (this->state == StatePaused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->Configure(buffer)) {
|
||||
this->Reset();
|
||||
return false;
|
||||
|
@ -144,6 +144,10 @@ bool PulseOut::Play(IBuffer *buffer, IBufferProvider* provider) {
|
||||
{
|
||||
Lock lock(this->stateMutex);
|
||||
|
||||
if (this->state == StatePaused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->OpenDevice(buffer);
|
||||
|
||||
if (!this->audioConnection || this->state != StatePlaying) {
|
||||
|
@ -122,6 +122,10 @@ bool WasapiOut::Play(IBuffer *buffer, IBufferProvider *provider) {
|
||||
{
|
||||
Lock lock(this->stateMutex);
|
||||
|
||||
if (this->state == StatePaused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->Configure(buffer)) {
|
||||
this->Reset();
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user