sprang@webrtc.org | ccd4284 | 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( |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 20 | const VideoSendStream::Config& config) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 21 | : config_(config), |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 22 | crit_(CriticalSectionWrapper::CreateCriticalSection()) { |
| 23 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 24 | |
| 25 | SendStatisticsProxy::~SendStatisticsProxy() {} |
| 26 | |
| 27 | void SendStatisticsProxy::OutgoingRate(const int video_channel, |
| 28 | const unsigned int framerate, |
| 29 | const unsigned int bitrate) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 30 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 31 | stats_.encode_frame_rate = framerate; |
| 32 | } |
| 33 | |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 34 | void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 35 | CriticalSectionScoped lock(crit_.get()); |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 36 | stats_.suspended = is_suspended; |
| 37 | } |
| 38 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 39 | void SendStatisticsProxy::CapturedFrameRate(const int capture_id, |
| 40 | const unsigned char frame_rate) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 41 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 42 | stats_.input_frame_rate = frame_rate; |
| 43 | } |
| 44 | |
| 45 | VideoSendStream::Stats SendStatisticsProxy::GetStats() const { |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 46 | CriticalSectionScoped lock(crit_.get()); |
| 47 | return stats_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | StreamStats* 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.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 56 | 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.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 60 | return NULL; |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 61 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 62 | |
| 63 | return &stats_.substreams[ssrc]; // Insert new entry and return ptr. |
| 64 | } |
| 65 | |
| 66 | void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
| 67 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 68 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 69 | StreamStats* stats = GetStatsEntry(ssrc); |
| 70 | if (stats == NULL) |
| 71 | return; |
| 72 | |
| 73 | stats->rtcp_stats = statistics; |
| 74 | } |
| 75 | |
| 76 | void SendStatisticsProxy::DataCountersUpdated( |
| 77 | const StreamDataCounters& counters, |
| 78 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 79 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 80 | StreamStats* stats = GetStatsEntry(ssrc); |
| 81 | if (stats == NULL) |
| 82 | return; |
| 83 | |
| 84 | stats->rtp_stats = counters; |
| 85 | } |
| 86 | |
| 87 | void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate, |
| 88 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 89 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 90 | StreamStats* stats = GetStatsEntry(ssrc); |
| 91 | if (stats == NULL) |
| 92 | return; |
| 93 | |
| 94 | stats->bitrate_bps = bitrate.bitrate_bps; |
| 95 | } |
| 96 | |
| 97 | void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type, |
| 98 | uint32_t frame_count, |
| 99 | const unsigned int ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 100 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 101 | 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.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 119 | void 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.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 130 | } // namespace webrtc |