diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 07:10:58 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 07:10:58 +0000 |
commit | 7ac673b55f9c2334d531c280f907e2d0edaed68b (patch) | |
tree | 1dbb373bcfb3cd61836fe17a3f1807f7aaf36ec5 /ppapi/examples | |
parent | 88f11549025ad46da215d208a016387619d7271d (diff) | |
download | chromium_src-7ac673b55f9c2334d531c280f907e2d0edaed68b.zip chromium_src-7ac673b55f9c2334d531c280f907e2d0edaed68b.tar.gz chromium_src-7ac673b55f9c2334d531c280f907e2d0edaed68b.tar.bz2 |
Change the cpp wrappers of audio input/video capture to use CompletionCallbackWithOutput.
And also fix a few bugs in the PP_ArrayOutput and CallbackWithOutput code.
- Make sure POD members of Dispatcher\.* are properly initialized.
- Avoid leaking var/resource references in DispatcherWithOutput\.*::operator().
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/9965080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130849 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples')
-rw-r--r-- | ppapi/examples/audio_input/audio_input.cc | 11 | ||||
-rw-r--r-- | ppapi/examples/video_capture/video_capture.cc | 15 |
2 files changed, 17 insertions, 9 deletions
diff --git a/ppapi/examples/audio_input/audio_input.cc b/ppapi/examples/audio_input/audio_input.cc index 7d156b7..62bf299 100644 --- a/ppapi/examples/audio_input/audio_input.cc +++ b/ppapi/examples/audio_input/audio_input.cc @@ -93,9 +93,10 @@ class MyInstance : public pp::Instance { if (message_data.is_string()) { std::string event = message_data.AsString(); if (event == "PageInitialized") { - pp::CompletionCallback callback = callback_factory_.NewCallback( - &MyInstance::EnumerateDevicesFinished); - int32_t result = audio_input_.EnumerateDevices(&devices_, callback); + pp::CompletionCallbackWithOutput<std::vector<pp::DeviceRef_Dev> > + callback = callback_factory_.NewCallbackWithOutput( + &MyInstance::EnumerateDevicesFinished); + int32_t result = audio_input_.EnumerateDevices(callback); if (result != PP_OK_COMPLETIONPENDING) PostMessage(pp::Var("EnumerationFailed")); } else if (event == "UseDefault") { @@ -241,10 +242,12 @@ class MyInstance : public pp::Instance { } } - void EnumerateDevicesFinished(int32_t result) { + void EnumerateDevicesFinished(int32_t result, + std::vector<pp::DeviceRef_Dev>& devices) { static const char* const kDelimiter = "#__#"; if (result == PP_OK) { + devices_.swap(devices); std::string device_names; for (size_t index = 0; index < devices_.size(); ++index) { pp::Var name = devices_[index].GetName(); diff --git a/ppapi/examples/video_capture/video_capture.cc b/ppapi/examples/video_capture/video_capture.cc index 20c0c75..07239c6 100644 --- a/ppapi/examples/video_capture/video_capture.cc +++ b/ppapi/examples/video_capture/video_capture.cc @@ -118,7 +118,8 @@ class VCDemoInstance : public pp::Instance, void CreateYUVTextures(); void Open(const pp::DeviceRef_Dev& device); - void EnumerateDevicesFinished(int32_t result); + void EnumerateDevicesFinished(int32_t result, + std::vector<pp::DeviceRef_Dev>& devices); void OpenFinished(int32_t result); pp::Size position_size_; @@ -185,9 +186,10 @@ void VCDemoInstance::HandleMessage(const pp::Var& message_data) { if (message_data.is_string()) { std::string event = message_data.AsString(); if (event == "PageInitialized") { - pp::CompletionCallback callback = callback_factory_.NewCallback( - &VCDemoInstance::EnumerateDevicesFinished); - video_capture_.EnumerateDevices(&devices_, callback); + pp::CompletionCallbackWithOutput<std::vector<pp::DeviceRef_Dev> > + callback = callback_factory_.NewCallbackWithOutput( + &VCDemoInstance::EnumerateDevicesFinished); + video_capture_.EnumerateDevices(callback); } else if (event == "UseDefault") { Open(pp::DeviceRef_Dev()); } else if (event == "UseDefault(v0.1)") { @@ -403,10 +405,13 @@ void VCDemoInstance::Open(const pp::DeviceRef_Dev& device) { video_capture_.Open(device, capture_info_, 4, callback); } -void VCDemoInstance::EnumerateDevicesFinished(int32_t result) { +void VCDemoInstance::EnumerateDevicesFinished( + int32_t result, + std::vector<pp::DeviceRef_Dev>& devices) { static const char* const kDelimiter = "#__#"; if (result == PP_OK) { + devices_.swap(devices); std::string device_names; for (size_t index = 0; index < devices_.size(); ++index) { pp::Var name = devices_[index].GetName(); |