Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: content/renderer/media/video_capture_impl.cc

Issue 2430313007: VideoCapture: remove last remnants of IPC (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Notes about usage of this object by VideoCaptureImplManager. 5 // Notes about usage of this object by VideoCaptureImplManager.
6 // 6 //
7 // VideoCaptureImplManager access this object by using a Unretained() 7 // VideoCaptureImplManager access this object by using a Unretained()
8 // binding and tasks on the IO thread. It is then important that 8 // binding and tasks on the IO thread. It is then important that
9 // VideoCaptureImpl never post task to itself. All operations must be 9 // VideoCaptureImpl never post task to itself. All operations must be
10 // synchronous. 10 // synchronous.
11 11
12 #include "content/renderer/media/video_capture_impl.h" 12 #include "content/renderer/media/video_capture_impl.h"
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 #include <utility> 15 #include <utility>
16 16
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/threading/thread_task_runner_handle.h"
21 #include "content/child/child_process.h" 20 #include "content/child/child_process.h"
22 #include "content/common/media/video_capture_messages.h" 21 #include "content/renderer/render_thread_impl.h"
23 #include "media/base/bind_to_current_loop.h" 22 #include "media/base/bind_to_current_loop.h"
24 #include "media/base/limits.h" 23 #include "media/base/limits.h"
25 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
26 #include "mojo/public/cpp/system/platform_handle.h" 25 #include "mojo/public/cpp/system/platform_handle.h"
26 #include "services/service_manager/public/cpp/interface_provider.h"
27 27
28 namespace content { 28 namespace content {
29 29
30 // A holder of a memory-backed buffer and accessors to it. 30 // A holder of a memory-backed buffer and accessors to it.
31 class VideoCaptureImpl::ClientBuffer 31 class VideoCaptureImpl::ClientBuffer
32 : public base::RefCountedThreadSafe<ClientBuffer> { 32 : public base::RefCountedThreadSafe<ClientBuffer> {
33 public: 33 public:
34 ClientBuffer(std::unique_ptr<base::SharedMemory> buffer, size_t buffer_size) 34 ClientBuffer(std::unique_ptr<base::SharedMemory> buffer, size_t buffer_size)
35 : buffer_(std::move(buffer)), buffer_size_(buffer_size) {} 35 : buffer_(std::move(buffer)), buffer_size_(buffer_size) {}
36 36
37 base::SharedMemory* buffer() const { return buffer_.get(); } 37 base::SharedMemory* buffer() const { return buffer_.get(); }
38 size_t buffer_size() const { return buffer_size_; } 38 size_t buffer_size() const { return buffer_size_; }
39 39
40 private: 40 private:
41 friend class base::RefCountedThreadSafe<ClientBuffer>; 41 friend class base::RefCountedThreadSafe<ClientBuffer>;
42 42
43 virtual ~ClientBuffer() {} 43 virtual ~ClientBuffer() {}
44 44
45 const std::unique_ptr<base::SharedMemory> buffer_; 45 const std::unique_ptr<base::SharedMemory> buffer_;
46 const size_t buffer_size_; 46 const size_t buffer_size_;
47 47
48 DISALLOW_COPY_AND_ASSIGN(ClientBuffer); 48 DISALLOW_COPY_AND_ASSIGN(ClientBuffer);
49 }; 49 };
50 50
51 VideoCaptureImpl::ClientInfo::ClientInfo() {} 51 // Information about a video capture client of ours.
52 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default; 52 struct VideoCaptureImpl::ClientInfo {
53 VideoCaptureImpl::ClientInfo::~ClientInfo() {} 53 ClientInfo() = default;
54 54
55 VideoCaptureImpl::VideoCaptureImpl( 55 ClientInfo(const ClientInfo& other) = default;
56 media::VideoCaptureSessionId session_id, 56
57 VideoCaptureMessageFilter* filter, 57 ~ClientInfo() = default;
58 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 58
59 : message_filter_(filter), 59 media::VideoCaptureParams params;
60 device_id_(0), 60
61 VideoCaptureStateUpdateCB state_update_cb;
62
63 VideoCaptureDeliverFrameCB deliver_frame_cb;
64 };
65
66 VideoCaptureImpl::VideoCaptureImpl(media::VideoCaptureSessionId session_id)
67 : device_id_(session_id),
61 session_id_(session_id), 68 session_id_(session_id),
62 video_capture_host_for_testing_(nullptr), 69 video_capture_host_for_testing_(nullptr),
63 observer_binding_(this), 70 observer_binding_(this),
64 state_(VIDEO_CAPTURE_STATE_STOPPED), 71 state_(VIDEO_CAPTURE_STATE_STOPPED),
65 io_task_runner_(std::move(io_task_runner)),
66 weak_factory_(this) { 72 weak_factory_(this) {
67 DCHECK(filter); 73 io_thread_checker_.DetachFromThread();
68 io_task_runner_->PostTask(FROM_HERE, 74
69 base::Bind(&VideoCaptureMessageFilter::AddDelegate, 75 if (RenderThreadImpl::current()) { // This is null in unit tests.
Ken Rockot(use gerrit already) 2016/10/21 17:29:27 nit: You don't need a RenderThreadImpl specificall
mcasas 2016/10/21 19:02:35 Done.
70 message_filter_, this)); 76 mojom::VideoCaptureHostPtr temp_video_capture_host;
77 RenderThreadImpl::current()->GetRemoteInterfaces()->GetInterface(
78 mojo::GetProxy(&temp_video_capture_host));
79 video_capture_host_info_ = temp_video_capture_host.PassInterface();
80 }
71 } 81 }
72 82
73 VideoCaptureImpl::~VideoCaptureImpl() { 83 VideoCaptureImpl::~VideoCaptureImpl() {
74 DCHECK(io_task_runner_->BelongsToCurrentThread()); 84 DCHECK(io_thread_checker_.CalledOnValidThread());
75 if (state_ == VIDEO_CAPTURE_STATE_STARTED && GetVideoCaptureHost()) 85 if (state_ == VIDEO_CAPTURE_STATE_STARTED && GetVideoCaptureHost())
76 GetVideoCaptureHost()->Stop(device_id_); 86 GetVideoCaptureHost()->Stop(device_id_);
77 message_filter_->RemoveDelegate(this);
78 } 87 }
79 88
80 void VideoCaptureImpl::SuspendCapture(bool suspend) { 89 void VideoCaptureImpl::SuspendCapture(bool suspend) {
81 DCHECK(io_task_runner_->BelongsToCurrentThread()); 90 DCHECK(io_thread_checker_.CalledOnValidThread());
82 if (suspend) 91 if (suspend)
83 GetVideoCaptureHost()->Pause(device_id_); 92 GetVideoCaptureHost()->Pause(device_id_);
84 else 93 else
85 GetVideoCaptureHost()->Resume(device_id_, session_id_, params_); 94 GetVideoCaptureHost()->Resume(device_id_, session_id_, params_);
86 } 95 }
87 96
88 void VideoCaptureImpl::StartCapture( 97 void VideoCaptureImpl::StartCapture(
89 int client_id, 98 int client_id,
90 const media::VideoCaptureParams& params, 99 const media::VideoCaptureParams& params,
91 const VideoCaptureStateUpdateCB& state_update_cb, 100 const VideoCaptureStateUpdateCB& state_update_cb,
92 const VideoCaptureDeliverFrameCB& deliver_frame_cb) { 101 const VideoCaptureDeliverFrameCB& deliver_frame_cb) {
93 DCHECK(io_task_runner_->BelongsToCurrentThread()); 102 DVLOG(1) << __func__ << " |device_id_| = " << device_id_;
103 DCHECK(io_thread_checker_.CalledOnValidThread());
94 ClientInfo client_info; 104 ClientInfo client_info;
95 client_info.params = params; 105 client_info.params = params;
96 client_info.state_update_cb = state_update_cb; 106 client_info.state_update_cb = state_update_cb;
97 client_info.deliver_frame_cb = deliver_frame_cb; 107 client_info.deliver_frame_cb = deliver_frame_cb;
98 108
99 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { 109 if (state_ == VIDEO_CAPTURE_STATE_ERROR) {
100 state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR); 110 state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR);
101 } else if (clients_pending_on_filter_.count(client_id) || 111 } else if (clients_pending_on_restart_.count(client_id) ||
102 clients_pending_on_restart_.count(client_id) ||
103 clients_.count(client_id)) { 112 clients_.count(client_id)) {
104 DLOG(FATAL) << __func__ << " This client has already started."; 113 DLOG(FATAL) << __func__ << " This client has already started.";
105 } else if (!device_id_) {
106 clients_pending_on_filter_[client_id] = client_info;
107 } else { 114 } else {
108 // Note: |state_| might not be started at this point. But we tell 115 // Note: |state_| might not be started at this point. But we tell
109 // client that we have started. 116 // client that we have started.
110 state_update_cb.Run(VIDEO_CAPTURE_STATE_STARTED); 117 state_update_cb.Run(VIDEO_CAPTURE_STATE_STARTED);
111 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 118 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
112 clients_[client_id] = client_info; 119 clients_[client_id] = client_info;
113 // TODO(sheu): Allowing resolution change will require that all 120 // TODO(sheu): Allowing resolution change will require that all
114 // outstanding clients of a capture session support resolution change. 121 // outstanding clients of a capture session support resolution change.
115 DCHECK_EQ(params_.resolution_change_policy, 122 DCHECK_EQ(params_.resolution_change_policy,
116 params.resolution_change_policy); 123 params.resolution_change_policy);
(...skipping 11 matching lines...) Expand all
128 static_cast<float>(media::limits::kMaxFramesPerSecond)); 135 static_cast<float>(media::limits::kMaxFramesPerSecond));
129 136
130 DVLOG(1) << "StartCapture: starting with first resolution " 137 DVLOG(1) << "StartCapture: starting with first resolution "
131 << params_.requested_format.frame_size.ToString(); 138 << params_.requested_format.frame_size.ToString();
132 StartCaptureInternal(); 139 StartCaptureInternal();
133 } 140 }
134 } 141 }
135 } 142 }
136 143
137 void VideoCaptureImpl::StopCapture(int client_id) { 144 void VideoCaptureImpl::StopCapture(int client_id) {
138 DCHECK(io_task_runner_->BelongsToCurrentThread()); 145 DCHECK(io_thread_checker_.CalledOnValidThread());
139 // A client ID can be in only one client list. 146 // A client ID can be in only one client list.
140 // If this ID is in any client list, we can just remove it from 147 // If this ID is in any client list, we can just remove it from
141 // that client list and don't have to run the other following RemoveClient(). 148 // that client list and don't have to run the other following RemoveClient().
142 if (!RemoveClient(client_id, &clients_pending_on_filter_)) { 149 if (!RemoveClient(client_id, &clients_pending_on_restart_)) {
143 if (!RemoveClient(client_id, &clients_pending_on_restart_)) { 150 RemoveClient(client_id, &clients_);
144 RemoveClient(client_id, &clients_);
145 }
146 } 151 }
147 152
148 if (!clients_.empty()) 153 if (!clients_.empty())
149 return; 154 return;
150 DVLOG(1) << "StopCapture: No more client, stopping ..."; 155 DVLOG(1) << "StopCapture: No more client, stopping ...";
151 StopDevice(); 156 StopDevice();
152 client_buffers_.clear(); 157 client_buffers_.clear();
153 weak_factory_.InvalidateWeakPtrs(); 158 weak_factory_.InvalidateWeakPtrs();
154 } 159 }
155 160
156 void VideoCaptureImpl::RequestRefreshFrame() { 161 void VideoCaptureImpl::RequestRefreshFrame() {
157 DCHECK(io_task_runner_->BelongsToCurrentThread()); 162 DCHECK(io_thread_checker_.CalledOnValidThread());
158 GetVideoCaptureHost()->RequestRefreshFrame(device_id_); 163 GetVideoCaptureHost()->RequestRefreshFrame(device_id_);
159 } 164 }
160 165
161 void VideoCaptureImpl::GetDeviceSupportedFormats( 166 void VideoCaptureImpl::GetDeviceSupportedFormats(
162 const VideoCaptureDeviceFormatsCB& callback) { 167 const VideoCaptureDeviceFormatsCB& callback) {
163 DCHECK(io_task_runner_->BelongsToCurrentThread()); 168 DCHECK(io_thread_checker_.CalledOnValidThread());
164 GetVideoCaptureHost()->GetDeviceSupportedFormats( 169 GetVideoCaptureHost()->GetDeviceSupportedFormats(
165 device_id_, session_id_, 170 device_id_, session_id_,
166 base::Bind(&VideoCaptureImpl::OnDeviceSupportedFormats, 171 base::Bind(&VideoCaptureImpl::OnDeviceSupportedFormats,
167 weak_factory_.GetWeakPtr(), callback)); 172 weak_factory_.GetWeakPtr(), callback));
168 } 173 }
169 174
170 void VideoCaptureImpl::GetDeviceFormatsInUse( 175 void VideoCaptureImpl::GetDeviceFormatsInUse(
171 const VideoCaptureDeviceFormatsCB& callback) { 176 const VideoCaptureDeviceFormatsCB& callback) {
172 DCHECK(io_task_runner_->BelongsToCurrentThread()); 177 DCHECK(io_thread_checker_.CalledOnValidThread());
173 GetVideoCaptureHost()->GetDeviceFormatsInUse( 178 GetVideoCaptureHost()->GetDeviceFormatsInUse(
174 device_id_, session_id_, 179 device_id_, session_id_,
175 base::Bind(&VideoCaptureImpl::OnDeviceFormatsInUse, 180 base::Bind(&VideoCaptureImpl::OnDeviceFormatsInUse,
176 weak_factory_.GetWeakPtr(), callback)); 181 weak_factory_.GetWeakPtr(), callback));
177 } 182 }
178 183
179 void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) {
180 DVLOG(1) << __func__ << " " << device_id;
181 DCHECK(io_task_runner_->BelongsToCurrentThread());
182
183 device_id_ = device_id;
184 ClientInfoMap::iterator it = clients_pending_on_filter_.begin();
185 while (it != clients_pending_on_filter_.end()) {
186 const int client_id = it->first;
187 const ClientInfo client_info = it->second;
188 clients_pending_on_filter_.erase(it++);
189 StartCapture(client_id, client_info.params, client_info.state_update_cb,
190 client_info.deliver_frame_cb);
191 }
192 }
193
194 void VideoCaptureImpl::OnStateChanged(mojom::VideoCaptureState state) { 184 void VideoCaptureImpl::OnStateChanged(mojom::VideoCaptureState state) {
195 DVLOG(1) << __func__ << " state: " << state; 185 DVLOG(1) << __func__ << " state: " << state;
196 DCHECK(io_task_runner_->BelongsToCurrentThread()); 186 DCHECK(io_thread_checker_.CalledOnValidThread());
197 187
198 switch (state) { 188 switch (state) {
199 case mojom::VideoCaptureState::STARTED: 189 case mojom::VideoCaptureState::STARTED:
200 // Capture has started in the browser process. Since we have already 190 // Capture has started in the browser process. Since we have already
201 // told all clients that we have started there's nothing to do. 191 // told all clients that we have started there's nothing to do.
202 break; 192 break;
203 case mojom::VideoCaptureState::STOPPED: 193 case mojom::VideoCaptureState::STOPPED:
204 state_ = VIDEO_CAPTURE_STATE_STOPPED; 194 state_ = VIDEO_CAPTURE_STATE_STOPPED;
205 client_buffers_.clear(); 195 client_buffers_.clear();
206 weak_factory_.InvalidateWeakPtrs(); 196 weak_factory_.InvalidateWeakPtrs();
(...skipping 20 matching lines...) Expand all
227 client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); 217 client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
228 clients_.clear(); 218 clients_.clear();
229 state_ = VIDEO_CAPTURE_STATE_ENDED; 219 state_ = VIDEO_CAPTURE_STATE_ENDED;
230 break; 220 break;
231 } 221 }
232 } 222 }
233 223
234 void VideoCaptureImpl::OnBufferCreated(int32_t buffer_id, 224 void VideoCaptureImpl::OnBufferCreated(int32_t buffer_id,
235 mojo::ScopedSharedBufferHandle handle) { 225 mojo::ScopedSharedBufferHandle handle) {
236 DVLOG(1) << __func__ << " buffer_id: " << buffer_id; 226 DVLOG(1) << __func__ << " buffer_id: " << buffer_id;
237 DCHECK(io_task_runner_->BelongsToCurrentThread()); 227 DCHECK(io_thread_checker_.CalledOnValidThread());
238 DCHECK(handle.is_valid()); 228 DCHECK(handle.is_valid());
239 229
240 if (state_ != VIDEO_CAPTURE_STATE_STARTED) 230 if (state_ != VIDEO_CAPTURE_STATE_STARTED)
241 return; 231 return;
242 232
243 base::SharedMemoryHandle memory_handle; 233 base::SharedMemoryHandle memory_handle;
244 size_t memory_size = 0; 234 size_t memory_size = 0;
245 bool read_only_flag = false; 235 bool read_only_flag = false;
246 236
247 const MojoResult result = mojo::UnwrapSharedMemoryHandle( 237 const MojoResult result = mojo::UnwrapSharedMemoryHandle(
(...skipping 11 matching lines...) Expand all
259 client_buffers_ 249 client_buffers_
260 .insert(std::make_pair(buffer_id, 250 .insert(std::make_pair(buffer_id,
261 new ClientBuffer(std::move(shm), memory_size))) 251 new ClientBuffer(std::move(shm), memory_size)))
262 .second; 252 .second;
263 DCHECK(inserted); 253 DCHECK(inserted);
264 } 254 }
265 255
266 void VideoCaptureImpl::OnBufferReady(int32_t buffer_id, 256 void VideoCaptureImpl::OnBufferReady(int32_t buffer_id,
267 mojom::VideoFrameInfoPtr info) { 257 mojom::VideoFrameInfoPtr info) {
268 DVLOG(1) << __func__ << " buffer_id: " << buffer_id; 258 DVLOG(1) << __func__ << " buffer_id: " << buffer_id;
269 DCHECK(io_task_runner_->BelongsToCurrentThread()); 259 DCHECK(io_thread_checker_.CalledOnValidThread());
270 DCHECK_EQ(media::PIXEL_FORMAT_I420, info->pixel_format); 260 DCHECK_EQ(media::PIXEL_FORMAT_I420, info->pixel_format);
271 DCHECK_EQ(media::PIXEL_STORAGE_CPU, info->storage_type); 261 DCHECK_EQ(media::PIXEL_STORAGE_CPU, info->storage_type);
272 262
273 if (state_ != VIDEO_CAPTURE_STATE_STARTED || 263 if (state_ != VIDEO_CAPTURE_STATE_STARTED ||
274 info->pixel_format != media::PIXEL_FORMAT_I420 || 264 info->pixel_format != media::PIXEL_FORMAT_I420 ||
275 info->storage_type != media::PIXEL_STORAGE_CPU) { 265 info->storage_type != media::PIXEL_STORAGE_CPU) {
276 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, 266 GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id,
277 gpu::SyncToken(), -1.0); 267 gpu::SyncToken(), -1.0);
278 return; 268 return;
279 } 269 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 319
330 frame->metadata()->MergeInternalValuesFrom(info->metadata); 320 frame->metadata()->MergeInternalValuesFrom(info->metadata);
331 321
332 // TODO(qiangchen): Dive into the full code path to let frame metadata hold 322 // TODO(qiangchen): Dive into the full code path to let frame metadata hold
333 // reference time rather than using an extra parameter. 323 // reference time rather than using an extra parameter.
334 for (const auto& client : clients_) 324 for (const auto& client : clients_)
335 client.second.deliver_frame_cb.Run(frame, reference_time); 325 client.second.deliver_frame_cb.Run(frame, reference_time);
336 } 326 }
337 327
338 void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) { 328 void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) {
339 DCHECK(io_task_runner_->BelongsToCurrentThread()); 329 DCHECK(io_thread_checker_.CalledOnValidThread());
340 330
341 const auto& cb_iter = client_buffers_.find(buffer_id); 331 const auto& cb_iter = client_buffers_.find(buffer_id);
342 if (cb_iter != client_buffers_.end()) { 332 if (cb_iter != client_buffers_.end()) {
343 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef()) 333 DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef())
344 << "Instructed to delete buffer we are still using."; 334 << "Instructed to delete buffer we are still using.";
345 client_buffers_.erase(cb_iter); 335 client_buffers_.erase(cb_iter);
346 } 336 }
347 } 337 }
348 338
349 void VideoCaptureImpl::OnClientBufferFinished( 339 void VideoCaptureImpl::OnClientBufferFinished(
350 int buffer_id, 340 int buffer_id,
351 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, 341 const scoped_refptr<ClientBuffer>& /* ignored_buffer */,
352 const gpu::SyncToken& release_sync_token, 342 const gpu::SyncToken& release_sync_token,
353 double consumer_resource_utilization) { 343 double consumer_resource_utilization) {
354 DCHECK(io_task_runner_->BelongsToCurrentThread()); 344 DCHECK(io_thread_checker_.CalledOnValidThread());
355 GetVideoCaptureHost()->ReleaseBuffer( 345 GetVideoCaptureHost()->ReleaseBuffer(
356 device_id_, buffer_id, release_sync_token, consumer_resource_utilization); 346 device_id_, buffer_id, release_sync_token, consumer_resource_utilization);
357 } 347 }
358 348
359 void VideoCaptureImpl::StopDevice() { 349 void VideoCaptureImpl::StopDevice() {
360 DCHECK(io_task_runner_->BelongsToCurrentThread()); 350 DCHECK(io_thread_checker_.CalledOnValidThread());
361 if (state_ != VIDEO_CAPTURE_STATE_STARTED) 351 if (state_ != VIDEO_CAPTURE_STATE_STARTED)
362 return; 352 return;
363 state_ = VIDEO_CAPTURE_STATE_STOPPING; 353 state_ = VIDEO_CAPTURE_STATE_STOPPING;
364 GetVideoCaptureHost()->Stop(device_id_); 354 GetVideoCaptureHost()->Stop(device_id_);
365 params_.requested_format.frame_size.SetSize(0, 0); 355 params_.requested_format.frame_size.SetSize(0, 0);
366 } 356 }
367 357
368 void VideoCaptureImpl::RestartCapture() { 358 void VideoCaptureImpl::RestartCapture() {
369 DCHECK(io_task_runner_->BelongsToCurrentThread()); 359 DCHECK(io_thread_checker_.CalledOnValidThread());
370 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED); 360 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED);
371 361
372 int width = 0; 362 int width = 0;
373 int height = 0; 363 int height = 0;
374 clients_.insert(clients_pending_on_restart_.begin(), 364 clients_.insert(clients_pending_on_restart_.begin(),
375 clients_pending_on_restart_.end()); 365 clients_pending_on_restart_.end());
376 clients_pending_on_restart_.clear(); 366 clients_pending_on_restart_.clear();
377 for (const auto& client : clients_) { 367 for (const auto& client : clients_) {
378 width = std::max(width, 368 width = std::max(width,
379 client.second.params.requested_format.frame_size.width()); 369 client.second.params.requested_format.frame_size.width());
380 height = std::max( 370 height = std::max(
381 height, client.second.params.requested_format.frame_size.height()); 371 height, client.second.params.requested_format.frame_size.height());
382 } 372 }
383 params_.requested_format.frame_size.SetSize(width, height); 373 params_.requested_format.frame_size.SetSize(width, height);
384 DVLOG(1) << __func__ << " " << params_.requested_format.frame_size.ToString(); 374 DVLOG(1) << __func__ << " " << params_.requested_format.frame_size.ToString();
385 StartCaptureInternal(); 375 StartCaptureInternal();
386 } 376 }
387 377
388 void VideoCaptureImpl::StartCaptureInternal() { 378 void VideoCaptureImpl::StartCaptureInternal() {
389 DCHECK(io_task_runner_->BelongsToCurrentThread()); 379 DCHECK(io_thread_checker_.CalledOnValidThread());
390 DCHECK(device_id_);
391 380
392 GetVideoCaptureHost()->Start(device_id_, session_id_, params_, 381 GetVideoCaptureHost()->Start(device_id_, session_id_, params_,
393 observer_binding_.CreateInterfacePtrAndBind()); 382 observer_binding_.CreateInterfacePtrAndBind());
394 state_ = VIDEO_CAPTURE_STATE_STARTED; 383 state_ = VIDEO_CAPTURE_STATE_STARTED;
395 } 384 }
396 385
397 void VideoCaptureImpl::OnDeviceSupportedFormats( 386 void VideoCaptureImpl::OnDeviceSupportedFormats(
398 const VideoCaptureDeviceFormatsCB& callback, 387 const VideoCaptureDeviceFormatsCB& callback,
399 const media::VideoCaptureFormats& supported_formats) { 388 const media::VideoCaptureFormats& supported_formats) {
400 DCHECK(io_task_runner_->BelongsToCurrentThread()); 389 DCHECK(io_thread_checker_.CalledOnValidThread());
401 callback.Run(supported_formats); 390 callback.Run(supported_formats);
402 } 391 }
403 392
404 void VideoCaptureImpl::OnDeviceFormatsInUse( 393 void VideoCaptureImpl::OnDeviceFormatsInUse(
405 const VideoCaptureDeviceFormatsCB& callback, 394 const VideoCaptureDeviceFormatsCB& callback,
406 const media::VideoCaptureFormats& formats_in_use) { 395 const media::VideoCaptureFormats& formats_in_use) {
407 DCHECK(io_task_runner_->BelongsToCurrentThread()); 396 DCHECK(io_thread_checker_.CalledOnValidThread());
408 callback.Run(formats_in_use); 397 callback.Run(formats_in_use);
409 } 398 }
410 399
411 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { 400 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) {
412 DCHECK(io_task_runner_->BelongsToCurrentThread()); 401 DCHECK(io_thread_checker_.CalledOnValidThread());
413 402
414 const ClientInfoMap::iterator it = clients->find(client_id); 403 const ClientInfoMap::iterator it = clients->find(client_id);
415 if (it == clients->end()) 404 if (it == clients->end())
416 return false; 405 return false;
417 406
418 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); 407 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
419 clients->erase(it); 408 clients->erase(it);
420 return true; 409 return true;
421 } 410 }
422 411
423 mojom::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() { 412 mojom::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() {
424 DCHECK(io_task_runner_->BelongsToCurrentThread()); 413 DCHECK(io_thread_checker_.CalledOnValidThread());
425 if (video_capture_host_for_testing_) 414 if (video_capture_host_for_testing_)
426 return video_capture_host_for_testing_; 415 return video_capture_host_for_testing_;
427 416
428 if (!video_capture_host_.get()) { 417 if (!video_capture_host_.get())
429 DCHECK(message_filter_->channel()); 418 video_capture_host_.Bind(std::move(video_capture_host_info_));
430 auto interface_support =
431 message_filter_->channel()->GetAssociatedInterfaceSupport();
432 if (!interface_support)
433 return nullptr;
434 interface_support->GetRemoteAssociatedInterface(&video_capture_host_);
435 }
436 return video_capture_host_.get(); 419 return video_capture_host_.get();
437 }; 420 };
438 421
439 // static 422 // static
440 void VideoCaptureImpl::DidFinishConsumingFrame( 423 void VideoCaptureImpl::DidFinishConsumingFrame(
441 const media::VideoFrameMetadata* metadata, 424 const media::VideoFrameMetadata* metadata,
442 std::unique_ptr<gpu::SyncToken> release_sync_token, 425 std::unique_ptr<gpu::SyncToken> release_sync_token,
443 const BufferFinishedCallback& callback_to_io_thread) { 426 const BufferFinishedCallback& callback_to_io_thread) {
444 // Note: This function may be called on any thread by the VideoFrame 427 // Note: This function may be called on any thread by the VideoFrame
445 // destructor. |metadata| is still valid for read-access at this point. 428 // destructor. |metadata| is still valid for read-access at this point.
446 double consumer_resource_utilization = -1.0; 429 double consumer_resource_utilization = -1.0;
447 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, 430 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
448 &consumer_resource_utilization)) { 431 &consumer_resource_utilization)) {
449 consumer_resource_utilization = -1.0; 432 consumer_resource_utilization = -1.0;
450 } 433 }
451 434
452 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); 435 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization);
453 } 436 }
454 437
455 } // namespace content 438 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698