2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -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
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#ifndef PC_DTMF_SENDER_H_
|
|
|
|
|
#define PC_DTMF_SENDER_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2021-01-29 14:45:08 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/dtmf_sender_interface.h"
|
2021-01-29 14:45:08 +00:00
|
|
|
#include "api/scoped_refptr.h"
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "api/sequence_checker.h"
|
2021-05-26 18:56:30 +02:00
|
|
|
#include "pc/proxy.h"
|
2021-01-29 14:45:08 +00:00
|
|
|
#include "rtc_base/location.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ref_count.h"
|
2021-03-18 09:18:48 +01:00
|
|
|
#include "rtc_base/task_utils/pending_task_safety_flag.h"
|
2021-01-29 14:45:08 +00:00
|
|
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
2018-06-20 11:16:53 -07:00
|
|
|
#include "rtc_base/thread.h"
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// DtmfSender is the native implementation of the RTCDTMFSender defined by
|
|
|
|
|
// the WebRTC W3C Editor's Draft.
|
2018-08-31 15:20:10 -07:00
|
|
|
// https://w3c.github.io/webrtc-pc/#rtcdtmfsender
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// This interface is called by DtmfSender to talk to the actual audio channel
|
|
|
|
|
// to send DTMF.
|
|
|
|
|
class DtmfProviderInterface {
|
|
|
|
|
public:
|
2017-02-01 20:27:00 -08:00
|
|
|
// Returns true if the audio sender is capable of sending DTMF. Otherwise
|
|
|
|
|
// returns false.
|
|
|
|
|
virtual bool CanInsertDtmf() = 0;
|
2021-07-30 22:30:23 +02:00
|
|
|
// Sends DTMF `code`.
|
|
|
|
|
// The `duration` indicates the length of the DTMF tone in ms.
|
2013-07-10 00:45:36 +00:00
|
|
|
// Returns true on success and false on failure.
|
2017-02-01 20:27:00 -08:00
|
|
|
virtual bool InsertDtmf(int code, int duration) = 0;
|
2021-08-10 01:22:31 +02:00
|
|
|
// Returns a `sigslot::signal0<>` signal. The signal should fire before
|
2013-07-10 00:45:36 +00:00
|
|
|
// the provider is destroyed.
|
|
|
|
|
virtual sigslot::signal0<>* GetOnDestroyedSignal() = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~DtmfProviderInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-31 15:20:10 -07:00
|
|
|
class DtmfSender : public DtmfSenderInterface, public sigslot::has_slots<> {
|
2013-07-10 00:45:36 +00:00
|
|
|
public:
|
2018-06-20 11:16:53 -07:00
|
|
|
static rtc::scoped_refptr<DtmfSender> Create(rtc::Thread* signaling_thread,
|
2013-07-10 00:45:36 +00:00
|
|
|
DtmfProviderInterface* provider);
|
|
|
|
|
|
|
|
|
|
// Implements DtmfSenderInterface.
|
2015-03-04 12:58:35 +00:00
|
|
|
void RegisterObserver(DtmfSenderObserverInterface* observer) override;
|
|
|
|
|
void UnregisterObserver() override;
|
|
|
|
|
bool CanInsertDtmf() override;
|
|
|
|
|
bool InsertDtmf(const std::string& tones,
|
|
|
|
|
int duration,
|
2020-01-21 03:09:47 +00:00
|
|
|
int inter_tone_gap,
|
|
|
|
|
int comma_delay = kDtmfDefaultCommaDelayMs) override;
|
2015-03-04 12:58:35 +00:00
|
|
|
std::string tones() const override;
|
|
|
|
|
int duration() const override;
|
|
|
|
|
int inter_tone_gap() const override;
|
2020-01-21 03:09:47 +00:00
|
|
|
int comma_delay() const override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
protected:
|
2018-06-20 11:16:53 -07:00
|
|
|
DtmfSender(rtc::Thread* signaling_thread, DtmfProviderInterface* provider);
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual ~DtmfSender();
|
|
|
|
|
|
2022-01-18 09:35:48 +09:00
|
|
|
DtmfSender(const DtmfSender&) = delete;
|
|
|
|
|
DtmfSender& operator=(const DtmfSender&) = delete;
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
|
|
|
|
DtmfSender();
|
|
|
|
|
|
2021-03-18 09:18:48 +01:00
|
|
|
void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms)
|
|
|
|
|
RTC_RUN_ON(signaling_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// The DTMF sending task.
|
2021-03-18 09:18:48 +01:00
|
|
|
void DoInsertDtmf() RTC_RUN_ON(signaling_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
void OnProviderDestroyed();
|
|
|
|
|
|
2021-03-18 09:18:48 +01:00
|
|
|
void StopSending() RTC_RUN_ON(signaling_thread_);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2021-03-18 09:18:48 +01:00
|
|
|
DtmfSenderObserverInterface* observer_ RTC_GUARDED_BY(signaling_thread_);
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::Thread* signaling_thread_;
|
2021-03-18 09:18:48 +01:00
|
|
|
DtmfProviderInterface* provider_ RTC_GUARDED_BY(signaling_thread_);
|
|
|
|
|
std::string tones_ RTC_GUARDED_BY(signaling_thread_);
|
|
|
|
|
int duration_ RTC_GUARDED_BY(signaling_thread_);
|
|
|
|
|
int inter_tone_gap_ RTC_GUARDED_BY(signaling_thread_);
|
|
|
|
|
int comma_delay_ RTC_GUARDED_BY(signaling_thread_);
|
|
|
|
|
|
|
|
|
|
// For cancelling the tasks which feed the DTMF provider one tone at a time.
|
|
|
|
|
rtc::scoped_refptr<PendingTaskSafetyFlag> safety_flag_ RTC_GUARDED_BY(
|
|
|
|
|
signaling_thread_) RTC_PT_GUARDED_BY(signaling_thread_) = nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Define proxy for DtmfSenderInterface.
|
2021-02-26 09:51:26 +01:00
|
|
|
BEGIN_PRIMARY_PROXY_MAP(DtmfSender)
|
2022-02-23 13:44:59 +00:00
|
|
|
|
2021-02-26 09:51:26 +01:00
|
|
|
PROXY_PRIMARY_THREAD_DESTRUCTOR()
|
2013-07-10 00:45:36 +00:00
|
|
|
PROXY_METHOD1(void, RegisterObserver, DtmfSenderObserverInterface*)
|
|
|
|
|
PROXY_METHOD0(void, UnregisterObserver)
|
|
|
|
|
PROXY_METHOD0(bool, CanInsertDtmf)
|
2020-01-21 03:09:47 +00:00
|
|
|
PROXY_METHOD4(bool, InsertDtmf, const std::string&, int, int, int)
|
2013-07-10 00:45:36 +00:00
|
|
|
PROXY_CONSTMETHOD0(std::string, tones)
|
|
|
|
|
PROXY_CONSTMETHOD0(int, duration)
|
|
|
|
|
PROXY_CONSTMETHOD0(int, inter_tone_gap)
|
2020-01-21 03:09:47 +00:00
|
|
|
PROXY_CONSTMETHOD0(int, comma_delay)
|
2021-05-27 21:42:57 +02:00
|
|
|
END_PROXY_MAP(DtmfSender)
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Get DTMF code from the DTMF event character.
|
|
|
|
|
bool GetDtmfCode(char tone, int* code);
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#endif // PC_DTMF_SENDER_H_
|