diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 23:43:57 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 23:43:57 +0000 |
commit | 38244d9bed99ff00c33235a27b80b28368c21cf3 (patch) | |
tree | b68e34ac9121cf548f384391fd8a303d5f2819fb /ppapi | |
parent | 72bbaccaa082a3ad6fff9bbc1cf70d01dabd79e8 (diff) | |
download | chromium_src-38244d9bed99ff00c33235a27b80b28368c21cf3.zip chromium_src-38244d9bed99ff00c33235a27b80b28368c21cf3.tar.gz chromium_src-38244d9bed99ff00c33235a27b80b28368c21cf3.tar.bz2 |
PepperPlatformAudioInputImpl: support audio input device selection.
BUG=None
TEST=ppapi/examples/audio_input
Review URL: http://codereview.chromium.org/9705056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/examples/audio_input/audio_input.cc | 12 | ||||
-rw-r--r-- | ppapi/examples/audio_input/audio_input.html | 15 | ||||
-rw-r--r-- | ppapi/shared_impl/ppb_audio_input_shared.cc | 37 |
3 files changed, 47 insertions, 17 deletions
diff --git a/ppapi/examples/audio_input/audio_input.cc b/ppapi/examples/audio_input/audio_input.cc index 7aff669..7d156b7 100644 --- a/ppapi/examples/audio_input/audio_input.cc +++ b/ppapi/examples/audio_input/audio_input.cc @@ -114,6 +114,8 @@ class MyInstance : public pp::Instance { audio_input_ = pp::AudioInput_Dev(); } else if (event == "Stop") { Stop(); + } else if (event == "Start") { + Start(); } } else if (message_data.is_number()) { int index = message_data.AsInt(); @@ -229,6 +231,16 @@ class MyInstance : public pp::Instance { } } + void Start() { + if (!audio_input_.is_null()) { + if (!audio_input_.StartCapture()) + PostMessage(pp::Var("StartFailed")); + } else if (audio_input_0_1_ != 0) { + if (!audio_input_interface_0_1_->StartCapture(audio_input_0_1_)) + PostMessage(pp::Var("StartFailed")); + } + } + void EnumerateDevicesFinished(int32_t result) { static const char* const kDelimiter = "#__#"; diff --git a/ppapi/examples/audio_input/audio_input.html b/ppapi/examples/audio_input/audio_input.html index a5256fa..34255f2 100644 --- a/ppapi/examples/audio_input/audio_input.html +++ b/ppapi/examples/audio_input/audio_input.html @@ -57,10 +57,7 @@ available_devices.parentNode.removeChild(available_devices); var control_panel = document.getElementById('control_panel'); - var link = document.createElement('a'); - link.href = 'javascript:Stop();'; - link.innerText = 'Stop'; - control_panel.appendChild(link); + control_panel.style.display = 'block'; } function Stop() { @@ -68,6 +65,11 @@ plugin.postMessage('Stop'); } + function Start() { + var plugin = document.getElementById('plugin'); + plugin.postMessage('Start'); + } + function Initialize() { var plugin = document.getElementById('plugin'); plugin.addEventListener('message', HandleMessage, false); @@ -93,7 +95,10 @@ Default - use interface version 0.2 and NULL device ref</a></li> </ul> </div> - <div id="control_panel"></div> + <div id="control_panel" style="display:none"> + <a href="javascript:Stop();">Stop</a> + <a href="javascript:Start();">Start</a> + </div> <div id="status"></div> </body> </html> diff --git a/ppapi/shared_impl/ppb_audio_input_shared.cc b/ppapi/shared_impl/ppb_audio_input_shared.cc index 3028894..9af25a9 100644 --- a/ppapi/shared_impl/ppb_audio_input_shared.cc +++ b/ppapi/shared_impl/ppb_audio_input_shared.cc @@ -91,17 +91,30 @@ PP_Bool PPB_AudioInput_Shared::StartCapture() { if (capturing_) return PP_TRUE; + // If the audio input device hasn't been opened, set |capturing_| to true and + // return directly. Capturing will be started once the open operation is + // completed. + if (open_state_ == BEFORE_OPEN) { + capturing_ = true; + return PP_TRUE; + } + return InternalStartCapture(); } PP_Bool PPB_AudioInput_Shared::StopCapture() { - if (open_state_ == CLOSED || (open_state_ == BEFORE_OPEN && - !TrackedCallback::IsPending(open_callback_))) { + if (open_state_ == CLOSED) return PP_FALSE; - } if (!capturing_) return PP_TRUE; + // If the audio input device hasn't been opened, set |capturing_| to false and + // return directly. + if (open_state_ == BEFORE_OPEN) { + capturing_ = false; + return PP_TRUE; + } + return InternalStopCapture(); } @@ -150,6 +163,7 @@ void PPB_AudioInput_Shared::OnOpenComplete( // Clean up the handles. base::SyncSocket temp_socket(socket_handle); base::SharedMemory temp_mem(shared_memory_handle, false); + capturing_ = false; } // The callback may have been aborted by Close(). @@ -166,11 +180,6 @@ void PPB_AudioInput_Shared::SetStartCaptureState() { DCHECK(!capturing_); DCHECK(!audio_input_thread_.get()); - // If the socket doesn't exist, that means that the plugin has started before - // the browser has had a chance to create all the shared memory info and - // notify us. This is a common case. In this case, we just set the capturing_ - // flag and the capture will automatically start when that data is available - // in SetStreamInfo. if (audio_input_callback_ && socket_.get()) StartThread(); capturing_ = true; @@ -194,12 +203,16 @@ void PPB_AudioInput_Shared::SetStreamInfo( shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false)); shared_memory_size_ = shared_memory_size; - if (audio_input_callback_) { + if (audio_input_callback_) shared_memory_->Map(shared_memory_size_); - // StartCapture() may be called before SetSreamInfo(). - if (capturing_) - StartThread(); + // There is a pending capture request before SetStreamInfo(). + if (capturing_) { + // Set |capturing_| to false so that the state looks consistent to + // InternalStartCapture(). It will be reset to true by + // SetStartCaptureState(). + capturing_ = false; + InternalStartCapture(); } } |