blob: 1b6081d2a14eb7c4b6a596316a90602410c0ea96 [file] [log] [blame]
sprang@webrtc.orgccd42842014-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(
stefan@webrtc.org168f23f2014-07-11 13:44:02 +000020 const VideoSendStream::Config& config)
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000021 : config_(config),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000022 crit_(CriticalSectionWrapper::CreateCriticalSection()) {
23}
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000024
25SendStatisticsProxy::~SendStatisticsProxy() {}
26
27void SendStatisticsProxy::OutgoingRate(const int video_channel,
28 const unsigned int framerate,
29 const unsigned int bitrate) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000030 CriticalSectionScoped lock(crit_.get());
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000031 stats_.encode_frame_rate = framerate;
32}
33
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +000034void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000035 CriticalSectionScoped lock(crit_.get());
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +000036 stats_.suspended = is_suspended;
37}
38
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000039void SendStatisticsProxy::CapturedFrameRate(const int capture_id,
40 const unsigned char frame_rate) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000041 CriticalSectionScoped lock(crit_.get());
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000042 stats_.input_frame_rate = frame_rate;
43}
44
45VideoSendStream::Stats SendStatisticsProxy::GetStats() const {
stefan@webrtc.org168f23f2014-07-11 13:44:02 +000046 CriticalSectionScoped lock(crit_.get());
47 return stats_;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000048}
49
50StreamStats* SendStatisticsProxy::GetStatsEntry(uint32_t ssrc) {
51 std::map<uint32_t, StreamStats>::iterator it = stats_.substreams.find(ssrc);
52 if (it != stats_.substreams.end())
53 return &it->second;
54
55 if (std::find(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end(), ssrc) ==
stefan@webrtc.org58e2d262014-08-14 15:10:49 +000056 config_.rtp.ssrcs.end() &&
57 std::find(config_.rtp.rtx.ssrcs.begin(),
58 config_.rtp.rtx.ssrcs.end(),
59 ssrc) == config_.rtp.rtx.ssrcs.end()) {
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000060 return NULL;
stefan@webrtc.org58e2d262014-08-14 15:10:49 +000061 }
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000062
63 return &stats_.substreams[ssrc]; // Insert new entry and return ptr.
64}
65
66void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
67 uint32_t ssrc) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000068 CriticalSectionScoped lock(crit_.get());
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000069 StreamStats* stats = GetStatsEntry(ssrc);
70 if (stats == NULL)
71 return;
72
73 stats->rtcp_stats = statistics;
74}
75
76void SendStatisticsProxy::DataCountersUpdated(
77 const StreamDataCounters& counters,
78 uint32_t ssrc) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000079 CriticalSectionScoped lock(crit_.get());
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000080 StreamStats* stats = GetStatsEntry(ssrc);
81 if (stats == NULL)
82 return;
83
84 stats->rtp_stats = counters;
85}
86
87void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate,
88 uint32_t ssrc) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000089 CriticalSectionScoped lock(crit_.get());
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000090 StreamStats* stats = GetStatsEntry(ssrc);
91 if (stats == NULL)
92 return;
93
94 stats->bitrate_bps = bitrate.bitrate_bps;
95}
96
97void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type,
98 uint32_t frame_count,
99 const unsigned int ssrc) {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000100 CriticalSectionScoped lock(crit_.get());
sprang@webrtc.orgccd42842014-01-07 09:54:34 +0000101 StreamStats* stats = GetStatsEntry(ssrc);
102 if (stats == NULL)
103 return;
104
105 switch (frame_type) {
106 case kVideoFrameDelta:
107 stats->delta_frames = frame_count;
108 break;
109 case kVideoFrameKey:
110 stats->key_frames = frame_count;
111 break;
112 case kFrameEmpty:
113 case kAudioFrameSpeech:
114 case kAudioFrameCN:
115 break;
116 }
117}
118
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000119void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms,
120 int max_delay_ms,
121 uint32_t ssrc) {
122 CriticalSectionScoped lock(crit_.get());
123 StreamStats* stats = GetStatsEntry(ssrc);
124 if (stats == NULL)
125 return;
126 stats->avg_delay_ms = avg_delay_ms;
127 stats->max_delay_ms = max_delay_ms;
128}
129
sprang@webrtc.orgccd42842014-01-07 09:54:34 +0000130} // namespace webrtc