| 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.h" | 5 #include "content/renderer/pepper/pepper_platform_video_capture.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/message_loop_proxy.h" | 9 #include "base/message_loop/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 10 matching lines...) Expand all Loading... |
| 21 const base::WeakPtr<RenderViewImpl>& render_view, | 21 const base::WeakPtr<RenderViewImpl>& render_view, |
| 22 const std::string& device_id, | 22 const std::string& device_id, |
| 23 const GURL& document_url, | 23 const GURL& document_url, |
| 24 PepperVideoCaptureHost* handler) | 24 PepperVideoCaptureHost* handler) |
| 25 : render_view_(render_view), | 25 : render_view_(render_view), |
| 26 device_id_(device_id), | 26 device_id_(device_id), |
| 27 session_id_(0), | 27 session_id_(0), |
| 28 handler_proxy_(new media::VideoCaptureHandlerProxy( | 28 handler_proxy_(new media::VideoCaptureHandlerProxy( |
| 29 this, base::MessageLoopProxy::current())), | 29 this, base::MessageLoopProxy::current())), |
| 30 handler_(handler), | 30 handler_(handler), |
| 31 video_capture_(NULL), |
| 31 unbalanced_start_(false), | 32 unbalanced_start_(false), |
| 32 pending_open_device_(false), | 33 pending_open_device_(false), |
| 33 pending_open_device_id_(-1) { | 34 pending_open_device_id_(-1) { |
| 34 // We need to open the device and obtain the label and session ID before | 35 // We need to open the device and obtain the label and session ID before |
| 35 // initializing. | 36 // initializing. |
| 36 if (render_view_.get()) { | 37 if (render_view_.get()) { |
| 37 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( | 38 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( |
| 38 PP_DEVICETYPE_DEV_VIDEOCAPTURE, | 39 PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
| 39 device_id, | 40 device_id, |
| 40 document_url, | 41 document_url, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 76 } |
| 76 | 77 |
| 77 int PepperPlatformVideoCapture::CaptureFrameRate() { | 78 int PepperPlatformVideoCapture::CaptureFrameRate() { |
| 78 return handler_proxy_->state().frame_rate; | 79 return handler_proxy_->state().frame_rate; |
| 79 } | 80 } |
| 80 | 81 |
| 81 void PepperPlatformVideoCapture::DetachEventHandler() { | 82 void PepperPlatformVideoCapture::DetachEventHandler() { |
| 82 handler_ = NULL; | 83 handler_ = NULL; |
| 83 StopCapture(NULL); | 84 StopCapture(NULL); |
| 84 | 85 |
| 85 video_capture_.reset(); | 86 if (video_capture_) { |
| 87 VideoCaptureImplManager* manager = |
| 88 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 89 manager->RemoveDevice(session_id_, handler_proxy_.get()); |
| 90 video_capture_ = NULL; |
| 91 } |
| 86 | 92 |
| 87 if (render_view_.get()) { | 93 if (render_view_.get()) { |
| 88 if (!label_.empty()) { | 94 if (!label_.empty()) { |
| 89 GetMediaDeviceManager()->CloseDevice(label_); | 95 GetMediaDeviceManager()->CloseDevice(label_); |
| 90 label_.clear(); | 96 label_.clear(); |
| 91 } | 97 } |
| 92 if (pending_open_device_) { | 98 if (pending_open_device_) { |
| 93 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); | 99 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); |
| 94 pending_open_device_ = false; | 100 pending_open_device_ = false; |
| 95 pending_open_device_id_ = -1; | 101 pending_open_device_id_ = -1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 140 |
| 135 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { | 141 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { |
| 136 DCHECK(!video_capture_); | 142 DCHECK(!video_capture_); |
| 137 DCHECK(label_.empty()); | 143 DCHECK(label_.empty()); |
| 138 DCHECK(!pending_open_device_); | 144 DCHECK(!pending_open_device_); |
| 139 } | 145 } |
| 140 | 146 |
| 141 void PepperPlatformVideoCapture::Initialize() { | 147 void PepperPlatformVideoCapture::Initialize() { |
| 142 VideoCaptureImplManager* manager = | 148 VideoCaptureImplManager* manager = |
| 143 RenderThreadImpl::current()->video_capture_impl_manager(); | 149 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 144 video_capture_ = manager->UseDevice(session_id_); | 150 video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get()); |
| 145 } | 151 } |
| 146 | 152 |
| 147 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, | 153 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, |
| 148 bool succeeded, | 154 bool succeeded, |
| 149 const std::string& label) { | 155 const std::string& label) { |
| 150 pending_open_device_ = false; | 156 pending_open_device_ = false; |
| 151 pending_open_device_id_ = -1; | 157 pending_open_device_id_ = -1; |
| 152 | 158 |
| 153 succeeded = succeeded && render_view_.get(); | 159 succeeded = succeeded && render_view_.get(); |
| 154 if (succeeded) { | 160 if (succeeded) { |
| 155 label_ = label; | 161 label_ = label; |
| 156 session_id_ = GetMediaDeviceManager()->GetSessionID( | 162 session_id_ = GetMediaDeviceManager()->GetSessionID( |
| 157 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); | 163 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); |
| 158 Initialize(); | 164 Initialize(); |
| 159 } | 165 } |
| 160 | 166 |
| 161 if (handler_) | 167 if (handler_) |
| 162 handler_->OnInitialized(this, succeeded); | 168 handler_->OnInitialized(this, succeeded); |
| 163 } | 169 } |
| 164 | 170 |
| 165 PepperMediaDeviceManager* | 171 PepperMediaDeviceManager* |
| 166 PepperPlatformVideoCapture::GetMediaDeviceManager() { | 172 PepperPlatformVideoCapture::GetMediaDeviceManager() { |
| 167 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); | 173 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); |
| 168 } | 174 } |
| 169 | 175 |
| 170 } // namespace content | 176 } // namespace content |
| OLD | NEW |