blob: 1d2c8ce0438b5537d5361ec60ff255789cdc1b29 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VOICE_ENGINE_CHANNEL_PROXY_H_
12#define VOICE_ENGINE_CHANNEL_PROXY_H_
solenberg13725082015-11-25 08:16:52 -080013
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010014#include <memory>
15#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio/audio_mixer.h"
19#include "api/audio_codecs/audio_encoder.h"
20#include "api/rtpreceiverinterface.h"
21#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"
solenbergdd3abbb2017-09-18 07:05:30 -070025#include "voice_engine/channel.h"
solenberg13725082015-11-25 08:16:52 -080026
27namespace webrtc {
Stefan Holmerb86d4e42015-12-07 10:26:18 +010028
Tommif888bb52015-12-12 01:37:01 +010029class AudioSinkInterface;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010030class PacketRouter;
ivoc14d5dbe2016-07-04 07:06:55 -070031class RtcEventLog;
stefan7de8d642017-02-07 07:14:08 -080032class RtcpBandwidthObserver;
michaelt9332b7d2016-11-30 07:51:13 -080033class RtcpRttStats;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010034class RtpPacketSender;
nisse657bab22017-02-21 06:28:10 -080035class RtpPacketReceived;
solenberg3ebbcb52017-01-31 03:58:40 -080036class RtpReceiver;
37class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070038class RtpTransportControllerSendInterface;
mflodman3d7db262016-04-29 00:57:13 -070039class Transport;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010040class TransportFeedbackObserver;
41
solenberg13725082015-11-25 08:16:52 -080042namespace voe {
43
44// This class provides the "view" of a voe::Channel that we need to implement
45// webrtc::AudioSendStream and webrtc::AudioReceiveStream. It serves two
46// purposes:
47// 1. Allow mocking just the interfaces used, instead of the entire
48// voe::Channel class.
49// 2. Provide a refined interface for the stream classes, including assumptions
50// on return values and input adaptation.
nisse0f15f922017-06-21 01:05:22 -070051class ChannelProxy : public RtpPacketSinkInterface {
solenberg13725082015-11-25 08:16:52 -080052 public:
53 ChannelProxy();
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010054 explicit ChannelProxy(std::unique_ptr<Channel> channel);
Tommif888bb52015-12-12 01:37:01 +010055 virtual ~ChannelProxy();
solenberg13725082015-11-25 08:16:52 -080056
ossu1ffbd6c2017-04-06 12:05:04 -070057 virtual bool SetEncoder(int payload_type,
58 std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -070059 virtual void ModifyEncoder(
60 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -070061
solenberg13725082015-11-25 08:16:52 -080062 virtual void SetRTCPStatus(bool enable);
63 virtual void SetLocalSSRC(uint32_t ssrc);
64 virtual void SetRTCP_CNAME(const std::string& c_name);
solenberg971cab02016-06-14 10:02:41 -070065 virtual void SetNACKStatus(bool enable, int max_packets);
solenberg358057b2015-11-27 10:46:42 -080066 virtual void SetSendAudioLevelIndicationStatus(bool enable, int id);
solenberg358057b2015-11-27 10:46:42 -080067 virtual void SetReceiveAudioLevelIndicationStatus(bool enable, int id);
stefan3313ec92016-01-21 06:32:43 -080068 virtual void EnableSendTransportSequenceNumber(int id);
69 virtual void EnableReceiveTransportSequenceNumber(int id);
stefanbba9dec2016-02-01 04:39:55 -080070 virtual void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -070071 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -080072 RtcpBandwidthObserver* bandwidth_observer);
stefanbba9dec2016-02-01 04:39:55 -080073 virtual void RegisterReceiverCongestionControlObjects(
74 PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -070075 virtual void ResetSenderCongestionControlObjects();
76 virtual void ResetReceiverCongestionControlObjects();
solenberg358057b2015-11-27 10:46:42 -080077 virtual CallStatistics GetRTCPStatistics() const;
78 virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const;
79 virtual NetworkStatistics GetNetworkStatistics() const;
80 virtual AudioDecodingCallStats GetDecodingCallStatistics() const;
ivoce1198e02017-09-08 08:13:19 -070081 virtual ANAStats GetANAStatistics() const;
solenberg8d73f8c2017-03-08 01:52:20 -080082 virtual int GetSpeechOutputLevel() const;
83 virtual int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -070084 // See description of "totalAudioEnergy" in the WebRTC stats spec:
85 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
86 virtual double GetTotalOutputEnergy() const;
87 virtual double GetTotalOutputDuration() const;
solenberg358057b2015-11-27 10:46:42 -080088 virtual uint32_t GetDelayEstimate() const;
solenbergffbbcac2016-11-17 05:25:37 -080089 virtual bool SetSendTelephoneEventPayloadType(int payload_type,
90 int payload_frequency);
solenberg8842c3e2016-03-11 03:06:41 -080091 virtual bool SendTelephoneEventOutband(int event, int duration_ms);
minyue78b4d562016-11-30 04:47:39 -080092 virtual void SetBitrate(int bitrate_bps, int64_t probing_interval_ms);
kwiberg1c07c702017-03-27 07:15:49 -070093 virtual void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010094 virtual void SetSink(AudioSinkInterface* sink);
solenberg94218532016-06-16 10:53:22 -070095 virtual void SetInputMute(bool muted);
solenberg1c239d42017-09-29 06:00:28 -070096 virtual void RegisterTransport(Transport* transport);
nisse0f15f922017-06-21 01:05:22 -070097
98 // Implements RtpPacketSinkInterface
99 void OnRtpPacket(const RtpPacketReceived& packet) override;
mflodman3d7db262016-04-29 00:57:13 -0700100 virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length);
solenberg217fb662016-06-17 08:30:54 -0700101 virtual void SetChannelOutputVolumeScaling(float scaling);
ivoc14d5dbe2016-07-04 07:06:55 -0700102 virtual void SetRtcEventLog(RtcEventLog* event_log);
aleloi6c278492016-10-20 14:24:39 -0700103 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
104 int sample_rate_hz,
105 AudioFrame* audio_frame);
solenberg2397b9a2017-09-22 06:48:10 -0700106 virtual int PreferredSampleRate() const;
Fredrik Solenberg2a877972017-12-15 16:42:15 +0100107 virtual void ProcessAndEncodeAudio(std::unique_ptr<AudioFrame> audio_frame);
michaelt79e05882016-11-08 02:50:09 -0800108 virtual void SetTransportOverhead(int transport_overhead_per_packet);
solenberg7602aab2016-11-14 11:30:07 -0800109 virtual void AssociateSendChannel(const ChannelProxy& send_channel_proxy);
110 virtual void DisassociateSendChannel();
solenberg3ebbcb52017-01-31 03:58:40 -0800111 virtual void GetRtpRtcp(RtpRtcp** rtp_rtcp,
112 RtpReceiver** rtp_receiver) const;
solenberg3ebbcb52017-01-31 03:58:40 -0800113 virtual uint32_t GetPlayoutTimestamp() const;
114 virtual void SetMinimumPlayoutDelay(int delay_ms);
michaelt9332b7d2016-11-30 07:51:13 -0800115 virtual void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
solenbergbd9a77f2017-02-06 12:53:57 -0800116 virtual bool GetRecCodec(CodecInst* codec_inst) const;
elad.alond12a8e12017-03-23 11:04:48 -0700117 virtual void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
elad.alondadb4dc2017-03-23 15:29:50 -0700118 virtual void OnRecoverableUplinkPacketLossRate(
119 float recoverable_packet_loss_rate);
hbos8d609f62017-04-10 07:39:05 -0700120 virtual std::vector<webrtc::RtpSource> GetSources() const;
Fredrik Solenbergaaedf752017-12-18 13:09:12 +0100121 virtual void StartSend();
122 virtual void StopSend();
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100123 virtual void StartPlayout();
124 virtual void StopPlayout();
michaelt9332b7d2016-11-30 07:51:13 -0800125
solenberg13725082015-11-25 08:16:52 -0800126 private:
solenberg08b19df2017-02-15 00:42:31 -0800127 // Thread checkers document and lock usage of some methods on voe::Channel to
128 // specific threads we know about. The goal is to eventually split up
129 // voe::Channel into parts with single-threaded semantics, and thereby reduce
130 // the need for locks.
131 rtc::ThreadChecker worker_thread_checker_;
132 rtc::ThreadChecker module_process_thread_checker_;
133 // Methods accessed from audio and video threads are checked for sequential-
134 // only access. We don't necessarily own and control these threads, so thread
135 // checkers cannot be used. E.g. Chromium may transfer "ownership" from one
136 // audio thread to another, but access is still sequential.
137 rtc::RaceChecker audio_thread_race_checker_;
138 rtc::RaceChecker video_capture_thread_race_checker_;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100139 std::unique_ptr<Channel> channel_;
solenbergff976312016-03-30 23:28:51 -0700140
141 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelProxy);
solenberg13725082015-11-25 08:16:52 -0800142};
143} // namespace voe
144} // namespace webrtc
145
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200146#endif // VOICE_ENGINE_CHANNEL_PROXY_H_