| 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_AUDIO_RECEIVE_STREAM_H_ |
| 12 | #define AUDIO_AUDIO_RECEIVE_STREAM_H_ |
| 13 |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 |
| 19 | #include "absl/strings/string_view.h" |
| 20 | #include "api/audio/audio_mixer.h" |
| 21 | #include "api/neteq/neteq_factory.h" |
| 22 | #include "api/rtp_headers.h" |
| 23 | #include "api/sequence_checker.h" |
| 24 | #include "audio/audio_state.h" |
| 25 | #include "call/audio_receive_stream.h" |
| 26 | #include "call/syncable.h" |
| 27 | #include "modules/rtp_rtcp/source/source_tracker.h" |
| 28 | #include "rtc_base/system/no_unique_address.h" |
| 29 | #include "system_wrappers/include/clock.h" |
| 30 |
| 31 | namespace webrtc { |
| 32 | class PacketRouter; |
| 33 | class RtcEventLog; |
| 34 | class RtpStreamReceiverControllerInterface; |
| 35 | class RtpStreamReceiverInterface; |
| 36 |
| 37 | namespace voe { |
| 38 | class ChannelReceiveInterface; |
| 39 | } // namespace voe |
| 40 |
| 41 | namespace internal { |
| 42 | class AudioSendStream; |
| 43 | } // namespace internal |
| 44 |
| 45 | class AudioReceiveStreamImpl final : public webrtc::AudioReceiveStreamInterface, |
| 46 | public AudioMixer::Source, |
| 47 | public Syncable { |
| 48 | public: |
| 49 | AudioReceiveStreamImpl( |
| 50 | Clock* clock, |
| 51 | PacketRouter* packet_router, |
| 52 | NetEqFactory* neteq_factory, |
| 53 | const webrtc::AudioReceiveStreamInterface::Config& config, |
| 54 | const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 55 | webrtc::RtcEventLog* event_log); |
| 56 | // For unit tests, which need to supply a mock channel receive. |
| 57 | AudioReceiveStreamImpl( |
| 58 | Clock* clock, |
| 59 | PacketRouter* packet_router, |
| 60 | const webrtc::AudioReceiveStreamInterface::Config& config, |
| 61 | const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 62 | webrtc::RtcEventLog* event_log, |
| 63 | std::unique_ptr<voe::ChannelReceiveInterface> channel_receive); |
| 64 |
| 65 | AudioReceiveStreamImpl() = delete; |
| 66 | AudioReceiveStreamImpl(const AudioReceiveStreamImpl&) = delete; |
| 67 | AudioReceiveStreamImpl& operator=(const AudioReceiveStreamImpl&) = delete; |
| 68 |
| 69 | // Destruction happens on the worker thread. Prior to destruction the caller |
| 70 | // must ensure that a registration with the transport has been cleared. See |
| 71 | // `RegisterWithTransport` for details. |
| 72 | // TODO(tommi): As a further improvement to this, performing the full |
| 73 | // destruction on the network thread could be made the default. |
| 74 | ~AudioReceiveStreamImpl() override; |
| 75 |
| 76 | // Called on the network thread to register/unregister with the network |
| 77 | // transport. |
| 78 | void RegisterWithTransport( |
| 79 | RtpStreamReceiverControllerInterface* receiver_controller); |
| 80 | // If registration has previously been done (via `RegisterWithTransport`) then |
| 81 | // `UnregisterFromTransport` must be called prior to destruction, on the |
| 82 | // network thread. |
| 83 | void UnregisterFromTransport(); |
| 84 |
| 85 | // webrtc::AudioReceiveStreamInterface implementation. |
| 86 | void Start() override; |
| 87 | void Stop() override; |
| 88 | bool IsRunning() const override; |
| 89 | void SetDepacketizerToDecoderFrameTransformer( |
| 90 | rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) |
| 91 | override; |
| 92 | void SetDecoderMap(std::map<int, SdpAudioFormat> decoder_map) override; |
| 93 | void SetNackHistory(int history_ms) override; |
| 94 | void SetNonSenderRttMeasurement(bool enabled) override; |
| 95 | void SetFrameDecryptor(rtc::scoped_refptr<webrtc::FrameDecryptorInterface> |
| 96 | frame_decryptor) override; |
| 97 |
| 98 | webrtc::AudioReceiveStreamInterface::Stats GetStats( |
| 99 | bool get_and_clear_legacy_stats) const override; |
| 100 | void SetSink(AudioSinkInterface* sink) override; |
| 101 | void SetGain(float gain) override; |
| 102 | bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override; |
| 103 | int GetBaseMinimumPlayoutDelayMs() const override; |
| 104 | std::vector<webrtc::RtpSource> GetSources() const override; |
| 105 |
| 106 | // AudioMixer::Source |
| 107 | AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz, |
| 108 | AudioFrame* audio_frame) override; |
| 109 | int Ssrc() const override; |
| 110 | int PreferredSampleRate() const override; |
| 111 |
| 112 | // Syncable |
| 113 | uint32_t id() const override; |
| 114 | absl::optional<Syncable::Info> GetInfo() const override; |
| 115 | bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp, |
| 116 | int64_t* time_ms) const override; |
| 117 | void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms, |
| 118 | int64_t time_ms) override; |
| 119 | bool SetMinimumPlayoutDelay(int delay_ms) override; |
| 120 |
| 121 | void AssociateSendStream(internal::AudioSendStream* send_stream); |
| 122 | void DeliverRtcp(const uint8_t* packet, size_t length); |
| 123 |
| 124 | void SetSyncGroup(absl::string_view sync_group); |
| 125 |
| 126 | void SetLocalSsrc(uint32_t local_ssrc); |
| 127 |
| 128 | uint32_t local_ssrc() const; |
| 129 |
| 130 | uint32_t remote_ssrc() const override { |
| 131 | // The remote_ssrc member variable of config_ will never change and can be |
| 132 | // considered const. |
| 133 | return config_.rtp.remote_ssrc; |
| 134 | } |
| 135 |
| 136 | // Returns a reference to the currently set sync group of the stream. |
| 137 | // Must be called on the packet delivery thread. |
| 138 | const std::string& sync_group() const; |
| 139 |
| 140 | const AudioSendStream* GetAssociatedSendStreamForTesting() const; |
| 141 |
| 142 | // TODO(tommi): Remove this method. |
| 143 | void ReconfigureForTesting( |
| 144 | const webrtc::AudioReceiveStreamInterface::Config& config); |
| 145 |
| 146 | private: |
| 147 | internal::AudioState* audio_state() const; |
| 148 |
| 149 | RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_thread_checker_; |
| 150 | // TODO(bugs.webrtc.org/11993): This checker conceptually represents |
| 151 | // operations that belong to the network thread. The Call class is currently |
| 152 | // moving towards handling network packets on the network thread and while |
| 153 | // that work is ongoing, this checker may in practice represent the worker |
| 154 | // thread, but still serves as a mechanism of grouping together concepts |
| 155 | // that belong to the network thread. Once the packets are fully delivered |
| 156 | // on the network thread, this comment will be deleted. |
| 157 | RTC_NO_UNIQUE_ADDRESS SequenceChecker packet_sequence_checker_{ |
| 158 | SequenceChecker::kDetached}; |
| 159 | webrtc::AudioReceiveStreamInterface::Config config_; |
| 160 | rtc::scoped_refptr<webrtc::AudioState> audio_state_; |
| 161 | SourceTracker source_tracker_; |
| 162 | const std::unique_ptr<voe::ChannelReceiveInterface> channel_receive_; |
| 163 | AudioSendStream* associated_send_stream_ |
| 164 | RTC_GUARDED_BY(packet_sequence_checker_) = nullptr; |
| 165 |
| 166 | bool playing_ RTC_GUARDED_BY(worker_thread_checker_) = false; |
| 167 |
| 168 | std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_ |
| 169 | RTC_GUARDED_BY(packet_sequence_checker_); |
| 170 | }; |
| 171 | } // namespace webrtc |
| 172 |
| 173 | #endif // AUDIO_AUDIO_RECEIVE_STREAM_H_ |
| 174 |