henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_DTMF_SENDER_H_ |
| 12 | #define PC_DTMF_SENDER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 16 | #include "api/dtmf_sender_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "rtc_base/async_invoker.h" |
| 19 | #include "rtc_base/constructor_magic.h" |
| 20 | #include "rtc_base/ref_count.h" |
Steve Anton | b983bae | 2018-06-20 11:16:53 -0700 | [diff] [blame] | 21 | #include "rtc_base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
| 23 | // DtmfSender is the native implementation of the RTCDTMFSender defined by |
| 24 | // the WebRTC W3C Editor's Draft. |
Steve Anton | 9a4fd9b | 2018-08-31 15:20:10 -0700 | [diff] [blame] | 25 | // https://w3c.github.io/webrtc-pc/#rtcdtmfsender |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | namespace webrtc { |
| 28 | |
| 29 | // This interface is called by DtmfSender to talk to the actual audio channel |
| 30 | // to send DTMF. |
| 31 | class DtmfProviderInterface { |
| 32 | public: |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 33 | // Returns true if the audio sender is capable of sending DTMF. Otherwise |
| 34 | // returns false. |
| 35 | virtual bool CanInsertDtmf() = 0; |
| 36 | // Sends DTMF |code|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | // The |duration| indicates the length of the DTMF tone in ms. |
| 38 | // Returns true on success and false on failure. |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 39 | virtual bool InsertDtmf(int code, int duration) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | // Returns a |sigslot::signal0<>| signal. The signal should fire before |
| 41 | // the provider is destroyed. |
| 42 | virtual sigslot::signal0<>* GetOnDestroyedSignal() = 0; |
| 43 | |
| 44 | protected: |
| 45 | virtual ~DtmfProviderInterface() {} |
| 46 | }; |
| 47 | |
Steve Anton | 9a4fd9b | 2018-08-31 15:20:10 -0700 | [diff] [blame] | 48 | class DtmfSender : public DtmfSenderInterface, public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | public: |
Steve Anton | b983bae | 2018-06-20 11:16:53 -0700 | [diff] [blame] | 50 | static rtc::scoped_refptr<DtmfSender> Create(rtc::Thread* signaling_thread, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 51 | DtmfProviderInterface* provider); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | |
| 53 | // Implements DtmfSenderInterface. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 54 | void RegisterObserver(DtmfSenderObserverInterface* observer) override; |
| 55 | void UnregisterObserver() override; |
| 56 | bool CanInsertDtmf() override; |
| 57 | bool InsertDtmf(const std::string& tones, |
| 58 | int duration, |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 59 | int inter_tone_gap, |
| 60 | int comma_delay = kDtmfDefaultCommaDelayMs) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 61 | std::string tones() const override; |
| 62 | int duration() const override; |
| 63 | int inter_tone_gap() const override; |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 64 | int comma_delay() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | |
| 66 | protected: |
Steve Anton | b983bae | 2018-06-20 11:16:53 -0700 | [diff] [blame] | 67 | DtmfSender(rtc::Thread* signaling_thread, DtmfProviderInterface* provider); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | virtual ~DtmfSender(); |
| 69 | |
| 70 | private: |
| 71 | DtmfSender(); |
| 72 | |
Steve Anton | 9a4fd9b | 2018-08-31 15:20:10 -0700 | [diff] [blame] | 73 | void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
| 75 | // The DTMF sending task. |
| 76 | void DoInsertDtmf(); |
| 77 | |
| 78 | void OnProviderDestroyed(); |
| 79 | |
| 80 | void StopSending(); |
| 81 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | DtmfSenderObserverInterface* observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 83 | rtc::Thread* signaling_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | DtmfProviderInterface* provider_; |
| 85 | std::string tones_; |
| 86 | int duration_; |
| 87 | int inter_tone_gap_; |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 88 | int comma_delay_; |
Steve Anton | 9a4fd9b | 2018-08-31 15:20:10 -0700 | [diff] [blame] | 89 | // Invoker for running delayed tasks which feed the DTMF provider one tone at |
| 90 | // a time. |
| 91 | rtc::AsyncInvoker dtmf_driver_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 93 | RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | // Define proxy for DtmfSenderInterface. |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 97 | BEGIN_SIGNALING_PROXY_MAP(DtmfSender) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 98 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
| 99 | PROXY_METHOD1(void, RegisterObserver, DtmfSenderObserverInterface*) |
| 100 | PROXY_METHOD0(void, UnregisterObserver) |
| 101 | PROXY_METHOD0(bool, CanInsertDtmf) |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 102 | PROXY_METHOD4(bool, InsertDtmf, const std::string&, int, int, int) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 103 | PROXY_CONSTMETHOD0(std::string, tones) |
| 104 | PROXY_CONSTMETHOD0(int, duration) |
| 105 | PROXY_CONSTMETHOD0(int, inter_tone_gap) |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 106 | PROXY_CONSTMETHOD0(int, comma_delay) |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 107 | END_PROXY_MAP() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | |
| 109 | // Get DTMF code from the DTMF event character. |
| 110 | bool GetDtmfCode(char tone, int* code); |
| 111 | |
| 112 | } // namespace webrtc |
| 113 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 114 | #endif // PC_DTMF_SENDER_H_ |