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 #include "media/cast/logging/logging_stats.h" | 5 #include "media/cast/logging/logging_stats.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Does this belong to an existing event? | 68 // Does this belong to an existing event? |
69 FrameStatsMap::iterator it = frame_stats_.find(event); | 69 FrameStatsMap::iterator it = frame_stats_.find(event); |
70 if (it == frame_stats_.end()) { | 70 if (it == frame_stats_.end()) { |
71 // New event. | 71 // New event. |
72 FrameLogStats stats; | 72 FrameLogStats stats; |
73 stats.first_event_time = time_of_event; | 73 stats.first_event_time = time_of_event; |
74 stats.last_event_time = time_of_event; | 74 stats.last_event_time = time_of_event; |
75 stats.event_counter = 1; | 75 stats.event_counter = 1; |
76 frame_stats_.insert(std::make_pair(event, stats)); | 76 frame_stats_.insert(std::make_pair(event, stats)); |
77 } else { | 77 } else { |
| 78 ++(it->second.event_counter); |
78 it->second.last_event_time = time_of_event; | 79 it->second.last_event_time = time_of_event; |
79 ++(it->second.event_counter); | |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event, | 83 void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event, |
84 CastLoggingEvent event, | 84 CastLoggingEvent event, |
85 uint32 rtp_timestamp, | 85 uint32 rtp_timestamp, |
86 uint32 frame_id, | 86 uint32 frame_id, |
87 uint16 packet_id, | 87 uint16 packet_id, |
88 uint16 max_packet_id, | 88 uint16 max_packet_id, |
89 size_t size) { | 89 size_t size) { |
90 // Does this packet belong to an existing event? | 90 // Does this packet belong to an existing event? |
91 PacketStatsMap::iterator it = packet_stats_.find(event); | 91 PacketStatsMap::iterator it = packet_stats_.find(event); |
92 if (it == packet_stats_.end()) { | 92 if (it == packet_stats_.end()) { |
93 // New event. | 93 // New event. |
94 PacketLogStats stats; | 94 PacketLogStats stats; |
95 stats.first_event_time = time_of_event; | 95 stats.first_event_time = time_of_event; |
96 stats.last_event_time = time_of_event; | 96 stats.last_event_time = time_of_event; |
97 stats.sum_size = size; | 97 stats.sum_size = size; |
98 stats.event_counter = 1; | 98 stats.event_counter = 1; |
99 packet_stats_.insert(std::make_pair(event, stats)); | 99 packet_stats_.insert(std::make_pair(event, stats)); |
100 } else { | 100 } else { |
101 // Add to an existing event. | 101 // Add to an existing event. |
102 it->second.sum_size += size; | 102 it->second.sum_size += size; |
103 ++(it->second.event_counter); | 103 ++(it->second.event_counter); |
| 104 it->second.last_event_time = time_of_event; |
104 } | 105 } |
105 } | 106 } |
106 | 107 |
107 void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event, | 108 void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event, |
108 CastLoggingEvent event, int value) { | 109 CastLoggingEvent event, int value) { |
109 // Does this event belong to an existing event? | 110 // Does this event belong to an existing event? |
110 GenericStatsMap::iterator it = generic_stats_.find(event); | 111 GenericStatsMap::iterator it = generic_stats_.find(event); |
111 if (it == generic_stats_.end()) { | 112 if (it == generic_stats_.end()) { |
112 // New event. | 113 // New event. |
113 GenericLogStats stats; | 114 GenericLogStats stats; |
(...skipping 12 matching lines...) Expand all Loading... |
126 ++(it->second.event_counter); | 127 ++(it->second.event_counter); |
127 it->second.last_event_time = time_of_event; | 128 it->second.last_event_time = time_of_event; |
128 if (it->second.min > value) { | 129 if (it->second.min > value) { |
129 it->second.min = value; | 130 it->second.min = value; |
130 } else if (it->second.max < value) { | 131 } else if (it->second.max < value) { |
131 it->second.max = value; | 132 it->second.max = value; |
132 } | 133 } |
133 } | 134 } |
134 } | 135 } |
135 | 136 |
136 FrameStatsMap LoggingStats::GetFrameStatsData() const { | 137 FrameStatsMap LoggingStats::GetFrameStatsData(EventMediaType media_type) const { |
137 return frame_stats_; | 138 DCHECK(media_type == AUDIO_EVENT || media_type == VIDEO_EVENT); |
| 139 |
| 140 FrameStatsMap frame_map_to_return; |
| 141 for (FrameStatsMap::const_iterator it = frame_stats_.begin(); |
| 142 it != frame_stats_.end(); |
| 143 ++it) { |
| 144 if (GetEventMediaType(it->first) == media_type) { |
| 145 frame_map_to_return.insert(std::make_pair(it->first, it->second)); |
| 146 } |
| 147 } |
| 148 |
| 149 return frame_map_to_return; |
138 } | 150 } |
139 | 151 |
140 PacketStatsMap LoggingStats::GetPacketStatsData() const { | 152 PacketStatsMap LoggingStats::GetPacketStatsData( |
141 return packet_stats_; | 153 EventMediaType media_type) const { |
| 154 DCHECK(media_type == AUDIO_EVENT || media_type == VIDEO_EVENT); |
| 155 |
| 156 PacketStatsMap packet_map_to_return; |
| 157 for (PacketStatsMap::const_iterator it = packet_stats_.begin(); |
| 158 it != packet_stats_.end(); |
| 159 ++it) { |
| 160 if (GetEventMediaType(it->first) == media_type) { |
| 161 packet_map_to_return.insert(std::make_pair(it->first, it->second)); |
| 162 } |
| 163 } |
| 164 |
| 165 return packet_map_to_return; |
142 } | 166 } |
143 | 167 |
144 GenericStatsMap LoggingStats::GetGenericStatsData() const { | 168 GenericStatsMap LoggingStats::GetGenericStatsData() const { |
145 return generic_stats_; | 169 return generic_stats_; |
146 } | 170 } |
147 | 171 |
148 } // namespace cast | 172 } // namespace cast |
149 } // namespace media | 173 } // namespace media |
OLD | NEW |