diff options
Diffstat (limited to 'media/cast/logging')
-rw-r--r-- | media/cast/logging/logging.cc | 113 | ||||
-rw-r--r-- | media/cast/logging/logging.h | 92 | ||||
-rw-r--r-- | media/cast/logging/logging_defines.h | 2 | ||||
-rw-r--r-- | media/cast/logging/logging_impl.cc | 22 | ||||
-rw-r--r-- | media/cast/logging/logging_impl.h | 4 | ||||
-rw-r--r-- | media/cast/logging/logging_raw.cc | 10 |
6 files changed, 31 insertions, 212 deletions
diff --git a/media/cast/logging/logging.cc b/media/cast/logging/logging.cc deleted file mode 100644 index 7f2658c..0000000 --- a/media/cast/logging/logging.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/cast/logging/logging.h" - -#include "base/debug/trace_event.h" -#include "base/logging.h" -#include "base/metrics/histogram.h" - -namespace media { -namespace cast { - -Logging::Logging(base::TickClock* clock) - : clock_(clock), - frame_map_(), - packet_map_(), - generic_map_(), - weak_factory_(this) {} - -Logging::~Logging() {} - -void Logging::InsertFrameEvent(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id) { - // Is this a new event? - FrameLogMap::iterator it = frame_map_.find(event); - if (it == frame_map_.end()) { - // Create new entry. - FrameLogData data(clock_); - data.Insert(rtp_timestamp, frame_id); - frame_map_.insert(std::make_pair(event, &data)); - } else { - // Insert to existing entry. - it->second->Insert(rtp_timestamp, frame_id); - } -} - -void Logging::InsertFrameEventWithSize(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - int size) { - // Is this a new event? - FrameLogMap::iterator it = frame_map_.find(event); - if (it == frame_map_.end()) { - // Create new entry. - FrameLogData data(clock_); - data.InsertWithSize(rtp_timestamp, frame_id, size); - frame_map_.insert(std::make_pair(event, &data)); - } else { - // Insert to existing entry. - it->second->InsertWithSize(rtp_timestamp, frame_id, size); - } -} - -void Logging::InsertFrameEventWithDelay(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - base::TimeDelta delay) { - // Is this a new event? - FrameLogMap::iterator it = frame_map_.find(event); - if (it == frame_map_.end()) { - // Create new entry. - FrameLogData data(clock_); - data.InsertWithDelay(rtp_timestamp, frame_id, delay); - frame_map_.insert(std::make_pair(event, &data)); - } else { - // Insert to existing entry. - it->second->InsertWithDelay(rtp_timestamp, frame_id, delay); - } -} - -void Logging::InsertPacketEvent(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - uint16 packet_id, - uint16 max_packet_id, - int size) { - // Is this a new event? - PacketLogMap::iterator it = packet_map_.find(event); - if (it == packet_map_.end()) { - // Create new entry. - PacketLogData data(clock_); - data.Insert(rtp_timestamp, frame_id, packet_id, max_packet_id, size); - packet_map_.insert(std::make_pair(event, &data)); - } else { - // Insert to existing entry. - it->second->Insert(rtp_timestamp, frame_id, packet_id, max_packet_id, size); - } -} - -void Logging::InsertGenericEvent(CastLoggingEvent event, int value) { - // Is this a new event? - GenericLogMap::iterator it = generic_map_.find(event); - if (it == generic_map_.end()) { - // Create new entry. - GenericLogData data(clock_); - data.Insert(value); - generic_map_.insert(std::make_pair(event, &data)); - } else { - // Insert to existing entry. - it->second->Insert(value); - } -} - -void Logging::Reset() { - frame_map_.clear(); - packet_map_.clear(); - generic_map_.clear(); -} -} // namespace cast -} // namespace media - diff --git a/media/cast/logging/logging.h b/media/cast/logging/logging.h deleted file mode 100644 index f327a6f..0000000 --- a/media/cast/logging/logging.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MEDIA_CAST_LOGGING_LOGGING_H_ -#define MEDIA_CAST_LOGGING_LOGGING_H_ - -// Generic class that handles event logging for the cast library. -// Logging has three possible forms: -// 1. [default] Raw data accessible by the application. -// 2. [optional] UMA stats. -// 3. [optional] Tracing. - -#include <map> -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/linked_ptr.h" -#include "base/memory/weak_ptr.h" -#include "base/threading/non_thread_safe.h" -#include "base/time/tick_clock.h" -#include "base/time/time.h" -#include "media/cast/logging/logging_defines.h" -#include "media/cast/logging/logging_internal.h" - -namespace media { -namespace cast { - -// Store all log types in a map based on the event. -typedef std::map<CastLoggingEvent, linked_ptr<FrameLogData> > FrameLogMap; -typedef std::map<CastLoggingEvent, linked_ptr<PacketLogData> > PacketLogMap; -typedef std::map<CastLoggingEvent, linked_ptr<GenericLogData> > GenericLogMap; - - -// This class is not thread safe, and should only be called from the main -// thread. -class Logging : public base::NonThreadSafe, - public base::SupportsWeakPtr<Logging> { - public: - // When tracing is enabled - all events will be added to the trace. - explicit Logging(base::TickClock* clock); - ~Logging(); - // Inform of new event: three types of events: frame, packets and generic. - // Frame events can be inserted with different parameters. - void InsertFrameEvent(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id); - // Size - Inserting the size implies that this is an encoded frame. - void InsertFrameEventWithSize(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - int frame_size); - // Render/playout delay - void InsertFrameEventWithDelay(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - base::TimeDelta delay); - - // Insert a packet event. - void InsertPacketEvent(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - uint16 packet_id, - uint16 max_packet_id, - int size); - - void InsertGenericEvent(CastLoggingEvent event, int value); - - // Get log data. - void GetRawFrameData(FrameLogMap frame_data); - void GetRawPacketData(PacketLogMap packet_data); - void GetRawGenericData(GenericLogMap generic_data); - - // Reset all log data (not flags). - void Reset(); - - private: - base::WeakPtrFactory<Logging> weak_factory_; - base::TickClock* const clock_; // Not owned by this class. - FrameLogMap frame_map_; - PacketLogMap packet_map_; - GenericLogMap generic_map_; - - DISALLOW_COPY_AND_ASSIGN(Logging); -}; - -} // namespace cast -} // namespace media - -#endif // MEDIA_CAST_LOGGING_LOGGING_H_ - diff --git a/media/cast/logging/logging_defines.h b/media/cast/logging/logging_defines.h index cdf9069..5a7bca15 100644 --- a/media/cast/logging/logging_defines.h +++ b/media/cast/logging/logging_defines.h @@ -15,6 +15,8 @@ namespace media { namespace cast { +static const uint32 kFrameIdUnknown = 0xFFFF; + struct CastLoggingConfig { CastLoggingConfig(); ~CastLoggingConfig(); diff --git a/media/cast/logging/logging_impl.cc b/media/cast/logging/logging_impl.cc index 97c9277..16117b0 100644 --- a/media/cast/logging/logging_impl.cc +++ b/media/cast/logging/logging_impl.cc @@ -5,6 +5,7 @@ #include "base/debug/trace_event.h" #include "base/metrics/histogram.h" #include "media/cast/logging/logging_impl.h" +#include "net/base/big_endian.h" namespace media { namespace cast { @@ -76,6 +77,27 @@ void LoggingImpl::InsertFrameEventWithDelay(CastLoggingEvent event, } } +void LoggingImpl::InsertPacketListEvent(CastLoggingEvent event, + const PacketList& packets) { + DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); + for (unsigned int i = 0; i < packets.size(); ++i) { + const Packet& packet = packets[i]; + // Parse basic properties. + uint32 rtp_timestamp; + uint16 packet_id, max_packet_id; + const uint8* packet_data = &packet[0]; + net::BigEndianReader big_endian_reader(packet_data + 4, 4); + big_endian_reader.ReadU32(&rtp_timestamp); + net::BigEndianReader cast_big_endian_reader(packet_data + 12 + 2, 4); + cast_big_endian_reader.ReadU16(&packet_id); + cast_big_endian_reader.ReadU16(&max_packet_id); + // rtp_timestamp is enough - no need for frame_id as well. + InsertPacketEvent(event, rtp_timestamp, kFrameIdUnknown, packet_id, + max_packet_id, packet.size()); + } + +} + void LoggingImpl::InsertPacketEvent(CastLoggingEvent event, uint32 rtp_timestamp, uint32 frame_id, diff --git a/media/cast/logging/logging_impl.h b/media/cast/logging/logging_impl.h index 628f346..6c2d863 100644 --- a/media/cast/logging/logging_impl.h +++ b/media/cast/logging/logging_impl.h @@ -12,6 +12,7 @@ #include "base/memory/ref_counted.h" #include "base/task_runner.h" +#include "media/cast/cast_config.h" #include "media/cast/logging/logging_defines.h" #include "media/cast/logging/logging_raw.h" #include "media/cast/logging/logging_stats.h" @@ -19,7 +20,6 @@ namespace media { namespace cast { -static const int kFrameIdUnknown = -1; // Should only be called from the main thread. class LoggingImpl : public base::NonThreadSafe { public: @@ -40,6 +40,8 @@ class LoggingImpl : public base::NonThreadSafe { uint32 rtp_timestamp, uint32 frame_id, base::TimeDelta delay); + void InsertPacketListEvent(CastLoggingEvent event, const PacketList& packets); + void InsertPacketEvent(CastLoggingEvent event, uint32 rtp_timestamp, uint32 frame_id, diff --git a/media/cast/logging/logging_raw.cc b/media/cast/logging/logging_raw.cc index 0fd0ae17..93a65f0 100644 --- a/media/cast/logging/logging_raw.cc +++ b/media/cast/logging/logging_raw.cc @@ -51,7 +51,7 @@ void LoggingRaw::InsertBaseFrameEvent(CastLoggingEvent event, uint32 frame_id, uint32 rtp_timestamp) { // Is this a new event? - FrameRawMap::iterator it = frame_map_.find(event); + FrameRawMap::iterator it = frame_map_.find(rtp_timestamp); if (it == frame_map_.end()) { // Create a new map entry. FrameEvent info; @@ -64,11 +64,9 @@ void LoggingRaw::InsertBaseFrameEvent(CastLoggingEvent event, it->second.timestamp.push_back(clock_->NowTicks()); it->second.type.push_back(event); // Do we have a valid frame_id? - // We don't always have it to begin with. - // TODO(mikhal): Switch frame_id to int when the fix gets in. - // This is currently illegal, as frame_id is uint8, so commenting it out. - // if (it->second.frame_id == -1 && frame_id != -1) - // it->second.frame_id = frame_id; + // Not all events have a valid frame id. + if (it->second.frame_id == kFrameIdUnknown && frame_id != kFrameIdUnknown) + it->second.frame_id = frame_id; } } |