rtp_sender_audio.h 4.1 KB

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