| 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" |
| 11 #include "content/renderer/pepper/pepper_media_device_manager.h" | 11 #include "content/renderer/pepper/pepper_media_device_manager.h" |
| 12 #include "content/renderer/pepper/pepper_video_capture_host.h" | 12 #include "content/renderer/pepper/pepper_video_capture_host.h" |
| 13 #include "content/renderer/render_frame_impl.h" |
| 13 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
| 14 #include "content/renderer/render_view_impl.h" | |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 PepperPlatformVideoCapture::PepperPlatformVideoCapture( | 20 PepperPlatformVideoCapture::PepperPlatformVideoCapture( |
| 21 const base::WeakPtr<RenderViewImpl>& render_view, | 21 int render_frame_id, |
| 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_frame_id_(render_frame_id), |
| 26 device_id_(device_id), | 26 device_id_(device_id), |
| 27 session_id_(0), | 27 session_id_(0), |
| 28 handler_(handler), | 28 handler_(handler), |
| 29 pending_open_device_(false), | 29 pending_open_device_(false), |
| 30 pending_open_device_id_(-1), | 30 pending_open_device_id_(-1), |
| 31 weak_factory_(this) { | 31 weak_factory_(this) { |
| 32 // We need to open the device and obtain the label and session ID before | 32 // We need to open the device and obtain the label and session ID before |
| 33 // initializing. | 33 // initializing. |
| 34 if (render_view_.get()) { | 34 PepperMediaDeviceManager* const device_manager = GetMediaDeviceManager(); |
| 35 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( | 35 if (device_manager) { |
| 36 pending_open_device_id_ = device_manager->OpenDevice( |
| 36 PP_DEVICETYPE_DEV_VIDEOCAPTURE, | 37 PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
| 37 device_id, | 38 device_id, |
| 38 document_url, | 39 document_url, |
| 39 base::Bind(&PepperPlatformVideoCapture::OnDeviceOpened, | 40 base::Bind(&PepperPlatformVideoCapture::OnDeviceOpened, |
| 40 weak_factory_.GetWeakPtr())); | 41 weak_factory_.GetWeakPtr())); |
| 41 pending_open_device_ = true; | 42 pending_open_device_ = true; |
| 42 } | 43 } |
| 43 } | 44 } |
| 44 | 45 |
| 45 void PepperPlatformVideoCapture::StartCapture( | 46 void PepperPlatformVideoCapture::StartCapture( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 68 stop_capture_cb_.Reset(); | 69 stop_capture_cb_.Reset(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void PepperPlatformVideoCapture::DetachEventHandler() { | 72 void PepperPlatformVideoCapture::DetachEventHandler() { |
| 72 handler_ = NULL; | 73 handler_ = NULL; |
| 73 StopCapture(); | 74 StopCapture(); |
| 74 if (!release_device_cb_.is_null()) { | 75 if (!release_device_cb_.is_null()) { |
| 75 release_device_cb_.Run(); | 76 release_device_cb_.Run(); |
| 76 release_device_cb_.Reset(); | 77 release_device_cb_.Reset(); |
| 77 } | 78 } |
| 78 if (render_view_.get()) { | 79 if (!label_.empty()) { |
| 79 if (!label_.empty()) { | 80 PepperMediaDeviceManager* const device_manager = GetMediaDeviceManager(); |
| 80 GetMediaDeviceManager()->CloseDevice(label_); | 81 if (device_manager) |
| 81 label_.clear(); | 82 device_manager->CloseDevice(label_); |
| 82 } | 83 label_.clear(); |
| 83 if (pending_open_device_) { | 84 } |
| 84 GetMediaDeviceManager()->CancelOpenDevice(pending_open_device_id_); | 85 if (pending_open_device_) { |
| 85 pending_open_device_ = false; | 86 PepperMediaDeviceManager* const device_manager = GetMediaDeviceManager(); |
| 86 pending_open_device_id_ = -1; | 87 if (device_manager) |
| 87 } | 88 device_manager->CancelOpenDevice(pending_open_device_id_); |
| 89 pending_open_device_ = false; |
| 90 pending_open_device_id_ = -1; |
| 88 } | 91 } |
| 89 } | 92 } |
| 90 | 93 |
| 91 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { | 94 PepperPlatformVideoCapture::~PepperPlatformVideoCapture() { |
| 92 DCHECK(stop_capture_cb_.is_null()); | 95 DCHECK(stop_capture_cb_.is_null()); |
| 93 DCHECK(release_device_cb_.is_null()); | 96 DCHECK(release_device_cb_.is_null()); |
| 94 DCHECK(label_.empty()); | 97 DCHECK(label_.empty()); |
| 95 DCHECK(!pending_open_device_); | 98 DCHECK(!pending_open_device_); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, | 101 void PepperPlatformVideoCapture::OnDeviceOpened(int request_id, |
| 99 bool succeeded, | 102 bool succeeded, |
| 100 const std::string& label) { | 103 const std::string& label) { |
| 101 pending_open_device_ = false; | 104 pending_open_device_ = false; |
| 102 pending_open_device_id_ = -1; | 105 pending_open_device_id_ = -1; |
| 103 | 106 |
| 104 succeeded = succeeded && render_view_.get(); | 107 PepperMediaDeviceManager* const device_manager = GetMediaDeviceManager(); |
| 108 succeeded = succeeded && device_manager; |
| 105 if (succeeded) { | 109 if (succeeded) { |
| 106 label_ = label; | 110 label_ = label; |
| 107 session_id_ = GetMediaDeviceManager()->GetSessionID( | 111 session_id_ = device_manager->GetSessionID( |
| 108 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); | 112 PP_DEVICETYPE_DEV_VIDEOCAPTURE, label); |
| 109 VideoCaptureImplManager* manager = | 113 VideoCaptureImplManager* manager = |
| 110 RenderThreadImpl::current()->video_capture_impl_manager(); | 114 RenderThreadImpl::current()->video_capture_impl_manager(); |
| 111 release_device_cb_ = manager->UseDevice(session_id_); | 115 release_device_cb_ = manager->UseDevice(session_id_); |
| 112 } | 116 } |
| 113 | 117 |
| 114 if (handler_) | 118 if (handler_) |
| 115 handler_->OnInitialized(succeeded); | 119 handler_->OnInitialized(succeeded); |
| 116 } | 120 } |
| 117 | 121 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 138 | 142 |
| 139 void PepperPlatformVideoCapture::OnFrameReady( | 143 void PepperPlatformVideoCapture::OnFrameReady( |
| 140 const scoped_refptr<media::VideoFrame>& frame, | 144 const scoped_refptr<media::VideoFrame>& frame, |
| 141 const media::VideoCaptureFormat& format, | 145 const media::VideoCaptureFormat& format, |
| 142 const base::TimeTicks& estimated_capture_time) { | 146 const base::TimeTicks& estimated_capture_time) { |
| 143 if (handler_ && !stop_capture_cb_.is_null()) | 147 if (handler_ && !stop_capture_cb_.is_null()) |
| 144 handler_->OnFrameReady(frame, format); | 148 handler_->OnFrameReady(frame, format); |
| 145 } | 149 } |
| 146 | 150 |
| 147 PepperMediaDeviceManager* PepperPlatformVideoCapture::GetMediaDeviceManager() { | 151 PepperMediaDeviceManager* PepperPlatformVideoCapture::GetMediaDeviceManager() { |
| 148 return PepperMediaDeviceManager::GetForRenderView(render_view_.get()); | 152 RenderFrameImpl* const render_frame = |
| 153 RenderFrameImpl::FromRoutingID(render_frame_id_); |
| 154 return render_frame ? |
| 155 PepperMediaDeviceManager::GetForRenderFrame(render_frame) : NULL; |
| 149 } | 156 } |
| 150 | 157 |
| 151 } // namespace content | 158 } // namespace content |
| OLD | NEW |