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

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

Issue 2377163002: VideoCaptureImpl cleanup: merge ctor+Init() and DeInit()+dtor. (Closed)
Patch Set: miu@s comment on passing |io_task_runner| argument 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 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_(std::move(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));
117 } 122 }
118 123
119 VideoCaptureImpl::~VideoCaptureImpl() { 124 VideoCaptureImpl::~VideoCaptureImpl() {
120 DCHECK(io_task_runner_->BelongsToCurrentThread()); 125 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) 126 if (state_ == VIDEO_CAPTURE_STATE_STARTED)
136 Send(new VideoCaptureHostMsg_Stop(device_id_)); 127 Send(new VideoCaptureHostMsg_Stop(device_id_));
137 message_filter_->RemoveDelegate(this); 128 message_filter_->RemoveDelegate(this);
138 } 129 }
139 130
140 void VideoCaptureImpl::SuspendCapture(bool suspend) { 131 void VideoCaptureImpl::SuspendCapture(bool suspend) {
141 DCHECK(io_task_runner_->BelongsToCurrentThread()); 132 DCHECK(io_task_runner_->BelongsToCurrentThread());
142 Send(suspend ? static_cast<IPC::Message*>( 133 Send(suspend ? static_cast<IPC::Message*>(
143 new VideoCaptureHostMsg_Pause(device_id_)) 134 new VideoCaptureHostMsg_Pause(device_id_))
144 : static_cast<IPC::Message*>(new VideoCaptureHostMsg_Resume( 135 : static_cast<IPC::Message*>(new VideoCaptureHostMsg_Resume(
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 double consumer_resource_utilization = -1.0; 562 double consumer_resource_utilization = -1.0;
572 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, 563 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
573 &consumer_resource_utilization)) { 564 &consumer_resource_utilization)) {
574 consumer_resource_utilization = -1.0; 565 consumer_resource_utilization = -1.0;
575 } 566 }
576 567
577 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); 568 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization);
578 } 569 }
579 570
580 } // 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