| 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 #include "base/values.h" |
| 9 | 10 |
| 10 namespace media { | 11 namespace media { |
| 11 namespace cast { | 12 namespace cast { |
| 12 | 13 |
| 13 LoggingStats::LoggingStats() | 14 LoggingStats::LoggingStats() |
| 14 : frame_stats_(), | 15 : frame_stats_(), |
| 15 packet_stats_(), | 16 packet_stats_(), |
| 16 generic_stats_() { | 17 generic_stats_() { |
| 17 } | 18 } |
| 18 | 19 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Does this belong to an existing event? | 69 // Does this belong to an existing event? |
| 69 FrameStatsMap::iterator it = frame_stats_.find(event); | 70 FrameStatsMap::iterator it = frame_stats_.find(event); |
| 70 if (it == frame_stats_.end()) { | 71 if (it == frame_stats_.end()) { |
| 71 // New event. | 72 // New event. |
| 72 FrameLogStats stats; | 73 FrameLogStats stats; |
| 73 stats.first_event_time = time_of_event; | 74 stats.first_event_time = time_of_event; |
| 74 stats.last_event_time = time_of_event; | 75 stats.last_event_time = time_of_event; |
| 75 stats.event_counter = 1; | 76 stats.event_counter = 1; |
| 76 frame_stats_.insert(std::make_pair(event, stats)); | 77 frame_stats_.insert(std::make_pair(event, stats)); |
| 77 } else { | 78 } else { |
| 79 ++(it->second.event_counter); |
| 78 it->second.last_event_time = time_of_event; | 80 it->second.last_event_time = time_of_event; |
| 79 ++(it->second.event_counter); | |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event, | 84 void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event, |
| 84 CastLoggingEvent event, | 85 CastLoggingEvent event, |
| 85 uint32 rtp_timestamp, | 86 uint32 rtp_timestamp, |
| 86 uint32 frame_id, | 87 uint32 frame_id, |
| 87 uint16 packet_id, | 88 uint16 packet_id, |
| 88 uint16 max_packet_id, | 89 uint16 max_packet_id, |
| 89 size_t size) { | 90 size_t size) { |
| 90 // Does this packet belong to an existing event? | 91 // Does this packet belong to an existing event? |
| 91 PacketStatsMap::iterator it = packet_stats_.find(event); | 92 PacketStatsMap::iterator it = packet_stats_.find(event); |
| 92 if (it == packet_stats_.end()) { | 93 if (it == packet_stats_.end()) { |
| 93 // New event. | 94 // New event. |
| 94 PacketLogStats stats; | 95 PacketLogStats stats; |
| 95 stats.first_event_time = time_of_event; | 96 stats.first_event_time = time_of_event; |
| 96 stats.last_event_time = time_of_event; | 97 stats.last_event_time = time_of_event; |
| 97 stats.sum_size = size; | 98 stats.sum_size = size; |
| 98 stats.event_counter = 1; | 99 stats.event_counter = 1; |
| 99 packet_stats_.insert(std::make_pair(event, stats)); | 100 packet_stats_.insert(std::make_pair(event, stats)); |
| 100 } else { | 101 } else { |
| 101 // Add to an existing event. | 102 // Add to an existing event. |
| 102 it->second.sum_size += size; | 103 it->second.sum_size += size; |
| 103 ++(it->second.event_counter); | 104 ++(it->second.event_counter); |
| 105 it->second.last_event_time = time_of_event; |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 | 108 |
| 107 void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event, | 109 void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event, |
| 108 CastLoggingEvent event, int value) { | 110 CastLoggingEvent event, int value) { |
| 109 // Does this event belong to an existing event? | 111 // Does this event belong to an existing event? |
| 110 GenericStatsMap::iterator it = generic_stats_.find(event); | 112 GenericStatsMap::iterator it = generic_stats_.find(event); |
| 111 if (it == generic_stats_.end()) { | 113 if (it == generic_stats_.end()) { |
| 112 // New event. | 114 // New event. |
| 113 GenericLogStats stats; | 115 GenericLogStats stats; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 126 ++(it->second.event_counter); | 128 ++(it->second.event_counter); |
| 127 it->second.last_event_time = time_of_event; | 129 it->second.last_event_time = time_of_event; |
| 128 if (it->second.min > value) { | 130 if (it->second.min > value) { |
| 129 it->second.min = value; | 131 it->second.min = value; |
| 130 } else if (it->second.max < value) { | 132 } else if (it->second.max < value) { |
| 131 it->second.max = value; | 133 it->second.max = value; |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 | 137 |
| 136 FrameStatsMap LoggingStats::GetFrameStatsData() const { | 138 FrameStatsMap LoggingStats::GetFrameStatsData(EventMediaType media_type) const { |
| 137 return frame_stats_; | 139 DCHECK(media_type == AUDIO_EVENT || media_type == VIDEO_EVENT); |
| 140 |
| 141 FrameStatsMap frame_map_to_return; |
| 142 for (FrameStatsMap::const_iterator it = frame_stats_.begin(); |
| 143 it != frame_stats_.end(); |
| 144 ++it) { |
| 145 if (GetEventMediaType(it->first) == media_type) { |
| 146 frame_map_to_return.insert(std::make_pair(it->first, it->second)); |
| 147 } |
| 148 } |
| 149 |
| 150 return frame_map_to_return; |
| 138 } | 151 } |
| 139 | 152 |
| 140 PacketStatsMap LoggingStats::GetPacketStatsData() const { | 153 PacketStatsMap LoggingStats::GetPacketStatsData( |
| 141 return packet_stats_; | 154 EventMediaType media_type) const { |
| 155 DCHECK(media_type == AUDIO_EVENT || media_type == VIDEO_EVENT); |
| 156 |
| 157 PacketStatsMap packet_map_to_return; |
| 158 for (PacketStatsMap::const_iterator it = packet_stats_.begin(); |
| 159 it != packet_stats_.end(); |
| 160 ++it) { |
| 161 if (GetEventMediaType(it->first) == media_type) { |
| 162 packet_map_to_return.insert(std::make_pair(it->first, it->second)); |
| 163 } |
| 164 } |
| 165 |
| 166 return packet_map_to_return; |
| 142 } | 167 } |
| 143 | 168 |
| 144 GenericStatsMap LoggingStats::GetGenericStatsData() const { | 169 GenericStatsMap LoggingStats::GetGenericStatsData() const { |
| 145 return generic_stats_; | 170 return generic_stats_; |
| 146 } | 171 } |
| 147 | 172 |
| 173 scoped_ptr<base::DictionaryValue> ConvertStats( |
| 174 const FrameStatsMap& frame_stats_map, |
| 175 const PacketStatsMap& packet_stats_map) { |
| 176 scoped_ptr<base::DictionaryValue> overall_stats(new base::DictionaryValue); |
| 177 |
| 178 scoped_ptr<base::DictionaryValue> overall_frame_stats( |
| 179 new base::DictionaryValue); |
| 180 for (FrameStatsMap::const_iterator it = frame_stats_map.begin(); |
| 181 it != frame_stats_map.end(); |
| 182 ++it) { |
| 183 scoped_ptr<base::DictionaryValue> frame_stats(new base::DictionaryValue); |
| 184 |
| 185 frame_stats->SetDouble("firstEventTime", |
| 186 it->second.first_event_time.ToInternalValue()); |
| 187 frame_stats->SetDouble("lastEventTime", |
| 188 it->second.last_event_time.ToInternalValue()); |
| 189 frame_stats->SetInteger("count", it->second.event_counter); |
| 190 frame_stats->SetInteger("sizeTotal", it->second.sum_size); |
| 191 frame_stats->SetInteger("minDelayMs", |
| 192 it->second.min_delay.InMilliseconds()); |
| 193 frame_stats->SetInteger("maxDelayMs", |
| 194 it->second.max_delay.InMilliseconds()); |
| 195 frame_stats->SetInteger("sumDelayMs", |
| 196 it->second.sum_delay.InMilliseconds()); |
| 197 |
| 198 overall_frame_stats->Set(CastLoggingToString(it->first), |
| 199 frame_stats.release()); |
| 200 } |
| 201 |
| 202 overall_stats->Set("frameStats", overall_frame_stats.release()); |
| 203 |
| 204 scoped_ptr<base::DictionaryValue> overall_packet_stats( |
| 205 new base::DictionaryValue); |
| 206 for (PacketStatsMap::const_iterator it = packet_stats_map.begin(); |
| 207 it != packet_stats_map.end(); |
| 208 ++it) { |
| 209 scoped_ptr<base::DictionaryValue> packet_stats(new base::DictionaryValue); |
| 210 |
| 211 packet_stats->SetDouble("firstEventTime", |
| 212 it->second.first_event_time.ToInternalValue()); |
| 213 packet_stats->SetDouble("lastEventTime", |
| 214 it->second.last_event_time.ToInternalValue()); |
| 215 packet_stats->SetDouble("lastEventTime", |
| 216 it->second.last_event_time.ToInternalValue()); |
| 217 packet_stats->SetInteger("count", it->second.event_counter); |
| 218 packet_stats->SetInteger("sizeTotal", it->second.sum_size); |
| 219 |
| 220 overall_packet_stats->Set(CastLoggingToString(it->first), |
| 221 packet_stats.release()); |
| 222 } |
| 223 |
| 224 overall_stats->Set("packetStats", overall_packet_stats.release()); |
| 225 |
| 226 return overall_stats.Pass(); |
| 227 } |
| 228 |
| 148 } // namespace cast | 229 } // namespace cast |
| 149 } // namespace media | 230 } // namespace media |
| OLD | NEW |