diff options
author | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 17:37:35 +0000 |
---|---|---|
committer | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 17:37:35 +0000 |
commit | b0deb15a7c1769f0a9814e7ec64975b68c016638 (patch) | |
tree | ac9cfdbad7f996701dc0c6e9efcee0f4f91b2607 | |
parent | e2c6ef63f7a8f4b49b689099e92004ea27c268c0 (diff) | |
download | chromium_src-b0deb15a7c1769f0a9814e7ec64975b68c016638.zip chromium_src-b0deb15a7c1769f0a9814e7ec64975b68c016638.tar.gz chromium_src-b0deb15a7c1769f0a9814e7ec64975b68c016638.tar.bz2 |
Guarantee PPAPI Audio playbacks are stopped in Pause().
BUG=none
TEST=pepper audio demo is playing audio
Review URL: http://codereview.chromium.org/3142005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58014 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/audio/audio_output_controller.cc | 7 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_audio.cc | 42 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_audio.h | 13 |
3 files changed, 51 insertions, 11 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index 27938f9..45ad62c 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -13,6 +13,8 @@ static const uint32 kMaxHardwareBufferSize = 2 * kMegabytes; static const int kMaxChannels = 32; static const int kMaxBitsPerSample = 64; static const int kMaxSampleRate = 192000; +// Signal a pause in low-latency mode. +static const int kPauseMark = -1; // Return true if the parameters for creating an audio stream is valid. // Return false otherwise. @@ -239,6 +241,11 @@ void AudioOutputController::DoPause() { // TODO(hclam): Actually pause the audio device. stream_->Stop(); + if (LowLatencyMode()) { + // Send a special pause mark to the low-latency audio thread. + sync_reader_->UpdatePendingBytes(kPauseMark); + } + handler_->OnPaused(this); } diff --git a/webkit/glue/plugins/pepper_audio.cc b/webkit/glue/plugins/pepper_audio.cc index 98edb22..3babc2f 100644 --- a/webkit/glue/plugins/pepper_audio.cc +++ b/webkit/glue/plugins/pepper_audio.cc @@ -113,6 +113,7 @@ AudioConfig* AudioConfig::AsAudioConfig() { Audio::Audio(PluginModule* module) : Resource(module), + playing_(false), socket_(NULL), shared_memory_(NULL), shared_memory_size_(0), @@ -160,6 +161,35 @@ bool Audio::Init(PluginDelegate* plugin_delegate, PP_Resource config_id, return audio_.get() != NULL; } +bool Audio::StartPlayback() { + if (playing_) + return true; + + CHECK(!audio_thread_.get()); + if (callback_ && socket_.get()) { + audio_thread_.reset(new base::DelegateSimpleThread(this, + "plugin_audio_thread")); + audio_thread_->Start(); + } + playing_ = true; + return audio_->StartPlayback(); +} + +bool Audio::StopPlayback() { + if (!playing_) + return true; + + if (!audio_->StopPlayback()) + return false; + + if (audio_thread_.get()) { + audio_thread_->Join(); + audio_thread_.reset(); + } + playing_ = false; + return true; +} + void Audio::StreamCreated(base::SharedMemoryHandle shared_memory_handle, size_t shared_memory_size, base::SyncSocket::Handle socket_handle) { @@ -169,9 +199,12 @@ void Audio::StreamCreated(base::SharedMemoryHandle shared_memory_handle, if (callback_) { shared_memory_->Map(shared_memory_size_); - audio_thread_.reset(new base::DelegateSimpleThread(this, - "plugin_audio_thread")); - audio_thread_->Start(); + // In common case StartPlayback() was called before StreamCreated(). + if (playing_) { + audio_thread_.reset(new base::DelegateSimpleThread(this, + "plugin_audio_thread")); + audio_thread_->Start(); + } } } @@ -182,6 +215,9 @@ void Audio::Run() { while (sizeof(pending_data) == socket_->Receive(&pending_data, sizeof(pending_data)) && pending_data >= 0) { + // Exit the thread on pause. + if (pending_data < 0) + return; callback_(buffer, user_data_); } } diff --git a/webkit/glue/plugins/pepper_audio.h b/webkit/glue/plugins/pepper_audio.h index d6a175b..d9a9e86 100644 --- a/webkit/glue/plugins/pepper_audio.h +++ b/webkit/glue/plugins/pepper_audio.h @@ -58,15 +58,9 @@ class Audio : public Resource, return config_->GetReference(); } - bool StartPlayback() { - // TODO(neb): Make this synchronous. - return audio_->StartPlayback(); - } + bool StartPlayback(); - bool StopPlayback() { - // TODO(neb): Make this synchronous. - return audio_->StopPlayback(); - } + bool StopPlayback(); // Resource override. virtual Audio* AsAudio(); @@ -82,6 +76,9 @@ class Audio : public Resource, virtual void Run(); // End of DelegateSimpleThread::Delegate implementation. + // True if playing the stream. + bool playing_; + // AudioConfig used for creating this Audio object. scoped_refptr<AudioConfig> config_; |