Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef AUDIO_AUDIO_RECEIVE_STREAM_H_ |
| 12 | #define AUDIO_AUDIO_RECEIVE_STREAM_H_ |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 13 | |
kwiberg | fffa42b | 2016-02-23 10:46:32 -0800 | [diff] [blame] | 14 | #include <memory> |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 15 | #include <vector> |
kwiberg | fffa42b | 2016-02-23 10:46:32 -0800 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 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" |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 26 | class PacketRouter; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 27 | class ProcessThread; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 28 | class RtcEventLog; |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 29 | class RtpPacketReceived; |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 30 | class RtpStreamReceiverControllerInterface; |
| 31 | class RtpStreamReceiverInterface; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 32 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 33 | namespace voe { |
| 34 | class ChannelProxy; |
| 35 | } // namespace voe |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 36 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 37 | namespace internal { |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 38 | class AudioSendStream; |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 39 | |
aleloi | aed581a | 2016-10-20 06:32:39 -0700 | [diff] [blame] | 40 | class AudioReceiveStream final : public webrtc::AudioReceiveStream, |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 41 | public AudioMixer::Source, |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 42 | public Syncable { |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 43 | public: |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 44 | AudioReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller, |
| 45 | PacketRouter* packet_router, |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 46 | ProcessThread* module_process_thread, |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 47 | const webrtc::AudioReceiveStream::Config& config, |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 48 | const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 49 | webrtc::RtcEventLog* event_log); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 50 | // For unit tests, which need to supply a mock channel proxy. |
| 51 | AudioReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller, |
| 52 | PacketRouter* packet_router, |
| 53 | const webrtc::AudioReceiveStream::Config& config, |
| 54 | const rtc::scoped_refptr<webrtc::AudioState>& audio_state, |
| 55 | webrtc::RtcEventLog* event_log, |
| 56 | std::unique_ptr<voe::ChannelProxy> channel_proxy); |
pbos | a2f30de | 2015-10-15 05:22:13 -0700 | [diff] [blame] | 57 | ~AudioReceiveStream() override; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 58 | |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 59 | // webrtc::AudioReceiveStream implementation. |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 60 | void Reconfigure(const webrtc::AudioReceiveStream::Config& config) override; |
Jelena Marusic | cd67022 | 2015-07-16 09:30:09 +0200 | [diff] [blame] | 61 | void Start() override; |
| 62 | void Stop() override; |
Jelena Marusic | cd67022 | 2015-07-16 09:30:09 +0200 | [diff] [blame] | 63 | webrtc::AudioReceiveStream::Stats GetStats() const override; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 64 | void SetSink(AudioSinkInterface* sink) override; |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame] | 65 | void SetGain(float gain) override; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 66 | std::vector<webrtc::RtpSource> GetSources() const override; |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 67 | |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 68 | // TODO(nisse): We don't formally implement RtpPacketSinkInterface, and this |
| 69 | // method shouldn't be needed. But it's currently used by the |
| 70 | // AudioReceiveStreamTest.ReceiveRtpPacket unittest. Figure out if that test |
| 71 | // shuld be refactored or deleted, and then delete this method. |
| 72 | void OnRtpPacket(const RtpPacketReceived& packet); |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 73 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 74 | // AudioMixer::Source |
| 75 | AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz, |
| 76 | AudioFrame* audio_frame) override; |
| 77 | int Ssrc() const override; |
| 78 | int PreferredSampleRate() const override; |
| 79 | |
| 80 | // Syncable |
| 81 | int id() const override; |
| 82 | rtc::Optional<Syncable::Info> GetInfo() const override; |
| 83 | uint32_t GetPlayoutTimestamp() const override; |
| 84 | void SetMinimumPlayoutDelay(int delay_ms) override; |
| 85 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 86 | void AssociateSendStream(AudioSendStream* send_stream); |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 87 | void SignalNetworkState(NetworkState state); |
| 88 | bool DeliverRtcp(const uint8_t* packet, size_t length); |
pbos | a2f30de | 2015-10-15 05:22:13 -0700 | [diff] [blame] | 89 | const webrtc::AudioReceiveStream::Config& config() const; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 90 | const AudioSendStream* GetAssociatedSendStreamForTesting() const; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 91 | |
| 92 | private: |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 93 | static void ConfigureStream(AudioReceiveStream* stream, |
| 94 | const Config& new_config, |
| 95 | bool first_time); |
| 96 | |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 97 | AudioState* audio_state() const; |
solenberg | 7add058 | 2015-11-20 09:59:34 -0800 | [diff] [blame] | 98 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 99 | rtc::ThreadChecker worker_thread_checker_; |
| 100 | rtc::ThreadChecker module_process_thread_checker_; |
Fredrik Solenberg | 3b903d0 | 2018-01-10 15:17:10 +0100 | [diff] [blame] | 101 | webrtc::AudioReceiveStream::Config config_; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 102 | rtc::scoped_refptr<webrtc::AudioState> audio_state_; |
kwiberg | fffa42b | 2016-02-23 10:46:32 -0800 | [diff] [blame] | 103 | std::unique_ptr<voe::ChannelProxy> channel_proxy_; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 104 | AudioSendStream* associated_send_stream_ = nullptr; |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 105 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 106 | bool playing_ RTC_ACCESS_ON(worker_thread_checker_) = false; |
aleloi | 04c0722 | 2016-11-22 06:42:53 -0800 | [diff] [blame] | 107 | |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 108 | std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_; |
| 109 | |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 110 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioReceiveStream); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 111 | }; |
| 112 | } // namespace internal |
| 113 | } // namespace webrtc |
| 114 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 115 | #endif // AUDIO_AUDIO_RECEIVE_STREAM_H_ |