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

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

Issue 2377163002: VideoCaptureImpl cleanup: merge ctor+Init() and DeInit()+dtor. (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.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 int32_t strides_[media::VideoFrame::kMaxPlanes]; 98 int32_t strides_[media::VideoFrame::kMaxPlanes];
99 99
100 DISALLOW_COPY_AND_ASSIGN(ClientBuffer2); 100 DISALLOW_COPY_AND_ASSIGN(ClientBuffer2);
101 }; 101 };
102 102
103 VideoCaptureImpl::ClientInfo::ClientInfo() {} 103 VideoCaptureImpl::ClientInfo::ClientInfo() {}
104 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default; 104 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default;
105 VideoCaptureImpl::ClientInfo::~ClientInfo() {} 105 VideoCaptureImpl::ClientInfo::~ClientInfo() {}
106 106
107 VideoCaptureImpl::VideoCaptureImpl( 107 VideoCaptureImpl::VideoCaptureImpl(
108 const media::VideoCaptureSessionId session_id, 108 media::VideoCaptureSessionId session_id,
109 VideoCaptureMessageFilter* filter) 109 VideoCaptureMessageFilter* filter,
110 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
110 : message_filter_(filter), 111 : message_filter_(filter),
111 device_id_(0), 112 device_id_(0),
112 session_id_(session_id), 113 session_id_(session_id),
113 suspended_(false), 114 suspended_(false),
114 state_(VIDEO_CAPTURE_STATE_STOPPED), 115 state_(VIDEO_CAPTURE_STATE_STOPPED),
116 io_task_runner_(io_task_runner),
115 weak_factory_(this) { 117 weak_factory_(this) {
116 DCHECK(filter); 118 DCHECK(filter);
119 io_task_runner_->PostTask(FROM_HERE,
120 base::Bind(&VideoCaptureMessageFilter::AddDelegate,
121 message_filter_, this));
122 // message_filter_->AddDelegate(this);
chfremer 2016/09/28 23:28:09 Can be removed?
mcasas 2016/09/28 23:49:52 oops, yeah, done.
117 } 123 }
118 124
119 VideoCaptureImpl::~VideoCaptureImpl() { 125 VideoCaptureImpl::~VideoCaptureImpl() {
120 DCHECK(io_task_runner_->BelongsToCurrentThread()); 126 DCHECK(io_task_runner_->BelongsToCurrentThread());
121 }
122
123 void VideoCaptureImpl::Init() {
124 // For creating callbacks in unittest, this class may be constructed from a
125 // different thread than the IO thread, e.g. wherever unittest runs on.
126 // Therefore, this function should define the thread ownership.
127 #if DCHECK_IS_ON()
128 io_task_runner_ = base::ThreadTaskRunnerHandle::Get();
129 #endif
130 message_filter_->AddDelegate(this);
131 }
132
133 void VideoCaptureImpl::DeInit() {
134 DCHECK(io_task_runner_->BelongsToCurrentThread());
135 if (state_ == VIDEO_CAPTURE_STATE_STARTED) 127 if (state_ == VIDEO_CAPTURE_STATE_STARTED)
136 Send(new VideoCaptureHostMsg_Stop(device_id_)); 128 Send(new VideoCaptureHostMsg_Stop(device_id_));
137 message_filter_->RemoveDelegate(this); 129 message_filter_->RemoveDelegate(this);
138 } 130 }
139 131
140 void VideoCaptureImpl::SuspendCapture(bool suspend) { 132 void VideoCaptureImpl::SuspendCapture(bool suspend) {
141 DCHECK(io_task_runner_->BelongsToCurrentThread()); 133 DCHECK(io_task_runner_->BelongsToCurrentThread());
142 Send(suspend ? static_cast<IPC::Message*>( 134 Send(suspend ? static_cast<IPC::Message*>(
143 new VideoCaptureHostMsg_Pause(device_id_)) 135 new VideoCaptureHostMsg_Pause(device_id_))
144 : static_cast<IPC::Message*>(new VideoCaptureHostMsg_Resume( 136 : static_cast<IPC::Message*>(new VideoCaptureHostMsg_Resume(
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 double consumer_resource_utilization = -1.0; 562 double consumer_resource_utilization = -1.0;
571 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, 563 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
572 &consumer_resource_utilization)) { 564 &consumer_resource_utilization)) {
573 consumer_resource_utilization = -1.0; 565 consumer_resource_utilization = -1.0;
574 } 566 }
575 567
576 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); 568 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization);
577 } 569 }
578 570
579 } // namespace content 571 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698