voip_dtmf.h (2435B)
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 14 #include <cstdint> 15 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. 48 // Returns following VoipResult; 49 // kOk - telephone event type is registered as provided. 50 // kInvalidArgument - `channel_id` is invalid. 51 virtual VoipResult RegisterTelephoneEventType(ChannelId channel_id, 52 int rtp_payload_type, 53 int sample_rate_hz) = 0; 54 55 // Send DTMF named event as specified by 56 // https://tools.ietf.org/html/rfc4733#section-3.2 57 // `duration_ms` specifies the duration of DTMF packets that will be emitted 58 // in place of real RTP packets instead. 59 // Must be called after RegisterTelephoneEventType and VoipBase::StartSend 60 // have been called. 61 // Returns following VoipResult; 62 // kOk - requested DTMF event is successfully scheduled. 63 // kInvalidArgument - `channel_id` is invalid. 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; 69 70 protected: 71 virtual ~VoipDtmf() = default; 72 }; 73 74 } // namespace webrtc 75 76 #endif // API_VOIP_VOIP_DTMF_H_