OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ | 5 #ifndef MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ |
6 #define MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ | 6 #define MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | |
9 #include "base/memory/scoped_ptr.h" | |
8 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "base/time/tick_clock.h" | |
9 #include "media/cast/logging/logging_defines.h" | 12 #include "media/cast/logging/logging_defines.h" |
10 #include "media/cast/logging/raw_event_subscriber.h" | 13 #include "media/cast/logging/raw_event_subscriber.h" |
14 #include "media/cast/logging/receiver_time_offset_estimator.h" | |
15 | |
16 namespace base { | |
17 class DictionaryValue; | |
18 } | |
11 | 19 |
12 namespace media { | 20 namespace media { |
13 namespace cast { | 21 namespace cast { |
14 | 22 |
23 class StatsEventSubscriberTest; | |
24 | |
15 // A RawEventSubscriber implementation that subscribes to events, | 25 // A RawEventSubscriber implementation that subscribes to events, |
16 // and aggregates them into stats. | 26 // and aggregates them into stats. |
17 class StatsEventSubscriber : public RawEventSubscriber { | 27 class StatsEventSubscriber : public RawEventSubscriber { |
18 public: | 28 public: |
19 StatsEventSubscriber(EventMediaType media_type); | 29 StatsEventSubscriber(EventMediaType event_media_type, |
30 base::TickClock* clock, | |
31 ReceiverTimeOffsetEstimator* offset_estimator); | |
20 | 32 |
21 virtual ~StatsEventSubscriber(); | 33 virtual ~StatsEventSubscriber(); |
22 | 34 |
23 // RawReventSubscriber implementations. | 35 // RawReventSubscriber implementations. |
24 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; | 36 virtual void OnReceiveFrameEvent(const FrameEvent& frame_event) OVERRIDE; |
25 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; | 37 virtual void OnReceivePacketEvent(const PacketEvent& packet_event) OVERRIDE; |
26 virtual void OnReceiveGenericEvent(const GenericEvent& generic_event) | 38 virtual void OnReceiveGenericEvent(const GenericEvent& generic_event) |
27 OVERRIDE; | 39 OVERRIDE; |
28 | 40 |
29 // Assigns |frame_stats_map| with frame stats. | 41 // Returns stats as a DictionaryValue. The dictionary contains one entry - |
30 void GetFrameStats(FrameStatsMap* frame_stats_map) const; | 42 // "audio" or "video" pointing to an inner dictionary. |
43 // The inner dictionary consists of string - double entries, where the string | |
44 // describes the name of the stat, and the double describes | |
45 // the value of the stat. See CastStat and StatsMap below. | |
46 scoped_ptr<base::DictionaryValue> GetStats() const; | |
31 | 47 |
32 // Assigns |packet_stats_map| with packet stats. | 48 // Resets stats in this object. |
33 void GetPacketStats(PacketStatsMap* packet_stats_map) const; | |
34 | |
35 // Assigns |generic_stats_map| with generic stats data. | |
36 void GetGenericStats(GenericStatsMap* generic_stats_map) const; | |
37 | |
38 // Resets all stats maps in this object. | |
39 void Reset(); | 49 void Reset(); |
40 | 50 |
41 private: | 51 private: |
52 friend class StatsEventSubscriberTest; | |
53 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, EmptyStats); | |
54 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Capture); | |
55 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Encode); | |
56 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Decode); | |
57 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, PlayoutDelay); | |
58 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, E2ELatency); | |
59 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Packets); | |
60 | |
61 // Generic statistics given the raw data. More specific data (e.g. frame rate | |
62 // and bit rate) can be computed given the basic metrics. | |
63 // Some of the metrics will only be set when applicable, e.g. delay and size. | |
64 struct FrameLogStats { | |
65 FrameLogStats(); | |
66 ~FrameLogStats(); | |
67 int event_counter; | |
68 size_t sum_size; | |
69 base::TimeDelta sum_delay; | |
70 }; | |
71 | |
72 struct PacketLogStats { | |
73 PacketLogStats(); | |
74 ~PacketLogStats(); | |
75 int event_counter; | |
76 size_t sum_size; | |
77 }; | |
78 | |
79 enum CastStat { | |
80 // Capture frame rate. | |
81 CAPTURE_FPS, | |
82 // Encode frame rate. | |
83 ENCODE_FPS, | |
84 // Decode frame rate. | |
85 DECODE_FPS, | |
86 // Average encode duration in milliseconds. | |
87 // TODO(imcheng): This stat is not populated yet because we do not have | |
88 // the time when encode started. Record it in kVideoFrameEncoded event. | |
89 AVG_ENCODE_TIME_MS, | |
miu
2014/04/18 00:02:03
Why not microseconds for all of these? Or, let's
imcheng
2014/04/18 18:20:27
I made sure of the latter.
| |
90 // Average playout delay in milliseconds, with target delay already | |
91 // accounted for. Ideally, every frame should have a playout delay of 0. | |
92 AVG_PLAYOUT_DELAY_MS, | |
93 // Duration from when a packet is transmitted to when it is received. | |
94 // This measures latency from sender to receiver. | |
95 AVG_NETWORK_LATENCY_MS, | |
96 // Duration from when a frame is captured to when it should be played out. | |
97 AVG_E2E_LATENCY_MS, | |
98 // Encode bitrate in kbps. | |
99 ENCODE_KBPS, | |
100 // Packet transmission bitrate in kbps. | |
101 TRANSMISSION_KBPS, | |
102 // Packet retransmission bitrate in kbps. | |
103 RETRANSMISSION_KBPS, | |
104 // Percentage of packet loss. | |
105 PACKET_LOSS_PERCENTAGE, | |
miu
2014/04/18 00:02:03
Suggest you use fraction instead of percentage her
imcheng
2014/04/18 18:20:27
Done.
| |
106 // Duration in milliseconds since last receiver response. | |
107 MS_SINCE_LAST_RECEIVER_RESPONSE | |
108 }; | |
109 | |
110 typedef std::map<CastStat, double> StatsMap; | |
111 typedef std::map<RtpTimestamp, base::TimeTicks> FrameEventTimeMap; | |
112 typedef std::map<std::pair<RtpTimestamp, uint16>, base::TimeTicks> | |
113 PacketEventTimeMap; | |
114 typedef std::map<CastLoggingEvent, FrameLogStats> FrameStatsMap; | |
115 typedef std::map<CastLoggingEvent, PacketLogStats> PacketStatsMap; | |
116 | |
117 static const char* CastStatToString(CastStat stat); | |
118 | |
119 // // Assigns |stats_map| with stats data. Used for testing. | |
miu
2014/04/18 00:02:03
nit: Duplicate //
imcheng
2014/04/18 18:20:27
Done.
| |
120 void GetStatsInternal(StatsMap* stats_map) const; | |
121 | |
122 bool GetReceiverOffset(base::TimeDelta* offset); | |
123 void RecordFrameCapturedTime(const FrameEvent& frame_event); | |
124 void RecordE2ELatency(const FrameEvent& frame_event); | |
125 void RecordPacketSentTime(const PacketEvent& packet_event); | |
126 void ErasePacketSentTime(const PacketEvent& packet_event); | |
127 void RecordNetworkLatency(const PacketEvent& packet_event); | |
128 | |
129 void PopulateFpsStat(base::TimeTicks now, | |
130 CastLoggingEvent event, | |
131 CastStat stat, | |
132 StatsMap* stats_map) const; | |
133 void PopulatePlayoutDelayStat(StatsMap* stats_map) const; | |
134 void PopulateFrameBitrateStat(base::TimeTicks now, StatsMap* stats_map) const; | |
135 void PopulatePacketBitrateStat(base::TimeTicks now, | |
136 CastLoggingEvent event, | |
137 CastStat stat, | |
138 StatsMap* stats_map) const; | |
139 void PopulatePacketLossPercentageStat(StatsMap* stats_map) const; | |
140 | |
42 EventMediaType event_media_type_; | 141 EventMediaType event_media_type_; |
miu
2014/04/18 00:02:03
const, please. :)
imcheng
2014/04/18 18:20:27
Done.
| |
43 FrameStatsMap frame_stats_; | 142 FrameStatsMap frame_stats_; |
44 PacketStatsMap packet_stats_; | 143 PacketStatsMap packet_stats_; |
45 GenericStatsMap generic_stats_; | 144 |
145 int64 total_network_latency_ms_; | |
miu
2014/04/18 00:02:03
This member and total_e2e_latency_ms_ should be ba
imcheng
2014/04/18 18:20:27
Good catch. Thanks.
| |
146 int network_latency_datapoints_; | |
147 int64 total_e2e_latency_ms_; | |
148 int e2e_latency_datapoints_; | |
149 | |
150 base::TimeTicks last_response_received_time_; | |
151 | |
152 // Fixed size map to record when recent frames were captured. | |
153 FrameEventTimeMap frame_captured_times_; | |
154 | |
155 // Fixed size map to record when recent packets were sent. | |
156 PacketEventTimeMap packet_sent_times_; | |
157 | |
158 // Sender time assigned on creation and |Reset()|. | |
159 base::TimeTicks start_time_; | |
160 | |
161 // Not owned by this class. | |
162 base::TickClock* clock_; | |
miu
2014/04/18 00:02:03
Since clock_ and offset_estimator_ are unchanging
imcheng
2014/04/18 18:20:27
Done.
| |
163 | |
164 // Not owned by this class. | |
165 ReceiverTimeOffsetEstimator* offset_estimator_; | |
166 | |
46 base::ThreadChecker thread_checker_; | 167 base::ThreadChecker thread_checker_; |
47 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber); | 168 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber); |
48 }; | 169 }; |
49 | 170 |
50 } // namespace cast | 171 } // namespace cast |
51 } // namespace media | 172 } // namespace media |
52 | 173 |
53 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ | 174 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ |
OLD | NEW |