OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <assert.h> | 5 #include <assert.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 // GL-related functions. | 112 // GL-related functions. |
113 void InitGL(); | 113 void InitGL(); |
114 GLuint CreateTexture(int32_t width, int32_t height, int unit); | 114 GLuint CreateTexture(int32_t width, int32_t height, int unit); |
115 void CreateGLObjects(); | 115 void CreateGLObjects(); |
116 void CreateShader(GLuint program, GLenum type, const char* source, int size); | 116 void CreateShader(GLuint program, GLenum type, const char* source, int size); |
117 void PaintFinished(int32_t result); | 117 void PaintFinished(int32_t result); |
118 void CreateYUVTextures(); | 118 void CreateYUVTextures(); |
119 | 119 |
120 void Open(const pp::DeviceRef_Dev& device); | 120 void Open(const pp::DeviceRef_Dev& device); |
121 void EnumerateDevicesFinished(int32_t result); | 121 void EnumerateDevicesFinished(int32_t result, |
| 122 std::vector<pp::DeviceRef_Dev>& devices); |
122 void OpenFinished(int32_t result); | 123 void OpenFinished(int32_t result); |
123 | 124 |
124 pp::Size position_size_; | 125 pp::Size position_size_; |
125 bool is_painting_; | 126 bool is_painting_; |
126 bool needs_paint_; | 127 bool needs_paint_; |
127 GLuint texture_y_; | 128 GLuint texture_y_; |
128 GLuint texture_u_; | 129 GLuint texture_u_; |
129 GLuint texture_v_; | 130 GLuint texture_v_; |
130 pp::VideoCapture_Dev video_capture_; | 131 pp::VideoCapture_Dev video_capture_; |
131 PP_VideoCaptureDeviceInfo_Dev capture_info_; | 132 PP_VideoCaptureDeviceInfo_Dev capture_info_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // Initialize graphics. | 179 // Initialize graphics. |
179 InitGL(); | 180 InitGL(); |
180 | 181 |
181 Render(); | 182 Render(); |
182 } | 183 } |
183 | 184 |
184 void VCDemoInstance::HandleMessage(const pp::Var& message_data) { | 185 void VCDemoInstance::HandleMessage(const pp::Var& message_data) { |
185 if (message_data.is_string()) { | 186 if (message_data.is_string()) { |
186 std::string event = message_data.AsString(); | 187 std::string event = message_data.AsString(); |
187 if (event == "PageInitialized") { | 188 if (event == "PageInitialized") { |
188 pp::CompletionCallback callback = callback_factory_.NewCallback( | 189 pp::CompletionCallbackWithOutput<std::vector<pp::DeviceRef_Dev> > |
189 &VCDemoInstance::EnumerateDevicesFinished); | 190 callback = callback_factory_.NewCallbackWithOutput( |
190 video_capture_.EnumerateDevices(&devices_, callback); | 191 &VCDemoInstance::EnumerateDevicesFinished); |
| 192 video_capture_.EnumerateDevices(callback); |
191 } else if (event == "UseDefault") { | 193 } else if (event == "UseDefault") { |
192 Open(pp::DeviceRef_Dev()); | 194 Open(pp::DeviceRef_Dev()); |
193 } else if (event == "UseDefault(v0.1)") { | 195 } else if (event == "UseDefault(v0.1)") { |
194 const PPB_VideoCapture_Dev_0_1* video_capture_0_1 = | 196 const PPB_VideoCapture_Dev_0_1* video_capture_0_1 = |
195 static_cast<const PPB_VideoCapture_Dev_0_1*>( | 197 static_cast<const PPB_VideoCapture_Dev_0_1*>( |
196 pp::Module::Get()->GetBrowserInterface( | 198 pp::Module::Get()->GetBrowserInterface( |
197 PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1)); | 199 PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1)); |
198 video_capture_0_1->StartCapture(video_capture_.pp_resource(), | 200 video_capture_0_1->StartCapture(video_capture_.pp_resource(), |
199 &capture_info_, 4); | 201 &capture_info_, 4); |
200 } else if (event == "Stop") { | 202 } else if (event == "Stop") { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 texture_u_ = CreateTexture(width, height, 1); | 398 texture_u_ = CreateTexture(width, height, 1); |
397 texture_v_ = CreateTexture(width, height, 2); | 399 texture_v_ = CreateTexture(width, height, 2); |
398 } | 400 } |
399 | 401 |
400 void VCDemoInstance::Open(const pp::DeviceRef_Dev& device) { | 402 void VCDemoInstance::Open(const pp::DeviceRef_Dev& device) { |
401 pp::CompletionCallback callback = callback_factory_.NewCallback( | 403 pp::CompletionCallback callback = callback_factory_.NewCallback( |
402 &VCDemoInstance::OpenFinished); | 404 &VCDemoInstance::OpenFinished); |
403 video_capture_.Open(device, capture_info_, 4, callback); | 405 video_capture_.Open(device, capture_info_, 4, callback); |
404 } | 406 } |
405 | 407 |
406 void VCDemoInstance::EnumerateDevicesFinished(int32_t result) { | 408 void VCDemoInstance::EnumerateDevicesFinished( |
| 409 int32_t result, |
| 410 std::vector<pp::DeviceRef_Dev>& devices) { |
407 static const char* const kDelimiter = "#__#"; | 411 static const char* const kDelimiter = "#__#"; |
408 | 412 |
409 if (result == PP_OK) { | 413 if (result == PP_OK) { |
| 414 devices_.swap(devices); |
410 std::string device_names; | 415 std::string device_names; |
411 for (size_t index = 0; index < devices_.size(); ++index) { | 416 for (size_t index = 0; index < devices_.size(); ++index) { |
412 pp::Var name = devices_[index].GetName(); | 417 pp::Var name = devices_[index].GetName(); |
413 assert(name.is_string()); | 418 assert(name.is_string()); |
414 | 419 |
415 if (index != 0) | 420 if (index != 0) |
416 device_names += kDelimiter; | 421 device_names += kDelimiter; |
417 device_names += name.AsString(); | 422 device_names += name.AsString(); |
418 } | 423 } |
419 PostMessage(pp::Var(device_names)); | 424 PostMessage(pp::Var(device_names)); |
(...skipping 15 matching lines...) Expand all Loading... |
435 } | 440 } |
436 | 441 |
437 } // anonymous namespace | 442 } // anonymous namespace |
438 | 443 |
439 namespace pp { | 444 namespace pp { |
440 // Factory function for your specialization of the Module object. | 445 // Factory function for your specialization of the Module object. |
441 Module* CreateModule() { | 446 Module* CreateModule() { |
442 return new VCDemoModule(); | 447 return new VCDemoModule(); |
443 } | 448 } |
444 } // namespace pp | 449 } // namespace pp |
OLD | NEW |