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) == |
| 56 | config_.rtp.ssrcs.end()) |
| 57 | return NULL; |
| 58 | |
| 59 | return &stats_.substreams[ssrc]; // Insert new entry and return ptr. |
| 60 | } |
| 61 | |
| 62 | void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
| 63 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 64 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 65 | StreamStats* stats = GetStatsEntry(ssrc); |
| 66 | if (stats == NULL) |
| 67 | return; |
| 68 | |
| 69 | stats->rtcp_stats = statistics; |
| 70 | } |
| 71 | |
| 72 | void SendStatisticsProxy::DataCountersUpdated( |
| 73 | const StreamDataCounters& counters, |
| 74 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 75 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 76 | StreamStats* stats = GetStatsEntry(ssrc); |
| 77 | if (stats == NULL) |
| 78 | return; |
| 79 | |
| 80 | stats->rtp_stats = counters; |
| 81 | } |
| 82 | |
| 83 | void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate, |
| 84 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 85 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 86 | StreamStats* stats = GetStatsEntry(ssrc); |
| 87 | if (stats == NULL) |
| 88 | return; |
| 89 | |
| 90 | stats->bitrate_bps = bitrate.bitrate_bps; |
| 91 | } |
| 92 | |
| 93 | void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type, |
| 94 | uint32_t frame_count, |
| 95 | const unsigned int ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 96 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 97 | StreamStats* stats = GetStatsEntry(ssrc); |
| 98 | if (stats == NULL) |
| 99 | return; |
| 100 | |
| 101 | switch (frame_type) { |
| 102 | case kVideoFrameDelta: |
| 103 | stats->delta_frames = frame_count; |
| 104 | break; |
| 105 | case kVideoFrameKey: |
| 106 | stats->key_frames = frame_count; |
| 107 | break; |
| 108 | case kFrameEmpty: |
| 109 | case kAudioFrameSpeech: |
| 110 | case kAudioFrameCN: |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame^] | 115 | void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, |
| 116 | int max_delay_ms, |
| 117 | uint32_t ssrc) { |
| 118 | CriticalSectionScoped lock(crit_.get()); |
| 119 | StreamStats* stats = GetStatsEntry(ssrc); |
| 120 | if (stats == NULL) |
| 121 | return; |
| 122 | stats->avg_delay_ms = avg_delay_ms; |
| 123 | stats->max_delay_ms = max_delay_ms; |
| 124 | } |
| 125 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 126 | } // namespace webrtc |