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 "api/transport/field_trial_based_config.h" 21 #include "modules/audio_coding/include/audio_coding_module_typedefs.h" 22 #include "modules/rtp_rtcp/source/absolute_capture_time_sender.h" 23 #include "modules/rtp_rtcp/source/dtmf_queue.h" 24 #include "modules/rtp_rtcp/source/rtp_sender.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 36 RTPSenderAudio() = delete; 37 RTPSenderAudio(const RTPSenderAudio&) = delete; 38 RTPSenderAudio& operator=(const RTPSenderAudio&) = delete; 39 40 ~RTPSenderAudio(); 41 42 int32_t RegisterAudioPayload(absl::string_view payload_name, 43 int8_t payload_type, 44 uint32_t frequency, 45 size_t channels, 46 uint32_t rate); 47 48 bool SendAudio(AudioFrameType frame_type, 49 int8_t payload_type, 50 uint32_t rtp_timestamp, 51 const uint8_t* payload_data, 52 size_t payload_size); 53 54 // `absolute_capture_timestamp_ms` and `Clock::CurrentTime` 55 // should be using the same epoch. 56 bool SendAudio(AudioFrameType frame_type, 57 int8_t payload_type, 58 uint32_t rtp_timestamp, 59 const uint8_t* payload_data, 60 size_t payload_size, 61 int64_t absolute_capture_timestamp_ms); 62 63 // Store the audio level in dBov for 64 // header-extension-for-audio-level-indication. 65 // Valid range is [0,127]. Actual value is negative. 66 int32_t SetAudioLevel(uint8_t level_dbov); 67 68 // Send a DTMF tone using RFC 2833 (4733) 69 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level); 70 71 protected: 72 bool SendTelephoneEventPacket( 73 bool ended, 74 uint32_t dtmf_timestamp, 75 uint16_t duration, 76 bool marker_bit); // set on first packet in talk burst 77 78 bool MarkerBit(AudioFrameType frame_type, int8_t payload_type); 79 80 private: 81 Clock* const clock_ = nullptr; 82 RTPSender* const rtp_sender_ = nullptr; 83 84 Mutex send_audio_mutex_; 85 86 // DTMF. 87 bool dtmf_event_is_on_ = false; 88 bool dtmf_event_first_packet_sent_ = false; 89 int8_t dtmf_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1; 90 uint32_t dtmf_payload_freq_ RTC_GUARDED_BY(send_audio_mutex_) = 8000; 91 uint32_t dtmf_timestamp_ = 0; 92 uint32_t dtmf_length_samples_ = 0; 93 int64_t dtmf_time_last_sent_ = 0; 94 uint32_t dtmf_timestamp_last_sent_ = 0; 95 DtmfQueue::Event dtmf_current_event_; 96 DtmfQueue dtmf_queue_; 97 98 // VAD detection, used for marker bit. 99 bool inband_vad_active_ RTC_GUARDED_BY(send_audio_mutex_) = false; 100 int8_t cngnb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1; 101 int8_t cngwb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1; 102 int8_t cngswb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1; 103 int8_t cngfb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1; 104 int8_t last_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1; 105 106 // Audio level indication. 107 // (https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/) 108 uint8_t audio_level_dbov_ RTC_GUARDED_BY(send_audio_mutex_) = 127; 109 OneTimeEvent first_packet_sent_; 110 111 absl::optional<uint32_t> encoder_rtp_timestamp_frequency_ 112 RTC_GUARDED_BY(send_audio_mutex_); 113 114 AbsoluteCaptureTimeSender absolute_capture_time_sender_; 115 116 const FieldTrialBasedConfig field_trials_; 117 const bool include_capture_clock_offset_; 118 }; 119 120 } // namespace webrtc 121 122 #endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_ 123