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:
parent
044a04d8b5
commit
9a4fd9bf74
@ -20,10 +20,6 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
enum {
|
||||
MSG_DO_INSERT_DTMF = 0,
|
||||
};
|
||||
|
||||
// RFC4733
|
||||
// +-------+--------+------+---------+
|
||||
// | Event | Code | Type | Volume? |
|
||||
@ -135,9 +131,9 @@ bool DtmfSender::InsertDtmf(const std::string& tones,
|
||||
duration_ = duration;
|
||||
inter_tone_gap_ = inter_tone_gap;
|
||||
// Clear the previous queue.
|
||||
signaling_thread_->Clear(this, MSG_DO_INSERT_DTMF);
|
||||
dtmf_driver_.Clear();
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -153,17 +149,10 @@ int DtmfSender::inter_tone_gap() const {
|
||||
return inter_tone_gap_;
|
||||
}
|
||||
|
||||
void DtmfSender::OnMessage(rtc::Message* msg) {
|
||||
switch (msg->message_id) {
|
||||
case MSG_DO_INSERT_DTMF: {
|
||||
DoInsertDtmf();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
RTC_NOTREACHED();
|
||||
break;
|
||||
}
|
||||
}
|
||||
void DtmfSender::QueueInsertDtmf(const rtc::Location& posted_from,
|
||||
uint32_t delay_ms) {
|
||||
dtmf_driver_.AsyncInvokeDelayed<void>(posted_from, signaling_thread_,
|
||||
[this] { DoInsertDtmf(); }, delay_ms);
|
||||
}
|
||||
|
||||
void DtmfSender::DoInsertDtmf() {
|
||||
@ -218,8 +207,7 @@ void DtmfSender::DoInsertDtmf() {
|
||||
tones_.erase(0, first_tone_pos + 1);
|
||||
|
||||
// Continue with the next tone.
|
||||
signaling_thread_->PostDelayed(RTC_FROM_HERE, tone_gap, this,
|
||||
MSG_DO_INSERT_DTMF);
|
||||
QueueInsertDtmf(RTC_FROM_HERE, tone_gap);
|
||||
}
|
||||
|
||||
void DtmfSender::OnProviderDestroyed() {
|
||||
@ -229,7 +217,7 @@ void DtmfSender::OnProviderDestroyed() {
|
||||
}
|
||||
|
||||
void DtmfSender::StopSending() {
|
||||
signaling_thread_->Clear(this);
|
||||
dtmf_driver_.Clear();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -15,14 +15,14 @@
|
||||
|
||||
#include "api/dtmfsenderinterface.h"
|
||||
#include "api/proxy.h"
|
||||
#include "rtc_base/asyncinvoker.h"
|
||||
#include "rtc_base/constructormagic.h"
|
||||
#include "rtc_base/messagehandler.h"
|
||||
#include "rtc_base/refcount.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
// DtmfSender is the native implementation of the RTCDTMFSender defined by
|
||||
// the WebRTC W3C Editor's Draft.
|
||||
// http://dev.w3.org/2011/webrtc/editor/webrtc.html
|
||||
// https://w3c.github.io/webrtc-pc/#rtcdtmfsender
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -45,9 +45,7 @@ class DtmfProviderInterface {
|
||||
virtual ~DtmfProviderInterface() {}
|
||||
};
|
||||
|
||||
class DtmfSender : public DtmfSenderInterface,
|
||||
public sigslot::has_slots<>,
|
||||
public rtc::MessageHandler {
|
||||
class DtmfSender : public DtmfSenderInterface, public sigslot::has_slots<> {
|
||||
public:
|
||||
static rtc::scoped_refptr<DtmfSender> Create(rtc::Thread* signaling_thread,
|
||||
DtmfProviderInterface* provider);
|
||||
@ -70,8 +68,7 @@ class DtmfSender : public DtmfSenderInterface,
|
||||
private:
|
||||
DtmfSender();
|
||||
|
||||
// Implements MessageHandler.
|
||||
void OnMessage(rtc::Message* msg) override;
|
||||
void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms);
|
||||
|
||||
// The DTMF sending task.
|
||||
void DoInsertDtmf();
|
||||
@ -86,6 +83,9 @@ class DtmfSender : public DtmfSenderInterface,
|
||||
std::string tones_;
|
||||
int duration_;
|
||||
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);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user