| 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 "content/renderer/pepper/pepper_platform_video_capture_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_video_capture_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "content/renderer/media/video_capture_impl_manager.h" | 10 #include "content/renderer/media/video_capture_impl_manager.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 handler_(handler), | 26 handler_(handler), |
| 27 video_capture_(NULL), | 27 video_capture_(NULL), |
| 28 unbalanced_start_(false) { | 28 unbalanced_start_(false) { |
| 29 if (device_id.empty()) { | 29 if (device_id.empty()) { |
| 30 // "1" is the session ID for the default device. | 30 // "1" is the session ID for the default device. |
| 31 session_id_ = 1; | 31 session_id_ = 1; |
| 32 Initialize(); | 32 Initialize(); |
| 33 } else { | 33 } else { |
| 34 // We need to open the device and obtain the label and session ID before | 34 // We need to open the device and obtain the label and session ID before |
| 35 // initializing. | 35 // initializing. |
| 36 if (plugin_delegate_) { | 36 if (plugin_delegate_.get()) { |
| 37 plugin_delegate_->OpenDevice( | 37 plugin_delegate_->OpenDevice( |
| 38 PP_DEVICETYPE_DEV_VIDEOCAPTURE, device_id, | 38 PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
| 39 device_id, |
| 39 base::Bind(&PepperPlatformVideoCaptureImpl::OnDeviceOpened, this)); | 40 base::Bind(&PepperPlatformVideoCaptureImpl::OnDeviceOpened, this)); |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 void PepperPlatformVideoCaptureImpl::StartCapture( | 45 void PepperPlatformVideoCaptureImpl::StartCapture( |
| 45 media::VideoCapture::EventHandler* handler, | 46 media::VideoCapture::EventHandler* handler, |
| 46 const media::VideoCaptureCapability& capability) { | 47 const media::VideoCaptureCapability& capability) { |
| 47 DCHECK(handler == handler_); | 48 DCHECK(handler == handler_); |
| 48 | 49 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 handler_->OnDeviceInfoReceived(capture, device_info); | 144 handler_->OnDeviceInfoReceived(capture, device_info); |
| 144 } | 145 } |
| 145 | 146 |
| 146 PepperPlatformVideoCaptureImpl::~PepperPlatformVideoCaptureImpl() { | 147 PepperPlatformVideoCaptureImpl::~PepperPlatformVideoCaptureImpl() { |
| 147 if (video_capture_) { | 148 if (video_capture_) { |
| 148 VideoCaptureImplManager* manager = | 149 VideoCaptureImplManager* manager = |
| 149 RenderThreadImpl::current()->video_capture_impl_manager(); | 150 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 150 manager->RemoveDevice(session_id_, handler_proxy_.get()); | 151 manager->RemoveDevice(session_id_, handler_proxy_.get()); |
| 151 } | 152 } |
| 152 | 153 |
| 153 if (plugin_delegate_ && !label_.empty()) | 154 if (plugin_delegate_.get() && !label_.empty()) |
| 154 plugin_delegate_->CloseDevice(label_); | 155 plugin_delegate_->CloseDevice(label_); |
| 155 } | 156 } |
| 156 | 157 |
| 157 void PepperPlatformVideoCaptureImpl::Initialize() { | 158 void PepperPlatformVideoCaptureImpl::Initialize() { |
| 158 VideoCaptureImplManager* manager = | 159 VideoCaptureImplManager* manager = |
| 159 RenderThreadImpl::current()->video_capture_impl_manager(); | 160 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 160 video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get()); | 161 video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void PepperPlatformVideoCaptureImpl::OnDeviceOpened(int request_id, | 164 void PepperPlatformVideoCaptureImpl::OnDeviceOpened(int request_id, |
| 164 bool succeeded, | 165 bool succeeded, |
| 165 const std::string& label) { | 166 const std::string& label) { |
| 166 succeeded = succeeded && plugin_delegate_; | 167 succeeded = succeeded && plugin_delegate_.get(); |
| 167 if (succeeded) { | 168 if (succeeded) { |
| 168 label_ = label; | 169 label_ = label; |
| 169 session_id_ = plugin_delegate_->GetSessionID(PP_DEVICETYPE_DEV_VIDEOCAPTURE, | 170 session_id_ = plugin_delegate_->GetSessionID(PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
| 170 label); | 171 label); |
| 171 Initialize(); | 172 Initialize(); |
| 172 } | 173 } |
| 173 | 174 |
| 174 if (handler_) | 175 if (handler_) |
| 175 handler_->OnInitialized(this, succeeded); | 176 handler_->OnInitialized(this, succeeded); |
| 176 } | 177 } |
| 177 | 178 |
| 178 } // namespace content | 179 } // namespace content |
| OLD | NEW |