blob: 7d0eed9cb215fb888a76047feb41cfd8913fa5b6 [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;
solenberg796b8f92017-03-01 17:02:23 -080064 int GetOutputLevel() const override;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010065 void SetSink(AudioSinkInterface* sink) override;
solenberg217fb662016-06-17 08:30:54 -070066 void SetGain(float gain) override;
hbos8d609f62017-04-10 07:39:05 -070067 std::vector<webrtc::RtpSource> GetSources() const override;
Tommif888bb52015-12-12 01:37:01 +010068
nisse0f15f922017-06-21 01:05:22 -070069 // TODO(nisse): We don't formally implement RtpPacketSinkInterface, and this
70 // method shouldn't be needed. But it's currently used by the
71 // AudioReceiveStreamTest.ReceiveRtpPacket unittest. Figure out if that test
72 // shuld be refactored or deleted, and then delete this method.
73 void OnRtpPacket(const RtpPacketReceived& packet);
nisse657bab22017-02-21 06:28:10 -080074
solenberg3ebbcb52017-01-31 03:58:40 -080075 // AudioMixer::Source
76 AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz,
77 AudioFrame* audio_frame) override;
78 int Ssrc() const override;
79 int PreferredSampleRate() const override;
80
81 // Syncable
82 int id() const override;
83 rtc::Optional<Syncable::Info> GetInfo() const override;
84 uint32_t GetPlayoutTimestamp() const override;
85 void SetMinimumPlayoutDelay(int delay_ms) override;
86
solenberg7602aab2016-11-14 11:30:07 -080087 void AssociateSendStream(AudioSendStream* send_stream);
pbos1ba8d392016-05-01 20:18:34 -070088 void SignalNetworkState(NetworkState state);
89 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbosa2f30de2015-10-15 05:22:13 -070090 const webrtc::AudioReceiveStream::Config& config() const;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010091 const AudioSendStream* GetAssociatedSendStreamForTesting() const;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020092
93 private:
Fredrik Solenberg3b903d02018-01-10 15:17:10 +010094 static void ConfigureStream(AudioReceiveStream* stream,
95 const Config& new_config,
96 bool first_time);
97
aleloi04c07222016-11-22 06:42:53 -080098 AudioState* audio_state() const;
solenberg7add0582015-11-20 09:59:34 -080099
solenberg3ebbcb52017-01-31 03:58:40 -0800100 rtc::ThreadChecker worker_thread_checker_;
101 rtc::ThreadChecker module_process_thread_checker_;
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100102 webrtc::AudioReceiveStream::Config config_;
solenberg566ef242015-11-06 15:34:49 -0800103 rtc::scoped_refptr<webrtc::AudioState> audio_state_;
kwibergfffa42b2016-02-23 10:46:32 -0800104 std::unique_ptr<voe::ChannelProxy> channel_proxy_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100105 AudioSendStream* associated_send_stream_ = nullptr;
solenberg85a04962015-10-27 03:35:21 -0700106
danilchapa37de392017-09-09 04:17:22 -0700107 bool playing_ RTC_ACCESS_ON(worker_thread_checker_) = false;
aleloi04c07222016-11-22 06:42:53 -0800108
nisse0f15f922017-06-21 01:05:22 -0700109 std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_;
110
solenberg85a04962015-10-27 03:35:21 -0700111 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioReceiveStream);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200112};
113} // namespace internal
114} // namespace webrtc
115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // AUDIO_AUDIO_RECEIVE_STREAM_H_