2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/video/receive_statistics_proxy.h"
13 #include "webrtc/system_wrappers/interface/clock.h"
14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
19 ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t ssrc,
21 ViERTP_RTCP* rtp_rtcp,
25 lock_(CriticalSectionWrapper::CreateCriticalSection()),
27 // 1000ms window, scale 1000 for ms to s.
28 decode_fps_estimator_(1000, 1000),
29 renders_fps_estimator_(1000, 1000),
35 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {}
37 VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
38 VideoReceiveStream::Stats stats;
40 CriticalSectionScoped cs(lock_.get());
43 stats.c_name = GetCName();
44 codec_->GetReceiveSideDelay(channel_, &stats.avg_delay_ms);
45 stats.discarded_packets = codec_->GetDiscardedPackets(channel_);
46 codec_->GetReceiveCodecStastistics(
47 channel_, stats.key_frames, stats.delta_frames);
52 std::string ReceiveStatisticsProxy::GetCName() const {
53 char rtcp_cname[ViERTP_RTCP::KMaxRTCPCNameLength];
54 if (rtp_rtcp_->GetRemoteRTCPCName(channel_, rtcp_cname) != 0)
59 void ReceiveStatisticsProxy::IncomingRate(const int video_channel,
60 const unsigned int framerate,
61 const unsigned int bitrate) {
62 CriticalSectionScoped cs(lock_.get());
63 stats_.network_frame_rate = framerate;
64 stats_.bitrate_bps = bitrate;
67 void ReceiveStatisticsProxy::StatisticsUpdated(
68 const webrtc::RtcpStatistics& statistics,
70 CriticalSectionScoped cs(lock_.get());
72 stats_.rtcp_stats = statistics;
75 void ReceiveStatisticsProxy::DataCountersUpdated(
76 const webrtc::StreamDataCounters& counters,
78 CriticalSectionScoped cs(lock_.get());
80 stats_.rtp_stats = counters;
83 void ReceiveStatisticsProxy::OnDecodedFrame() {
84 uint64_t now = clock_->TimeInMilliseconds();
86 CriticalSectionScoped cs(lock_.get());
87 decode_fps_estimator_.Update(1, now);
88 stats_.decode_frame_rate = decode_fps_estimator_.Rate(now);
91 void ReceiveStatisticsProxy::OnRenderedFrame() {
92 uint64_t now = clock_->TimeInMilliseconds();
94 CriticalSectionScoped cs(lock_.get());
95 renders_fps_estimator_.Update(1, now);
96 stats_.render_frame_rate = renders_fps_estimator_.Rate(now);
99 } // namespace internal
100 } // namespace webrtc