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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef API_DTMFSENDERINTERFACE_H_ |
| 12 | #define API_DTMFSENDERINTERFACE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "api/mediastreaminterface.h" |
| 17 | #include "rtc_base/refcount.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 18 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [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 | [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. |
| 29 | virtual void OnToneChange(const std::string& tone) = 0; |
| 30 | |
| 31 | protected: |
| 32 | virtual ~DtmfSenderObserverInterface() {} |
| 33 | }; |
| 34 | |
| 35 | // The interface of native implementation of the RTCDTMFSender defined by the |
| 36 | // WebRTC W3C Editor's Draft. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 37 | // See: https://www.w3.org/TR/webrtc/#peer-to-peer-dtmf |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 38 | class DtmfSenderInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 39 | public: |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 40 | // Used to receive events from the DTMF sender. Only one observer can be |
| 41 | // registered at a time. UnregisterObserver should be called before the |
| 42 | // observer object is destroyed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 43 | virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0; |
| 44 | virtual void UnregisterObserver() = 0; |
| 45 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 46 | // Returns true if this DtmfSender is capable of sending DTMF. Otherwise |
| 47 | // returns false. To be able to send DTMF, the associated RtpSender must be |
| 48 | // able to send packets, and a "telephone-event" codec must be negotiated. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 49 | virtual bool CanInsertDtmf() = 0; |
| 50 | |
| 51 | // Queues a task that sends the DTMF |tones|. The |tones| parameter is treated |
| 52 | // as a series of characters. The characters 0 through 9, A through D, #, and |
| 53 | // * generate the associated DTMF tones. The characters a to d are equivalent |
| 54 | // to A to D. The character ',' indicates a delay of 2 seconds before |
| 55 | // processing the next character in the tones parameter. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 56 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 57 | // Unrecognized characters are ignored. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 58 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 59 | // The |duration| parameter indicates the duration in ms to use for each |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 60 | // character passed in the |tones| parameter. The duration cannot be more |
| 61 | // than 6000 or less than 70. |
| 62 | // |
| 63 | // The |inter_tone_gap| parameter indicates the gap between tones in ms. The |
| 64 | // |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] | 65 | // possible. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 66 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 67 | // If InsertDtmf is called on the same object while an existing task for this |
| 68 | // object to generate DTMF is still running, the previous task is canceled. |
| 69 | // Returns true on success and false on failure. |
| 70 | virtual bool InsertDtmf(const std::string& tones, int duration, |
| 71 | int inter_tone_gap) = 0; |
| 72 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 73 | // Returns the track given as argument to the constructor. Only exists for |
| 74 | // backwards compatibilty; now that DtmfSenders are tied to RtpSenders, it's |
| 75 | // no longer relevant. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 76 | virtual const AudioTrackInterface* track() const = 0; |
| 77 | |
| 78 | // Returns the tones remaining to be played out. |
| 79 | virtual std::string tones() const = 0; |
| 80 | |
| 81 | // Returns the current tone duration value in ms. |
| 82 | // This value will be the value last set via the InsertDtmf() method, or the |
| 83 | // default value of 100 ms if InsertDtmf() was never called. |
| 84 | virtual int duration() const = 0; |
| 85 | |
| 86 | // Returns the current value of the between-tone gap in ms. |
| 87 | // This value will be the value last set via the InsertDtmf() method, or the |
| 88 | // default value of 50 ms if InsertDtmf() was never called. |
| 89 | virtual int inter_tone_gap() const = 0; |
| 90 | |
| 91 | protected: |
| 92 | virtual ~DtmfSenderInterface() {} |
| 93 | }; |
| 94 | |
| 95 | } // namespace webrtc |
| 96 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 97 | #endif // API_DTMFSENDERINTERFACE_H_ |