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