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, |
| 59 | int inter_tone_gap) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 60 | std::string tones() const override; |
| 61 | int duration() const override; |
| 62 | int inter_tone_gap() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | |
| 64 | protected: |
Steve Anton | b983bae | 2018-06-20 11:16:53 -0700 | [diff] [blame] | 65 | DtmfSender(rtc::Thread* signaling_thread, DtmfProviderInterface* provider); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | virtual ~DtmfSender(); |
| 67 | |
| 68 | private: |
| 69 | DtmfSender(); |
| 70 | |
Steve Anton | 9a4fd9b | 2018-08-31 15:20:10 -0700 | [diff] [blame] | 71 | void QueueInsertDtmf(const rtc::Location& posted_from, uint32_t delay_ms); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | |
| 73 | // The DTMF sending task. |
| 74 | void DoInsertDtmf(); |
| 75 | |
| 76 | void OnProviderDestroyed(); |
| 77 | |
| 78 | void StopSending(); |
| 79 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | DtmfSenderObserverInterface* observer_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 81 | rtc::Thread* signaling_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | DtmfProviderInterface* provider_; |
| 83 | std::string tones_; |
| 84 | int duration_; |
| 85 | int inter_tone_gap_; |
Steve Anton | 9a4fd9b | 2018-08-31 15:20:10 -0700 | [diff] [blame] | 86 | // Invoker for running delayed tasks which feed the DTMF provider one tone at |
| 87 | // a time. |
| 88 | rtc::AsyncInvoker dtmf_driver_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 90 | RTC_DISALLOW_COPY_AND_ASSIGN(DtmfSender); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | // Define proxy for DtmfSenderInterface. |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 94 | BEGIN_SIGNALING_PROXY_MAP(DtmfSender) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 95 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
| 96 | PROXY_METHOD1(void, RegisterObserver, DtmfSenderObserverInterface*) |
| 97 | PROXY_METHOD0(void, UnregisterObserver) |
| 98 | PROXY_METHOD0(bool, CanInsertDtmf) |
| 99 | PROXY_METHOD3(bool, InsertDtmf, const std::string&, int, int) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 100 | PROXY_CONSTMETHOD0(std::string, tones) |
| 101 | PROXY_CONSTMETHOD0(int, duration) |
| 102 | PROXY_CONSTMETHOD0(int, inter_tone_gap) |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 103 | END_PROXY_MAP() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
| 105 | // Get DTMF code from the DTMF event character. |
| 106 | bool GetDtmfCode(char tone, int* code); |
| 107 | |
| 108 | } // namespace webrtc |
| 109 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 110 | #endif // PC_DTMF_SENDER_H_ |