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; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 32 | stats_.media_bitrate_bps = bitrate; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 33 | } |
| 34 | |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 35 | void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 36 | CriticalSectionScoped lock(crit_.get()); |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 37 | stats_.suspended = is_suspended; |
| 38 | } |
| 39 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 40 | void SendStatisticsProxy::CapturedFrameRate(const int capture_id, |
| 41 | const unsigned char frame_rate) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 42 | CriticalSectionScoped lock(crit_.get()); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 43 | stats_.input_frame_rate = frame_rate; |
| 44 | } |
| 45 | |
| 46 | VideoSendStream::Stats SendStatisticsProxy::GetStats() const { |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 47 | CriticalSectionScoped lock(crit_.get()); |
| 48 | return stats_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 49 | } |
| 50 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 51 | SsrcStats* SendStatisticsProxy::GetStatsEntry(uint32_t ssrc) { |
| 52 | std::map<uint32_t, SsrcStats>::iterator it = stats_.substreams.find(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 53 | if (it != stats_.substreams.end()) |
| 54 | return &it->second; |
| 55 | |
| 56 | 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] | 57 | config_.rtp.ssrcs.end() && |
| 58 | std::find(config_.rtp.rtx.ssrcs.begin(), |
| 59 | config_.rtp.rtx.ssrcs.end(), |
| 60 | ssrc) == config_.rtp.rtx.ssrcs.end()) { |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 61 | return NULL; |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 62 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 63 | |
| 64 | return &stats_.substreams[ssrc]; // Insert new entry and return ptr. |
| 65 | } |
| 66 | |
| 67 | void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
| 68 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 69 | CriticalSectionScoped lock(crit_.get()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 70 | SsrcStats* stats = GetStatsEntry(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 71 | if (stats == NULL) |
| 72 | return; |
| 73 | |
| 74 | stats->rtcp_stats = statistics; |
| 75 | } |
| 76 | |
| 77 | void SendStatisticsProxy::DataCountersUpdated( |
| 78 | const StreamDataCounters& counters, |
| 79 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 80 | CriticalSectionScoped lock(crit_.get()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 81 | SsrcStats* stats = GetStatsEntry(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 82 | if (stats == NULL) |
| 83 | return; |
| 84 | |
| 85 | stats->rtp_stats = counters; |
| 86 | } |
| 87 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 88 | void SendStatisticsProxy::Notify(const BitrateStatistics& total_stats, |
| 89 | const BitrateStatistics& retransmit_stats, |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 90 | uint32_t ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 91 | CriticalSectionScoped lock(crit_.get()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 92 | SsrcStats* stats = GetStatsEntry(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 93 | if (stats == NULL) |
| 94 | return; |
| 95 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 96 | stats->total_bitrate_bps = total_stats.bitrate_bps; |
| 97 | stats->retransmit_bitrate_bps = retransmit_stats.bitrate_bps; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type, |
| 101 | uint32_t frame_count, |
| 102 | const unsigned int ssrc) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 103 | CriticalSectionScoped lock(crit_.get()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 104 | SsrcStats* stats = GetStatsEntry(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 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 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 122 | void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, |
| 123 | int max_delay_ms, |
| 124 | uint32_t ssrc) { |
| 125 | CriticalSectionScoped lock(crit_.get()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 126 | SsrcStats* stats = GetStatsEntry(ssrc); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 127 | if (stats == NULL) |
| 128 | return; |
| 129 | stats->avg_delay_ms = avg_delay_ms; |
| 130 | stats->max_delay_ms = max_delay_ms; |
| 131 | } |
| 132 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 133 | } // namespace webrtc |