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

Side by Side Diff: chrome/renderer/media/cast_session_delegate.cc

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/renderer/media/cast_session_delegate.h" 5 #include "chrome/renderer/media/cast_session_delegate.h"
6 6
7 #include <utility>
8
7 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
8 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
12 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
13 #include "build/build_config.h" 15 #include "build/build_config.h"
14 #include "chrome/renderer/media/cast_threads.h" 16 #include "chrome/renderer/media/cast_threads.h"
15 #include "chrome/renderer/media/cast_transport_sender_ipc.h" 17 #include "chrome/renderer/media/cast_transport_sender_ipc.h"
16 #include "components/version_info/version_info.h" 18 #include "components/version_info/version_info.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const net::IPEndPoint& local_endpoint, 60 const net::IPEndPoint& local_endpoint,
59 const net::IPEndPoint& remote_endpoint, 61 const net::IPEndPoint& remote_endpoint,
60 scoped_ptr<base::DictionaryValue> options, 62 scoped_ptr<base::DictionaryValue> options,
61 const ErrorCallback& error_callback) { 63 const ErrorCallback& error_callback) {
62 DCHECK(io_task_runner_->BelongsToCurrentThread()); 64 DCHECK(io_task_runner_->BelongsToCurrentThread());
63 65
64 // CastSender uses the renderer's IO thread as the main thread. This reduces 66 // CastSender uses the renderer's IO thread as the main thread. This reduces
65 // thread hopping for incoming video frames and outgoing network packets. 67 // thread hopping for incoming video frames and outgoing network packets.
66 // TODO(hubbe): Create cast environment in ctor instead. 68 // TODO(hubbe): Create cast environment in ctor instead.
67 cast_environment_ = new CastEnvironment( 69 cast_environment_ = new CastEnvironment(
68 scoped_ptr<base::TickClock>(new base::DefaultTickClock()).Pass(), 70 scoped_ptr<base::TickClock>(new base::DefaultTickClock()),
69 base::ThreadTaskRunnerHandle::Get(), 71 base::ThreadTaskRunnerHandle::Get(),
70 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(), 72 g_cast_threads.Get().GetAudioEncodeMessageLoopProxy(),
71 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy()); 73 g_cast_threads.Get().GetVideoEncodeMessageLoopProxy());
72 74
73 // Rationale for using unretained: The callback cannot be called after the 75 // Rationale for using unretained: The callback cannot be called after the
74 // destruction of CastTransportSenderIPC, and they both share the same thread. 76 // destruction of CastTransportSenderIPC, and they both share the same thread.
75 cast_transport_.reset(new CastTransportSenderIPC( 77 cast_transport_.reset(new CastTransportSenderIPC(
76 local_endpoint, 78 local_endpoint, remote_endpoint, std::move(options),
77 remote_endpoint,
78 options.Pass(),
79 base::Bind(&CastSessionDelegateBase::ReceivePacket, 79 base::Bind(&CastSessionDelegateBase::ReceivePacket,
80 base::Unretained(this)), 80 base::Unretained(this)),
81 base::Bind(&CastSessionDelegateBase::StatusNotificationCB, 81 base::Bind(&CastSessionDelegateBase::StatusNotificationCB,
82 base::Unretained(this), error_callback), 82 base::Unretained(this), error_callback),
83 base::Bind(&media::cast::LogEventDispatcher::DispatchBatchOfEvents, 83 base::Bind(&media::cast::LogEventDispatcher::DispatchBatchOfEvents,
84 base::Unretained(cast_environment_->logger())))); 84 base::Unretained(cast_environment_->logger()))));
85 } 85 }
86 86
87 void CastSessionDelegateBase::StatusNotificationCB( 87 void CastSessionDelegateBase::StatusNotificationCB(
88 const ErrorCallback& error_callback, 88 const ErrorCallback& error_callback,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 create_video_encode_mem_cb); 156 create_video_encode_mem_cb);
157 } 157 }
158 158
159 159
160 void CastSessionDelegate::StartUDP( 160 void CastSessionDelegate::StartUDP(
161 const net::IPEndPoint& local_endpoint, 161 const net::IPEndPoint& local_endpoint,
162 const net::IPEndPoint& remote_endpoint, 162 const net::IPEndPoint& remote_endpoint,
163 scoped_ptr<base::DictionaryValue> options, 163 scoped_ptr<base::DictionaryValue> options,
164 const ErrorCallback& error_callback) { 164 const ErrorCallback& error_callback) {
165 DCHECK(io_task_runner_->BelongsToCurrentThread()); 165 DCHECK(io_task_runner_->BelongsToCurrentThread());
166 CastSessionDelegateBase::StartUDP(local_endpoint, 166 CastSessionDelegateBase::StartUDP(local_endpoint, remote_endpoint,
167 remote_endpoint, 167 std::move(options), error_callback);
168 options.Pass(),
169 error_callback);
170 event_subscribers_.reset( 168 event_subscribers_.reset(
171 new media::cast::RawEventSubscriberBundle(cast_environment_)); 169 new media::cast::RawEventSubscriberBundle(cast_environment_));
172 170
173 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get()); 171 cast_sender_ = CastSender::Create(cast_environment_, cast_transport_.get());
174 } 172 }
175 173
176 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) { 174 void CastSessionDelegate::ToggleLogging(bool is_audio, bool enable) {
177 DCHECK(io_task_runner_->BelongsToCurrentThread()); 175 DCHECK(io_task_runner_->BelongsToCurrentThread());
178 if (!event_subscribers_.get()) 176 if (!event_subscribers_.get())
179 return; 177 return;
180 178
181 if (enable) 179 if (enable)
182 event_subscribers_->AddEventSubscribers(is_audio); 180 event_subscribers_->AddEventSubscribers(is_audio);
183 else 181 else
184 event_subscribers_->RemoveEventSubscribers(is_audio); 182 event_subscribers_->RemoveEventSubscribers(is_audio);
185 } 183 }
186 184
187 void CastSessionDelegate::GetEventLogsAndReset( 185 void CastSessionDelegate::GetEventLogsAndReset(
188 bool is_audio, 186 bool is_audio,
189 const std::string& extra_data, 187 const std::string& extra_data,
190 const EventLogsCallback& callback) { 188 const EventLogsCallback& callback) {
191 DCHECK(io_task_runner_->BelongsToCurrentThread()); 189 DCHECK(io_task_runner_->BelongsToCurrentThread());
192 190
193 if (!event_subscribers_.get()) { 191 if (!event_subscribers_.get()) {
194 callback.Run(make_scoped_ptr(new base::BinaryValue).Pass()); 192 callback.Run(make_scoped_ptr(new base::BinaryValue));
195 return; 193 return;
196 } 194 }
197 195
198 media::cast::EncodingEventSubscriber* subscriber = 196 media::cast::EncodingEventSubscriber* subscriber =
199 event_subscribers_->GetEncodingEventSubscriber(is_audio); 197 event_subscribers_->GetEncodingEventSubscriber(is_audio);
200 if (!subscriber) { 198 if (!subscriber) {
201 callback.Run(make_scoped_ptr(new base::BinaryValue).Pass()); 199 callback.Run(make_scoped_ptr(new base::BinaryValue));
202 return; 200 return;
203 } 201 }
204 202
205 media::cast::proto::LogMetadata metadata; 203 media::cast::proto::LogMetadata metadata;
206 media::cast::FrameEventList frame_events; 204 media::cast::FrameEventList frame_events;
207 media::cast::PacketEventList packet_events; 205 media::cast::PacketEventList packet_events;
208 206
209 subscriber->GetEventsAndReset(&metadata, &frame_events, &packet_events); 207 subscriber->GetEventsAndReset(&metadata, &frame_events, &packet_events);
210 208
211 if (!extra_data.empty()) 209 if (!extra_data.empty())
212 metadata.set_extra_data(extra_data); 210 metadata.set_extra_data(extra_data);
213 media::cast::proto::GeneralDescription* gen_desc = 211 media::cast::proto::GeneralDescription* gen_desc =
214 metadata.mutable_general_description(); 212 metadata.mutable_general_description();
215 gen_desc->set_product(version_info::GetProductName()); 213 gen_desc->set_product(version_info::GetProductName());
216 gen_desc->set_product_version(version_info::GetVersionNumber()); 214 gen_desc->set_product_version(version_info::GetVersionNumber());
217 gen_desc->set_os(version_info::GetOSType()); 215 gen_desc->set_os(version_info::GetOSType());
218 216
219 scoped_ptr<char[]> serialized_log(new char[media::cast::kMaxSerializedBytes]); 217 scoped_ptr<char[]> serialized_log(new char[media::cast::kMaxSerializedBytes]);
220 int output_bytes; 218 int output_bytes;
221 bool success = media::cast::SerializeEvents(metadata, 219 bool success = media::cast::SerializeEvents(metadata,
222 frame_events, 220 frame_events,
223 packet_events, 221 packet_events,
224 true, 222 true,
225 media::cast::kMaxSerializedBytes, 223 media::cast::kMaxSerializedBytes,
226 serialized_log.get(), 224 serialized_log.get(),
227 &output_bytes); 225 &output_bytes);
228 226
229 if (!success) { 227 if (!success) {
230 DVLOG(2) << "Failed to serialize event log."; 228 DVLOG(2) << "Failed to serialize event log.";
231 callback.Run(make_scoped_ptr(new base::BinaryValue).Pass()); 229 callback.Run(make_scoped_ptr(new base::BinaryValue));
232 return; 230 return;
233 } 231 }
234 232
235 DVLOG(2) << "Serialized log length: " << output_bytes; 233 DVLOG(2) << "Serialized log length: " << output_bytes;
236 234
237 scoped_ptr<base::BinaryValue> blob( 235 scoped_ptr<base::BinaryValue> blob(
238 new base::BinaryValue(serialized_log.Pass(), output_bytes)); 236 new base::BinaryValue(std::move(serialized_log), output_bytes));
239 callback.Run(blob.Pass()); 237 callback.Run(std::move(blob));
240 } 238 }
241 239
242 void CastSessionDelegate::GetStatsAndReset(bool is_audio, 240 void CastSessionDelegate::GetStatsAndReset(bool is_audio,
243 const StatsCallback& callback) { 241 const StatsCallback& callback) {
244 DCHECK(io_task_runner_->BelongsToCurrentThread()); 242 DCHECK(io_task_runner_->BelongsToCurrentThread());
245 243
246 if (!event_subscribers_.get()) { 244 if (!event_subscribers_.get()) {
247 callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass()); 245 callback.Run(make_scoped_ptr(new base::DictionaryValue));
248 return; 246 return;
249 } 247 }
250 248
251 media::cast::StatsEventSubscriber* subscriber = 249 media::cast::StatsEventSubscriber* subscriber =
252 event_subscribers_->GetStatsEventSubscriber(is_audio); 250 event_subscribers_->GetStatsEventSubscriber(is_audio);
253 if (!subscriber) { 251 if (!subscriber) {
254 callback.Run(make_scoped_ptr(new base::DictionaryValue).Pass()); 252 callback.Run(make_scoped_ptr(new base::DictionaryValue));
255 return; 253 return;
256 } 254 }
257 255
258 scoped_ptr<base::DictionaryValue> stats = subscriber->GetStats(); 256 scoped_ptr<base::DictionaryValue> stats = subscriber->GetStats();
259 subscriber->Reset(); 257 subscriber->Reset();
260 258
261 callback.Run(stats.Pass()); 259 callback.Run(std::move(stats));
262 } 260 }
263 261
264 void CastSessionDelegate::OnOperationalStatusChange( 262 void CastSessionDelegate::OnOperationalStatusChange(
265 bool is_for_audio, 263 bool is_for_audio,
266 const ErrorCallback& error_callback, 264 const ErrorCallback& error_callback,
267 media::cast::OperationalStatus status) { 265 media::cast::OperationalStatus status) {
268 DCHECK(cast_sender_); 266 DCHECK(cast_sender_);
269 267
270 switch (status) { 268 switch (status) {
271 case media::cast::STATUS_UNINITIALIZED: 269 case media::cast::STATUS_UNINITIALIZED:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 error_callback.Run(base::StringPrintf("%s codec runtime error.", 305 error_callback.Run(base::StringPrintf("%s codec runtime error.",
308 is_for_audio ? "Audio" : "Video")); 306 is_for_audio ? "Audio" : "Video"));
309 break; 307 break;
310 } 308 }
311 } 309 }
312 310
313 void CastSessionDelegate::ReceivePacket( 311 void CastSessionDelegate::ReceivePacket(
314 scoped_ptr<media::cast::Packet> packet) { 312 scoped_ptr<media::cast::Packet> packet) {
315 // Do nothing (frees packet) 313 // Do nothing (frees packet)
316 } 314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698