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. 4 5 #include "media/cast/logging/logging_raw.h" 6 7 #include "base/logging.h" 8 #include "base/metrics/histogram.h" 9 #include "base/time/time.h" 10 11 namespace media { 12 namespace cast { 13 14 LoggingRaw::LoggingRaw(base::TickClock* clock) 15 : clock_(clock), 16 frame_map_(), 17 packet_map_(), 18 generic_map_(), 19 weak_factory_(this) {} 20 21 LoggingRaw::~LoggingRaw() {} 22 23 void LoggingRaw::InsertFrameEvent(CastLoggingEvent event, 24 uint32 rtp_timestamp, 25 uint32 frame_id) { 26 InsertBaseFrameEvent(event, frame_id, rtp_timestamp); 27 } 28 29 void LoggingRaw::InsertFrameEventWithSize(CastLoggingEvent event, 30 uint32 rtp_timestamp, 31 uint32 frame_id, 32 int size) { 33 InsertBaseFrameEvent(event, frame_id, rtp_timestamp); 34 // Now insert size. 35 FrameRawMap::iterator it = frame_map_.find(rtp_timestamp); 36 DCHECK(it != frame_map_.end()); 37 it->second.size = size; 38 } 39 40 void LoggingRaw::InsertFrameEventWithDelay(CastLoggingEvent event, 41 uint32 rtp_timestamp, 42 uint32 frame_id, 43 base::TimeDelta delay) { 44 InsertBaseFrameEvent(event, frame_id, rtp_timestamp); 45 // Now insert delay. 46 FrameRawMap::iterator it = frame_map_.find(rtp_timestamp); 47 DCHECK(it != frame_map_.end()); 48 it->second.delay_delta = delay; 49 } 50 51 void LoggingRaw::InsertBaseFrameEvent(CastLoggingEvent event, 52 uint32 frame_id, 53 uint32 rtp_timestamp) { 54 // Is this a new event? 55 FrameRawMap::iterator it = frame_map_.find(rtp_timestamp); 56 if (it == frame_map_.end()) { 57 // Create a new map entry. 58 FrameEvent info; 59 info.frame_id = frame_id; 60 info.timestamp.push_back(clock_->NowTicks()); 61 info.type.push_back(event); 62 frame_map_.insert(std::make_pair(rtp_timestamp, info)); 63 } else { 64 // Insert to an existing entry. 65 it->second.timestamp.push_back(clock_->NowTicks()); 66 it->second.type.push_back(event); 67 // Do we have a valid frame_id? 68 // Not all events have a valid frame id. 69 if (it->second.frame_id == kFrameIdUnknown && frame_id != kFrameIdUnknown) 70 it->second.frame_id = frame_id; 71 } 72 } 73 74 void LoggingRaw::InsertPacketEvent(CastLoggingEvent event, 75 uint32 rtp_timestamp, 76 uint32 frame_id, 77 uint16 packet_id, 78 uint16 max_packet_id, 79 size_t size) { 80 // Is this packet belonging to a new frame? 81 PacketRawMap::iterator it = packet_map_.find(rtp_timestamp); 82 if (it == packet_map_.end()) { 83 // Create a new entry - start with base packet map. 84 PacketEvent info; 85 info.frame_id = frame_id; 86 info.max_packet_id = max_packet_id; 87 BasePacketInfo base_info; 88 base_info.size = size; 89 base_info.timestamp.push_back(clock_->NowTicks()); 90 base_info.type.push_back(event); 91 packet_map_.insert(std::make_pair(rtp_timestamp, info)); 92 } else { 93 // Is this a new packet? 94 BasePacketMap::iterator packet_it = it->second.packet_map.find(packet_id); 95 if (packet_it == it->second.packet_map.end()) { 96 BasePacketInfo base_info; 97 base_info.size = size; 98 base_info.timestamp.push_back(clock_->NowTicks()); 99 base_info.type.push_back(event); 100 it->second.packet_map.insert(std::make_pair(packet_id, base_info)); 101 } else { 102 packet_it->second.timestamp.push_back(clock_->NowTicks()); 103 packet_it->second.type.push_back(event); 104 } 105 } 106 } 107 108 void LoggingRaw::InsertGenericEvent(CastLoggingEvent event, int value) { 109 GenericEvent event_data; 110 event_data.value.push_back(value); 111 event_data.timestamp.push_back(clock_->NowTicks()); 112 // Is this a new event? 113 GenericRawMap::iterator it = generic_map_.find(event); 114 if (it == generic_map_.end()) { 115 // Create new entry. 116 generic_map_.insert(std::make_pair(event, event_data)); 117 } else { 118 // Insert to existing entry. 119 it->second.value.push_back(value); 120 it->second.timestamp.push_back(clock_->NowTicks()); 121 } 122 } 123 124 FrameRawMap LoggingRaw::GetFrameData() const { 125 return frame_map_; 126 } 127 128 PacketRawMap LoggingRaw::GetPacketData() const { 129 return packet_map_; 130 } 131 132 GenericRawMap LoggingRaw::GetGenericData() const { 133 return generic_map_; 134 } 135 136 void LoggingRaw::Reset() { 137 frame_map_.clear(); 138 packet_map_.clear(); 139 generic_map_.clear(); 140 } 141 142 } // namespace cast 143 } // namespace media 144