| OLD | NEW |
| 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 // Test application that simulates a cast sender - Data can be either generated | 5 // Test application that simulates a cast sender - Data can be either generated |
| 6 // or read from a file. | 6 // or read from a file. |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Sleep if that time has yet to elapse. | 249 // Sleep if that time has yet to elapse. |
| 250 base::TimeTicks now = clock_->NowTicks(); | 250 base::TimeTicks now = clock_->NowTicks(); |
| 251 base::TimeDelta video_frame_time = | 251 base::TimeDelta video_frame_time = |
| 252 base::TimeDelta::FromMilliseconds(kFrameTimerMs); | 252 base::TimeDelta::FromMilliseconds(kFrameTimerMs); |
| 253 base::TimeDelta elapsed_time = now - send_time_; | 253 base::TimeDelta elapsed_time = now - send_time_; |
| 254 if (elapsed_time < video_frame_time) { | 254 if (elapsed_time < video_frame_time) { |
| 255 VLOG(1) << "Wait" << (video_frame_time - elapsed_time).InMilliseconds(); | 255 VLOG(1) << "Wait" << (video_frame_time - elapsed_time).InMilliseconds(); |
| 256 test_app_thread_proxy_->PostDelayedTask( | 256 test_app_thread_proxy_->PostDelayedTask( |
| 257 FROM_HERE, | 257 FROM_HERE, |
| 258 base::Bind(&SendProcess::SendVideoFrameOnTime, | 258 base::Bind(&SendProcess::SendVideoFrameOnTime, |
| 259 base::Unretained(this), | 259 weak_factory_.GetWeakPtr(), |
| 260 video_frame), | 260 video_frame), |
| 261 video_frame_time - elapsed_time); | 261 video_frame_time - elapsed_time); |
| 262 } else { | 262 } else { |
| 263 test_app_thread_proxy_->PostTask( | 263 test_app_thread_proxy_->PostTask( |
| 264 FROM_HERE, | 264 FROM_HERE, |
| 265 base::Bind(&SendProcess::SendVideoFrameOnTime, | 265 base::Bind(&SendProcess::SendVideoFrameOnTime, |
| 266 base::Unretained(this), | 266 weak_factory_.GetWeakPtr(), |
| 267 video_frame)); | 267 video_frame)); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 void SendVideoFrameOnTime(scoped_refptr<media::VideoFrame> video_frame) { | 271 void SendVideoFrameOnTime(scoped_refptr<media::VideoFrame> video_frame) { |
| 272 send_time_ = clock_->NowTicks(); | 272 send_time_ = clock_->NowTicks(); |
| 273 frame_input_->InsertRawVideoFrame(video_frame, send_time_); | 273 frame_input_->InsertRawVideoFrame(video_frame, send_time_); |
| 274 test_app_thread_proxy_->PostTask( | 274 test_app_thread_proxy_->PostTask( |
| 275 FROM_HERE, base::Bind(&SendProcess::SendFrame, base::Unretained(this))); | 275 FROM_HERE, base::Bind(&SendProcess::SendFrame, base::Unretained(this))); |
| 276 } | 276 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 } // namespace cast | 292 } // namespace cast |
| 293 } // namespace media | 293 } // namespace media |
| 294 | 294 |
| 295 namespace { | 295 namespace { |
| 296 void UpdateCastTransportStatus( | 296 void UpdateCastTransportStatus( |
| 297 media::cast::transport::CastTransportStatus status) {} | 297 media::cast::transport::CastTransportStatus status) {} |
| 298 | 298 |
| 299 void InitializationResult(media::cast::CastInitializationStatus result) { | 299 void InitializationResult(media::cast::CastInitializationStatus result) { |
| 300 CHECK_EQ(result, media::cast::STATUS_INITIALIZED); | 300 bool end_result = result == media::cast::STATUS_AUDIO_INITIALIZED || |
| 301 VLOG(1) << "Cast Sender initialized"; | 301 result == media::cast::STATUS_VIDEO_INITIALIZED; |
| 302 CHECK(end_result); |
| 302 } | 303 } |
| 303 | 304 |
| 304 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { | 305 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { |
| 305 net::IPAddressNumber ip_number; | 306 net::IPAddressNumber ip_number; |
| 306 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); | 307 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); |
| 307 return net::IPEndPoint(ip_number, port); | 308 return net::IPEndPoint(ip_number, port); |
| 308 } | 309 } |
| 309 | 310 |
| 310 } // namespace | 311 } // namespace |
| 311 | 312 |
| 312 int main(int argc, char** argv) { | 313 int main(int argc, char** argv) { |
| 313 base::AtExitManager at_exit; | 314 base::AtExitManager at_exit; |
| 314 VLOG(1) << "Cast Sender"; | |
| 315 base::Thread test_thread("Cast sender test app thread"); | 315 base::Thread test_thread("Cast sender test app thread"); |
| 316 base::Thread audio_thread("Cast audio encoder thread"); | 316 base::Thread audio_thread("Cast audio encoder thread"); |
| 317 base::Thread video_thread("Cast video encoder thread"); | 317 base::Thread video_thread("Cast video encoder thread"); |
| 318 test_thread.Start(); | 318 test_thread.Start(); |
| 319 audio_thread.Start(); | 319 audio_thread.Start(); |
| 320 video_thread.Start(); | 320 video_thread.Start(); |
| 321 | 321 |
| 322 scoped_ptr<base::TickClock> clock(new base::DefaultTickClock()); | 322 scoped_ptr<base::TickClock> clock(new base::DefaultTickClock()); |
| 323 base::MessageLoopForIO io_message_loop; | 323 base::MessageLoopForIO io_message_loop; |
| 324 | 324 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 clock.Pass(), | 356 clock.Pass(), |
| 357 io_message_loop.message_loop_proxy(), | 357 io_message_loop.message_loop_proxy(), |
| 358 audio_thread.message_loop_proxy(), | 358 audio_thread.message_loop_proxy(), |
| 359 NULL, | 359 NULL, |
| 360 video_thread.message_loop_proxy(), | 360 video_thread.message_loop_proxy(), |
| 361 NULL, | 361 NULL, |
| 362 io_message_loop.message_loop_proxy(), | 362 io_message_loop.message_loop_proxy(), |
| 363 media::cast::GetDefaultCastSenderLoggingConfig())); | 363 media::cast::GetDefaultCastSenderLoggingConfig())); |
| 364 | 364 |
| 365 scoped_ptr<media::cast::CastSender> cast_sender( | 365 scoped_ptr<media::cast::CastSender> cast_sender( |
| 366 media::cast::CastSender::CreateCastSender( | 366 media::cast::CastSender::Create(cast_environment, |
| 367 cast_environment, | 367 base::Bind(&InitializationResult), |
| 368 &audio_config, | 368 transport_sender.get())); |
| 369 &video_config, | 369 |
| 370 NULL, // gpu_factories. | 370 cast_sender->InitializeVideo(video_config, NULL); |
| 371 base::Bind(&InitializationResult), | 371 cast_sender->InitializeAudio(audio_config); |
| 372 transport_sender.get())); | |
| 373 | 372 |
| 374 transport_sender->SetPacketReceiver(cast_sender->packet_receiver()); | 373 transport_sender->SetPacketReceiver(cast_sender->packet_receiver()); |
| 375 | 374 |
| 376 media::cast::FrameInput* frame_input = cast_sender->frame_input(); | 375 media::cast::FrameInput* frame_input = cast_sender->frame_input(); |
| 377 scoped_ptr<media::cast::SendProcess> send_process( | 376 scoped_ptr<media::cast::SendProcess> send_process( |
| 378 new media::cast::SendProcess(test_thread.message_loop_proxy(), | 377 new media::cast::SendProcess(test_thread.message_loop_proxy(), |
| 379 cast_environment->Clock(), | 378 cast_environment->Clock(), |
| 380 video_config, | 379 video_config, |
| 381 frame_input)); | 380 frame_input)); |
| 382 | 381 |
| 383 test_thread.message_loop_proxy()->PostTask( | 382 test_thread.message_loop_proxy()->PostTask( |
| 384 FROM_HERE, | 383 FROM_HERE, |
| 385 base::Bind(&media::cast::SendProcess::SendFrame, | 384 base::Bind(&media::cast::SendProcess::SendFrame, |
| 386 base::Unretained(send_process.get()))); | 385 base::Unretained(send_process.get()))); |
| 387 | 386 |
| 388 io_message_loop.Run(); | 387 io_message_loop.Run(); |
| 389 return 0; | 388 return 0; |
| 390 } | 389 } |
| OLD | NEW |