henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2005 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | // Class to collect statistics from a media channel |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #ifndef PC_MEDIAMONITOR_H_ |
| 14 | #define PC_MEDIAMONITOR_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "media/base/mediachannel.h" |
| 17 | #include "rtc_base/criticalsection.h" |
| 18 | #include "rtc_base/sigslot.h" |
| 19 | #include "rtc_base/thread.h" |
| 20 | #include "rtc_base/thread_annotations.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | |
| 22 | namespace cricket { |
| 23 | |
| 24 | // The base MediaMonitor class, independent of voice and video. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 25 | class MediaMonitor : public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | public sigslot::has_slots<> { |
| 27 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 28 | MediaMonitor(rtc::Thread* worker_thread, |
| 29 | rtc::Thread* monitor_thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | ~MediaMonitor(); |
| 31 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 32 | void Start(uint32_t milliseconds); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | void Stop(); |
| 34 | |
| 35 | protected: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 36 | void OnMessage(rtc::Message *message); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | void PollMediaChannel(); |
| 38 | virtual void GetStats() = 0; |
| 39 | virtual void Update() = 0; |
| 40 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 41 | rtc::CriticalSection crit_; |
| 42 | rtc::Thread* worker_thread_; |
| 43 | rtc::Thread* monitor_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | bool monitoring_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 45 | uint32_t rate_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | // Templatized MediaMonitor that can deal with different kinds of media. |
| 49 | template<class MC, class MI> |
| 50 | class MediaMonitorT : public MediaMonitor { |
| 51 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | MediaMonitorT(MC* media_channel, rtc::Thread* worker_thread, |
| 53 | rtc::Thread* monitor_thread) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | : MediaMonitor(worker_thread, monitor_thread), |
| 55 | media_channel_(media_channel) {} |
| 56 | sigslot::signal2<MC*, const MI&> SignalUpdate; |
| 57 | |
| 58 | protected: |
| 59 | // These routines assume the crit_ lock is held by the calling thread. |
| 60 | virtual void GetStats() { |
| 61 | media_info_.Clear(); |
| 62 | media_channel_->GetStats(&media_info_); |
| 63 | } |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 64 | virtual void Update() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | MI stats(media_info_); |
| 66 | crit_.Leave(); |
| 67 | SignalUpdate(media_channel_, stats); |
| 68 | crit_.Enter(); |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | MC* media_channel_; |
| 73 | MI media_info_; |
| 74 | }; |
| 75 | |
| 76 | typedef MediaMonitorT<VoiceMediaChannel, VoiceMediaInfo> VoiceMediaMonitor; |
| 77 | typedef MediaMonitorT<VideoMediaChannel, VideoMediaInfo> VideoMediaMonitor; |
| 78 | typedef MediaMonitorT<DataMediaChannel, DataMediaInfo> DataMediaMonitor; |
| 79 | |
| 80 | } // namespace cricket |
| 81 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 82 | #endif // PC_MEDIAMONITOR_H_ |