Jason Long | a534729 | 2020-08-18 17:22:39 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_VOIP_VOIP_DTMF_H_ |
| 12 | #define API_VOIP_VOIP_DTMF_H_ |
| 13 | |
Dor Hen | 52e4624 | 2024-08-19 09:44:56 | [diff] [blame] | 14 | #include <cstdint> |
| 15 | |
Jason Long | a534729 | 2020-08-18 17:22:39 | [diff] [blame] | 16 | #include "api/voip/voip_base.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // DTMF events and their event codes as defined in |
| 21 | // https://tools.ietf.org/html/rfc4733#section-7 |
| 22 | enum class DtmfEvent : uint8_t { |
| 23 | kDigitZero = 0, |
| 24 | kDigitOne, |
| 25 | kDigitTwo, |
| 26 | kDigitThree, |
| 27 | kDigitFour, |
| 28 | kDigitFive, |
| 29 | kDigitSix, |
| 30 | kDigitSeven, |
| 31 | kDigitEight, |
| 32 | kDigitNine, |
| 33 | kAsterisk, |
| 34 | kHash, |
| 35 | kLetterA, |
| 36 | kLetterB, |
| 37 | kLetterC, |
| 38 | kLetterD |
| 39 | }; |
| 40 | |
| 41 | // VoipDtmf interface provides DTMF related interfaces such |
| 42 | // as sending DTMF events to the remote endpoint. |
| 43 | class VoipDtmf { |
| 44 | public: |
| 45 | // Register the payload type and sample rate for DTMF (RFC 4733) payload. |
| 46 | // Must be called exactly once prior to calling SendDtmfEvent after payload |
| 47 | // type has been negotiated with remote. |
Tim Na | b223cb6 | 2020-11-20 17:34:47 | [diff] [blame] | 48 | // Returns following VoipResult; |
| 49 | // kOk - telephone event type is registered as provided. |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 50 | // kInvalidArgument - `channel_id` is invalid. |
Tim Na | b223cb6 | 2020-11-20 17:34:47 | [diff] [blame] | 51 | virtual VoipResult RegisterTelephoneEventType(ChannelId channel_id, |
| 52 | int rtp_payload_type, |
| 53 | int sample_rate_hz) = 0; |
Jason Long | a534729 | 2020-08-18 17:22:39 | [diff] [blame] | 54 | |
| 55 | // Send DTMF named event as specified by |
| 56 | // https://tools.ietf.org/html/rfc4733#section-3.2 |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 57 | // `duration_ms` specifies the duration of DTMF packets that will be emitted |
Jason Long | a534729 | 2020-08-18 17:22:39 | [diff] [blame] | 58 | // in place of real RTP packets instead. |
| 59 | // Must be called after RegisterTelephoneEventType and VoipBase::StartSend |
| 60 | // have been called. |
Tim Na | b223cb6 | 2020-11-20 17:34:47 | [diff] [blame] | 61 | // Returns following VoipResult; |
| 62 | // kOk - requested DTMF event is successfully scheduled. |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 63 | // kInvalidArgument - `channel_id` is invalid. |
Tim Na | b223cb6 | 2020-11-20 17:34:47 | [diff] [blame] | 64 | // kFailedPrecondition - Missing prerequisite on RegisterTelephoneEventType |
| 65 | // or sending state. |
| 66 | virtual VoipResult SendDtmfEvent(ChannelId channel_id, |
| 67 | DtmfEvent dtmf_event, |
| 68 | int duration_ms) = 0; |
Jason Long | a534729 | 2020-08-18 17:22:39 | [diff] [blame] | 69 | |
| 70 | protected: |
| 71 | virtual ~VoipDtmf() = default; |
| 72 | }; |
| 73 | |
| 74 | } // namespace webrtc |
| 75 | |
| 76 | #endif // API_VOIP_VOIP_DTMF_H_ |