blob: a61c8963d248fd2f009ec83a104a342902c9c2e4 [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;
ivoc14d5dbe2016-07-04 07:06:55 -070027class RtcEventLog;
nisse657bab22017-02-21 06:28:10 -080028class RtpPacketReceived;
nisse0f15f922017-06-21 01:05:22 -070029class RtpStreamReceiverControllerInterface;
30class RtpStreamReceiverInterface;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020031
solenberg13725082015-11-25 08:16:52 -080032namespace voe {
33class ChannelProxy;
34} // namespace voe
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020035
solenberg13725082015-11-25 08:16:52 -080036namespace internal {
solenberg7602aab2016-11-14 11:30:07 -080037class AudioSendStream;
Tommif888bb52015-12-12 01:37:01 +010038
aleloiaed581a2016-10-20 06:32:39 -070039class AudioReceiveStream final : public webrtc::AudioReceiveStream,
solenberg3ebbcb52017-01-31 03:58:40 -080040 public AudioMixer::Source,
nisse0f15f922017-06-21 01:05:22 -070041 public Syncable {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020042 public:
nisse0f15f922017-06-21 01:05:22 -070043 AudioReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller,
44 PacketRouter* packet_router,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020045 const webrtc::AudioReceiveStream::Config& config,
ivoc14d5dbe2016-07-04 07:06:55 -070046 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
47 webrtc::RtcEventLog* event_log);
pbosa2f30de2015-10-15 05:22:13 -070048 ~AudioReceiveStream() override;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020049
pbos1ba8d392016-05-01 20:18:34 -070050 // webrtc::AudioReceiveStream implementation.
Jelena Marusiccd670222015-07-16 09:30:09 +020051 void Start() override;
52 void Stop() override;
Jelena Marusiccd670222015-07-16 09:30:09 +020053 webrtc::AudioReceiveStream::Stats GetStats() const override;
solenberg796b8f92017-03-01 17:02:23 -080054 int GetOutputLevel() const override;
kwibergfffa42b2016-02-23 10:46:32 -080055 void SetSink(std::unique_ptr<AudioSinkInterface> sink) override;
solenberg217fb662016-06-17 08:30:54 -070056 void SetGain(float gain) override;
hbos8d609f62017-04-10 07:39:05 -070057 std::vector<webrtc::RtpSource> GetSources() const override;
Tommif888bb52015-12-12 01:37:01 +010058
nisse0f15f922017-06-21 01:05:22 -070059 // 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);
nisse657bab22017-02-21 06:28:10 -080064
solenberg3ebbcb52017-01-31 03:58:40 -080065 // 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
solenberg7602aab2016-11-14 11:30:07 -080077 void AssociateSendStream(AudioSendStream* send_stream);
pbos1ba8d392016-05-01 20:18:34 -070078 void SignalNetworkState(NetworkState state);
79 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbosa2f30de2015-10-15 05:22:13 -070080 const webrtc::AudioReceiveStream::Config& config() const;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020081
82 private:
solenberg7add0582015-11-20 09:59:34 -080083 VoiceEngine* voice_engine() const;
aleloi04c07222016-11-22 06:42:53 -080084 AudioState* audio_state() const;
85 int SetVoiceEnginePlayout(bool playout);
solenberg7add0582015-11-20 09:59:34 -080086
solenberg3ebbcb52017-01-31 03:58:40 -080087 rtc::ThreadChecker worker_thread_checker_;
88 rtc::ThreadChecker module_process_thread_checker_;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020089 const webrtc::AudioReceiveStream::Config config_;
solenberg566ef242015-11-06 15:34:49 -080090 rtc::scoped_refptr<webrtc::AudioState> audio_state_;
kwibergfffa42b2016-02-23 10:46:32 -080091 std::unique_ptr<voe::ChannelProxy> channel_proxy_;
solenberg85a04962015-10-27 03:35:21 -070092
danilchapa37de392017-09-09 04:17:22 -070093 bool playing_ RTC_ACCESS_ON(worker_thread_checker_) = false;
aleloi04c07222016-11-22 06:42:53 -080094
nisse0f15f922017-06-21 01:05:22 -070095 std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_;
96
solenberg85a04962015-10-27 03:35:21 -070097 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioReceiveStream);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020098};
99} // namespace internal
100} // namespace webrtc
101
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200102#endif // AUDIO_AUDIO_RECEIVE_STREAM_H_