audio_channel.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef AUDIO_VOIP_AUDIO_CHANNEL_H_
  11. #define AUDIO_VOIP_AUDIO_CHANNEL_H_
  12. #include <map>
  13. #include <memory>
  14. #include <queue>
  15. #include <utility>
  16. #include "api/task_queue/task_queue_factory.h"
  17. #include "api/voip/voip_base.h"
  18. #include "audio/voip/audio_egress.h"
  19. #include "audio/voip/audio_ingress.h"
  20. #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
  21. #include "modules/utility/include/process_thread.h"
  22. #include "rtc_base/critical_section.h"
  23. #include "rtc_base/ref_count.h"
  24. namespace webrtc {
  25. // AudioChannel represents a single media session and provides APIs over
  26. // AudioIngress and AudioEgress. Note that a single RTP stack is shared with
  27. // these two classes as it has both sending and receiving capabilities.
  28. class AudioChannel : public rtc::RefCountInterface {
  29. public:
  30. AudioChannel(Transport* transport,
  31. uint32_t local_ssrc,
  32. TaskQueueFactory* task_queue_factory,
  33. ProcessThread* process_thread,
  34. AudioMixer* audio_mixer,
  35. rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
  36. ~AudioChannel() override;
  37. // Set and get ChannelId that this audio channel belongs for debugging and
  38. // logging purpose.
  39. void SetId(ChannelId id) { id_ = id; }
  40. ChannelId GetId() const { return id_; }
  41. // APIs to start/stop audio channel on each direction.
  42. void StartSend();
  43. void StopSend();
  44. void StartPlay();
  45. void StopPlay();
  46. // APIs relayed to AudioEgress.
  47. bool IsSendingMedia() const { return egress_->IsSending(); }
  48. AudioSender* GetAudioSender() { return egress_.get(); }
  49. void SetEncoder(int payload_type,
  50. const SdpAudioFormat& encoder_format,
  51. std::unique_ptr<AudioEncoder> encoder) {
  52. egress_->SetEncoder(payload_type, encoder_format, std::move(encoder));
  53. }
  54. absl::optional<SdpAudioFormat> GetEncoderFormat() const {
  55. return egress_->GetEncoderFormat();
  56. }
  57. // APIs relayed to AudioIngress.
  58. bool IsPlaying() const { return ingress_->IsPlaying(); }
  59. void ReceivedRTPPacket(rtc::ArrayView<const uint8_t> rtp_packet) {
  60. ingress_->ReceivedRTPPacket(rtp_packet);
  61. }
  62. void ReceivedRTCPPacket(rtc::ArrayView<const uint8_t> rtcp_packet) {
  63. ingress_->ReceivedRTCPPacket(rtcp_packet);
  64. }
  65. void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) {
  66. ingress_->SetReceiveCodecs(codecs);
  67. }
  68. private:
  69. // ChannelId that this audio channel belongs for logging purpose.
  70. ChannelId id_;
  71. // Synchronization is handled internally by AudioMixer.
  72. AudioMixer* audio_mixer_;
  73. // Synchronization is handled internally by ProcessThread.
  74. ProcessThread* process_thread_;
  75. // Listed in order for safe destruction of AudioChannel object.
  76. // Synchronization for these are handled internally.
  77. std::unique_ptr<ReceiveStatistics> receive_statistics_;
  78. std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_;
  79. std::unique_ptr<AudioIngress> ingress_;
  80. std::unique_ptr<AudioEgress> egress_;
  81. };
  82. } // namespace webrtc
  83. #endif // AUDIO_VOIP_AUDIO_CHANNEL_H_