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" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // describes the name of the stat, and the double describes | 42 // describes the name of the stat, and the double describes |
43 // the value of the stat. See CastStat and StatsMap below. | 43 // the value of the stat. See CastStat and StatsMap below. |
44 scoped_ptr<base::DictionaryValue> GetStats() const; | 44 scoped_ptr<base::DictionaryValue> GetStats() const; |
45 | 45 |
46 // Resets stats in this object. | 46 // Resets stats in this object. |
47 void Reset(); | 47 void Reset(); |
48 | 48 |
49 private: | 49 private: |
50 friend class StatsEventSubscriberTest; | 50 friend class StatsEventSubscriberTest; |
51 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, EmptyStats); | 51 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, EmptyStats); |
52 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Capture); | 52 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, CaptureEncode); |
53 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Encode); | 53 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Encode); |
54 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Decode); | 54 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Decode); |
55 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, PlayoutDelay); | 55 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, PlayoutDelay); |
56 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, E2ELatency); | 56 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, E2ELatency); |
57 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Packets); | 57 FRIEND_TEST_ALL_PREFIXES(StatsEventSubscriberTest, Packets); |
58 | 58 |
| 59 static const size_t kMaxFrameInfoMapSize = 100; |
| 60 |
59 // Generic statistics given the raw data. More specific data (e.g. frame rate | 61 // Generic statistics given the raw data. More specific data (e.g. frame rate |
60 // and bit rate) can be computed given the basic metrics. | 62 // and bit rate) can be computed given the basic metrics. |
61 // Some of the metrics will only be set when applicable, e.g. delay and size. | 63 // Some of the metrics will only be set when applicable, e.g. delay and size. |
62 struct FrameLogStats { | 64 struct FrameLogStats { |
63 FrameLogStats(); | 65 FrameLogStats(); |
64 ~FrameLogStats(); | 66 ~FrameLogStats(); |
65 int event_counter; | 67 int event_counter; |
66 size_t sum_size; | 68 size_t sum_size; |
67 base::TimeDelta sum_delay; | 69 base::TimeDelta sum_delay; |
68 }; | 70 }; |
69 | 71 |
70 struct PacketLogStats { | 72 struct PacketLogStats { |
71 PacketLogStats(); | 73 PacketLogStats(); |
72 ~PacketLogStats(); | 74 ~PacketLogStats(); |
73 int event_counter; | 75 int event_counter; |
74 size_t sum_size; | 76 size_t sum_size; |
75 }; | 77 }; |
76 | 78 |
77 enum CastStat { | 79 enum CastStat { |
78 // Capture frame rate. | 80 // Capture frame rate. |
79 CAPTURE_FPS, | 81 CAPTURE_FPS, |
80 // Encode frame rate. | 82 // Encode frame rate. |
81 ENCODE_FPS, | 83 ENCODE_FPS, |
82 // Decode frame rate. | 84 // Decode frame rate. |
83 DECODE_FPS, | 85 DECODE_FPS, |
84 // Average encode duration in milliseconds. | 86 // Average encode duration in milliseconds. |
85 // TODO(imcheng): This stat is not populated yet because we do not have | 87 // TODO(imcheng): This stat is not populated yet because we do not have |
86 // the time when encode started. Record it in FRAME_ENCODED event. | 88 // the time when encode started. Record it in FRAME_ENCODED event. |
87 AVG_ENCODE_TIME_MS, | 89 AVG_ENCODE_TIME_MS, |
88 // Average playout delay in milliseconds, with target delay already | 90 // Average playout delay in milliseconds. |
89 // accounted for. Ideally, every frame should have a playout delay of 0. | |
90 AVG_PLAYOUT_DELAY_MS, | 91 AVG_PLAYOUT_DELAY_MS, |
91 // Duration from when a packet is transmitted to when it is received. | 92 // Duration from when a packet is transmitted to when it is received. |
92 // This measures latency from sender to receiver. | 93 // This measures latency from sender to receiver. |
93 AVG_NETWORK_LATENCY_MS, | 94 AVG_NETWORK_LATENCY_MS, |
94 // Duration from when a frame is captured to when it should be played out. | 95 // Duration from when a frame is captured to when it should be played out. |
95 AVG_E2E_LATENCY_MS, | 96 AVG_E2E_LATENCY_MS, |
96 // Encode bitrate in kbps. | 97 // Encode bitrate in kbps. |
97 ENCODE_KBPS, | 98 ENCODE_KBPS, |
98 // Packet transmission bitrate in kbps. | 99 // Packet transmission bitrate in kbps. |
99 TRANSMISSION_KBPS, | 100 TRANSMISSION_KBPS, |
100 // Packet retransmission bitrate in kbps. | 101 // Packet retransmission bitrate in kbps. |
101 RETRANSMISSION_KBPS, | 102 RETRANSMISSION_KBPS, |
102 // Fraction of packet loss. | 103 // Fraction of packet loss. |
103 PACKET_LOSS_FRACTION, | 104 PACKET_LOSS_FRACTION, |
104 // Duration in milliseconds since last receiver response. | 105 // Duration in milliseconds since last receiver response. |
105 MS_SINCE_LAST_RECEIVER_RESPONSE | 106 MS_SINCE_LAST_RECEIVER_RESPONSE, |
| 107 // Number of frames captured. |
| 108 NUM_FRAMES_CAPTURED, |
| 109 // Number of frames dropped by encoder. |
| 110 NUM_FRAMES_DROPPED_BY_ENCODER, |
| 111 // Number of late frames. |
| 112 NUM_FRAMES_LATE, |
| 113 // Number of packets that were sent (not retransmitted). |
| 114 NUM_PACKETS_SENT, |
| 115 // Number of packets that were retransmitted. |
| 116 NUM_PACKETS_RETRANSMITTED, |
| 117 // Number of packets that had their retransmission cancelled. |
| 118 NUM_PACKETS_RTX_REJECTED, |
| 119 }; |
| 120 |
| 121 struct FrameInfo { |
| 122 explicit FrameInfo(base::TimeTicks capture_time); |
| 123 ~FrameInfo(); |
| 124 |
| 125 base::TimeTicks capture_time; |
| 126 bool encoded; |
106 }; | 127 }; |
107 | 128 |
108 typedef std::map<CastStat, double> StatsMap; | 129 typedef std::map<CastStat, double> StatsMap; |
109 typedef std::map<RtpTimestamp, base::TimeTicks> FrameEventTimeMap; | 130 typedef std::map<RtpTimestamp, FrameInfo> FrameInfoMap; |
110 typedef std::map< | 131 typedef std::map< |
111 std::pair<RtpTimestamp, uint16>, | 132 std::pair<RtpTimestamp, uint16>, |
112 std::pair<base::TimeTicks, CastLoggingEvent> > | 133 std::pair<base::TimeTicks, CastLoggingEvent> > |
113 PacketEventTimeMap; | 134 PacketEventTimeMap; |
114 typedef std::map<CastLoggingEvent, FrameLogStats> FrameStatsMap; | 135 typedef std::map<CastLoggingEvent, FrameLogStats> FrameStatsMap; |
115 typedef std::map<CastLoggingEvent, PacketLogStats> PacketStatsMap; | 136 typedef std::map<CastLoggingEvent, PacketLogStats> PacketStatsMap; |
116 | 137 |
117 static const char* CastStatToString(CastStat stat); | 138 static const char* CastStatToString(CastStat stat); |
118 | 139 |
119 // Assigns |stats_map| with stats data. Used for testing. | 140 // Assigns |stats_map| with stats data. Used for testing. |
120 void GetStatsInternal(StatsMap* stats_map) const; | 141 void GetStatsInternal(StatsMap* stats_map) const; |
121 | 142 |
122 bool GetReceiverOffset(base::TimeDelta* offset); | 143 bool GetReceiverOffset(base::TimeDelta* offset); |
123 void RecordFrameCapturedTime(const FrameEvent& frame_event); | 144 void RecordFrameCaptureTime(const FrameEvent& frame_event); |
| 145 void MarkAsEncoded(RtpTimestamp rtp_timestamp); |
124 void RecordE2ELatency(const FrameEvent& frame_event); | 146 void RecordE2ELatency(const FrameEvent& frame_event); |
125 void RecordPacketSentTime(const PacketEvent& packet_event); | 147 void RecordPacketSentTime(const PacketEvent& packet_event); |
126 void ErasePacketSentTime(const PacketEvent& packet_event); | 148 void ErasePacketSentTime(const PacketEvent& packet_event); |
127 void RecordNetworkLatency(const PacketEvent& packet_event); | 149 void RecordNetworkLatency(const PacketEvent& packet_event); |
128 void UpdateLastResponseTime(base::TimeTicks receiver_time); | 150 void UpdateLastResponseTime(base::TimeTicks receiver_time); |
129 | 151 |
130 void PopulateFpsStat(base::TimeTicks now, | 152 void PopulateFpsStat(base::TimeTicks now, |
131 CastLoggingEvent event, | 153 CastLoggingEvent event, |
132 CastStat stat, | 154 CastStat stat, |
133 StatsMap* stats_map) const; | 155 StatsMap* stats_map) const; |
| 156 void PopulateFrameCountStat(CastLoggingEvent event, |
| 157 CastStat stat, |
| 158 StatsMap* stats_map) const; |
| 159 void PopulatePacketCountStat(CastLoggingEvent event, |
| 160 CastStat stat, |
| 161 StatsMap* stats_map) const; |
134 void PopulatePlayoutDelayStat(StatsMap* stats_map) const; | 162 void PopulatePlayoutDelayStat(StatsMap* stats_map) const; |
135 void PopulateFrameBitrateStat(base::TimeTicks now, StatsMap* stats_map) const; | 163 void PopulateFrameBitrateStat(base::TimeTicks now, StatsMap* stats_map) const; |
136 void PopulatePacketBitrateStat(base::TimeTicks now, | 164 void PopulatePacketBitrateStat(base::TimeTicks now, |
137 CastLoggingEvent event, | 165 CastLoggingEvent event, |
138 CastStat stat, | 166 CastStat stat, |
139 StatsMap* stats_map) const; | 167 StatsMap* stats_map) const; |
140 void PopulatePacketLossPercentageStat(StatsMap* stats_map) const; | 168 void PopulatePacketLossPercentageStat(StatsMap* stats_map) const; |
141 | 169 |
142 const EventMediaType event_media_type_; | 170 const EventMediaType event_media_type_; |
143 | 171 |
144 // Not owned by this class. | 172 // Not owned by this class. |
145 base::TickClock* const clock_; | 173 base::TickClock* const clock_; |
146 | 174 |
147 // Not owned by this class. | 175 // Not owned by this class. |
148 ReceiverTimeOffsetEstimator* const offset_estimator_; | 176 ReceiverTimeOffsetEstimator* const offset_estimator_; |
149 | 177 |
150 FrameStatsMap frame_stats_; | 178 FrameStatsMap frame_stats_; |
151 PacketStatsMap packet_stats_; | 179 PacketStatsMap packet_stats_; |
152 | 180 |
153 base::TimeDelta total_network_latency_; | 181 base::TimeDelta total_network_latency_; |
154 int network_latency_datapoints_; | 182 int network_latency_datapoints_; |
155 base::TimeDelta total_e2e_latency_; | 183 base::TimeDelta total_e2e_latency_; |
156 int e2e_latency_datapoints_; | 184 int e2e_latency_datapoints_; |
157 | 185 |
158 base::TimeTicks last_response_received_time_; | 186 base::TimeTicks last_response_received_time_; |
159 | 187 |
160 // Fixed size map to record when recent frames were captured. | 188 int num_frames_dropped_by_encoder_; |
161 FrameEventTimeMap frame_captured_times_; | 189 int num_frames_late_; |
| 190 |
| 191 // Fixed size map to record when recent frames were captured and other info. |
| 192 FrameInfoMap recent_captured_frames_; |
162 | 193 |
163 // Fixed size map to record when recent packets were sent. | 194 // Fixed size map to record when recent packets were sent. |
164 PacketEventTimeMap packet_sent_times_; | 195 PacketEventTimeMap packet_sent_times_; |
165 | 196 |
166 // Sender time assigned on creation and |Reset()|. | 197 // Sender time assigned on creation and |Reset()|. |
167 base::TimeTicks start_time_; | 198 base::TimeTicks start_time_; |
168 | 199 |
169 base::ThreadChecker thread_checker_; | 200 base::ThreadChecker thread_checker_; |
170 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber); | 201 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber); |
171 }; | 202 }; |
172 | 203 |
173 } // namespace cast | 204 } // namespace cast |
174 } // namespace media | 205 } // namespace media |
175 | 206 |
176 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ | 207 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ |
OLD | NEW |