1 /* 2 * Copyright (c) 2015 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_AUDIO_RECEIVE_STREAM_H_ 12 #define AUDIO_AUDIO_RECEIVE_STREAM_H_ 13 14 #include <memory> 15 #include <vector> 16 17 #include "api/audio/audio_mixer.h" 18 #include "audio/audio_state.h" 19 #include "call/audio_receive_stream.h" 20 #include "call/rtp_packet_sink_interface.h" 21 #include "call/syncable.h" 22 #include "rtc_base/constructormagic.h" 23 #include "rtc_base/thread_checker.h" 24 25 namespace webrtc { 26 class PacketRouter; 27 class RtcEventLog; 28 class RtpPacketReceived; 29 class RtpStreamReceiverControllerInterface; 30 class RtpStreamReceiverInterface; 31 32 namespace voe { 33 class ChannelProxy; 34 } // namespace voe 35 36 namespace internal { 37 class AudioSendStream; 38 39 class AudioReceiveStream final : public webrtc::AudioReceiveStream, 40 public AudioMixer::Source, 41 public Syncable { 42 public: 43 AudioReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller, 44 PacketRouter* packet_router, 45 const webrtc::AudioReceiveStream::Config& config, 46 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, 47 webrtc::RtcEventLog* event_log); 48 ~AudioReceiveStream() override; 49 50 // webrtc::AudioReceiveStream implementation. 51 void Start() override; 52 void Stop() override; 53 webrtc::AudioReceiveStream::Stats GetStats() const override; 54 int GetOutputLevel() const override; 55 void SetSink(std::unique_ptr<AudioSinkInterface> sink) override; 56 void SetGain(float gain) override; 57 std::vector<webrtc::RtpSource> GetSources() const override; 58 59 // TODO(nisse): We don't formally implement RtpPacketSinkInterface, and this 60 // method shouldn't be needed. But it's currently used by the 61 // AudioReceiveStreamTest.ReceiveRtpPacket unittest. Figure out if that test 62 // shuld be refactored or deleted, and then delete this method. 63 void OnRtpPacket(const RtpPacketReceived& packet); 64 65 // AudioMixer::Source 66 AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz, 67 AudioFrame* audio_frame) override; 68 int Ssrc() const override; 69 int PreferredSampleRate() const override; 70 71 // Syncable 72 int id() const override; 73 rtc::Optional<Syncable::Info> GetInfo() const override; 74 uint32_t GetPlayoutTimestamp() const override; 75 void SetMinimumPlayoutDelay(int delay_ms) override; 76 77 void AssociateSendStream(AudioSendStream* send_stream); 78 void SignalNetworkState(NetworkState state); 79 bool DeliverRtcp(const uint8_t* packet, size_t length); 80 const webrtc::AudioReceiveStream::Config& config() const; 81 82 private: 83 VoiceEngine* voice_engine() const; 84 AudioState* audio_state() const; 85 int SetVoiceEnginePlayout(bool playout); 86 87 rtc::ThreadChecker worker_thread_checker_; 88 rtc::ThreadChecker module_process_thread_checker_; 89 const webrtc::AudioReceiveStream::Config config_; 90 rtc::scoped_refptr<webrtc::AudioState> audio_state_; 91 std::unique_ptr<voe::ChannelProxy> channel_proxy_; 92 93 bool playing_ RTC_ACCESS_ON(worker_thread_checker_) = false; 94 95 std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_; 96 97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioReceiveStream); 98 }; 99 } // namespace internal 100 } // namespace webrtc 101 102 #endif // AUDIO_AUDIO_RECEIVE_STREAM_H_ 103