blob: 16ce665e53f2000b4ac292a65f49ab5e91d4b63b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.org28e20752013-07-10 00:45:369 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef API_DTMF_SENDER_INTERFACE_H_
12#define API_DTMF_SENDER_INTERFACE_H_
henrike@webrtc.org28e20752013-07-10 00:45:3613
14#include <string>
15
Harald Alvestrande8a2b3c2023-10-31 13:30:3016#include "api/ref_count.h"
henrike@webrtc.org28e20752013-07-10 00:45:3617
henrike@webrtc.org28e20752013-07-10 00:45:3618namespace webrtc {
19
deadbeefb10f32f2017-02-08 09:38:2120// DtmfSender callback interface, used to implement RTCDtmfSender events.
21// Applications should implement this interface to get notifications from the
22// DtmfSender.
henrike@webrtc.org28e20752013-07-10 00:45:3623class DtmfSenderObserverInterface {
24 public:
Artem Titov0e61fdd2021-07-25 19:50:1425 // Triggered when DTMF `tone` is sent.
26 // If `tone` is empty that means the DtmfSender has sent out all the given
henrike@webrtc.org28e20752013-07-10 00:45:3627 // tones.
Harald Alvestrandd7b79af2018-09-06 07:33:5628 // The callback includes the state of the tone buffer at the time when
29 // the tone finished playing.
Dor Hen049b43b2024-10-15 07:51:5430 virtual void OnToneChange(const std::string& /* tone */,
31 const std::string& /* tone_buffer */) {}
Harald Alvestrandd7b79af2018-09-06 07:33:5632 // 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 Hen049b43b2024-10-15 07:51:5435 virtual void OnToneChange(const std::string& /* tone */) {}
henrike@webrtc.org28e20752013-07-10 00:45:3636
37 protected:
Mirko Bonadei79eb4dd2018-07-19 08:39:3038 virtual ~DtmfSenderObserverInterface() = default;
henrike@webrtc.org28e20752013-07-10 00:45:3639};
40
41// The interface of native implementation of the RTCDTMFSender defined by the
42// WebRTC W3C Editor's Draft.
deadbeefb10f32f2017-02-08 09:38:2143// See: https://www.w3.org/TR/webrtc/#peer-to-peer-dtmf
Harald Alvestrande8a2b3c2023-10-31 13:30:3044class DtmfSenderInterface : public webrtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3645 public:
Aaron Alaniz529d8862020-01-21 03:09:4746 // Provides the spec compliant default 2 second delay for the ',' character.
47 static const int kDtmfDefaultCommaDelayMs = 2000;
48
deadbeefb10f32f2017-02-08 09:38:2149 // 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.org28e20752013-07-10 00:45:3652 virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0;
53 virtual void UnregisterObserver() = 0;
54
deadbeefb10f32f2017-02-08 09:38:2155 // 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.org28e20752013-07-10 00:45:3658 virtual bool CanInsertDtmf() = 0;
59
Artem Titov0e61fdd2021-07-25 19:50:1460 // Queues a task that sends the DTMF `tones`. The `tones` parameter is treated
henrike@webrtc.org28e20752013-07-10 00:45:3661 // 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.
deadbeefb10f32f2017-02-08 09:38:2165 //
henrike@webrtc.org28e20752013-07-10 00:45:3666 // Unrecognized characters are ignored.
deadbeefb10f32f2017-02-08 09:38:2167 //
Artem Titov0e61fdd2021-07-25 19:50:1468 // The `duration` parameter indicates the duration in ms to use for each
69 // character passed in the `tones` parameter. The duration cannot be more
deadbeefb10f32f2017-02-08 09:38:2170 // than 6000 or less than 70.
71 //
Artem Titov0e61fdd2021-07-25 19:50:1472 // 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.org28e20752013-07-10 00:45:3674 // possible.
deadbeefb10f32f2017-02-08 09:38:2175 //
Artem Titov0e61fdd2021-07-25 19:50:1476 // The `comma_delay` parameter indicates the delay after the ','
77 // character. InsertDtmf specifies `comma_delay` as an argument
Aaron Alaniz529d8862020-01-21 03:09:4778 // with a default value of 2 seconds as per the WebRTC spec. This parameter
Artem Titov0e61fdd2021-07-25 19:50:1479 // allows users to comply with legacy WebRTC clients. The `comma_delay`
Aaron Alaniz529d8862020-01-21 03:09:4780 // must be at least 50 ms.
81 //
henrike@webrtc.org28e20752013-07-10 00:45:3682 // 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 Gerey665174f2018-06-19 13:03:0585 virtual bool InsertDtmf(const std::string& tones,
86 int duration,
Aaron Alaniz529d8862020-01-21 03:09:4787 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 Hen049b43b2024-10-15 07:51:5494 int /* comma_delay */) {
Aaron Alaniz529d8862020-01-21 03:09:4795 // 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.org28e20752013-07-10 00:45:3699
henrike@webrtc.org28e20752013-07-10 00:45:36100 // 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 Alaniz529d8862020-01-21 03:09:47113 // 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.org28e20752013-07-10 00:45:36118 protected:
Mirko Bonadei79eb4dd2018-07-19 08:39:30119 ~DtmfSenderInterface() override = default;
henrike@webrtc.org28e20752013-07-10 00:45:36120};
121
122} // namespace webrtc
123
Steve Anton10542f22019-01-11 17:11:00124#endif // API_DTMF_SENDER_INTERFACE_H_