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