diff options
Diffstat (limited to 'media/cast/logging/logging_stats.cc')
-rw-r--r-- | media/cast/logging/logging_stats.cc | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/media/cast/logging/logging_stats.cc b/media/cast/logging/logging_stats.cc index 84fdbf7..4b9d000 100644 --- a/media/cast/logging/logging_stats.cc +++ b/media/cast/logging/logging_stats.cc @@ -9,12 +9,11 @@ namespace media { namespace cast { -LoggingStats::LoggingStats(base::TickClock* clock) +LoggingStats::LoggingStats() : frame_stats_(), packet_stats_(), generic_stats_(), - start_time_(), - clock_(clock) { + start_time_() { memset(counts_, 0, sizeof(counts_)); memset(start_time_, 0, sizeof(start_time_)); } @@ -28,28 +27,33 @@ void LoggingStats::Reset() { memset(counts_, 0, sizeof(counts_)); } -void LoggingStats::InsertFrameEvent(CastLoggingEvent event, +void LoggingStats::InsertFrameEvent(const base::TimeTicks& time_of_event, + CastLoggingEvent event, uint32 rtp_timestamp, uint32 frame_id) { - InsertBaseFrameEvent(event, frame_id, rtp_timestamp); + InsertBaseFrameEvent(time_of_event, event, frame_id, rtp_timestamp); } -void LoggingStats::InsertFrameEventWithSize(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - int frame_size) { - InsertBaseFrameEvent(event, frame_id, rtp_timestamp); +void LoggingStats::InsertFrameEventWithSize( + const base::TimeTicks& time_of_event, + CastLoggingEvent event, + uint32 rtp_timestamp, + uint32 frame_id, + int frame_size) { + InsertBaseFrameEvent(time_of_event, event, frame_id, rtp_timestamp); // Update size. FrameStatsMap::iterator it = frame_stats_.find(event); DCHECK(it != frame_stats_.end()); it->second->bitrate_kbps += frame_size; } -void LoggingStats::InsertFrameEventWithDelay(CastLoggingEvent event, - uint32 rtp_timestamp, - uint32 frame_id, - base::TimeDelta delay) { - InsertBaseFrameEvent(event, frame_id, rtp_timestamp); +void LoggingStats::InsertFrameEventWithDelay( + const base::TimeTicks& time_of_event, + CastLoggingEvent event, + uint32 rtp_timestamp, + uint32 frame_id, + base::TimeDelta delay) { + InsertBaseFrameEvent(time_of_event, event, frame_id, rtp_timestamp); // Update size. FrameStatsMap::iterator it = frame_stats_.find(event); DCHECK(it != frame_stats_.end()); @@ -63,14 +67,15 @@ void LoggingStats::InsertFrameEventWithDelay(CastLoggingEvent event, it->second->min_delay_ms = delay.InMilliseconds(); } -void LoggingStats::InsertBaseFrameEvent(CastLoggingEvent event, +void LoggingStats::InsertBaseFrameEvent(const base::TimeTicks& time_of_event, + CastLoggingEvent event, uint32 frame_id, uint32 rtp_timestamp) { // Does this belong to an existing event? FrameStatsMap::iterator it = frame_stats_.find(event); if (it == frame_stats_.end()) { // New event. - start_time_[event] = clock_->NowTicks(); + start_time_[event] = time_of_event; linked_ptr<FrameLogStats> stats(new FrameLogStats()); frame_stats_.insert(std::make_pair(event, stats)); } @@ -78,7 +83,8 @@ void LoggingStats::InsertBaseFrameEvent(CastLoggingEvent event, ++counts_[event]; } -void LoggingStats::InsertPacketEvent(CastLoggingEvent event, +void LoggingStats::InsertPacketEvent(const base::TimeTicks& time_of_event, + CastLoggingEvent event, uint32 rtp_timestamp, uint32 frame_id, uint16 packet_id, @@ -88,7 +94,7 @@ void LoggingStats::InsertPacketEvent(CastLoggingEvent event, PacketStatsMap::iterator it = packet_stats_.find(event); if (it == packet_stats_.end()) { // New event. - start_time_[event] = clock_->NowTicks(); + start_time_[event] = time_of_event; packet_stats_.insert(std::make_pair(event, size)); } else { // Add to existing. @@ -97,25 +103,27 @@ void LoggingStats::InsertPacketEvent(CastLoggingEvent event, ++counts_[event]; } -void LoggingStats::InsertGenericEvent(CastLoggingEvent event, int value) { +void LoggingStats::InsertGenericEvent(const base::TimeTicks& time_of_event, + CastLoggingEvent event, int value) { // Does this event belong to an existing event? GenericStatsMap::iterator it = generic_stats_.find(event); if (it == generic_stats_.end()) { // New event. - start_time_[event] = clock_->NowTicks(); + start_time_[event] = time_of_event; generic_stats_.insert(std::make_pair(event, value)); } else { // Add to existing (will be used to compute average). it->second += value; } - ++counts_[event]; + ++counts_[event]; } -const FrameStatsMap* LoggingStats::GetFrameStatsData() { +const FrameStatsMap* LoggingStats::GetFrameStatsData( + const base::TimeTicks& now) { // Compute framerate and bitrate (when available). FrameStatsMap::iterator it; for (it = frame_stats_.begin(); it != frame_stats_.end(); ++it) { - base::TimeDelta time_diff = clock_->NowTicks() - start_time_[it->first]; + base::TimeDelta time_diff = now - start_time_[it->first]; it->second->framerate_fps = counts_[it->first] / time_diff.InSecondsF(); if (it->second->bitrate_kbps > 0) { it->second->bitrate_kbps = (8 / 1000) * @@ -127,11 +135,12 @@ const FrameStatsMap* LoggingStats::GetFrameStatsData() { return &frame_stats_; } -const PacketStatsMap* LoggingStats::GetPacketStatsData() { +const PacketStatsMap* LoggingStats::GetPacketStatsData( + const base::TimeTicks& now) { PacketStatsMap::iterator it; for (it = packet_stats_.begin(); it != packet_stats_.end(); ++it) { if (counts_[it->first] == 0) continue; - base::TimeDelta time_diff = clock_->NowTicks() - start_time_[it->first]; + base::TimeDelta time_diff = now - start_time_[it->first]; it->second = (8 / 1000) * it->second / time_diff.InSecondsF(); } return &packet_stats_; |