sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 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/send_statistics_proxy.h" |
| 12 | |
| 13 | #include <map> |
| 14 | |
| 15 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | SendStatisticsProxy::SendStatisticsProxy( |
| 20 | const VideoSendStream::Config& config, |
sprang@webrtc.org | c8ab721 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 21 | SendStatisticsProxy::StatsProvider* stats_provider) |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 22 | : config_(config), |
| 23 | lock_(CriticalSectionWrapper::CreateCriticalSection()), |
| 24 | stats_provider_(stats_provider) {} |
| 25 | |
| 26 | SendStatisticsProxy::~SendStatisticsProxy() {} |
| 27 | |
| 28 | void 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.org | 9376c69 | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 35 | void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) { |
| 36 | CriticalSectionScoped cs(lock_.get()); |
| 37 | stats_.suspended = is_suspended; |
| 38 | } |
| 39 | |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 40 | void 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 | |
| 46 | VideoSendStream::Stats SendStatisticsProxy::GetStats() const { |
sprang@webrtc.org | c8ab721 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 47 | VideoSendStream::Stats stats; |
| 48 | { |
| 49 | CriticalSectionScoped cs(lock_.get()); |
| 50 | stats = stats_; |
| 51 | } |
sprang@webrtc.org | 49812e6 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 52 | stats_provider_->GetSendSideDelay(&stats); |
| 53 | stats.c_name = stats_provider_->GetCName(); |
| 54 | return stats; |
| 55 | } |
| 56 | |
| 57 | StreamStats* 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 | |
| 69 | void 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 | |
| 79 | void 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 | |
| 90 | void 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 | |
| 100 | void 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 |