blob: 9cdfba189c1c08edfcd46b8df94f39e4f89e6d86 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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:36 +00009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef API_DTMF_SENDER_INTERFACE_H_
12#define API_DTMF_SENDER_INTERFACE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
15
Steve Anton10542f22019-01-11 09:11:00 -080016#include "api/media_stream_interface.h"
17#include "rtc_base/ref_count.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019namespace webrtc {
20
deadbeefb10f32f2017-02-08 01:38:21 -080021// DtmfSender callback interface, used to implement RTCDtmfSender events.
22// Applications should implement this interface to get notifications from the
23// DtmfSender.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024class 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 Alvestrandd7b79af2018-09-06 09:33:56 +020029 // 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.org28e20752013-07-10 00:45:36 +000037
38 protected:
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +020039 virtual ~DtmfSenderObserverInterface() = default;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040};
41
42// The interface of native implementation of the RTCDTMFSender defined by the
43// WebRTC W3C Editor's Draft.
deadbeefb10f32f2017-02-08 01:38:21 -080044// See: https://www.w3.org/TR/webrtc/#peer-to-peer-dtmf
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000045class DtmfSenderInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046 public:
deadbeefb10f32f2017-02-08 01:38:21 -080047 // Used to receive events from the DTMF sender. Only one observer can be
48 // registered at a time. UnregisterObserver should be called before the
49 // observer object is destroyed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0;
51 virtual void UnregisterObserver() = 0;
52
deadbeefb10f32f2017-02-08 01:38:21 -080053 // Returns true if this DtmfSender is capable of sending DTMF. Otherwise
54 // returns false. To be able to send DTMF, the associated RtpSender must be
55 // able to send packets, and a "telephone-event" codec must be negotiated.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056 virtual bool CanInsertDtmf() = 0;
57
58 // Queues a task that sends the DTMF |tones|. The |tones| parameter is treated
59 // as a series of characters. The characters 0 through 9, A through D, #, and
60 // * generate the associated DTMF tones. The characters a to d are equivalent
61 // to A to D. The character ',' indicates a delay of 2 seconds before
62 // processing the next character in the tones parameter.
deadbeefb10f32f2017-02-08 01:38:21 -080063 //
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 // Unrecognized characters are ignored.
deadbeefb10f32f2017-02-08 01:38:21 -080065 //
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 // The |duration| parameter indicates the duration in ms to use for each
deadbeefb10f32f2017-02-08 01:38:21 -080067 // character passed in the |tones| parameter. The duration cannot be more
68 // than 6000 or less than 70.
69 //
70 // The |inter_tone_gap| parameter indicates the gap between tones in ms. The
71 // |inter_tone_gap| must be at least 50 ms but should be as short as
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 // possible.
deadbeefb10f32f2017-02-08 01:38:21 -080073 //
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 // If InsertDtmf is called on the same object while an existing task for this
75 // object to generate DTMF is still running, the previous task is canceled.
76 // Returns true on success and false on failure.
Yves Gerey665174f2018-06-19 15:03:05 +020077 virtual bool InsertDtmf(const std::string& tones,
78 int duration,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 int inter_tone_gap) = 0;
80
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081 // Returns the tones remaining to be played out.
82 virtual std::string tones() const = 0;
83
84 // Returns the current tone duration value in ms.
85 // This value will be the value last set via the InsertDtmf() method, or the
86 // default value of 100 ms if InsertDtmf() was never called.
87 virtual int duration() const = 0;
88
89 // Returns the current value of the between-tone gap in ms.
90 // This value will be the value last set via the InsertDtmf() method, or the
91 // default value of 50 ms if InsertDtmf() was never called.
92 virtual int inter_tone_gap() const = 0;
93
94 protected:
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +020095 ~DtmfSenderInterface() override = default;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096};
97
98} // namespace webrtc
99
Steve Anton10542f22019-01-11 09:11:00 -0800100#endif // API_DTMF_SENDER_INTERFACE_H_