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

Side by Side Diff: media/cast/logging/stats_event_subscriber.h

Issue 236123003: Cast: Provide more meaningful stats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
OLDNEW
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,
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
106 };
107
108 typedef std::map<CastStat, double> StatsMap;
109 typedef std::map<RtpTimestamp, base::TimeTicks> FrameEventTimeMap;
110 typedef std::map<std::pair<RtpTimestamp, uint16>, base::TimeTicks>
111 PacketEventTimeMap;
112 typedef std::map<CastLoggingEvent, FrameLogStats> FrameStatsMap;
113 typedef std::map<CastLoggingEvent, PacketLogStats> PacketStatsMap;
114
115 static const char* CastStatToString(CastStat stat);
116
117 // // Assigns |stats_map| with stats data. Used for testing.
118 void GetStatsInternal(StatsMap* stats_map) const;
119
120 bool GetReceiverOffset(base::TimeDelta* offset);
121 void RecordFrameCapturedTime(const FrameEvent& frame_event);
122 void RecordE2ELatency(const FrameEvent& frame_event);
123 void RecordPacketSentTime(const PacketEvent& packet_event);
124 void ErasePacketSentTime(const PacketEvent& packet_event);
125 void RecordNetworkLatency(const PacketEvent& packet_event);
126
127 void PopulateFpsStat(base::TimeTicks now,
128 CastLoggingEvent event,
129 CastStat stat,
130 StatsMap* stats_map) const;
131 void PopulatePlayoutDelayStat(StatsMap* stats_map) const;
132 void PopulateFrameBitrateStat(base::TimeTicks now, StatsMap* stats_map) const;
133 void PopulatePacketBitrateStat(base::TimeTicks now,
134 CastLoggingEvent event,
135 CastStat stat,
136 StatsMap* stats_map) const;
137 void PopulatePacketLossPercentageStat(StatsMap* stats_map) const;
138
42 EventMediaType event_media_type_; 139 EventMediaType event_media_type_;
43 FrameStatsMap frame_stats_; 140 FrameStatsMap frame_stats_;
44 PacketStatsMap packet_stats_; 141 PacketStatsMap packet_stats_;
45 GenericStatsMap generic_stats_; 142
143 int64 total_network_latency_ms_;
144 int network_latency_datapoints_;
145 int64 total_e2e_latency_ms_;
146 int e2e_latency_datapoints_;
147
148 // Fixed size map to record when recent frames were captured.
149 FrameEventTimeMap frame_captured_times_;
150
151 // Fixed size map to record when recent packets were sent.
152 PacketEventTimeMap packet_sent_times_;
153
154 // Sender time assigned on creation and |Reset()|.
155 base::TimeTicks start_time_;
156
157 // Not owned by this class.
158 base::TickClock* clock_;
159
160 // Not owned by this class.
161 ReceiverTimeOffsetEstimator* offset_estimator_;
162
46 base::ThreadChecker thread_checker_; 163 base::ThreadChecker thread_checker_;
47 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber); 164 DISALLOW_COPY_AND_ASSIGN(StatsEventSubscriber);
48 }; 165 };
49 166
50 } // namespace cast 167 } // namespace cast
51 } // namespace media 168 } // namespace media
52 169
53 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_ 170 #endif // MEDIA_CAST_LOGGING_STATS_EVENT_SUBSCRIBER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698