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

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

Issue 2396413002: VideoCaptureImpl: check that there's still a channel in ~VideoCaptureImpl() before sending (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
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 VideoCaptureImpl::ClientInfo::~ClientInfo() {} 105 VideoCaptureImpl::ClientInfo::~ClientInfo() {}
106 106
107 VideoCaptureImpl::VideoCaptureImpl( 107 VideoCaptureImpl::VideoCaptureImpl(
108 media::VideoCaptureSessionId session_id, 108 media::VideoCaptureSessionId session_id,
109 VideoCaptureMessageFilter* filter, 109 VideoCaptureMessageFilter* filter,
110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
111 : message_filter_(filter), 111 : message_filter_(filter),
112 device_id_(0), 112 device_id_(0),
113 session_id_(session_id), 113 session_id_(session_id),
114 video_capture_host_for_testing_(nullptr), 114 video_capture_host_for_testing_(nullptr),
115 suspended_(false),
116 state_(VIDEO_CAPTURE_STATE_STOPPED), 115 state_(VIDEO_CAPTURE_STATE_STOPPED),
117 io_task_runner_(std::move(io_task_runner)), 116 io_task_runner_(std::move(io_task_runner)),
118 weak_factory_(this) { 117 weak_factory_(this) {
119 DCHECK(filter); 118 DCHECK(filter);
120 io_task_runner_->PostTask(FROM_HERE, 119 io_task_runner_->PostTask(FROM_HERE,
121 base::Bind(&VideoCaptureMessageFilter::AddDelegate, 120 base::Bind(&VideoCaptureMessageFilter::AddDelegate,
122 message_filter_, this)); 121 message_filter_, this));
123 } 122 }
124 123
125 VideoCaptureImpl::~VideoCaptureImpl() { 124 VideoCaptureImpl::~VideoCaptureImpl() {
126 DCHECK(io_task_runner_->BelongsToCurrentThread()); 125 DCHECK(io_task_runner_->BelongsToCurrentThread());
127 if (state_ == VIDEO_CAPTURE_STATE_STARTED) 126 if (state_ == VIDEO_CAPTURE_STATE_STARTED && GetVideoCaptureHost())
128 GetVideoCaptureHost()->Stop(device_id_); 127 GetVideoCaptureHost()->Stop(device_id_);
129 message_filter_->RemoveDelegate(this); 128 message_filter_->RemoveDelegate(this);
130 } 129 }
131 130
132 void VideoCaptureImpl::SuspendCapture(bool suspend) { 131 void VideoCaptureImpl::SuspendCapture(bool suspend) {
133 DCHECK(io_task_runner_->BelongsToCurrentThread()); 132 DCHECK(io_task_runner_->BelongsToCurrentThread());
134 if (suspend) 133 if (suspend)
135 GetVideoCaptureHost()->Pause(device_id_); 134 GetVideoCaptureHost()->Pause(device_id_);
136 else 135 else
137 GetVideoCaptureHost()->Resume(device_id_, session_id_, params_); 136 GetVideoCaptureHost()->Resume(device_id_, session_id_, params_);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 296
298 void VideoCaptureImpl::OnBufferReceived( 297 void VideoCaptureImpl::OnBufferReceived(
299 int buffer_id, 298 int buffer_id,
300 base::TimeDelta timestamp, 299 base::TimeDelta timestamp,
301 const base::DictionaryValue& metadata, 300 const base::DictionaryValue& metadata,
302 media::VideoPixelFormat pixel_format, 301 media::VideoPixelFormat pixel_format,
303 media::VideoFrame::StorageType storage_type, 302 media::VideoFrame::StorageType storage_type,
304 const gfx::Size& coded_size, 303 const gfx::Size& coded_size,
305 const gfx::Rect& visible_rect) { 304 const gfx::Rect& visible_rect) {
306 DCHECK(io_task_runner_->BelongsToCurrentThread()); 305 DCHECK(io_task_runner_->BelongsToCurrentThread());
307 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_ || 306 if (state_ != VIDEO_CAPTURE_STATE_STARTED ||
308 pixel_format != media::PIXEL_FORMAT_I420 || 307 pixel_format != media::PIXEL_FORMAT_I420 ||
309 (storage_type != media::VideoFrame::STORAGE_SHMEM && 308 (storage_type != media::VideoFrame::STORAGE_SHMEM &&
310 storage_type != media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS)) { 309 storage_type != media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS)) {
311 // Crash in debug builds since the host should not have provided a buffer 310 // Crash in debug builds since the host should not have provided a buffer
312 // with an unsupported pixel format or storage type. 311 // with an unsupported pixel format or storage type.
313 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); 312 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format);
314 DCHECK(storage_type == media::VideoFrame::STORAGE_SHMEM || 313 DCHECK(storage_type == media::VideoFrame::STORAGE_SHMEM ||
315 storage_type == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS); 314 storage_type == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS);
316 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 315 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id,
317 gpu::SyncToken(), -1.0)); 316 gpu::SyncToken(), -1.0));
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 state_ = VIDEO_CAPTURE_STATE_STARTED; 535 state_ = VIDEO_CAPTURE_STATE_STARTED;
537 } 536 }
538 537
539 void VideoCaptureImpl::Send(IPC::Message* message) { 538 void VideoCaptureImpl::Send(IPC::Message* message) {
540 DCHECK(io_task_runner_->BelongsToCurrentThread()); 539 DCHECK(io_task_runner_->BelongsToCurrentThread());
541 message_filter_->Send(message); 540 message_filter_->Send(message);
542 } 541 }
543 542
544 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { 543 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) {
545 DCHECK(io_task_runner_->BelongsToCurrentThread()); 544 DCHECK(io_task_runner_->BelongsToCurrentThread());
546 bool found = false;
547 545
548 const ClientInfoMap::iterator it = clients->find(client_id); 546 const ClientInfoMap::iterator it = clients->find(client_id);
549 if (it != clients->end()) { 547 if (it == clients->end())
550 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); 548 return false;
551 clients->erase(it); 549
552 found = true; 550 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
553 } 551 clients->erase(it);
554 return found; 552 return true;
555 } 553 }
556 554
557 mojom::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() { 555 mojom::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() {
558 DCHECK(io_task_runner_->BelongsToCurrentThread()); 556 DCHECK(io_task_runner_->BelongsToCurrentThread());
559 if (video_capture_host_for_testing_) 557 if (video_capture_host_for_testing_)
560 return video_capture_host_for_testing_; 558 return video_capture_host_for_testing_;
561 559
562 if (!video_capture_host_.get()) { 560 if (!video_capture_host_.get()) {
563 DCHECK(message_filter_->channel()); 561 DCHECK(message_filter_->channel());
564 message_filter_->channel() 562 auto interface_support =
565 ->GetAssociatedInterfaceSupport() 563 message_filter_->channel()->GetAssociatedInterfaceSupport();
566 ->GetRemoteAssociatedInterface(&video_capture_host_); 564 if (!interface_support)
565 return nullptr;
566 interface_support->GetRemoteAssociatedInterface(&video_capture_host_);
567 } 567 }
568 return video_capture_host_.get(); 568 return video_capture_host_.get();
569 }; 569 };
570 570
571 // static 571 // static
572 void VideoCaptureImpl::DidFinishConsumingFrame( 572 void VideoCaptureImpl::DidFinishConsumingFrame(
573 const media::VideoFrameMetadata* metadata, 573 const media::VideoFrameMetadata* metadata,
574 std::unique_ptr<gpu::SyncToken> release_sync_token, 574 std::unique_ptr<gpu::SyncToken> release_sync_token,
575 const BufferFinishedCallback& callback_to_io_thread) { 575 const BufferFinishedCallback& callback_to_io_thread) {
576 // Note: This function may be called on any thread by the VideoFrame 576 // Note: This function may be called on any thread by the VideoFrame
577 // destructor. |metadata| is still valid for read-access at this point. 577 // destructor. |metadata| is still valid for read-access at this point.
578 double consumer_resource_utilization = -1.0; 578 double consumer_resource_utilization = -1.0;
579 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, 579 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
580 &consumer_resource_utilization)) { 580 &consumer_resource_utilization)) {
581 consumer_resource_utilization = -1.0; 581 consumer_resource_utilization = -1.0;
582 } 582 }
583 583
584 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); 584 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization);
585 } 585 }
586 586
587 } // namespace content 587 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698