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 API_DTMF_SENDER_INTERFACE_H_ |
| 12 | #define API_DTMF_SENDER_INTERFACE_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/media_stream_interface.h" |
| 17 | #include "rtc_base/ref_count.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 21 | // DtmfSender callback interface, used to implement RTCDtmfSender events. |
| 22 | // Applications should implement this interface to get notifications from the |
| 23 | // DtmfSender. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | class DtmfSenderObserverInterface { |
| 25 | public: |
| 26 | // Triggered when DTMF |tone| is sent. |
| 27 | // If |tone| is empty that means the DtmfSender has sent out all the given |
| 28 | // tones. |
Harald Alvestrand | d7b79af | 2018-09-06 09:33:56 +0200 | [diff] [blame] | 29 | // The callback includes the state of the tone buffer at the time when |
| 30 | // the tone finished playing. |
| 31 | virtual void OnToneChange(const std::string& tone, |
| 32 | const std::string& tone_buffer) {} |
| 33 | // DEPRECATED: Older API without tone buffer. |
| 34 | // TODO(bugs.webrtc.org/9725): Remove old API and default implementation |
| 35 | // when old callers are gone. |
| 36 | virtual void OnToneChange(const std::string& tone) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | |
| 38 | protected: |
Mirko Bonadei | 79eb4dd | 2018-07-19 10:39:30 +0200 | [diff] [blame] | 39 | virtual ~DtmfSenderObserverInterface() = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | // The interface of native implementation of the RTCDTMFSender defined by the |
| 43 | // WebRTC W3C Editor's Draft. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 44 | // See: https://www.w3.org/TR/webrtc/#peer-to-peer-dtmf |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 45 | class DtmfSenderInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | public: |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 47 | // Provides the spec compliant default 2 second delay for the ',' character. |
| 48 | static const int kDtmfDefaultCommaDelayMs = 2000; |
| 49 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 50 | // Used to receive events from the DTMF sender. Only one observer can be |
| 51 | // registered at a time. UnregisterObserver should be called before the |
| 52 | // observer object is destroyed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0; |
| 54 | virtual void UnregisterObserver() = 0; |
| 55 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 56 | // Returns true if this DtmfSender is capable of sending DTMF. Otherwise |
| 57 | // returns false. To be able to send DTMF, the associated RtpSender must be |
| 58 | // able to send packets, and a "telephone-event" codec must be negotiated. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | virtual bool CanInsertDtmf() = 0; |
| 60 | |
| 61 | // Queues a task that sends the DTMF |tones|. The |tones| parameter is treated |
| 62 | // as a series of characters. The characters 0 through 9, A through D, #, and |
| 63 | // * generate the associated DTMF tones. The characters a to d are equivalent |
| 64 | // to A to D. The character ',' indicates a delay of 2 seconds before |
| 65 | // processing the next character in the tones parameter. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 66 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | // Unrecognized characters are ignored. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 68 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | // The |duration| parameter indicates the duration in ms to use for each |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 70 | // character passed in the |tones| parameter. The duration cannot be more |
| 71 | // than 6000 or less than 70. |
| 72 | // |
| 73 | // The |inter_tone_gap| parameter indicates the gap between tones in ms. The |
| 74 | // |inter_tone_gap| must be at least 50 ms but should be as short as |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | // possible. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 76 | // |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 77 | // The |comma_delay| parameter indicates the delay after the ',' |
| 78 | // character. InsertDtmf specifies |comma_delay| as an argument |
| 79 | // with a default value of 2 seconds as per the WebRTC spec. This parameter |
| 80 | // allows users to comply with legacy WebRTC clients. The |comma_delay| |
| 81 | // must be at least 50 ms. |
| 82 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | // If InsertDtmf is called on the same object while an existing task for this |
| 84 | // object to generate DTMF is still running, the previous task is canceled. |
| 85 | // Returns true on success and false on failure. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 86 | virtual bool InsertDtmf(const std::string& tones, |
| 87 | int duration, |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 88 | int inter_tone_gap) { |
| 89 | return InsertDtmf(tones, duration, inter_tone_gap, |
| 90 | kDtmfDefaultCommaDelayMs); |
| 91 | } |
| 92 | virtual bool InsertDtmf(const std::string& tones, |
| 93 | int duration, |
| 94 | int inter_tone_gap, |
| 95 | int comma_delay) { |
| 96 | // TODO(bugs.webrtc.org/165700): Remove once downstream implementations |
| 97 | // override this signature rather than the 3-parameter one. |
| 98 | return InsertDtmf(tones, duration, inter_tone_gap); |
| 99 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | // Returns the tones remaining to be played out. |
| 102 | virtual std::string tones() const = 0; |
| 103 | |
| 104 | // Returns the current tone duration value in ms. |
| 105 | // This value will be the value last set via the InsertDtmf() method, or the |
| 106 | // default value of 100 ms if InsertDtmf() was never called. |
| 107 | virtual int duration() const = 0; |
| 108 | |
| 109 | // Returns the current value of the between-tone gap in ms. |
| 110 | // This value will be the value last set via the InsertDtmf() method, or the |
| 111 | // default value of 50 ms if InsertDtmf() was never called. |
| 112 | virtual int inter_tone_gap() const = 0; |
| 113 | |
Aaron Alaniz | 529d886 | 2020-01-21 03:09:47 +0000 | [diff] [blame] | 114 | // Returns the current value of the "," character delay in ms. |
| 115 | // This value will be the value last set via the InsertDtmf() method, or the |
| 116 | // default value of 2000 ms if InsertDtmf() was never called. |
| 117 | virtual int comma_delay() const { return kDtmfDefaultCommaDelayMs; } |
| 118 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | protected: |
Mirko Bonadei | 79eb4dd | 2018-07-19 10:39:30 +0200 | [diff] [blame] | 120 | ~DtmfSenderInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace webrtc |
| 124 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 125 | #endif // API_DTMF_SENDER_INTERFACE_H_ |