2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Copyright 2005 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-07-01 16:48:15 +02:00
|
|
|
#include "webrtc/pc/mediamonitor.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/pc/channelmanager.h"
|
|
|
|
|
#include "webrtc/rtc_base/checks.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
MSG_MONITOR_POLL = 1,
|
|
|
|
|
MSG_MONITOR_START = 2,
|
|
|
|
|
MSG_MONITOR_STOP = 3,
|
|
|
|
|
MSG_MONITOR_SIGNAL = 4
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
MediaMonitor::MediaMonitor(rtc::Thread* worker_thread,
|
|
|
|
|
rtc::Thread* monitor_thread)
|
2013-07-10 00:45:36 +00:00
|
|
|
: worker_thread_(worker_thread),
|
|
|
|
|
monitor_thread_(monitor_thread), monitoring_(false), rate_(0) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaMonitor::~MediaMonitor() {
|
|
|
|
|
monitoring_ = false;
|
|
|
|
|
monitor_thread_->Clear(this);
|
|
|
|
|
worker_thread_->Clear(this);
|
|
|
|
|
}
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
void MediaMonitor::Start(uint32_t milliseconds) {
|
2013-07-10 00:45:36 +00:00
|
|
|
rate_ = milliseconds;
|
|
|
|
|
if (rate_ < 100)
|
|
|
|
|
rate_ = 100;
|
2016-06-10 14:17:27 -07:00
|
|
|
worker_thread_->Post(RTC_FROM_HERE, this, MSG_MONITOR_START);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MediaMonitor::Stop() {
|
2016-06-10 14:17:27 -07:00
|
|
|
worker_thread_->Post(RTC_FROM_HERE, this, MSG_MONITOR_STOP);
|
2013-07-10 00:45:36 +00:00
|
|
|
rate_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
void MediaMonitor::OnMessage(rtc::Message* message) {
|
|
|
|
|
rtc::CritScope cs(&crit_);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
switch (message->message_id) {
|
|
|
|
|
case MSG_MONITOR_START:
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!monitoring_) {
|
|
|
|
|
monitoring_ = true;
|
|
|
|
|
PollMediaChannel();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MSG_MONITOR_STOP:
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
if (monitoring_) {
|
|
|
|
|
monitoring_ = false;
|
|
|
|
|
worker_thread_->Clear(this);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MSG_MONITOR_POLL:
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
PollMediaChannel();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MSG_MONITOR_SIGNAL:
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(rtc::Thread::Current() == monitor_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
Update();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MediaMonitor::PollMediaChannel() {
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::CritScope cs(&crit_);
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(rtc::Thread::Current() == worker_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
GetStats();
|
|
|
|
|
|
|
|
|
|
// Signal the monitoring thread, start another poll timer
|
2016-06-10 14:17:27 -07:00
|
|
|
monitor_thread_->Post(RTC_FROM_HERE, this, MSG_MONITOR_SIGNAL);
|
|
|
|
|
worker_thread_->PostDelayed(RTC_FROM_HERE, rate_, this, MSG_MONITOR_POLL);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 05:28:11 -07:00
|
|
|
} // namespace cricket
|