blob: 1cd4e26afc37e1421e9feb6b541c2c279c69bcc3 [file] [log] [blame]
sprang@webrtc.org49812e62014-01-07 09:54:34 +00001/*
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/send_statistics_proxy.h"
12
13#include <map>
14
15#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
16
17namespace webrtc {
18
19SendStatisticsProxy::SendStatisticsProxy(
20 const VideoSendStream::Config& config,
sprang@webrtc.orgc8ab7212014-02-07 12:06:29 +000021 SendStatisticsProxy::StatsProvider* stats_provider)
sprang@webrtc.org49812e62014-01-07 09:54:34 +000022 : config_(config),
23 lock_(CriticalSectionWrapper::CreateCriticalSection()),
24 stats_provider_(stats_provider) {}
25
26SendStatisticsProxy::~SendStatisticsProxy() {}
27
28void SendStatisticsProxy::OutgoingRate(const int video_channel,
29 const unsigned int framerate,
30 const unsigned int bitrate) {
31 CriticalSectionScoped cs(lock_.get());
32 stats_.encode_frame_rate = framerate;
33}
34
henrik.lundin@webrtc.org9376c692014-03-13 13:31:21 +000035void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) {
36 CriticalSectionScoped cs(lock_.get());
37 stats_.suspended = is_suspended;
38}
39
sprang@webrtc.org49812e62014-01-07 09:54:34 +000040void SendStatisticsProxy::CapturedFrameRate(const int capture_id,
41 const unsigned char frame_rate) {
42 CriticalSectionScoped cs(lock_.get());
43 stats_.input_frame_rate = frame_rate;
44}
45
46VideoSendStream::Stats SendStatisticsProxy::GetStats() const {
sprang@webrtc.orgc8ab7212014-02-07 12:06:29 +000047 VideoSendStream::Stats stats;
48 {
49 CriticalSectionScoped cs(lock_.get());
50 stats = stats_;
51 }
sprang@webrtc.org49812e62014-01-07 09:54:34 +000052 stats_provider_->GetSendSideDelay(&stats);
53 stats.c_name = stats_provider_->GetCName();
54 return stats;
55}
56
57StreamStats* SendStatisticsProxy::GetStatsEntry(uint32_t ssrc) {
58 std::map<uint32_t, StreamStats>::iterator it = stats_.substreams.find(ssrc);
59 if (it != stats_.substreams.end())
60 return &it->second;
61
62 if (std::find(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end(), ssrc) ==
63 config_.rtp.ssrcs.end())
64 return NULL;
65
66 return &stats_.substreams[ssrc]; // Insert new entry and return ptr.
67}
68
69void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
70 uint32_t ssrc) {
71 CriticalSectionScoped cs(lock_.get());
72 StreamStats* stats = GetStatsEntry(ssrc);
73 if (stats == NULL)
74 return;
75
76 stats->rtcp_stats = statistics;
77}
78
79void SendStatisticsProxy::DataCountersUpdated(
80 const StreamDataCounters& counters,
81 uint32_t ssrc) {
82 CriticalSectionScoped cs(lock_.get());
83 StreamStats* stats = GetStatsEntry(ssrc);
84 if (stats == NULL)
85 return;
86
87 stats->rtp_stats = counters;
88}
89
90void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate,
91 uint32_t ssrc) {
92 CriticalSectionScoped cs(lock_.get());
93 StreamStats* stats = GetStatsEntry(ssrc);
94 if (stats == NULL)
95 return;
96
97 stats->bitrate_bps = bitrate.bitrate_bps;
98}
99
100void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type,
101 uint32_t frame_count,
102 const unsigned int ssrc) {
103 CriticalSectionScoped cs(lock_.get());
104 StreamStats* stats = GetStatsEntry(ssrc);
105 if (stats == NULL)
106 return;
107
108 switch (frame_type) {
109 case kVideoFrameDelta:
110 stats->delta_frames = frame_count;
111 break;
112 case kVideoFrameKey:
113 stats->key_frames = frame_count;
114 break;
115 case kFrameEmpty:
116 case kAudioFrameSpeech:
117 case kAudioFrameCN:
118 break;
119 }
120}
121
122} // namespace webrtc