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