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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 base::WeakPtrFactory<SendProcess> weak_factory_; | 310 base::WeakPtrFactory<SendProcess> weak_factory_; |
311 }; | 311 }; |
312 | 312 |
313 } // namespace cast | 313 } // namespace cast |
314 } // namespace media | 314 } // namespace media |
315 | 315 |
316 namespace { | 316 namespace { |
317 void UpdateCastTransportStatus( | 317 void UpdateCastTransportStatus( |
318 media::cast::transport::CastTransportStatus status) {} | 318 media::cast::transport::CastTransportStatus status) {} |
319 | 319 |
| 320 void LogRawEvents( |
| 321 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, |
| 322 const std::vector<media::cast::PacketEvent>& packet_events) { |
| 323 VLOG(1) << "Got packet events from transport, size: " << packet_events.size(); |
| 324 for (std::vector<media::cast::PacketEvent>::const_iterator it = |
| 325 packet_events.begin(); |
| 326 it != packet_events.end(); |
| 327 ++it) { |
| 328 cast_environment->Logging()->InsertPacketEvent(it->timestamp, |
| 329 it->type, |
| 330 it->rtp_timestamp, |
| 331 it->frame_id, |
| 332 it->packet_id, |
| 333 it->max_packet_id, |
| 334 it->size); |
| 335 } |
| 336 } |
| 337 |
320 void InitializationResult(media::cast::CastInitializationStatus result) { | 338 void InitializationResult(media::cast::CastInitializationStatus result) { |
321 CHECK_EQ(result, media::cast::STATUS_INITIALIZED); | 339 CHECK_EQ(result, media::cast::STATUS_INITIALIZED); |
322 VLOG(1) << "Cast Sender initialized"; | 340 VLOG(1) << "Cast Sender initialized"; |
323 } | 341 } |
324 | 342 |
325 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { | 343 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { |
326 net::IPAddressNumber ip_number; | 344 net::IPAddressNumber ip_number; |
327 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); | 345 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); |
328 return net::IPEndPoint(ip_number, port); | 346 return net::IPEndPoint(ip_number, port); |
329 } | 347 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 media::cast::GetPort(&remote_port); | 421 media::cast::GetPort(&remote_port); |
404 | 422 |
405 std::string remote_ip_address = | 423 std::string remote_ip_address = |
406 media::cast::GetIpAddress("Enter receiver IP."); | 424 media::cast::GetIpAddress("Enter receiver IP."); |
407 | 425 |
408 media::cast::AudioSenderConfig audio_config = | 426 media::cast::AudioSenderConfig audio_config = |
409 media::cast::GetAudioSenderConfig(); | 427 media::cast::GetAudioSenderConfig(); |
410 media::cast::VideoSenderConfig video_config = | 428 media::cast::VideoSenderConfig video_config = |
411 media::cast::GetVideoSenderConfig(); | 429 media::cast::GetVideoSenderConfig(); |
412 | 430 |
| 431 // Enable main and send side threads only. Enable raw event logging. |
| 432 // Running transport on the main thread. |
| 433 media::cast::CastLoggingConfig logging_config; |
| 434 logging_config.enable_raw_data_collection = true; |
| 435 |
413 // Setting up transport config. | 436 // Setting up transport config. |
414 media::cast::transport::CastTransportAudioConfig transport_audio_config; | 437 media::cast::transport::CastTransportAudioConfig transport_audio_config; |
415 media::cast::transport::CastTransportVideoConfig transport_video_config; | 438 media::cast::transport::CastTransportVideoConfig transport_video_config; |
416 net::IPEndPoint remote_endpoint = | 439 net::IPEndPoint remote_endpoint = |
417 CreateUDPAddress(remote_ip_address, remote_port); | 440 CreateUDPAddress(remote_ip_address, remote_port); |
418 net::IPEndPoint local_endpoint = CreateUDPAddress("0.0.0.0", 0); | 441 net::IPEndPoint local_endpoint = CreateUDPAddress("0.0.0.0", 0); |
419 transport_audio_config.base.ssrc = audio_config.sender_ssrc; | 442 transport_audio_config.base.ssrc = audio_config.sender_ssrc; |
420 transport_audio_config.base.rtp_config = audio_config.rtp_config; | 443 transport_audio_config.base.rtp_config = audio_config.rtp_config; |
421 transport_video_config.base.ssrc = video_config.sender_ssrc; | 444 transport_video_config.base.ssrc = video_config.sender_ssrc; |
422 transport_video_config.base.rtp_config = video_config.rtp_config; | 445 transport_video_config.base.rtp_config = video_config.rtp_config; |
423 | 446 |
424 scoped_ptr<media::cast::transport::CastTransportSender> transport_sender = | |
425 media::cast::transport::CastTransportSender::Create( | |
426 NULL, // net log. | |
427 clock.get(), | |
428 local_endpoint, | |
429 remote_endpoint, | |
430 base::Bind(&UpdateCastTransportStatus), | |
431 io_message_loop.message_loop_proxy()); | |
432 | |
433 transport_sender->InitializeAudio(transport_audio_config); | |
434 transport_sender->InitializeVideo(transport_video_config); | |
435 | |
436 // Enable main and send side threads only. Enable raw event and stats logging. | 447 // Enable main and send side threads only. Enable raw event and stats logging. |
437 // Running transport on the main thread. | 448 // Running transport on the main thread. |
438 scoped_refptr<media::cast::CastEnvironment> cast_environment( | 449 scoped_refptr<media::cast::CastEnvironment> cast_environment( |
439 new media::cast::CastEnvironment( | 450 new media::cast::CastEnvironment( |
440 clock.Pass(), | 451 clock.Pass(), |
441 io_message_loop.message_loop_proxy(), | 452 io_message_loop.message_loop_proxy(), |
442 audio_thread.message_loop_proxy(), | 453 audio_thread.message_loop_proxy(), |
443 NULL, | 454 NULL, |
444 video_thread.message_loop_proxy(), | 455 video_thread.message_loop_proxy(), |
445 NULL, | 456 NULL, |
446 io_message_loop.message_loop_proxy(), | 457 io_message_loop.message_loop_proxy(), |
447 media::cast::GetLoggingConfigWithRawEventsAndStatsEnabled())); | 458 media::cast::GetLoggingConfigWithRawEventsAndStatsEnabled())); |
448 | 459 |
| 460 scoped_ptr<media::cast::transport::CastTransportSender> transport_sender = |
| 461 media::cast::transport::CastTransportSender::Create( |
| 462 NULL, // net log. |
| 463 clock.get(), |
| 464 local_endpoint, |
| 465 remote_endpoint, |
| 466 logging_config, |
| 467 base::Bind(&UpdateCastTransportStatus), |
| 468 base::Bind(&LogRawEvents, cast_environment), |
| 469 base::TimeDelta::FromSeconds(1), |
| 470 io_message_loop.message_loop_proxy()); |
| 471 |
| 472 transport_sender->InitializeAudio(transport_audio_config); |
| 473 transport_sender->InitializeVideo(transport_video_config); |
| 474 |
449 scoped_ptr<media::cast::CastSender> cast_sender( | 475 scoped_ptr<media::cast::CastSender> cast_sender( |
450 media::cast::CastSender::CreateCastSender( | 476 media::cast::CastSender::CreateCastSender( |
451 cast_environment, | 477 cast_environment, |
452 &audio_config, | 478 &audio_config, |
453 &video_config, | 479 &video_config, |
454 NULL, // gpu_factories. | 480 NULL, // gpu_factories. |
455 base::Bind(&InitializationResult), | 481 base::Bind(&InitializationResult), |
456 transport_sender.get())); | 482 transport_sender.get())); |
457 | 483 |
458 transport_sender->SetPacketReceiver(cast_sender->packet_receiver()); | 484 transport_sender->SetPacketReceiver(cast_sender->packet_receiver()); |
459 | 485 |
460 media::cast::FrameInput* frame_input = cast_sender->frame_input(); | 486 media::cast::FrameInput* frame_input = cast_sender->frame_input(); |
461 scoped_ptr<media::cast::SendProcess> send_process( | 487 scoped_ptr<media::cast::SendProcess> send_process( |
462 new media::cast::SendProcess(test_thread.message_loop_proxy(), | 488 new media::cast::SendProcess(test_thread.message_loop_proxy(), |
463 cast_environment->Clock(), | 489 cast_environment->Clock(), |
464 video_config, | 490 video_config, |
465 frame_input)); | 491 frame_input)); |
466 | 492 |
467 // Set up event subscribers. | 493 // Set up event subscribers. |
468 // TODO(imcheng): Set up separate subscribers for audio / video / other. | |
469 int logging_duration = media::cast::GetLoggingDuration(); | 494 int logging_duration = media::cast::GetLoggingDuration(); |
470 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; | 495 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; |
471 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; | 496 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; |
472 if (logging_duration > 0) { | 497 if (logging_duration > 0) { |
473 std::string log_file_name(media::cast::GetLogFileDestination()); | 498 std::string log_file_name(media::cast::GetLogFileDestination()); |
474 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 499 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
475 media::cast::VIDEO_EVENT, 10000)); | 500 media::cast::VIDEO_EVENT, 10000)); |
476 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 501 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
477 media::cast::AUDIO_EVENT, 10000)); | 502 media::cast::AUDIO_EVENT, 10000)); |
478 cast_environment->Logging()->AddRawEventSubscriber( | 503 cast_environment->Logging()->AddRawEventSubscriber( |
(...skipping 18 matching lines...) Expand all Loading... |
497 | 522 |
498 test_thread.message_loop_proxy()->PostTask( | 523 test_thread.message_loop_proxy()->PostTask( |
499 FROM_HERE, | 524 FROM_HERE, |
500 base::Bind(&media::cast::SendProcess::SendFrame, | 525 base::Bind(&media::cast::SendProcess::SendFrame, |
501 base::Unretained(send_process.get()))); | 526 base::Unretained(send_process.get()))); |
502 | 527 |
503 io_message_loop.Run(); | 528 io_message_loop.Run(); |
504 | 529 |
505 return 0; | 530 return 0; |
506 } | 531 } |
OLD | NEW |