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 | #ifndef WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ |
| 12 | #define WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ |
| 13 | |
| 14 | #include <string> |
| 15 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 16 | #include "webrtc/base/scoped_ptr.h" |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 +0000 | [diff] [blame] | 17 | #include "webrtc/base/thread_annotations.h" |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 18 | #include "webrtc/common_types.h" |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h" |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 20 | #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h" |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/clock.h" |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 22 | #include "webrtc/video_engine/include/vie_base.h" |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 23 | #include "webrtc/video_engine/include/vie_capture.h" |
| 24 | #include "webrtc/video_engine/include/vie_codec.h" |
| 25 | #include "webrtc/video_send_stream.h" |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | class CriticalSectionWrapper; |
| 30 | |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 31 | class SendStatisticsProxy : public CpuOveruseMetricsObserver, |
| 32 | public RtcpStatisticsCallback, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 33 | public RtcpPacketTypeCounterObserver, |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 34 | public StreamDataCountersCallback, |
| 35 | public BitrateStatisticsObserver, |
| 36 | public FrameCountObserver, |
| 37 | public ViEEncoderObserver, |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 38 | public ViECaptureObserver, |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 39 | public VideoEncoderRateObserver, |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 40 | public SendSideDelayObserver { |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 41 | public: |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 42 | static const int kStatsTimeoutMs; |
| 43 | |
| 44 | SendStatisticsProxy(Clock* clock, const VideoSendStream::Config& config); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 45 | virtual ~SendStatisticsProxy(); |
| 46 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 47 | VideoSendStream::Stats GetStats(); |
| 48 | |
| 49 | virtual void OnSendEncodedImage(const EncodedImage& encoded_image, |
| 50 | const RTPVideoHeader* rtp_video_header); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 51 | |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 52 | // From VideoEncoderRateObserver. |
| 53 | void OnSetRates(uint32_t bitrate_bps, int framerate) override; |
| 54 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 55 | protected: |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 56 | // From CpuOveruseMetricsObserver. |
| 57 | void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) OVERRIDE; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 58 | // From RtcpStatisticsCallback. |
| 59 | virtual void StatisticsUpdated(const RtcpStatistics& statistics, |
| 60 | uint32_t ssrc) OVERRIDE; |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 61 | virtual void CNameChanged(const char *cname, uint32_t ssrc) OVERRIDE; |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 62 | // From RtcpPacketTypeCounterObserver |
| 63 | virtual void RtcpPacketTypesCounterUpdated( |
| 64 | uint32_t ssrc, |
| 65 | const RtcpPacketTypeCounter& packet_counter) OVERRIDE; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 66 | // From StreamDataCountersCallback. |
| 67 | virtual void DataCountersUpdated(const StreamDataCounters& counters, |
| 68 | uint32_t ssrc) OVERRIDE; |
| 69 | |
| 70 | // From BitrateStatisticsObserver. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 71 | virtual void Notify(const BitrateStatistics& total_stats, |
| 72 | const BitrateStatistics& retransmit_stats, |
| 73 | uint32_t ssrc) OVERRIDE; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 74 | |
| 75 | // From FrameCountObserver. |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 76 | virtual void FrameCountUpdated(const FrameCounts& frame_counts, |
| 77 | uint32_t ssrc) OVERRIDE; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 78 | |
| 79 | // From ViEEncoderObserver. |
| 80 | virtual void OutgoingRate(const int video_channel, |
| 81 | const unsigned int framerate, |
| 82 | const unsigned int bitrate) OVERRIDE; |
| 83 | |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 84 | virtual void SuspendChange(int video_channel, bool is_suspended) OVERRIDE; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 85 | |
| 86 | // From ViECaptureObserver. |
| 87 | virtual void BrightnessAlarm(const int capture_id, |
| 88 | const Brightness brightness) OVERRIDE {} |
| 89 | |
| 90 | virtual void CapturedFrameRate(const int capture_id, |
| 91 | const unsigned char frame_rate) OVERRIDE; |
| 92 | |
| 93 | virtual void NoPictureAlarm(const int capture_id, |
| 94 | const CaptureAlarm alarm) OVERRIDE {} |
| 95 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 96 | virtual void SendSideDelayUpdated(int avg_delay_ms, |
| 97 | int max_delay_ms, |
| 98 | uint32_t ssrc) OVERRIDE; |
| 99 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 100 | private: |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 101 | struct StatsUpdateTimes { |
| 102 | StatsUpdateTimes() : resolution_update_ms(0) {} |
| 103 | int64_t resolution_update_ms; |
| 104 | }; |
| 105 | void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 106 | VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) |
| 107 | EXCLUSIVE_LOCKS_REQUIRED(crit_); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 108 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 109 | Clock* const clock_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 110 | const VideoSendStream::Config config_; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 111 | rtc::scoped_ptr<CriticalSectionWrapper> crit_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 112 | VideoSendStream::Stats stats_ GUARDED_BY(crit_); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 113 | std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace webrtc |
| 117 | #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ |