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/trace_event/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::InsertCapturedVideoFrameEvent(
32 const base::TimeTicks
& time_of_event
,
36 DCHECK(thread_checker_
.CalledOnValidThread());
37 raw_
.InsertCapturedVideoFrameEvent(
38 time_of_event
, rtp_timestamp
, width
, height
);
42 void LoggingImpl::InsertEncodedFrameEvent(
43 const base::TimeTicks
& time_of_event
,
44 CastLoggingEvent event
,
45 EventMediaType event_media_type
,
51 double encoder_cpu_utilization
,
52 double idealized_bitrate_utilization
) {
53 DCHECK(thread_checker_
.CalledOnValidThread());
54 raw_
.InsertEncodedFrameEvent(time_of_event
, event
, event_media_type
,
55 rtp_timestamp
, frame_id
, encoded_size
, key_frame
, target_bitrate
,
56 encoder_cpu_utilization
, idealized_bitrate_utilization
);
59 void LoggingImpl::InsertFrameEventWithDelay(
60 const base::TimeTicks
& time_of_event
, CastLoggingEvent event
,
61 EventMediaType event_media_type
, uint32 rtp_timestamp
, uint32 frame_id
,
62 base::TimeDelta delay
) {
63 DCHECK(thread_checker_
.CalledOnValidThread());
64 raw_
.InsertFrameEventWithDelay(time_of_event
, event
, event_media_type
,
65 rtp_timestamp
, frame_id
, delay
);
68 void LoggingImpl::InsertSinglePacketEvent(const base::TimeTicks
& time_of_event
,
69 CastLoggingEvent event
,
70 EventMediaType event_media_type
,
71 const Packet
& packet
) {
72 DCHECK(thread_checker_
.CalledOnValidThread());
74 // Parse basic properties.
76 uint16 packet_id
, max_packet_id
;
77 const uint8
* packet_data
= &packet
[0];
78 base::BigEndianReader
big_endian_reader(
79 reinterpret_cast<const char*>(packet_data
+ 4), 4);
80 big_endian_reader
.ReadU32(&rtp_timestamp
);
81 base::BigEndianReader
cast_big_endian_reader(
82 reinterpret_cast<const char*>(packet_data
+ 12 + 2), 4);
83 cast_big_endian_reader
.ReadU16(&packet_id
);
84 cast_big_endian_reader
.ReadU16(&max_packet_id
);
86 // rtp_timestamp is enough - no need for frame_id as well.
87 InsertPacketEvent(time_of_event
,
97 void LoggingImpl::InsertPacketListEvent(const base::TimeTicks
& time_of_event
,
98 CastLoggingEvent event
,
99 EventMediaType event_media_type
,
100 const PacketList
& packets
) {
101 DCHECK(thread_checker_
.CalledOnValidThread());
102 for (PacketList::const_iterator it
= packets
.begin(); it
!= packets
.end();
104 InsertSinglePacketEvent(time_of_event
, event
, event_media_type
,
109 void LoggingImpl::InsertPacketEvent(const base::TimeTicks
& time_of_event
,
110 CastLoggingEvent event
,
111 EventMediaType event_media_type
,
112 uint32 rtp_timestamp
, uint32 frame_id
,
113 uint16 packet_id
, uint16 max_packet_id
,
115 DCHECK(thread_checker_
.CalledOnValidThread());
116 raw_
.InsertPacketEvent(time_of_event
, event
, event_media_type
,
117 rtp_timestamp
, frame_id
, packet_id
, max_packet_id
, size
);
120 void LoggingImpl::AddRawEventSubscriber(RawEventSubscriber
* subscriber
) {
121 DCHECK(thread_checker_
.CalledOnValidThread());
122 raw_
.AddSubscriber(subscriber
);
125 void LoggingImpl::RemoveRawEventSubscriber(RawEventSubscriber
* subscriber
) {
126 DCHECK(thread_checker_
.CalledOnValidThread());
127 raw_
.RemoveSubscriber(subscriber
);