| 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), | |
| 32 unbalanced_start_(false), | 31 unbalanced_start_(false), |
| 33 pending_open_device_(false), | 32 pending_open_device_(false), |
| 34 pending_open_device_id_(-1) { | 33 pending_open_device_id_(-1) { |
| 35 // 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 |
| 36 // initializing. | 35 // initializing. |
| 37 if (render_view_.get()) { | 36 if (render_view_.get()) { |
| 38 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( | 37 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( |
| 39 PP_DEVICETYPE_DEV_VIDEOCAPTURE, | 38 PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
| 40 device_id, | 39 device_id, |
| 41 document_url, | 40 document_url, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 75 } |
| 77 | 76 |
| 78 int PepperPlatformVideoCapture::CaptureFrameRate() { | 77 int PepperPlatformVideoCapture::CaptureFrameRate() { |
| 79 return handler_proxy_->state().frame_rate; | 78 return handler_proxy_->state().frame_rate; |
| 80 } | 79 } |
| 81 | 80 |
| 82 void PepperPlatformVideoCapture::DetachEventHandler() { | 81 void PepperPlatformVideoCapture::DetachEventHandler() { |
| 83 handler_ = NULL; | 82 handler_ = NULL; |
| 84 StopCapture(NULL); | 83 StopCapture(NULL); |
| 85 | 84 |
| 86 if (video_capture_) { | 85 video_capture_.reset(); |
| 87 VideoCaptureImplManager* manager = | |
| 88 RenderThreadImpl::current()->video_capture_impl_manager(); | |
| 89 manager->RemoveDevice(session_id_, handler_proxy_.get()); | |
| 90 video_capture_ = NULL; | |
| 91 } | |
| 92 | 86 |
| 93 if (render_view_.get()) { | 87 if (render_view_.get()) { |
| 94 if (!label_.empty()) { | 88 if (!label_.empty()) { |
| 95 GetMediaDeviceManager()->CloseDevice(label_); | 89 GetMediaDeviceManager()->CloseDevice(label_); |
| 96 label_.clear(); | 90 label_.clear(); |
| 97 } | 91 } |
| 98 if (pending_open_device_) { | 92 if (pending_open_device_) { |
| 99 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); | 93 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); |
| 100 pending_open_device_ = false; | 94 pending_open_device_ = false; |
| 101 pending_open_device_id_ = -1; | 95 pending_open_device_id_ = -1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 134 |
| 141 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { | 135 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { |
| 142 DCHECK(!video_capture_); | 136 DCHECK(!video_capture_); |
| 143 DCHECK(label_.empty()); | 137 DCHECK(label_.empty()); |
| 144 DCHECK(!pending_open_device_); | 138 DCHECK(!pending_open_device_); |
| 145 } | 139 } |
| 146 | 140 |
| 147 void PepperPlatformVideoCapture::Initialize() { | 141 void PepperPlatformVideoCapture::Initialize() { |
| 148 VideoCaptureImplManager* manager = | 142 VideoCaptureImplManager* manager = |
| 149 RenderThreadImpl::current()->video_capture_impl_manager(); | 143 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 150 video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get()); | 144 video_capture_ = manager->UseDevice(session_id_); |
| 151 } | 145 } |
| 152 | 146 |
| 153 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, | 147 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, |
| 154 bool succeeded, | 148 bool succeeded, |
| 155 const std::string& label) { | 149 const std::string& label) { |
| 156 pending_open_device_ = false; | 150 pending_open_device_ = false; |
| 157 pending_open_device_id_ = -1; | 151 pending_open_device_id_ = -1; |
| 158 | 152 |
| 159 succeeded = succeeded && render_view_.get(); | 153 succeeded = succeeded && render_view_.get(); |
| 160 if (succeeded) { | 154 if (succeeded) { |
| 161 label_ = label; | 155 label_ = label; |
| 162 session_id_ = GetMediaDeviceManager()->GetSessionID( | 156 session_id_ = GetMediaDeviceManager()->GetSessionID( |
| 163 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); | 157 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); |
| 164 Initialize(); | 158 Initialize(); |
| 165 } | 159 } |
| 166 | 160 |
| 167 if (handler_) | 161 if (handler_) |
| 168 handler_->OnInitialized(this, succeeded); | 162 handler_->OnInitialized(this, succeeded); |
| 169 } | 163 } |
| 170 | 164 |
| 171 PepperMediaDeviceManager* | 165 PepperMediaDeviceManager* |
| 172 PepperPlatformVideoCapture::GetMediaDeviceManager() { | 166 PepperPlatformVideoCapture::GetMediaDeviceManager() { |
| 173 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); | 167 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); |
| 174 } | 168 } |
| 175 | 169 |
| 176 } // namespace content | 170 } // namespace content |
| OLD | NEW |