• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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 MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
12 #define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <memory>
18 
19 #include "absl/strings/string_view.h"
20 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
21 #include "modules/rtp_rtcp/source/absolute_capture_time_sender.h"
22 #include "modules/rtp_rtcp/source/dtmf_queue.h"
23 #include "modules/rtp_rtcp/source/rtp_sender.h"
24 #include "rtc_base/constructor_magic.h"
25 #include "rtc_base/one_time_event.h"
26 #include "rtc_base/synchronization/mutex.h"
27 #include "rtc_base/thread_annotations.h"
28 #include "system_wrappers/include/clock.h"
29 
30 namespace webrtc {
31 
32 class RTPSenderAudio {
33  public:
34   RTPSenderAudio(Clock* clock, RTPSender* rtp_sender);
35   ~RTPSenderAudio();
36 
37   int32_t RegisterAudioPayload(absl::string_view payload_name,
38                                int8_t payload_type,
39                                uint32_t frequency,
40                                size_t channels,
41                                uint32_t rate);
42 
43   bool SendAudio(AudioFrameType frame_type,
44                  int8_t payload_type,
45                  uint32_t rtp_timestamp,
46                  const uint8_t* payload_data,
47                  size_t payload_size);
48 
49   bool SendAudio(AudioFrameType frame_type,
50                  int8_t payload_type,
51                  uint32_t rtp_timestamp,
52                  const uint8_t* payload_data,
53                  size_t payload_size,
54                  int64_t absolute_capture_timestamp_ms);
55 
56   // Store the audio level in dBov for
57   // header-extension-for-audio-level-indication.
58   // Valid range is [0,100]. Actual value is negative.
59   int32_t SetAudioLevel(uint8_t level_dbov);
60 
61   // Send a DTMF tone using RFC 2833 (4733)
62   int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
63 
64  protected:
65   bool SendTelephoneEventPacket(
66       bool ended,
67       uint32_t dtmf_timestamp,
68       uint16_t duration,
69       bool marker_bit);  // set on first packet in talk burst
70 
71   bool MarkerBit(AudioFrameType frame_type, int8_t payload_type);
72 
73  private:
74   Clock* const clock_ = nullptr;
75   RTPSender* const rtp_sender_ = nullptr;
76 
77   Mutex send_audio_mutex_;
78 
79   // DTMF.
80   bool dtmf_event_is_on_ = false;
81   bool dtmf_event_first_packet_sent_ = false;
82   int8_t dtmf_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
83   uint32_t dtmf_payload_freq_ RTC_GUARDED_BY(send_audio_mutex_) = 8000;
84   uint32_t dtmf_timestamp_ = 0;
85   uint32_t dtmf_length_samples_ = 0;
86   int64_t dtmf_time_last_sent_ = 0;
87   uint32_t dtmf_timestamp_last_sent_ = 0;
88   DtmfQueue::Event dtmf_current_event_;
89   DtmfQueue dtmf_queue_;
90 
91   // VAD detection, used for marker bit.
92   bool inband_vad_active_ RTC_GUARDED_BY(send_audio_mutex_) = false;
93   int8_t cngnb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
94   int8_t cngwb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
95   int8_t cngswb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
96   int8_t cngfb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
97   int8_t last_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
98 
99   // Audio level indication.
100   // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/)
101   uint8_t audio_level_dbov_ RTC_GUARDED_BY(send_audio_mutex_) = 0;
102   OneTimeEvent first_packet_sent_;
103 
104   absl::optional<uint32_t> encoder_rtp_timestamp_frequency_
105       RTC_GUARDED_BY(send_audio_mutex_);
106 
107   AbsoluteCaptureTimeSender absolute_capture_time_sender_;
108 
109   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSenderAudio);
110 };
111 
112 }  // namespace webrtc
113 
114 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_
115