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_RECEIVE_STATISTICS_PROXY_H_ 12 #define WEBRTC_VIDEO_RECEIVE_STATISTICS_PROXY_H_ 13 14 #include <string> 15 16 #include "webrtc/base/criticalsection.h" 17 #include "webrtc/base/ratetracker.h" 18 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/common_types.h" 20 #include "webrtc/frame_callback.h" 21 #include "webrtc/modules/remote_bitrate_estimator/rate_statistics.h" 22 #include "webrtc/modules/video_coding/include/video_coding_defines.h" 23 #include "webrtc/video/report_block_stats.h" 24 #include "webrtc/video/vie_channel.h" 25 #include "webrtc/video_receive_stream.h" 26 #include "webrtc/video_renderer.h" 27 28 namespace webrtc { 29 30 class Clock; 31 class ViECodec; 32 class ViEDecoderObserver; 33 struct CodecSpecificInfo; 34 35 class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback, 36 public RtcpStatisticsCallback, 37 public RtcpPacketTypeCounterObserver, 38 public StreamDataCountersCallback { 39 public: 40 ReceiveStatisticsProxy(uint32_t ssrc, Clock* clock); 41 virtual ~ReceiveStatisticsProxy(); 42 43 VideoReceiveStream::Stats GetStats() const; 44 45 void OnDecodedFrame(); 46 void OnRenderedFrame(int width, int height); 47 void OnIncomingPayloadType(int payload_type); 48 void OnDecoderImplementationName(const char* implementation_name); 49 void OnIncomingRate(unsigned int framerate, unsigned int bitrate_bps); 50 void OnDecoderTiming(int decode_ms, 51 int max_decode_ms, 52 int current_delay_ms, 53 int target_delay_ms, 54 int jitter_buffer_ms, 55 int min_playout_delay_ms, 56 int render_delay_ms, 57 int64_t rtt_ms); 58 59 void OnPreDecode(const EncodedImage& encoded_image, 60 const CodecSpecificInfo* codec_specific_info); 61 62 // Overrides VCMReceiveStatisticsCallback. 63 void OnReceiveRatesUpdated(uint32_t bitRate, uint32_t frameRate) override; 64 void OnFrameCountsUpdated(const FrameCounts& frame_counts) override; 65 void OnDiscardedPacketsUpdated(int discarded_packets) override; 66 67 // Overrides RtcpStatisticsCallback. 68 void StatisticsUpdated(const webrtc::RtcpStatistics& statistics, 69 uint32_t ssrc) override; 70 void CNameChanged(const char* cname, uint32_t ssrc) override; 71 72 // Overrides RtcpPacketTypeCounterObserver. 73 void RtcpPacketTypesCounterUpdated( 74 uint32_t ssrc, 75 const RtcpPacketTypeCounter& packet_counter) override; 76 // Overrides StreamDataCountersCallback. 77 void DataCountersUpdated(const webrtc::StreamDataCounters& counters, 78 uint32_t ssrc) override; 79 80 private: 81 struct SampleCounter { SampleCounterSampleCounter82 SampleCounter() : sum(0), num_samples(0) {} 83 void Add(int sample); 84 int Avg(int min_required_samples) const; 85 86 private: 87 int sum; 88 int num_samples; 89 }; 90 struct QpCounters { 91 SampleCounter vp8; 92 }; 93 94 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_); 95 96 Clock* const clock_; 97 98 mutable rtc::CriticalSection crit_; 99 VideoReceiveStream::Stats stats_ GUARDED_BY(crit_); 100 RateStatistics decode_fps_estimator_ GUARDED_BY(crit_); 101 RateStatistics renders_fps_estimator_ GUARDED_BY(crit_); 102 rtc::RateTracker render_fps_tracker_ GUARDED_BY(crit_); 103 rtc::RateTracker render_pixel_tracker_ GUARDED_BY(crit_); 104 SampleCounter render_width_counter_ GUARDED_BY(crit_); 105 SampleCounter render_height_counter_ GUARDED_BY(crit_); 106 SampleCounter decode_time_counter_ GUARDED_BY(crit_); 107 SampleCounter delay_counter_ GUARDED_BY(crit_); 108 ReportBlockStats report_block_stats_ GUARDED_BY(crit_); 109 QpCounters qp_counters_; // Only accessed on the decoding thread. 110 }; 111 112 } // namespace webrtc 113 #endif // WEBRTC_VIDEO_RECEIVE_STATISTICS_PROXY_H_ 114