Chromium Code Reviews| 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 if (video_capture_) |
|
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
nit: don't need the conditional
Alpha Left Google
2014/01/08 00:23:36
Done.
| |
| 87 VideoCaptureImplManager* manager = | 86 video_capture_.reset(); |
| 88 RenderThreadImpl::current()->video_capture_impl_manager(); | |
| 89 manager->RemoveDevice(session_id_, handler_proxy_.get()); | |
| 90 video_capture_ = NULL; | |
| 91 } | |
| 92 | 87 |
| 93 if (render_view_.get()) { | 88 if (render_view_.get()) { |
| 94 if (!label_.empty()) { | 89 if (!label_.empty()) { |
| 95 GetMediaDeviceManager()->CloseDevice(label_); | 90 GetMediaDeviceManager()->CloseDevice(label_); |
| 96 label_.clear(); | 91 label_.clear(); |
| 97 } | 92 } |
| 98 if (pending_open_device_) { | 93 if (pending_open_device_) { |
| 99 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); | 94 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); |
| 100 pending_open_device_ = false; | 95 pending_open_device_ = false; |
| 101 pending_open_device_id_ = -1; | 96 pending_open_device_id_ = -1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 135 |
| 141 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { | 136 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { |
| 142 DCHECK(!video_capture_); | 137 DCHECK(!video_capture_); |
| 143 DCHECK(label_.empty()); | 138 DCHECK(label_.empty()); |
| 144 DCHECK(!pending_open_device_); | 139 DCHECK(!pending_open_device_); |
| 145 } | 140 } |
| 146 | 141 |
| 147 void PepperPlatformVideoCapture::Initialize() { | 142 void PepperPlatformVideoCapture::Initialize() { |
| 148 VideoCaptureImplManager* manager = | 143 VideoCaptureImplManager* manager = |
| 149 RenderThreadImpl::current()->video_capture_impl_manager(); | 144 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 150 video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get()); | 145 video_capture_ = manager->UseDevice(session_id_); |
| 151 } | 146 } |
| 152 | 147 |
| 153 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, | 148 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, |
| 154 bool succeeded, | 149 bool succeeded, |
| 155 const std::string& label) { | 150 const std::string& label) { |
| 156 pending_open_device_ = false; | 151 pending_open_device_ = false; |
| 157 pending_open_device_id_ = -1; | 152 pending_open_device_id_ = -1; |
| 158 | 153 |
| 159 succeeded = succeeded && render_view_.get(); | 154 succeeded = succeeded && render_view_.get(); |
| 160 if (succeeded) { | 155 if (succeeded) { |
| 161 label_ = label; | 156 label_ = label; |
| 162 session_id_ = GetMediaDeviceManager()->GetSessionID( | 157 session_id_ = GetMediaDeviceManager()->GetSessionID( |
| 163 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); | 158 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); |
| 164 Initialize(); | 159 Initialize(); |
| 165 } | 160 } |
| 166 | 161 |
| 167 if (handler_) | 162 if (handler_) |
| 168 handler_->OnInitialized(this, succeeded); | 163 handler_->OnInitialized(this, succeeded); |
| 169 } | 164 } |
| 170 | 165 |
| 171 PepperMediaDeviceManager* | 166 PepperMediaDeviceManager* |
| 172 PepperPlatformVideoCapture::GetMediaDeviceManager() { | 167 PepperPlatformVideoCapture::GetMediaDeviceManager() { |
| 173 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); | 168 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); |
| 174 } | 169 } |
| 175 | 170 |
| 176 } // namespace content | 171 } // namespace content |
| OLD | NEW |