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
3 // found in the LICENSE file.
5 #include "media/cast/logging/stats_util.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
14 scoped_ptr<base::DictionaryValue> ConvertStats(
15 const FrameStatsMap& frame_stats_map,
16 const PacketStatsMap& packet_stats_map) {
17 scoped_ptr<base::DictionaryValue> overall_stats(new base::DictionaryValue);
19 scoped_ptr<base::DictionaryValue> overall_frame_stats(
20 new base::DictionaryValue);
21 for (FrameStatsMap::const_iterator it = frame_stats_map.begin();
22 it != frame_stats_map.end();
24 scoped_ptr<base::DictionaryValue> frame_stats(new base::DictionaryValue);
26 frame_stats->SetDouble("firstEventTime",
27 it->second.first_event_time.ToInternalValue());
28 frame_stats->SetDouble("lastEventTime",
29 it->second.last_event_time.ToInternalValue());
30 frame_stats->SetInteger("count", it->second.event_counter);
31 frame_stats->SetInteger("sizeTotal", static_cast<int>(it->second.sum_size));
32 frame_stats->SetInteger("minDelayMs",
33 it->second.min_delay.InMilliseconds());
34 frame_stats->SetInteger("maxDelayMs",
35 it->second.max_delay.InMilliseconds());
36 frame_stats->SetInteger("sumDelayMs",
37 it->second.sum_delay.InMilliseconds());
39 overall_frame_stats->Set(CastLoggingToString(it->first),
40 frame_stats.release());
43 overall_stats->Set("frameStats", overall_frame_stats.release());
45 scoped_ptr<base::DictionaryValue> overall_packet_stats(
46 new base::DictionaryValue);
47 for (PacketStatsMap::const_iterator it = packet_stats_map.begin();
48 it != packet_stats_map.end();
50 scoped_ptr<base::DictionaryValue> packet_stats(new base::DictionaryValue);
52 packet_stats->SetDouble("firstEventTime",
53 it->second.first_event_time.ToInternalValue());
54 packet_stats->SetDouble("lastEventTime",
55 it->second.last_event_time.ToInternalValue());
56 packet_stats->SetDouble("lastEventTime",
57 it->second.last_event_time.ToInternalValue());
58 packet_stats->SetInteger("count", it->second.event_counter);
59 packet_stats->SetInteger("sizeTotal",
60 static_cast<int>(it->second.sum_size));
62 overall_packet_stats->Set(CastLoggingToString(it->first),
63 packet_stats.release());
66 overall_stats->Set("packetStats", overall_packet_stats.release());
68 return overall_stats.Pass();