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

Side by Side Diff: media/cast/test/sender.cc

Issue 236123003: Cast: Provide more meaningful stats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile Created 6 years, 7 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
« no previous file with comments | « media/cast/test/fake_receiver_time_offset_estimator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 <queue> 8 #include <queue>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/memory_mapped_file.h" 15 #include "base/files/memory_mapped_file.h"
16 #include "base/files/scoped_file.h" 16 #include "base/files/scoped_file.h"
17 #include "base/json/json_writer.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
19 #include "base/path_service.h" 20 #include "base/path_service.h"
20 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
21 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
22 #include "base/time/default_tick_clock.h" 23 #include "base/time/default_tick_clock.h"
24 #include "base/values.h"
23 #include "media/audio/audio_parameters.h" 25 #include "media/audio/audio_parameters.h"
24 #include "media/base/audio_buffer.h" 26 #include "media/base/audio_buffer.h"
25 #include "media/base/audio_bus.h" 27 #include "media/base/audio_bus.h"
26 #include "media/base/audio_fifo.h" 28 #include "media/base/audio_fifo.h"
27 #include "media/base/audio_timestamp_helper.h" 29 #include "media/base/audio_timestamp_helper.h"
28 #include "media/base/media.h" 30 #include "media/base/media.h"
29 #include "media/base/multi_channel_resampler.h" 31 #include "media/base/multi_channel_resampler.h"
30 #include "media/base/video_frame.h" 32 #include "media/base/video_frame.h"
31 #include "media/base/video_util.h" 33 #include "media/base/video_util.h"
32 #include "media/cast/cast_config.h" 34 #include "media/cast/cast_config.h"
33 #include "media/cast/cast_environment.h" 35 #include "media/cast/cast_environment.h"
34 #include "media/cast/cast_sender.h" 36 #include "media/cast/cast_sender.h"
35 #include "media/cast/logging/encoding_event_subscriber.h" 37 #include "media/cast/logging/encoding_event_subscriber.h"
36 #include "media/cast/logging/log_serializer.h" 38 #include "media/cast/logging/log_serializer.h"
37 #include "media/cast/logging/logging_defines.h" 39 #include "media/cast/logging/logging_defines.h"
38 #include "media/cast/logging/proto/raw_events.pb.h" 40 #include "media/cast/logging/proto/raw_events.pb.h"
41 #include "media/cast/logging/receiver_time_offset_estimator_impl.h"
42 #include "media/cast/logging/stats_event_subscriber.h"
39 #include "media/cast/test/utility/audio_utility.h" 43 #include "media/cast/test/utility/audio_utility.h"
40 #include "media/cast/test/utility/default_config.h" 44 #include "media/cast/test/utility/default_config.h"
41 #include "media/cast/test/utility/input_builder.h" 45 #include "media/cast/test/utility/input_builder.h"
42 #include "media/cast/test/utility/video_utility.h" 46 #include "media/cast/test/utility/video_utility.h"
43 #include "media/cast/transport/cast_transport_defines.h" 47 #include "media/cast/transport/cast_transport_defines.h"
44 #include "media/cast/transport/cast_transport_sender.h" 48 #include "media/cast/transport/cast_transport_sender.h"
45 #include "media/cast/transport/transport/udp_transport.h" 49 #include "media/cast/transport/transport/udp_transport.h"
46 #include "media/ffmpeg/ffmpeg_common.h" 50 #include "media/ffmpeg/ffmpeg_common.h"
47 #include "media/ffmpeg/ffmpeg_deleters.h" 51 #include "media/ffmpeg/ffmpeg_deleters.h"
48 #include "media/filters/audio_renderer_algorithm.h" 52 #include "media/filters/audio_renderer_algorithm.h"
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 return; 798 return;
795 } 799 }
796 800
797 VLOG(0) << "Events serialized length: " << event_log_bytes; 801 VLOG(0) << "Events serialized length: " << event_log_bytes;
798 802
799 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); 803 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get());
800 if (ret != event_log_bytes) 804 if (ret != event_log_bytes)
801 VLOG(0) << "Failed to write logs to file."; 805 VLOG(0) << "Failed to write logs to file.";
802 } 806 }
803 807
804 void WriteLogsToFileAndStopSubscribing( 808 void WriteLogsToFileAndDestroySubscribers(
805 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, 809 const scoped_refptr<media::cast::CastEnvironment>& cast_environment,
806 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber, 810 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber,
807 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber, 811 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber,
808 base::ScopedFILE video_log_file, 812 base::ScopedFILE video_log_file,
809 base::ScopedFILE audio_log_file) { 813 base::ScopedFILE audio_log_file) {
810 cast_environment->Logging()->RemoveRawEventSubscriber( 814 cast_environment->Logging()->RemoveRawEventSubscriber(
811 video_event_subscriber.get()); 815 video_event_subscriber.get());
812 cast_environment->Logging()->RemoveRawEventSubscriber( 816 cast_environment->Logging()->RemoveRawEventSubscriber(
813 audio_event_subscriber.get()); 817 audio_event_subscriber.get());
814 818
(...skipping 12 matching lines...) Expand all
827 VLOG(0) << "Dumping logging data for audio stream."; 831 VLOG(0) << "Dumping logging data for audio stream.";
828 audio_event_subscriber->GetEventsAndReset( 832 audio_event_subscriber->GetEventsAndReset(
829 &log_metadata, &frame_events, &packet_events); 833 &log_metadata, &frame_events, &packet_events);
830 834
831 DumpLoggingData(log_metadata, 835 DumpLoggingData(log_metadata,
832 frame_events, 836 frame_events,
833 packet_events, 837 packet_events,
834 audio_log_file.Pass()); 838 audio_log_file.Pass());
835 } 839 }
836 840
841 void WriteStatsAndDestroySubscribers(
842 const scoped_refptr<media::cast::CastEnvironment>& cast_environment,
843 scoped_ptr<media::cast::StatsEventSubscriber> video_event_subscriber,
844 scoped_ptr<media::cast::StatsEventSubscriber> audio_event_subscriber,
845 scoped_ptr<media::cast::ReceiverTimeOffsetEstimatorImpl> estimator) {
846 cast_environment->Logging()->RemoveRawEventSubscriber(
847 video_event_subscriber.get());
848 cast_environment->Logging()->RemoveRawEventSubscriber(
849 audio_event_subscriber.get());
850 cast_environment->Logging()->RemoveRawEventSubscriber(estimator.get());
851
852 scoped_ptr<base::DictionaryValue> stats = video_event_subscriber->GetStats();
853 std::string json;
854 base::JSONWriter::WriteWithOptions(
855 stats.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
856 VLOG(0) << "Video stats: " << json;
857
858 stats = audio_event_subscriber->GetStats();
859 json.clear();
860 base::JSONWriter::WriteWithOptions(
861 stats.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
862 VLOG(0) << "Audio stats: " << json;
863 }
864
837 } // namespace 865 } // namespace
838 866
839 int main(int argc, char** argv) { 867 int main(int argc, char** argv) {
840 base::AtExitManager at_exit; 868 base::AtExitManager at_exit;
841 CommandLine::Init(argc, argv); 869 CommandLine::Init(argc, argv);
842 InitLogging(logging::LoggingSettings()); 870 InitLogging(logging::LoggingSettings());
843 871
844 // Load the media module for FFmpeg decoding. 872 // Load the media module for FFmpeg decoding.
845 base::FilePath path; 873 base::FilePath path;
846 PathService::Get(base::DIR_MODULE, &path); 874 PathService::Get(base::DIR_MODULE, &path);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 LOG(INFO) << "Logging video events to: " << video_log_file_name; 963 LOG(INFO) << "Logging video events to: " << video_log_file_name;
936 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( 964 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber(
937 media::cast::VIDEO_EVENT, 10000)); 965 media::cast::VIDEO_EVENT, 10000));
938 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( 966 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber(
939 media::cast::AUDIO_EVENT, 10000)); 967 media::cast::AUDIO_EVENT, 10000));
940 cast_environment->Logging()->AddRawEventSubscriber( 968 cast_environment->Logging()->AddRawEventSubscriber(
941 video_event_subscriber.get()); 969 video_event_subscriber.get());
942 cast_environment->Logging()->AddRawEventSubscriber( 970 cast_environment->Logging()->AddRawEventSubscriber(
943 audio_event_subscriber.get()); 971 audio_event_subscriber.get());
944 972
973 // Subscribers for stats.
974 scoped_ptr<media::cast::ReceiverTimeOffsetEstimatorImpl> offset_estimator(
975 new media::cast::ReceiverTimeOffsetEstimatorImpl);
976 cast_environment->Logging()->AddRawEventSubscriber(offset_estimator.get());
977 scoped_ptr<media::cast::StatsEventSubscriber> video_stats_subscriber(
978 new media::cast::StatsEventSubscriber(media::cast::VIDEO_EVENT,
979 cast_environment->Clock(),
980 offset_estimator.get()));
981 scoped_ptr<media::cast::StatsEventSubscriber> audio_stats_subscriber(
982 new media::cast::StatsEventSubscriber(media::cast::AUDIO_EVENT,
983 cast_environment->Clock(),
984 offset_estimator.get()));
985 cast_environment->Logging()->AddRawEventSubscriber(
986 video_stats_subscriber.get());
987 cast_environment->Logging()->AddRawEventSubscriber(
988 audio_stats_subscriber.get());
989
945 base::ScopedFILE video_log_file(fopen(video_log_file_name.c_str(), "w")); 990 base::ScopedFILE video_log_file(fopen(video_log_file_name.c_str(), "w"));
946 if (!video_log_file) { 991 if (!video_log_file) {
947 VLOG(1) << "Failed to open video log file for writing."; 992 VLOG(1) << "Failed to open video log file for writing.";
948 exit(-1); 993 exit(-1);
949 } 994 }
950 995
951 base::ScopedFILE audio_log_file(fopen(audio_log_file_name.c_str(), "w")); 996 base::ScopedFILE audio_log_file(fopen(audio_log_file_name.c_str(), "w"));
952 if (!audio_log_file) { 997 if (!audio_log_file) {
953 VLOG(1) << "Failed to open audio log file for writing."; 998 VLOG(1) << "Failed to open audio log file for writing.";
954 exit(-1); 999 exit(-1);
955 } 1000 }
956 1001
957 const int logging_duration_seconds = 300; 1002 const int logging_duration_seconds = 10;
958 io_message_loop.message_loop_proxy()->PostDelayedTask( 1003 io_message_loop.message_loop_proxy()->PostDelayedTask(
959 FROM_HERE, 1004 FROM_HERE,
960 base::Bind(&WriteLogsToFileAndStopSubscribing, 1005 base::Bind(&WriteLogsToFileAndDestroySubscribers,
961 cast_environment, 1006 cast_environment,
962 base::Passed(&video_event_subscriber), 1007 base::Passed(&video_event_subscriber),
963 base::Passed(&audio_event_subscriber), 1008 base::Passed(&audio_event_subscriber),
964 base::Passed(&video_log_file), 1009 base::Passed(&video_log_file),
965 base::Passed(&audio_log_file)), 1010 base::Passed(&audio_log_file)),
966 base::TimeDelta::FromSeconds(logging_duration_seconds)); 1011 base::TimeDelta::FromSeconds(logging_duration_seconds));
1012
1013 io_message_loop.message_loop_proxy()->PostDelayedTask(
1014 FROM_HERE,
1015 base::Bind(&WriteStatsAndDestroySubscribers,
1016 cast_environment,
1017 base::Passed(&video_stats_subscriber),
1018 base::Passed(&audio_stats_subscriber),
1019 base::Passed(&offset_estimator)),
1020 base::TimeDelta::FromSeconds(logging_duration_seconds));
1021
967 send_process->Start(cast_sender->audio_frame_input(), 1022 send_process->Start(cast_sender->audio_frame_input(),
968 cast_sender->video_frame_input()); 1023 cast_sender->video_frame_input());
1024
969 io_message_loop.Run(); 1025 io_message_loop.Run();
970 return 0; 1026 return 0;
971 } 1027 }
OLDNEW
« no previous file with comments | « media/cast/test/fake_receiver_time_offset_estimator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698