Remove Unused AsTextButtonBorder RTTI helper.
[chromium-blink-merge.git] / media / cast / logging / logging_impl.cc
blob5aebbe1856a28cc05f430ef5593a0dc25e49c271
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
3 // found in the LICENSE file.
5 #include "base/debug/trace_event.h"
6 #include "media/cast/logging/logging_impl.h"
7 #include "net/base/big_endian.h"
9 namespace media {
10 namespace cast {
12 LoggingImpl::LoggingImpl(
13 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy,
14 const CastLoggingConfig& config)
15 : main_thread_proxy_(main_thread_proxy),
16 config_(config),
17 raw_(),
18 stats_() {}
20 LoggingImpl::~LoggingImpl() {}
22 void LoggingImpl::InsertFrameEvent(const base::TimeTicks& time_of_event,
23 CastLoggingEvent event, uint32 rtp_timestamp,
24 uint32 frame_id) {
25 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
26 if (config_.enable_raw_data_collection) {
27 raw_.InsertFrameEvent(time_of_event, event, rtp_timestamp, frame_id);
29 if (config_.enable_stats_data_collection) {
30 stats_.InsertFrameEvent(time_of_event, event, rtp_timestamp, frame_id);
32 if (config_.enable_tracing) {
33 std::string event_string = CastLoggingToString(event);
34 TRACE_EVENT_INSTANT2(event_string.c_str(), "FE", TRACE_EVENT_SCOPE_THREAD,
35 "rtp_timestamp", rtp_timestamp, "frame_id", frame_id);
39 void LoggingImpl::InsertFrameEventWithSize(const base::TimeTicks& time_of_event,
40 CastLoggingEvent event,
41 uint32 rtp_timestamp,
42 uint32 frame_id, int frame_size) {
43 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
44 if (config_.enable_raw_data_collection) {
45 raw_.InsertFrameEventWithSize(time_of_event, event, rtp_timestamp, frame_id,
46 frame_size);
48 if (config_.enable_stats_data_collection) {
49 stats_.InsertFrameEventWithSize(time_of_event, event, rtp_timestamp,
50 frame_id, frame_size);
53 if (config_.enable_tracing) {
54 std::string event_string = CastLoggingToString(event);
55 TRACE_EVENT_INSTANT2(event_string.c_str(), "FES", TRACE_EVENT_SCOPE_THREAD,
56 "rtp_timestamp", rtp_timestamp, "frame_size",
57 frame_size);
61 void LoggingImpl::InsertFrameEventWithDelay(
62 const base::TimeTicks& time_of_event, CastLoggingEvent event,
63 uint32 rtp_timestamp, uint32 frame_id, base::TimeDelta delay) {
64 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
65 if (config_.enable_raw_data_collection) {
66 raw_.InsertFrameEventWithDelay(time_of_event, event, rtp_timestamp,
67 frame_id, delay);
69 if (config_.enable_stats_data_collection) {
70 stats_.InsertFrameEventWithDelay(time_of_event, event, rtp_timestamp,
71 frame_id, delay);
74 if (config_.enable_tracing) {
75 std::string event_string = CastLoggingToString(event);
76 TRACE_EVENT_INSTANT2(event_string.c_str(), "FED", TRACE_EVENT_SCOPE_THREAD,
77 "rtp_timestamp", rtp_timestamp, "delay",
78 delay.InMilliseconds());
82 void LoggingImpl::InsertPacketListEvent(const base::TimeTicks& time_of_event,
83 CastLoggingEvent event,
84 const PacketList& packets) {
85 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
86 for (unsigned int i = 0; i < packets.size(); ++i) {
87 const Packet& packet = packets[i];
88 // Parse basic properties.
89 uint32 rtp_timestamp;
90 uint16 packet_id, max_packet_id;
91 const uint8* packet_data = &packet[0];
92 net::BigEndianReader big_endian_reader(packet_data + 4, 4);
93 big_endian_reader.ReadU32(&rtp_timestamp);
94 net::BigEndianReader cast_big_endian_reader(packet_data + 12 + 2, 4);
95 cast_big_endian_reader.ReadU16(&packet_id);
96 cast_big_endian_reader.ReadU16(&max_packet_id);
97 // rtp_timestamp is enough - no need for frame_id as well.
98 InsertPacketEvent(time_of_event, event, rtp_timestamp, kFrameIdUnknown,
99 packet_id, max_packet_id, packet.size());
103 void LoggingImpl::InsertPacketEvent(const base::TimeTicks& time_of_event,
104 CastLoggingEvent event,
105 uint32 rtp_timestamp, uint32 frame_id,
106 uint16 packet_id, uint16 max_packet_id,
107 size_t size) {
108 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
109 if (config_.enable_raw_data_collection) {
110 raw_.InsertPacketEvent(time_of_event, event, rtp_timestamp, frame_id,
111 packet_id, max_packet_id, size);
113 if (config_.enable_stats_data_collection) {
114 stats_.InsertPacketEvent(time_of_event, event, rtp_timestamp, frame_id,
115 packet_id, max_packet_id, size);
117 if (config_.enable_tracing) {
118 std::string event_string = CastLoggingToString(event);
119 TRACE_EVENT_INSTANT2(event_string.c_str(), "PE", TRACE_EVENT_SCOPE_THREAD,
120 "rtp_timestamp", rtp_timestamp, "packet_id",
121 packet_id);
125 void LoggingImpl::InsertGenericEvent(const base::TimeTicks& time_of_event,
126 CastLoggingEvent event, int value) {
127 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
128 if (config_.enable_raw_data_collection) {
129 raw_.InsertGenericEvent(time_of_event, event, value);
131 if (config_.enable_stats_data_collection) {
132 stats_.InsertGenericEvent(time_of_event, event, value);
135 if (config_.enable_tracing) {
136 std::string event_string = CastLoggingToString(event);
137 TRACE_EVENT_INSTANT1(event_string.c_str(), "GE", TRACE_EVENT_SCOPE_THREAD,
138 "value", value);
142 void LoggingImpl::AddRawEventSubscriber(RawEventSubscriber* subscriber) {
143 raw_.AddSubscriber(subscriber);
146 void LoggingImpl::RemoveRawEventSubscriber(RawEventSubscriber* subscriber) {
147 raw_.RemoveSubscriber(subscriber);
150 FrameStatsMap LoggingImpl::GetFrameStatsData() const {
151 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
152 return stats_.GetFrameStatsData();
155 PacketStatsMap LoggingImpl::GetPacketStatsData() const {
156 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
157 return stats_.GetPacketStatsData();
160 GenericStatsMap LoggingImpl::GetGenericStatsData() const {
161 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
162 return stats_.GetGenericStatsData();
165 void LoggingImpl::ResetStats() {
166 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
167 stats_.Reset();
170 } // namespace cast
171 } // namespace media