blob: 9426968bd6c91e956b6715cbcc897d85de6516a2 [file] [log] [blame]
solenberg13725082015-11-25 08:16:52 -08001/*
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
Niels Möllerb222f492018-10-03 16:50:08 +020011#ifndef AUDIO_CHANNEL_RECEIVE_PROXY_H_
12#define AUDIO_CHANNEL_RECEIVE_PROXY_H_
solenberg13725082015-11-25 08:16:52 -080013
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010014#include <map>
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010015#include <memory>
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010016#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio/audio_mixer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/rtpreceiverinterface.h"
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010020#include "audio/channel.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "call/rtp_packet_sink_interface.h"
22#include "rtc_base/constructormagic.h"
23#include "rtc_base/race_checker.h"
24#include "rtc_base/thread_checker.h"
solenberg13725082015-11-25 08:16:52 -080025
26namespace webrtc {
Stefan Holmerb86d4e42015-12-07 10:26:18 +010027
Tommif888bb52015-12-12 01:37:01 +010028class AudioSinkInterface;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010029class PacketRouter;
nisse657bab22017-02-21 06:28:10 -080030class RtpPacketReceived;
mflodman3d7db262016-04-29 00:57:13 -070031class Transport;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010032
solenberg13725082015-11-25 08:16:52 -080033namespace voe {
34
Niels Möllerb222f492018-10-03 16:50:08 +020035class ChannelSendProxy;
36
solenberg13725082015-11-25 08:16:52 -080037// This class provides the "view" of a voe::Channel that we need to implement
Niels Möllerb222f492018-10-03 16:50:08 +020038// webrtc::AudioReceiveStream. It serves two purposes:
solenberg13725082015-11-25 08:16:52 -080039// 1. Allow mocking just the interfaces used, instead of the entire
40// voe::Channel class.
41// 2. Provide a refined interface for the stream classes, including assumptions
42// on return values and input adaptation.
Niels Möllerb222f492018-10-03 16:50:08 +020043class ChannelReceiveProxy : public RtpPacketSinkInterface {
solenberg13725082015-11-25 08:16:52 -080044 public:
Niels Möllerb222f492018-10-03 16:50:08 +020045 ChannelReceiveProxy();
46 explicit ChannelReceiveProxy(std::unique_ptr<Channel> channel);
47 virtual ~ChannelReceiveProxy();
solenberg13725082015-11-25 08:16:52 -080048
Niels Möllerb222f492018-10-03 16:50:08 +020049 // Shared with ChannelSendProxy
solenberg13725082015-11-25 08:16:52 -080050 virtual void SetLocalSSRC(uint32_t ssrc);
solenberg971cab02016-06-14 10:02:41 -070051 virtual void SetNACKStatus(bool enable, int max_packets);
Niels Möllerb222f492018-10-03 16:50:08 +020052 virtual CallStatistics GetRTCPStatistics() const;
53 virtual void RegisterTransport(Transport* transport);
54 virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length);
55
stefanbba9dec2016-02-01 04:39:55 -080056 virtual void RegisterReceiverCongestionControlObjects(
57 PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -070058 virtual void ResetReceiverCongestionControlObjects();
solenberg358057b2015-11-27 10:46:42 -080059 virtual NetworkStatistics GetNetworkStatistics() const;
60 virtual AudioDecodingCallStats GetDecodingCallStatistics() const;
solenberg8d73f8c2017-03-08 01:52:20 -080061 virtual int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -070062 // See description of "totalAudioEnergy" in the WebRTC stats spec:
63 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
64 virtual double GetTotalOutputEnergy() const;
65 virtual double GetTotalOutputDuration() const;
solenberg358057b2015-11-27 10:46:42 -080066 virtual uint32_t GetDelayEstimate() const;
kwiberg1c07c702017-03-27 07:15:49 -070067 virtual void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010068 virtual void SetSink(AudioSinkInterface* sink);
nisse0f15f922017-06-21 01:05:22 -070069
70 // Implements RtpPacketSinkInterface
71 void OnRtpPacket(const RtpPacketReceived& packet) override;
Niels Möllerb222f492018-10-03 16:50:08 +020072
solenberg217fb662016-06-17 08:30:54 -070073 virtual void SetChannelOutputVolumeScaling(float scaling);
aleloi6c278492016-10-20 14:24:39 -070074 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
75 int sample_rate_hz,
76 AudioFrame* audio_frame);
solenberg2397b9a2017-09-22 06:48:10 -070077 virtual int PreferredSampleRate() const;
Niels Möllerb222f492018-10-03 16:50:08 +020078 virtual void AssociateSendChannel(const ChannelSendProxy& send_channel_proxy);
solenberg7602aab2016-11-14 11:30:07 -080079 virtual void DisassociateSendChannel();
Niels Möller848d6d32018-08-08 10:49:16 +020080
81 // Produces the transport-related timestamps; current_delay_ms is left unset.
82 absl::optional<Syncable::Info> GetSyncInfo() const;
solenberg3ebbcb52017-01-31 03:58:40 -080083 virtual uint32_t GetPlayoutTimestamp() const;
84 virtual void SetMinimumPlayoutDelay(int delay_ms);
solenbergbd9a77f2017-02-06 12:53:57 -080085 virtual bool GetRecCodec(CodecInst* codec_inst) const;
hbos8d609f62017-04-10 07:39:05 -070086 virtual std::vector<webrtc::RtpSource> GetSources() const;
Fredrik Solenbergd5247512017-12-18 22:41:03 +010087 virtual void StartPlayout();
88 virtual void StopPlayout();
michaelt9332b7d2016-11-30 07:51:13 -080089
solenberg13725082015-11-25 08:16:52 -080090 private:
solenberg08b19df2017-02-15 00:42:31 -080091 // Thread checkers document and lock usage of some methods on voe::Channel to
92 // specific threads we know about. The goal is to eventually split up
93 // voe::Channel into parts with single-threaded semantics, and thereby reduce
94 // the need for locks.
95 rtc::ThreadChecker worker_thread_checker_;
96 rtc::ThreadChecker module_process_thread_checker_;
97 // Methods accessed from audio and video threads are checked for sequential-
98 // only access. We don't necessarily own and control these threads, so thread
99 // checkers cannot be used. E.g. Chromium may transfer "ownership" from one
100 // audio thread to another, but access is still sequential.
101 rtc::RaceChecker audio_thread_race_checker_;
102 rtc::RaceChecker video_capture_thread_race_checker_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100103 std::unique_ptr<Channel> channel_;
solenbergff976312016-03-30 23:28:51 -0700104
Niels Möllerb222f492018-10-03 16:50:08 +0200105 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelReceiveProxy);
solenberg13725082015-11-25 08:16:52 -0800106};
107} // namespace voe
108} // namespace webrtc
109
Niels Möllerb222f492018-10-03 16:50:08 +0200110#endif // AUDIO_CHANNEL_RECEIVE_PROXY_H_