1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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.
9 */
10
11 #include "webrtc/video/receive_statistics_proxy.h"
12
13 #include "webrtc/system_wrappers/interface/clock.h"
14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
15
16 namespace webrtc {
17 namespace internal {
18
ReceiveStatisticsProxy(uint32_t ssrc,Clock * clock,ViERTP_RTCP * rtp_rtcp,ViECodec * codec,int channel)19 ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t ssrc,
20 Clock* clock,
21 ViERTP_RTCP* rtp_rtcp,
22 ViECodec* codec,
23 int channel)
24 : channel_(channel),
25 clock_(clock),
26 codec_(codec),
27 rtp_rtcp_(rtp_rtcp),
28 crit_(CriticalSectionWrapper::CreateCriticalSection()),
29 // 1000ms window, scale 1000 for ms to s.
30 decode_fps_estimator_(1000, 1000),
31 renders_fps_estimator_(1000, 1000) {
32 stats_.ssrc = ssrc;
33 }
34
~ReceiveStatisticsProxy()35 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {}
36
GetStats() const37 VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
38 VideoReceiveStream::Stats stats;
39 {
40 CriticalSectionScoped lock(crit_.get());
41 stats = stats_;
42 }
43 stats.c_name = GetCName();
44 codec_->GetReceiveSideDelay(channel_, &stats.avg_delay_ms);
45 stats.discarded_packets = codec_->GetNumDiscardedPackets(channel_);
46 codec_->GetReceiveCodecStastistics(
47 channel_, stats.key_frames, stats.delta_frames);
48
49 return stats;
50 }
51
GetCName() const52 std::string ReceiveStatisticsProxy::GetCName() const {
53 char rtcp_cname[ViERTP_RTCP::KMaxRTCPCNameLength];
54 if (rtp_rtcp_->GetRemoteRTCPCName(channel_, rtcp_cname) != 0)
55 rtcp_cname[0] = '\0';
56 return rtcp_cname;
57 }
58
IncomingRate(const int video_channel,const unsigned int framerate,const unsigned int bitrate)59 void ReceiveStatisticsProxy::IncomingRate(const int video_channel,
60 const unsigned int framerate,
61 const unsigned int bitrate) {
62 CriticalSectionScoped lock(crit_.get());
63 stats_.network_frame_rate = framerate;
64 stats_.bitrate_bps = bitrate;
65 }
66
StatisticsUpdated(const webrtc::RtcpStatistics & statistics,uint32_t ssrc)67 void ReceiveStatisticsProxy::StatisticsUpdated(
68 const webrtc::RtcpStatistics& statistics,
69 uint32_t ssrc) {
70 CriticalSectionScoped lock(crit_.get());
71
72 stats_.rtcp_stats = statistics;
73 }
74
DataCountersUpdated(const webrtc::StreamDataCounters & counters,uint32_t ssrc)75 void ReceiveStatisticsProxy::DataCountersUpdated(
76 const webrtc::StreamDataCounters& counters,
77 uint32_t ssrc) {
78 CriticalSectionScoped lock(crit_.get());
79
80 stats_.rtp_stats = counters;
81 }
82
OnDecodedFrame()83 void ReceiveStatisticsProxy::OnDecodedFrame() {
84 uint64_t now = clock_->TimeInMilliseconds();
85
86 CriticalSectionScoped lock(crit_.get());
87 decode_fps_estimator_.Update(1, now);
88 stats_.decode_frame_rate = decode_fps_estimator_.Rate(now);
89 }
90
OnRenderedFrame()91 void ReceiveStatisticsProxy::OnRenderedFrame() {
92 uint64_t now = clock_->TimeInMilliseconds();
93
94 CriticalSectionScoped lock(crit_.get());
95 renders_fps_estimator_.Update(1, now);
96 stats_.render_frame_rate = renders_fps_estimator_.Rate(now);
97 }
98
99 } // namespace internal
100 } // namespace webrtc
101