Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / cast / logging / logging_impl.cc
blobb64674f0f9cbff7caca49a27a9f610ba938f4363
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"
9 namespace media {
10 namespace cast {
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,
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);
31 void LoggingImpl::InsertCapturedVideoFrameEvent(
32 const base::TimeTicks& time_of_event,
33 uint32 rtp_timestamp,
34 int width,
35 int height) {
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,
46 uint32 rtp_timestamp,
47 uint32 frame_id,
48 int encoded_size,
49 bool key_frame,
50 int target_bitrate,
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.
75 uint32 rtp_timestamp;
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,
88 event,
89 event_media_type,
90 rtp_timestamp,
91 kFrameIdUnknown,
92 packet_id,
93 max_packet_id,
94 packet.size());
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();
103 ++it) {
104 InsertSinglePacketEvent(time_of_event, event, event_media_type,
105 (*it)->data);
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,
114 size_t size) {
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);
130 } // namespace cast
131 } // namespace media