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/big_endian.h"
6 #include "base/debug/trace_event.h"
7 #include "media/cast/logging/logging_impl.h"
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();
19 LoggingImpl::~LoggingImpl() {}
21 void LoggingImpl::InsertFrameEvent(const base::TimeTicks
& time_of_event
,
22 CastLoggingEvent event
,
23 EventMediaType event_media_type
,
26 DCHECK(thread_checker_
.CalledOnValidThread());
27 raw_
.InsertFrameEvent(time_of_event
, event
, event_media_type
,
28 rtp_timestamp
, frame_id
);
31 void LoggingImpl::InsertEncodedFrameEvent(const base::TimeTicks
& time_of_event
,
32 CastLoggingEvent event
,
33 EventMediaType event_media_type
,
35 uint32 frame_id
, int frame_size
,
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
);
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
);
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());
58 // Parse basic properties.
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
);
70 // rtp_timestamp is enough - no need for frame_id as well.
71 InsertPacketEvent(time_of_event
,
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();
88 InsertSinglePacketEvent(time_of_event
, event
, event_media_type
,
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
,
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
);
104 void LoggingImpl::AddRawEventSubscriber(RawEventSubscriber
* subscriber
) {
105 DCHECK(thread_checker_
.CalledOnValidThread());
106 raw_
.AddSubscriber(subscriber
);
109 void LoggingImpl::RemoveRawEventSubscriber(RawEventSubscriber
* subscriber
) {
110 DCHECK(thread_checker_
.CalledOnValidThread());
111 raw_
.RemoveSubscriber(subscriber
);