blob: 295f5f7aa617ddc0d5a199a6e66c25db50f2b9bb [file] [log] [blame]
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +02001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef AUDIO_AUDIO_RECEIVE_STREAM_H_
12#define AUDIO_AUDIO_RECEIVE_STREAM_H_
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020013
kwibergfffa42b2016-02-23 10:46:32 -080014#include <memory>
hbos8d609f62017-04-10 07:39:05 -070015#include <vector>
kwibergfffa42b2016-02-23 10:46:32 -080016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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 Solenberg23fba1f2015-04-29 15:24:01 +020024
25namespace webrtc {
solenberg3ebbcb52017-01-31 03:58:40 -080026class PacketRouter;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010027class ProcessThread;
ivoc14d5dbe2016-07-04 07:06:55 -070028class RtcEventLog;
nisse657bab22017-02-21 06:28:10 -080029class RtpPacketReceived;
nisse0f15f922017-06-21 01:05:22 -070030class RtpStreamReceiverControllerInterface;
31class RtpStreamReceiverInterface;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020032
solenberg13725082015-11-25 08:16:52 -080033namespace voe {
34class ChannelProxy;
35} // namespace voe
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020036
solenberg13725082015-11-25 08:16:52 -080037namespace internal {
solenberg7602aab2016-11-14 11:30:07 -080038class AudioSendStream;
Tommif888bb52015-12-12 01:37:01 +010039
aleloiaed581a2016-10-20 06:32:39 -070040class AudioReceiveStream final : public webrtc::AudioReceiveStream,
solenberg3ebbcb52017-01-31 03:58:40 -080041 public AudioMixer::Source,
nisse0f15f922017-06-21 01:05:22 -070042 public Syncable {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020043 public:
nisse0f15f922017-06-21 01:05:22 -070044 AudioReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller,
45 PacketRouter* packet_router,
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010046 ProcessThread* module_process_thread,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020047 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 07:06:55 -070048 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
49 webrtc::RtcEventLog* event_log);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010050 // 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);
pbosa2f30de2015-10-15 05:22:13 -070057 ~AudioReceiveStream() override;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020058
pbos1ba8d392016-05-01 20:18:34 -070059 // webrtc::AudioReceiveStream implementation.
Fredrik Solenberg3b903d02018-01-10 15:17:10 +010060 void Reconfigure(const webrtc::AudioReceiveStream::Config& config) override;
Jelena Marusiccd670222015-07-16 09:30:09 +020061 void Start() override;
62 void Stop() override;
Jelena Marusiccd670222015-07-16 09:30:09 +020063 webrtc::AudioReceiveStream::Stats GetStats() const override;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010064 void SetSink(AudioSinkInterface* sink) override;
solenberg217fb662016-06-17 08:30:54 -070065 void SetGain(float gain) override;
hbos8d609f62017-04-10 07:39:05 -070066 std::vector<webrtc::RtpSource> GetSources() const override;
Tommif888bb52015-12-12 01:37:01 +010067
nisse0f15f922017-06-21 01:05:22 -070068 // 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);
nisse657bab22017-02-21 06:28:10 -080073
solenberg3ebbcb52017-01-31 03:58:40 -080074 // 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
solenberg7602aab2016-11-14 11:30:07 -080086 void AssociateSendStream(AudioSendStream* send_stream);
pbos1ba8d392016-05-01 20:18:34 -070087 void SignalNetworkState(NetworkState state);
88 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbosa2f30de2015-10-15 05:22:13 -070089 const webrtc::AudioReceiveStream::Config& config() const;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010090 const AudioSendStream* GetAssociatedSendStreamForTesting() const;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020091
92 private:
Fredrik Solenberg3b903d02018-01-10 15:17:10 +010093 static void ConfigureStream(AudioReceiveStream* stream,
94 const Config& new_config,
95 bool first_time);
96
aleloi04c07222016-11-22 06:42:53 -080097 AudioState* audio_state() const;
solenberg7add0582015-11-20 09:59:34 -080098
solenberg3ebbcb52017-01-31 03:58:40 -080099 rtc::ThreadChecker worker_thread_checker_;
100 rtc::ThreadChecker module_process_thread_checker_;
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100101 webrtc::AudioReceiveStream::Config config_;
solenberg566ef242015-11-06 15:34:49 -0800102 rtc::scoped_refptr<webrtc::AudioState> audio_state_;
kwibergfffa42b2016-02-23 10:46:32 -0800103 std::unique_ptr<voe::ChannelProxy> channel_proxy_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100104 AudioSendStream* associated_send_stream_ = nullptr;
solenberg85a04962015-10-27 03:35:21 -0700105
danilchapa37de392017-09-09 04:17:22 -0700106 bool playing_ RTC_ACCESS_ON(worker_thread_checker_) = false;
aleloi04c07222016-11-22 06:42:53 -0800107
nisse0f15f922017-06-21 01:05:22 -0700108 std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_;
109
solenberg85a04962015-10-27 03:35:21 -0700110 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioReceiveStream);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200111};
112} // namespace internal
113} // namespace webrtc
114
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200115#endif // AUDIO_AUDIO_RECEIVE_STREAM_H_