tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtp_sender_audio.h (4065B)


      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 <optional>
     18 
     19 #include "absl/strings/string_view.h"
     20 #include "api/array_view.h"
     21 #include "api/units/timestamp.h"
     22 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
     23 #include "modules/rtp_rtcp/source/absolute_capture_time_sender.h"
     24 #include "modules/rtp_rtcp/source/dtmf_queue.h"
     25 #include "modules/rtp_rtcp/source/rtp_sender.h"
     26 #include "rtc_base/one_time_event.h"
     27 #include "rtc_base/synchronization/mutex.h"
     28 #include "rtc_base/thread_annotations.h"
     29 #include "system_wrappers/include/clock.h"
     30 
     31 namespace webrtc {
     32 
     33 class RTPSenderAudio {
     34 public:
     35  RTPSenderAudio(Clock* clock, RTPSender* rtp_sender);
     36 
     37  RTPSenderAudio() = delete;
     38  RTPSenderAudio(const RTPSenderAudio&) = delete;
     39  RTPSenderAudio& operator=(const RTPSenderAudio&) = delete;
     40 
     41  ~RTPSenderAudio();
     42 
     43  int32_t RegisterAudioPayload(absl::string_view payload_name,
     44                               int8_t payload_type,
     45                               uint32_t frequency,
     46                               size_t channels,
     47                               uint32_t rate);
     48 
     49  struct RtpAudioFrame {
     50    AudioFrameType type = AudioFrameType::kAudioFrameSpeech;
     51    ArrayView<const uint8_t> payload;
     52 
     53    // Payload id to write to the payload type field of the rtp packet.
     54    int payload_id = -1;
     55 
     56    // capture time of the audio frame represented as rtp timestamp.
     57    uint32_t rtp_timestamp = 0;
     58 
     59    // capture time of the audio frame in the same epoch as `clock->CurrentTime`
     60    std::optional<Timestamp> capture_time;
     61 
     62    // Audio level in dBov for
     63    // header-extension-for-audio-level-indication.
     64    // Valid range is [0,127]. Actual value is negative.
     65    std::optional<int> audio_level_dbov;
     66 
     67    // Contributing sources list.
     68    ArrayView<const uint32_t> csrcs;
     69  };
     70  bool SendAudio(const RtpAudioFrame& frame);
     71 
     72  // Send a DTMF tone using RFC 2833 (4733)
     73  int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
     74 
     75 protected:
     76  bool SendTelephoneEventPacket(
     77      bool ended,
     78      uint32_t dtmf_timestamp,
     79      uint16_t duration,
     80      bool marker_bit);  // set on first packet in talk burst
     81 
     82  bool MarkerBit(AudioFrameType frame_type, int8_t payload_type);
     83 
     84 private:
     85  Clock* const clock_ = nullptr;
     86  RTPSender* const rtp_sender_ = nullptr;
     87 
     88  Mutex send_audio_mutex_;
     89 
     90  // DTMF.
     91  bool dtmf_event_is_on_ = false;
     92  bool dtmf_event_first_packet_sent_ = false;
     93  int8_t dtmf_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
     94  uint32_t dtmf_payload_freq_ RTC_GUARDED_BY(send_audio_mutex_) = 8000;
     95  uint32_t dtmf_timestamp_ = 0;
     96  uint32_t dtmf_length_samples_ = 0;
     97  int64_t dtmf_time_last_sent_ = 0;
     98  uint32_t dtmf_timestamp_last_sent_ = 0;
     99  DtmfQueue::Event dtmf_current_event_;
    100  DtmfQueue dtmf_queue_;
    101 
    102  // VAD detection, used for marker bit.
    103  bool inband_vad_active_ RTC_GUARDED_BY(send_audio_mutex_) = false;
    104  int8_t cngnb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
    105  int8_t cngwb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
    106  int8_t cngswb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
    107  int8_t cngfb_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
    108  int8_t last_payload_type_ RTC_GUARDED_BY(send_audio_mutex_) = -1;
    109 
    110  OneTimeEvent first_packet_sent_;
    111 
    112  std::optional<int> encoder_rtp_timestamp_frequency_
    113      RTC_GUARDED_BY(send_audio_mutex_);
    114 
    115  AbsoluteCaptureTimeSender absolute_capture_time_sender_
    116      RTC_GUARDED_BY(send_audio_mutex_);
    117 };
    118 
    119 }  // namespace webrtc
    120 
    121 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_AUDIO_H_