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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 bool compress, | 381 bool compress, |
378 base::ScopedFILE log_file) { | 382 base::ScopedFILE log_file) { |
379 VLOG(0) << "Frame map size: " << frame_events.size(); | 383 VLOG(0) << "Frame map size: " << frame_events.size(); |
380 VLOG(0) << "Packet map size: " << packet_events.size(); | 384 VLOG(0) << "Packet map size: " << packet_events.size(); |
381 | 385 |
382 scoped_ptr<char[]> event_log(new char[media::cast::kMaxSerializedLogBytes]); | 386 scoped_ptr<char[]> event_log(new char[media::cast::kMaxSerializedLogBytes]); |
383 int event_log_bytes; | 387 int event_log_bytes; |
384 if (!media::cast::SerializeEvents(log_metadata, | 388 if (!media::cast::SerializeEvents(log_metadata, |
385 frame_events, | 389 frame_events, |
386 packet_events, | 390 packet_events, |
387 compress, | 391 true, |
388 media::cast::kMaxSerializedLogBytes, | 392 media::cast::kMaxSerializedLogBytes, |
389 event_log.get(), | 393 event_log.get(), |
390 &event_log_bytes)) { | 394 &event_log_bytes)) { |
391 VLOG(0) << "Failed to serialize events."; | 395 VLOG(0) << "Failed to serialize events."; |
392 return; | 396 return; |
393 } | 397 } |
394 | 398 |
395 VLOG(0) << "Events serialized length: " << event_log_bytes; | 399 VLOG(0) << "Events serialized length: " << event_log_bytes; |
396 | 400 |
397 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); | 401 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); |
(...skipping 30 matching lines...) Expand all Loading... |
428 audio_event_subscriber->GetEventsAndReset( | 432 audio_event_subscriber->GetEventsAndReset( |
429 &log_metadata, &frame_events, &packet_events); | 433 &log_metadata, &frame_events, &packet_events); |
430 | 434 |
431 DumpLoggingData(log_metadata, | 435 DumpLoggingData(log_metadata, |
432 frame_events, | 436 frame_events, |
433 packet_events, | 437 packet_events, |
434 compress, | 438 compress, |
435 audio_log_file.Pass()); | 439 audio_log_file.Pass()); |
436 } | 440 } |
437 | 441 |
| 442 void WriteStats( |
| 443 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, |
| 444 scoped_ptr<media::cast::StatsEventSubscriber> video_event_subscriber, |
| 445 scoped_ptr<media::cast::StatsEventSubscriber> audio_event_subscriber, |
| 446 scoped_ptr<media::cast::ReceiverTimeOffsetEstimatorImpl> estimator) { |
| 447 cast_environment->Logging()->RemoveRawEventSubscriber( |
| 448 video_event_subscriber.get()); |
| 449 cast_environment->Logging()->RemoveRawEventSubscriber( |
| 450 audio_event_subscriber.get()); |
| 451 cast_environment->Logging()->RemoveRawEventSubscriber(estimator.get()); |
| 452 |
| 453 scoped_ptr<base::DictionaryValue> stats = video_event_subscriber->GetStats(); |
| 454 std::string json; |
| 455 base::JSONWriter::WriteWithOptions( |
| 456 stats.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
| 457 VLOG(0) << "Video stats: " << json; |
| 458 |
| 459 stats = audio_event_subscriber->GetStats(); |
| 460 json.clear(); |
| 461 base::JSONWriter::WriteWithOptions( |
| 462 stats.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
| 463 VLOG(0) << "Audio stats: " << json; |
| 464 } |
| 465 |
438 } // namespace | 466 } // namespace |
439 | 467 |
440 int main(int argc, char** argv) { | 468 int main(int argc, char** argv) { |
441 base::AtExitManager at_exit; | 469 base::AtExitManager at_exit; |
442 CommandLine::Init(argc, argv); | 470 CommandLine::Init(argc, argv); |
443 InitLogging(logging::LoggingSettings()); | 471 InitLogging(logging::LoggingSettings()); |
444 base::Thread test_thread("Cast sender test app thread"); | 472 base::Thread test_thread("Cast sender test app thread"); |
445 base::Thread audio_thread("Cast audio encoder thread"); | 473 base::Thread audio_thread("Cast audio encoder thread"); |
446 base::Thread video_thread("Cast video encoder thread"); | 474 base::Thread video_thread("Cast video encoder thread"); |
447 test_thread.Start(); | 475 test_thread.Start(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 cast_sender->video_frame_input(); | 542 cast_sender->video_frame_input(); |
515 scoped_ptr<media::cast::SendProcess> send_process( | 543 scoped_ptr<media::cast::SendProcess> send_process( |
516 new media::cast::SendProcess(test_thread.message_loop_proxy(), | 544 new media::cast::SendProcess(test_thread.message_loop_proxy(), |
517 cast_environment->Clock(), | 545 cast_environment->Clock(), |
518 video_config, | 546 video_config, |
519 audio_frame_input, | 547 audio_frame_input, |
520 video_frame_input)); | 548 video_frame_input)); |
521 | 549 |
522 // Set up event subscribers. | 550 // Set up event subscribers. |
523 int logging_duration = media::cast::GetLoggingDuration(); | 551 int logging_duration = media::cast::GetLoggingDuration(); |
| 552 scoped_ptr<media::cast::ReceiverTimeOffsetEstimatorImpl> offset_estimator( |
| 553 new media::cast::ReceiverTimeOffsetEstimatorImpl); |
| 554 cast_environment->Logging()->AddRawEventSubscriber(offset_estimator.get()); |
| 555 |
524 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; | 556 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; |
525 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; | 557 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; |
| 558 scoped_ptr<media::cast::StatsEventSubscriber> video_stats_subscriber( |
| 559 new media::cast::StatsEventSubscriber(media::cast::VIDEO_EVENT, |
| 560 cast_environment->Clock(), |
| 561 offset_estimator.get())); |
| 562 scoped_ptr<media::cast::StatsEventSubscriber> audio_stats_subscriber( |
| 563 new media::cast::StatsEventSubscriber(media::cast::AUDIO_EVENT, |
| 564 cast_environment->Clock(), |
| 565 offset_estimator.get())); |
| 566 cast_environment->Logging()->AddRawEventSubscriber( |
| 567 video_stats_subscriber.get()); |
| 568 cast_environment->Logging()->AddRawEventSubscriber( |
| 569 audio_stats_subscriber.get()); |
526 if (logging_duration > 0) { | 570 if (logging_duration > 0) { |
527 bool compress = media::cast::CompressLogs(); | 571 bool compress = media::cast::CompressLogs(); |
528 std::string video_log_file_name( | 572 std::string video_log_file_name( |
529 media::cast::GetVideoLogFileDestination(compress)); | 573 media::cast::GetVideoLogFileDestination(compress)); |
530 std::string audio_log_file_name( | 574 std::string audio_log_file_name( |
531 media::cast::GetAudioLogFileDestination(compress)); | 575 media::cast::GetAudioLogFileDestination(compress)); |
532 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 576 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
533 media::cast::VIDEO_EVENT, 10000)); | 577 media::cast::VIDEO_EVENT, 10000)); |
534 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 578 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
535 media::cast::AUDIO_EVENT, 10000)); | 579 media::cast::AUDIO_EVENT, 10000)); |
(...skipping 17 matching lines...) Expand all Loading... |
553 io_message_loop.message_loop_proxy()->PostDelayedTask( | 597 io_message_loop.message_loop_proxy()->PostDelayedTask( |
554 FROM_HERE, | 598 FROM_HERE, |
555 base::Bind(&WriteLogsToFileAndStopSubscribing, | 599 base::Bind(&WriteLogsToFileAndStopSubscribing, |
556 cast_environment, | 600 cast_environment, |
557 base::Passed(&video_event_subscriber), | 601 base::Passed(&video_event_subscriber), |
558 base::Passed(&audio_event_subscriber), | 602 base::Passed(&audio_event_subscriber), |
559 base::Passed(&video_log_file), | 603 base::Passed(&video_log_file), |
560 base::Passed(&audio_log_file), | 604 base::Passed(&audio_log_file), |
561 compress), | 605 compress), |
562 base::TimeDelta::FromSeconds(logging_duration)); | 606 base::TimeDelta::FromSeconds(logging_duration)); |
| 607 |
| 608 io_message_loop.message_loop_proxy()->PostDelayedTask( |
| 609 FROM_HERE, |
| 610 base::Bind(&WriteStats, |
| 611 cast_environment, |
| 612 base::Passed(&video_stats_subscriber), |
| 613 base::Passed(&audio_stats_subscriber), |
| 614 base::Passed(&offset_estimator)), |
| 615 base::TimeDelta::FromSeconds(logging_duration)); |
563 } | 616 } |
564 | 617 |
565 test_thread.message_loop_proxy()->PostTask( | 618 test_thread.message_loop_proxy()->PostTask( |
566 FROM_HERE, | 619 FROM_HERE, |
567 base::Bind(&media::cast::SendProcess::SendFrame, | 620 base::Bind(&media::cast::SendProcess::SendFrame, |
568 base::Unretained(send_process.get()))); | 621 base::Unretained(send_process.get()))); |
569 | 622 |
570 io_message_loop.Run(); | 623 io_message_loop.Run(); |
571 | 624 |
572 return 0; | 625 return 0; |
573 } | 626 } |
OLD | NEW |