Chromium Code Reviews| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/json/json_writer.h" | |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "base/time/default_tick_clock.h" | 16 #include "base/time/default_tick_clock.h" |
| 17 #include "base/values.h" | |
| 16 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 17 #include "media/cast/cast_config.h" | 19 #include "media/cast/cast_config.h" |
| 18 #include "media/cast/cast_environment.h" | 20 #include "media/cast/cast_environment.h" |
| 19 #include "media/cast/cast_sender.h" | 21 #include "media/cast/cast_sender.h" |
| 20 #include "media/cast/logging/encoding_event_subscriber.h" | 22 #include "media/cast/logging/encoding_event_subscriber.h" |
| 21 #include "media/cast/logging/log_serializer.h" | 23 #include "media/cast/logging/log_serializer.h" |
| 22 #include "media/cast/logging/logging_defines.h" | 24 #include "media/cast/logging/logging_defines.h" |
| 23 #include "media/cast/logging/proto/raw_events.pb.h" | 25 #include "media/cast/logging/proto/raw_events.pb.h" |
| 26 #include "media/cast/logging/receiver_time_offset_estimator_impl.h" | |
| 27 #include "media/cast/logging/stats_event_subscriber.h" | |
| 24 #include "media/cast/test/utility/audio_utility.h" | 28 #include "media/cast/test/utility/audio_utility.h" |
| 25 #include "media/cast/test/utility/default_config.h" | 29 #include "media/cast/test/utility/default_config.h" |
| 26 #include "media/cast/test/utility/input_builder.h" | 30 #include "media/cast/test/utility/input_builder.h" |
| 27 #include "media/cast/test/utility/video_utility.h" | 31 #include "media/cast/test/utility/video_utility.h" |
| 28 #include "media/cast/transport/cast_transport_defines.h" | 32 #include "media/cast/transport/cast_transport_defines.h" |
| 29 #include "media/cast/transport/cast_transport_sender.h" | 33 #include "media/cast/transport/cast_transport_sender.h" |
| 30 #include "media/cast/transport/transport/udp_transport.h" | 34 #include "media/cast/transport/transport/udp_transport.h" |
| 31 #include "ui/gfx/size.h" | 35 #include "ui/gfx/size.h" |
| 32 | 36 |
| 33 namespace media { | 37 namespace media { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 | 370 |
| 367 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { | 371 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { |
| 368 net::IPAddressNumber ip_number; | 372 net::IPAddressNumber ip_number; |
| 369 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); | 373 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); |
| 370 return net::IPEndPoint(ip_number, port); | 374 return net::IPEndPoint(ip_number, port); |
| 371 } | 375 } |
| 372 | 376 |
| 373 void DumpLoggingData(const media::cast::proto::LogMetadata& log_metadata, | 377 void DumpLoggingData(const media::cast::proto::LogMetadata& log_metadata, |
| 374 const media::cast::FrameEventMap& frame_events, | 378 const media::cast::FrameEventMap& frame_events, |
| 375 const media::cast::PacketEventMap& packet_events, | 379 const media::cast::PacketEventMap& packet_events, |
| 376 bool compress, | 380 bool compress, |
|
miu
2014/04/17 02:14:14
Remove this argument if it is unused. Or, did you
imcheng
2014/04/17 19:19:06
The arg has been removed in another CL.
| |
| 377 base::ScopedFILE log_file) { | 381 base::ScopedFILE log_file) { |
| 378 VLOG(0) << "Frame map size: " << frame_events.size(); | 382 VLOG(0) << "Frame map size: " << frame_events.size(); |
| 379 VLOG(0) << "Packet map size: " << packet_events.size(); | 383 VLOG(0) << "Packet map size: " << packet_events.size(); |
| 380 | 384 |
| 381 scoped_ptr<char[]> event_log(new char[media::cast::kMaxSerializedLogBytes]); | 385 scoped_ptr<char[]> event_log(new char[media::cast::kMaxSerializedLogBytes]); |
| 382 int event_log_bytes; | 386 int event_log_bytes; |
| 383 if (!media::cast::SerializeEvents(log_metadata, | 387 if (!media::cast::SerializeEvents(log_metadata, |
| 384 frame_events, | 388 frame_events, |
| 385 packet_events, | 389 packet_events, |
| 386 compress, | 390 true, |
| 387 media::cast::kMaxSerializedLogBytes, | 391 media::cast::kMaxSerializedLogBytes, |
| 388 event_log.get(), | 392 event_log.get(), |
| 389 &event_log_bytes)) { | 393 &event_log_bytes)) { |
| 390 VLOG(0) << "Failed to serialize events."; | 394 VLOG(0) << "Failed to serialize events."; |
| 391 return; | 395 return; |
| 392 } | 396 } |
| 393 | 397 |
| 394 VLOG(0) << "Events serialized length: " << event_log_bytes; | 398 VLOG(0) << "Events serialized length: " << event_log_bytes; |
| 395 | 399 |
| 396 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); | 400 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 427 audio_event_subscriber->GetEventsAndReset( | 431 audio_event_subscriber->GetEventsAndReset( |
| 428 &log_metadata, &frame_events, &packet_events); | 432 &log_metadata, &frame_events, &packet_events); |
| 429 | 433 |
| 430 DumpLoggingData(log_metadata, | 434 DumpLoggingData(log_metadata, |
| 431 frame_events, | 435 frame_events, |
| 432 packet_events, | 436 packet_events, |
| 433 compress, | 437 compress, |
| 434 audio_log_file.Pass()); | 438 audio_log_file.Pass()); |
| 435 } | 439 } |
| 436 | 440 |
| 441 void WriteStats( | |
|
miu
2014/04/17 02:14:14
naming: This method does more than just write the
imcheng
2014/04/17 19:19:06
Done. Also renamed the method above.
| |
| 442 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, | |
| 443 scoped_ptr<media::cast::StatsEventSubscriber> video_event_subscriber, | |
| 444 scoped_ptr<media::cast::StatsEventSubscriber> audio_event_subscriber, | |
| 445 scoped_ptr<media::cast::ReceiverTimeOffsetEstimatorImpl> estimator) { | |
| 446 cast_environment->Logging()->RemoveRawEventSubscriber( | |
| 447 video_event_subscriber.get()); | |
| 448 cast_environment->Logging()->RemoveRawEventSubscriber( | |
| 449 audio_event_subscriber.get()); | |
| 450 cast_environment->Logging()->RemoveRawEventSubscriber(estimator.get()); | |
| 451 | |
| 452 scoped_ptr<base::DictionaryValue> stats = video_event_subscriber->GetStats(); | |
| 453 std::string json; | |
| 454 base::JSONWriter::WriteWithOptions( | |
| 455 stats.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | |
| 456 VLOG(0) << "Video stats: " << json; | |
| 457 | |
| 458 stats = audio_event_subscriber->GetStats(); | |
| 459 json.clear(); | |
| 460 base::JSONWriter::WriteWithOptions( | |
| 461 stats.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | |
| 462 VLOG(0) << "Audio stats: " << json; | |
| 463 } | |
| 464 | |
| 437 } // namespace | 465 } // namespace |
| 438 | 466 |
| 439 int main(int argc, char** argv) { | 467 int main(int argc, char** argv) { |
| 440 base::AtExitManager at_exit; | 468 base::AtExitManager at_exit; |
| 441 CommandLine::Init(argc, argv); | 469 CommandLine::Init(argc, argv); |
| 442 InitLogging(logging::LoggingSettings()); | 470 InitLogging(logging::LoggingSettings()); |
| 443 base::Thread test_thread("Cast sender test app thread"); | 471 base::Thread test_thread("Cast sender test app thread"); |
| 444 base::Thread audio_thread("Cast audio encoder thread"); | 472 base::Thread audio_thread("Cast audio encoder thread"); |
| 445 base::Thread video_thread("Cast video encoder thread"); | 473 base::Thread video_thread("Cast video encoder thread"); |
| 446 test_thread.Start(); | 474 test_thread.Start(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 cast_sender->video_frame_input(); | 541 cast_sender->video_frame_input(); |
| 514 scoped_ptr<media::cast::SendProcess> send_process( | 542 scoped_ptr<media::cast::SendProcess> send_process( |
| 515 new media::cast::SendProcess(test_thread.message_loop_proxy(), | 543 new media::cast::SendProcess(test_thread.message_loop_proxy(), |
| 516 cast_environment->Clock(), | 544 cast_environment->Clock(), |
| 517 video_config, | 545 video_config, |
| 518 audio_frame_input, | 546 audio_frame_input, |
| 519 video_frame_input)); | 547 video_frame_input)); |
| 520 | 548 |
| 521 // Set up event subscribers. | 549 // Set up event subscribers. |
| 522 int logging_duration = media::cast::GetLoggingDuration(); | 550 int logging_duration = media::cast::GetLoggingDuration(); |
| 551 scoped_ptr<media::cast::ReceiverTimeOffsetEstimatorImpl> offset_estimator( | |
| 552 new media::cast::ReceiverTimeOffsetEstimatorImpl); | |
| 553 cast_environment->Logging()->AddRawEventSubscriber(offset_estimator.get()); | |
| 554 | |
| 523 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; | 555 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; |
| 524 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; | 556 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; |
| 557 scoped_ptr<media::cast::StatsEventSubscriber> video_stats_subscriber( | |
| 558 new media::cast::StatsEventSubscriber(media::cast::VIDEO_EVENT, | |
| 559 cast_environment->Clock(), | |
| 560 offset_estimator.get())); | |
| 561 scoped_ptr<media::cast::StatsEventSubscriber> audio_stats_subscriber( | |
| 562 new media::cast::StatsEventSubscriber(media::cast::AUDIO_EVENT, | |
| 563 cast_environment->Clock(), | |
| 564 offset_estimator.get())); | |
| 565 cast_environment->Logging()->AddRawEventSubscriber( | |
| 566 video_stats_subscriber.get()); | |
| 567 cast_environment->Logging()->AddRawEventSubscriber( | |
| 568 audio_stats_subscriber.get()); | |
| 525 if (logging_duration > 0) { | 569 if (logging_duration > 0) { |
| 526 bool compress = media::cast::CompressLogs(); | 570 bool compress = media::cast::CompressLogs(); |
| 527 std::string video_log_file_name( | 571 std::string video_log_file_name( |
| 528 media::cast::GetVideoLogFileDestination(compress)); | 572 media::cast::GetVideoLogFileDestination(compress)); |
| 529 std::string audio_log_file_name( | 573 std::string audio_log_file_name( |
| 530 media::cast::GetAudioLogFileDestination(compress)); | 574 media::cast::GetAudioLogFileDestination(compress)); |
| 531 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 575 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
| 532 media::cast::VIDEO_EVENT, 10000)); | 576 media::cast::VIDEO_EVENT, 10000)); |
| 533 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 577 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
| 534 media::cast::AUDIO_EVENT, 10000)); | 578 media::cast::AUDIO_EVENT, 10000)); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 552 io_message_loop.message_loop_proxy()->PostDelayedTask( | 596 io_message_loop.message_loop_proxy()->PostDelayedTask( |
| 553 FROM_HERE, | 597 FROM_HERE, |
| 554 base::Bind(&WriteLogsToFileAndStopSubscribing, | 598 base::Bind(&WriteLogsToFileAndStopSubscribing, |
| 555 cast_environment, | 599 cast_environment, |
| 556 base::Passed(&video_event_subscriber), | 600 base::Passed(&video_event_subscriber), |
| 557 base::Passed(&audio_event_subscriber), | 601 base::Passed(&audio_event_subscriber), |
| 558 base::Passed(&video_log_file), | 602 base::Passed(&video_log_file), |
| 559 base::Passed(&audio_log_file), | 603 base::Passed(&audio_log_file), |
| 560 compress), | 604 compress), |
| 561 base::TimeDelta::FromSeconds(logging_duration)); | 605 base::TimeDelta::FromSeconds(logging_duration)); |
| 606 | |
| 607 io_message_loop.message_loop_proxy()->PostDelayedTask( | |
| 608 FROM_HERE, | |
| 609 base::Bind(&WriteStats, | |
| 610 cast_environment, | |
| 611 base::Passed(&video_stats_subscriber), | |
| 612 base::Passed(&audio_stats_subscriber), | |
| 613 base::Passed(&offset_estimator)), | |
| 614 base::TimeDelta::FromSeconds(logging_duration)); | |
| 562 } | 615 } |
| 563 | 616 |
| 564 test_thread.message_loop_proxy()->PostTask( | 617 test_thread.message_loop_proxy()->PostTask( |
| 565 FROM_HERE, | 618 FROM_HERE, |
| 566 base::Bind(&media::cast::SendProcess::SendFrame, | 619 base::Bind(&media::cast::SendProcess::SendFrame, |
| 567 base::Unretained(send_process.get()))); | 620 base::Unretained(send_process.get()))); |
| 568 | 621 |
| 569 io_message_loop.Run(); | 622 io_message_loop.Run(); |
| 570 | 623 |
| 571 return 0; | 624 return 0; |
| 572 } | 625 } |
| OLD | NEW |