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 "base/big_endian.h" 6 #include "base/debug/trace_event.h" 7 #include "media/cast/logging/logging_impl.h" 8 9 namespace media { 10 namespace cast { 11 12 // TODO(imcheng): Collapse LoggingRaw onto LoggingImpl. 13 LoggingImpl::LoggingImpl() { 14 // LoggingImpl can be constructed on any thread, but its methods should all be 15 // called on the same thread. 16 thread_checker_.DetachFromThread(); 17 } 18 19 LoggingImpl::~LoggingImpl() {} 20 21 void LoggingImpl::InsertFrameEvent(const base::TimeTicks& time_of_event, 22 CastLoggingEvent event, 23 EventMediaType event_media_type, 24 uint32 rtp_timestamp, 25 uint32 frame_id) { 26 DCHECK(thread_checker_.CalledOnValidThread()); 27 raw_.InsertFrameEvent(time_of_event, event, event_media_type, 28 rtp_timestamp, frame_id); 29 } 30 31 void LoggingImpl::InsertEncodedFrameEvent(const base::TimeTicks& time_of_event, 32 CastLoggingEvent event, 33 EventMediaType event_media_type, 34 uint32 rtp_timestamp, 35 uint32 frame_id, int frame_size, 36 bool key_frame, 37 int target_bitrate) { 38 DCHECK(thread_checker_.CalledOnValidThread()); 39 raw_.InsertEncodedFrameEvent(time_of_event, event, event_media_type, 40 rtp_timestamp, frame_id, frame_size, key_frame, target_bitrate); 41 } 42 43 void LoggingImpl::InsertFrameEventWithDelay( 44 const base::TimeTicks& time_of_event, CastLoggingEvent event, 45 EventMediaType event_media_type, uint32 rtp_timestamp, uint32 frame_id, 46 base::TimeDelta delay) { 47 DCHECK(thread_checker_.CalledOnValidThread()); 48 raw_.InsertFrameEventWithDelay(time_of_event, event, event_media_type, 49 rtp_timestamp, frame_id, delay); 50 } 51 52 void LoggingImpl::InsertSinglePacketEvent(const base::TimeTicks& time_of_event, 53 CastLoggingEvent event, 54 EventMediaType event_media_type, 55 const Packet& packet) { 56 DCHECK(thread_checker_.CalledOnValidThread()); 57 58 // Parse basic properties. 59 uint32 rtp_timestamp; 60 uint16 packet_id, max_packet_id; 61 const uint8* packet_data = &packet[0]; 62 base::BigEndianReader big_endian_reader( 63 reinterpret_cast<const char*>(packet_data + 4), 4); 64 big_endian_reader.ReadU32(&rtp_timestamp); 65 base::BigEndianReader cast_big_endian_reader( 66 reinterpret_cast<const char*>(packet_data + 12 + 2), 4); 67 cast_big_endian_reader.ReadU16(&packet_id); 68 cast_big_endian_reader.ReadU16(&max_packet_id); 69 70 // rtp_timestamp is enough - no need for frame_id as well. 71 InsertPacketEvent(time_of_event, 72 event, 73 event_media_type, 74 rtp_timestamp, 75 kFrameIdUnknown, 76 packet_id, 77 max_packet_id, 78 packet.size()); 79 } 80 81 void LoggingImpl::InsertPacketListEvent(const base::TimeTicks& time_of_event, 82 CastLoggingEvent event, 83 EventMediaType event_media_type, 84 const PacketList& packets) { 85 DCHECK(thread_checker_.CalledOnValidThread()); 86 for (PacketList::const_iterator it = packets.begin(); it != packets.end(); 87 ++it) { 88 InsertSinglePacketEvent(time_of_event, event, event_media_type, 89 (*it)->data); 90 } 91 } 92 93 void LoggingImpl::InsertPacketEvent(const base::TimeTicks& time_of_event, 94 CastLoggingEvent event, 95 EventMediaType event_media_type, 96 uint32 rtp_timestamp, uint32 frame_id, 97 uint16 packet_id, uint16 max_packet_id, 98 size_t size) { 99 DCHECK(thread_checker_.CalledOnValidThread()); 100 raw_.InsertPacketEvent(time_of_event, event, event_media_type, 101 rtp_timestamp, frame_id, packet_id, max_packet_id, size); 102 } 103 104 void LoggingImpl::AddRawEventSubscriber(RawEventSubscriber* subscriber) { 105 DCHECK(thread_checker_.CalledOnValidThread()); 106 raw_.AddSubscriber(subscriber); 107 } 108 109 void LoggingImpl::RemoveRawEventSubscriber(RawEventSubscriber* subscriber) { 110 DCHECK(thread_checker_.CalledOnValidThread()); 111 raw_.RemoveSubscriber(subscriber); 112 } 113 114 } // namespace cast 115 } // namespace media 116