| 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" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id)); | 70 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, | 73 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, |
| 74 int buffer_id) { | 74 int buffer_id) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 76 if (controllers_.find(controller_id) == controllers_.end()) | 76 if (controllers_.find(controller_id) == controllers_.end()) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id)); | 79 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) |
| 80 device_id_to_observer_map_[controller_id]->OnBufferDestroyed(buffer_id); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void VideoCaptureHost::OnBufferReady( | 83 void VideoCaptureHost::OnBufferReady( |
| 83 VideoCaptureControllerID controller_id, | 84 VideoCaptureControllerID controller_id, |
| 84 int buffer_id, | 85 int buffer_id, |
| 85 const scoped_refptr<media::VideoFrame>& video_frame) { | 86 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 87 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 87 if (controllers_.find(controller_id) == controllers_.end()) | 88 if (controllers_.find(controller_id) == controllers_.end()) |
| 88 return; | 89 return; |
| 89 | 90 |
| 90 VideoCaptureMsg_BufferReady_Params params; | 91 if (!base::ContainsKey(device_id_to_observer_map_, controller_id)) |
| 91 params.device_id = controller_id; | 92 return; |
| 92 params.buffer_id = buffer_id; | |
| 93 params.timestamp = video_frame->timestamp(); | |
| 94 video_frame->metadata()->MergeInternalValuesInto(¶ms.metadata); | |
| 95 params.pixel_format = video_frame->format(); | |
| 96 params.storage_type = video_frame->storage_type(); | |
| 97 params.coded_size = video_frame->coded_size(); | |
| 98 params.visible_rect = video_frame->visible_rect(); | |
| 99 | 93 |
| 100 Send(new VideoCaptureMsg_BufferReady(params)); | 94 mojom::VideoFrameInfoPtr info = mojom::VideoFrameInfo::New(); |
| 95 info->timestamp = video_frame->timestamp(); |
| 96 video_frame->metadata()->MergeInternalValuesInto(&info->metadata); |
| 97 |
| 98 DCHECK_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); |
| 99 info->pixel_format = media::mojom::VideoFormat::I420; |
| 100 info->storage_type = media::PIXEL_STORAGE_CPU; |
| 101 info->coded_size = video_frame->coded_size(); |
| 102 info->visible_rect = video_frame->visible_rect(); |
| 103 |
| 104 device_id_to_observer_map_[controller_id]->OnBufferReady(buffer_id, |
| 105 std::move(info)); |
| 101 } | 106 } |
| 102 | 107 |
| 103 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { | 108 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { |
| 104 DVLOG(1) << __func__; | 109 DVLOG(1) << __func__; |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 106 BrowserThread::PostTask( | 111 BrowserThread::PostTask( |
| 107 BrowserThread::IO, FROM_HERE, | 112 BrowserThread::IO, FROM_HERE, |
| 108 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); | 113 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); |
| 109 } | 114 } |
| 110 | 115 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 const base::WeakPtr<VideoCaptureController> controller = it->second; | 325 const base::WeakPtr<VideoCaptureController> controller = it->second; |
| 321 controllers_.erase(it); | 326 controllers_.erase(it); |
| 322 if (!controller) | 327 if (!controller) |
| 323 return; | 328 return; |
| 324 | 329 |
| 325 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 330 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 326 controller.get(), controller_id, this, on_error); | 331 controller.get(), controller_id, this, on_error); |
| 327 } | 332 } |
| 328 | 333 |
| 329 } // namespace content | 334 } // namespace content |
| OLD | NEW |