blob: 423d7146fcc096cc0db3df5709ebdb3e7972dd05 [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(
20 const VideoSendStream::Config& config,
21 SendStatisticsProxy::StreamStatsProvider* stats_provider)
22 : 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
35void SendStatisticsProxy::CapturedFrameRate(const int capture_id,
36 const unsigned char frame_rate) {
37 CriticalSectionScoped cs(lock_.get());
38 stats_.input_frame_rate = frame_rate;
39}
40
41VideoSendStream::Stats SendStatisticsProxy::GetStats() const {
42 VideoSendStream::Stats stats = stats_;
43 CriticalSectionScoped cs(lock_.get());
44 stats_provider_->GetSendSideDelay(&stats);
45 stats.c_name = stats_provider_->GetCName();
46 return stats;
47}
48
49StreamStats* SendStatisticsProxy::GetStatsEntry(uint32_t ssrc) {
50 std::map<uint32_t, StreamStats>::iterator it = stats_.substreams.find(ssrc);
51 if (it != stats_.substreams.end())
52 return &it->second;
53
54 if (std::find(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end(), ssrc) ==
55 config_.rtp.ssrcs.end())
56 return NULL;
57
58 return &stats_.substreams[ssrc]; // Insert new entry and return ptr.
59}
60
61void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
62 uint32_t ssrc) {
63 CriticalSectionScoped cs(lock_.get());
64 StreamStats* stats = GetStatsEntry(ssrc);
65 if (stats == NULL)
66 return;
67
68 stats->rtcp_stats = statistics;
69}
70
71void SendStatisticsProxy::DataCountersUpdated(
72 const StreamDataCounters& counters,
73 uint32_t ssrc) {
74 CriticalSectionScoped cs(lock_.get());
75 StreamStats* stats = GetStatsEntry(ssrc);
76 if (stats == NULL)
77 return;
78
79 stats->rtp_stats = counters;
80}
81
82void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate,
83 uint32_t ssrc) {
84 CriticalSectionScoped cs(lock_.get());
85 StreamStats* stats = GetStatsEntry(ssrc);
86 if (stats == NULL)
87 return;
88
89 stats->bitrate_bps = bitrate.bitrate_bps;
90}
91
92void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type,
93 uint32_t frame_count,
94 const unsigned int ssrc) {
95 CriticalSectionScoped cs(lock_.get());
96 StreamStats* stats = GetStatsEntry(ssrc);
97 if (stats == NULL)
98 return;
99
100 switch (frame_type) {
101 case kVideoFrameDelta:
102 stats->delta_frames = frame_count;
103 break;
104 case kVideoFrameKey:
105 stats->key_frames = frame_count;
106 break;
107 case kFrameEmpty:
108 case kAudioFrameSpeech:
109 case kAudioFrameCN:
110 break;
111 }
112}
113
114} // namespace webrtc