Use AsyncInvoker in DtmfSender instead of MessageHandler

Bug: webrtc:9702
Change-Id: Ib9a9a2cf5bbb7aff24e6690deca51a021961ead3
Reviewed-on: https://webrtc-review.googlesource.com/97182
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24518}
This commit is contained in:
Steve Anton
2018-08-31 15:20:10 -07:00
committed by Commit Bot
parent 044a04d8b5
commit 9a4fd9bf74
2 changed files with 15 additions and 27 deletions

View File

@ -20,10 +20,6 @@
namespace webrtc { namespace webrtc {
enum {
MSG_DO_INSERT_DTMF = 0,
};
// RFC4733 // RFC4733
// +-------+--------+------+---------+ // +-------+--------+------+---------+
// | Event | Code | Type | Volume? | // | Event | Code | Type | Volume? |
@ -135,9 +131,9 @@ bool DtmfSender::InsertDtmf(const std::string& tones,
duration_ = duration; duration_ = duration;
inter_tone_gap_ = inter_tone_gap; inter_tone_gap_ = inter_tone_gap;
// Clear the previous queue. // Clear the previous queue.
signaling_thread_->Clear(this, MSG_DO_INSERT_DTMF); dtmf_driver_.Clear();
// Kick off a new DTMF task queue. // Kick off a new DTMF task queue.
signaling_thread_->PostDelayed(RTC_FROM_HERE, 1, this, MSG_DO_INSERT_DTMF); QueueInsertDtmf(RTC_FROM_HERE, 1 /*ms*/);
return true; return true;
} }
@ -153,17 +149,10 @@ int DtmfSender::inter_tone_gap() const {
return inter_tone_gap_; return inter_tone_gap_;
} }
void DtmfSender::OnMessage(rtc::Message* msg) { void DtmfSender::QueueInsertDtmf(const rtc::Location& posted_from,
switch (msg->message_id) { uint32_t delay_ms) {
case MSG_DO_INSERT_DTMF: { dtmf_driver_.AsyncInvokeDelayed<void>(posted_from, signaling_thread_,
DoInsertDtmf(); [this] { DoInsertDtmf(); }, delay_ms);
break;
}
default: {
RTC_NOTREACHED();
break;
}
}
} }
void DtmfSender::DoInsertDtmf() { void DtmfSender::DoInsertDtmf() {
@ -218,8 +207,7 @@ void DtmfSender::DoInsertDtmf() {
tones_.erase(0, first_tone_pos + 1); tones_.erase(0, first_tone_pos + 1);
// Continue with the next tone. // Continue with the next tone.
signaling_thread_->PostDelayed(RTC_FROM_HERE, tone_gap, this, QueueInsertDtmf(RTC_FROM_HERE, tone_gap);
MSG_DO_INSERT_DTMF);
} }
void DtmfSender::OnProviderDestroyed() { void DtmfSender::OnProviderDestroyed() {
@ -229,7 +217,7 @@ void DtmfSender::OnProviderDestroyed() {
} }
void DtmfSender::StopSending() { void DtmfSender::StopSending() {
signaling_thread_->Clear(this); dtmf_driver_.Clear();
} }
} // namespace webrtc } // namespace webrtc

View File

@ -15,14 +15,14 @@
#include "api/dtmfsenderinterface.h" #include "api/dtmfsenderinterface.h"
#include "api/proxy.h" #include "api/proxy.h"
#include "rtc_base/asyncinvoker.h"
#include "rtc_base/constructormagic.h" #include "rtc_base/constructormagic.h"
#include "rtc_base/messagehandler.h"
#include "rtc_base/refcount.h" #include "rtc_base/refcount.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
// DtmfSender is the native implementation of the RTCDTMFSender defined by // DtmfSender is the native implementation of the RTCDTMFSender defined by
// the WebRTC W3C Editor's Draft. // the WebRTC W3C Editor's Draft.
// http://dev.w3.org/2011/webrtc/editor/webrtc.html // https://w3c.github.io/webrtc-pc/#rtcdtmfsender
namespace webrtc { namespace webrtc {
@ -45,9 +45,7 @@ class DtmfProviderInterface {
virtual ~DtmfProviderInterface() {} virtual ~DtmfProviderInterface() {}
}; };
class DtmfSender : public DtmfSenderInterface, class DtmfSender : public DtmfSenderInterface, public sigslot::has_slots<> {
public sigslot::has_slots<>,
public rtc::MessageHandler {
public: public:
static rtc::scoped_refptr<DtmfSender> Create(rtc::Thread* signaling_thread, static rtc::scoped_refptr<DtmfSender> Create(rtc::Thread* signaling_thread,
DtmfProviderInterface* provider); DtmfProviderInterface* provider);
@ -70,8 +68,7 @@ class DtmfSender : public DtmfSenderInterface,
private: private:
DtmfSender(); DtmfSender();
// Implements MessageHandler. void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms);
void OnMessage(rtc::Message* msg) override;
// The DTMF sending task. // The DTMF sending task.
void DoInsertDtmf(); void DoInsertDtmf();
@ -86,6 +83,9 @@ class DtmfSender : public DtmfSenderInterface,
std::string tones_; std::string tones_;
int duration_; int duration_;
int inter_tone_gap_; int inter_tone_gap_;
// Invoker for running delayed tasks which feed the DTMF provider one tone at
// a time.
rtc::AsyncInvoker dtmf_driver_;
RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender); RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender);
}; };