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
, uint32 rtp_timestamp
,
24 DCHECK(thread_checker_
.CalledOnValidThread());
25 raw_
.InsertFrameEvent(time_of_event
, event
, rtp_timestamp
, frame_id
);
28 void LoggingImpl::InsertEncodedFrameEvent(const base::TimeTicks
& time_of_event
,
29 CastLoggingEvent event
,
31 uint32 frame_id
, int frame_size
,
34 DCHECK(thread_checker_
.CalledOnValidThread());
35 raw_
.InsertEncodedFrameEvent(time_of_event
, event
, rtp_timestamp
, frame_id
,
36 frame_size
, key_frame
, target_bitrate
);
39 void LoggingImpl::InsertFrameEventWithDelay(
40 const base::TimeTicks
& time_of_event
, CastLoggingEvent event
,
41 uint32 rtp_timestamp
, uint32 frame_id
, base::TimeDelta delay
) {
42 DCHECK(thread_checker_
.CalledOnValidThread());
43 raw_
.InsertFrameEventWithDelay(time_of_event
, event
, rtp_timestamp
,
47 void LoggingImpl::InsertSinglePacketEvent(const base::TimeTicks
& time_of_event
,
48 CastLoggingEvent event
,
49 const Packet
& packet
) {
50 DCHECK(thread_checker_
.CalledOnValidThread());
52 // Parse basic properties.
54 uint16 packet_id
, max_packet_id
;
55 const uint8
* packet_data
= &packet
[0];
56 base::BigEndianReader
big_endian_reader(
57 reinterpret_cast<const char*>(packet_data
+ 4), 4);
58 big_endian_reader
.ReadU32(&rtp_timestamp
);
59 base::BigEndianReader
cast_big_endian_reader(
60 reinterpret_cast<const char*>(packet_data
+ 12 + 2), 4);
61 cast_big_endian_reader
.ReadU16(&packet_id
);
62 cast_big_endian_reader
.ReadU16(&max_packet_id
);
64 // rtp_timestamp is enough - no need for frame_id as well.
65 InsertPacketEvent(time_of_event
,
74 void LoggingImpl::InsertPacketListEvent(const base::TimeTicks
& time_of_event
,
75 CastLoggingEvent event
,
76 const PacketList
& packets
) {
77 DCHECK(thread_checker_
.CalledOnValidThread());
78 for (PacketList::const_iterator it
= packets
.begin(); it
!= packets
.end();
80 InsertSinglePacketEvent(time_of_event
, event
, (*it
)->data
);
84 void LoggingImpl::InsertPacketEvent(const base::TimeTicks
& time_of_event
,
85 CastLoggingEvent event
,
86 uint32 rtp_timestamp
, uint32 frame_id
,
87 uint16 packet_id
, uint16 max_packet_id
,
89 DCHECK(thread_checker_
.CalledOnValidThread());
90 raw_
.InsertPacketEvent(time_of_event
, event
, rtp_timestamp
, frame_id
,
91 packet_id
, max_packet_id
, size
);
94 void LoggingImpl::AddRawEventSubscriber(RawEventSubscriber
* subscriber
) {
95 DCHECK(thread_checker_
.CalledOnValidThread());
96 raw_
.AddSubscriber(subscriber
);
99 void LoggingImpl::RemoveRawEventSubscriber(RawEventSubscriber
* subscriber
) {
100 DCHECK(thread_checker_
.CalledOnValidThread());
101 raw_
.RemoveSubscriber(subscriber
);