| 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/browser/renderer_host/media/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "content/browser/browser_main_loop.h" | 12 #include "content/browser/browser_main_loop.h" |
| 13 #include "content/browser/renderer_host/media/media_stream_manager.h" | 13 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 14 #include "content/browser/renderer_host/media/video_capture_manager.h" | 14 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 15 #include "mojo/common/values_struct_traits.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" | 16 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) | 20 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
| 20 : media_stream_manager_(media_stream_manager), | 21 : media_stream_manager_(media_stream_manager), |
| 21 weak_factory_(this) { | 22 weak_factory_(this) { |
| 22 DVLOG(1) << __func__; | 23 DVLOG(1) << __func__; |
| 23 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 24 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 24 } | 25 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 if (controllers_.find(controller_id) == controllers_.end()) | 80 if (controllers_.find(controller_id) == controllers_.end()) |
| 80 return; | 81 return; |
| 81 | 82 |
| 82 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) | 83 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) |
| 83 device_id_to_observer_map_[controller_id]->OnBufferDestroyed(buffer_id); | 84 device_id_to_observer_map_[controller_id]->OnBufferDestroyed(buffer_id); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void VideoCaptureHost::OnBufferReady( | 87 void VideoCaptureHost::OnBufferReady( |
| 87 VideoCaptureControllerID controller_id, | 88 VideoCaptureControllerID controller_id, |
| 88 int buffer_id, | 89 int buffer_id, |
| 89 const scoped_refptr<media::VideoFrame>& video_frame) { | 90 const media::mojom::VideoFrameInfoPtr& frame_info) { |
| 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 91 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 91 if (controllers_.find(controller_id) == controllers_.end()) | 92 if (controllers_.find(controller_id) == controllers_.end()) |
| 92 return; | 93 return; |
| 93 | 94 |
| 94 if (!base::ContainsKey(device_id_to_observer_map_, controller_id)) | 95 if (!base::ContainsKey(device_id_to_observer_map_, controller_id)) |
| 95 return; | 96 return; |
| 96 | 97 |
| 97 media::mojom::VideoFrameInfoPtr info = media::mojom::VideoFrameInfo::New(); | |
| 98 info->timestamp = video_frame->timestamp(); | |
| 99 info->metadata = video_frame->metadata()->CopyInternalValues(); | |
| 100 | |
| 101 DCHECK(media::PIXEL_FORMAT_I420 == video_frame->format() || | |
| 102 media::PIXEL_FORMAT_Y16 == video_frame->format()); | |
| 103 info->pixel_format = video_frame->format(); | |
| 104 info->storage_type = media::PIXEL_STORAGE_CPU; | |
| 105 info->coded_size = video_frame->coded_size(); | |
| 106 info->visible_rect = video_frame->visible_rect(); | |
| 107 | |
| 108 device_id_to_observer_map_[controller_id]->OnBufferReady(buffer_id, | 98 device_id_to_observer_map_[controller_id]->OnBufferReady(buffer_id, |
| 109 std::move(info)); | 99 frame_info.Clone()); |
| 110 } | 100 } |
| 111 | 101 |
| 112 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { | 102 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { |
| 113 DVLOG(1) << __func__; | 103 DVLOG(1) << __func__; |
| 114 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 115 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
| 116 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
| 117 base::Bind(&VideoCaptureHost::DoEnded, weak_factory_.GetWeakPtr(), | 107 base::Bind(&VideoCaptureHost::DoEnded, weak_factory_.GetWeakPtr(), |
| 118 controller_id)); | 108 controller_id)); |
| 119 } | 109 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 const base::WeakPtr<VideoCaptureController> controller = it->second; | 316 const base::WeakPtr<VideoCaptureController> controller = it->second; |
| 327 controllers_.erase(it); | 317 controllers_.erase(it); |
| 328 if (!controller) | 318 if (!controller) |
| 329 return; | 319 return; |
| 330 | 320 |
| 331 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 321 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 332 controller.get(), controller_id, this, on_error); | 322 controller.get(), controller_id, this, on_error); |
| 333 } | 323 } |
| 334 | 324 |
| 335 } // namespace content | 325 } // namespace content |
| OLD | NEW |