blob: fcd24106aac4a183886fe531e7d56e5920e65dd6 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2005 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
11// Class to collect statistics from a media channel
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#ifndef PC_MEDIAMONITOR_H_
14#define PC_MEDIAMONITOR_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#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.org28e20752013-07-10 00:45:36 +000021
22namespace cricket {
23
24// The base MediaMonitor class, independent of voice and video.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000025class MediaMonitor : public rtc::MessageHandler,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026 public sigslot::has_slots<> {
27 public:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000028 MediaMonitor(rtc::Thread* worker_thread,
29 rtc::Thread* monitor_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030 ~MediaMonitor();
31
Peter Boström0c4e06b2015-10-07 12:23:21 +020032 void Start(uint32_t milliseconds);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033 void Stop();
34
35 protected:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000036 void OnMessage(rtc::Message *message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037 void PollMediaChannel();
38 virtual void GetStats() = 0;
39 virtual void Update() = 0;
40
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000041 rtc::CriticalSection crit_;
42 rtc::Thread* worker_thread_;
43 rtc::Thread* monitor_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044 bool monitoring_;
Peter Boström0c4e06b2015-10-07 12:23:21 +020045 uint32_t rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046};
47
48// Templatized MediaMonitor that can deal with different kinds of media.
49template<class MC, class MI>
50class MediaMonitorT : public MediaMonitor {
51 public:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052 MediaMonitorT(MC* media_channel, rtc::Thread* worker_thread,
53 rtc::Thread* monitor_thread)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 : 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 }
danilchapa37de392017-09-09 04:17:22 -070064 virtual void Update() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 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
76typedef MediaMonitorT<VoiceMediaChannel, VoiceMediaInfo> VoiceMediaMonitor;
77typedef MediaMonitorT<VideoMediaChannel, VideoMediaInfo> VideoMediaMonitor;
78typedef MediaMonitorT<DataMediaChannel, DataMediaInfo> DataMediaMonitor;
79
80} // namespace cricket
81
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020082#endif // PC_MEDIAMONITOR_H_