blob: d964bd4b5e0ca80f0f14bb7750e3d70c6fd8daac [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
11#ifndef WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_
12#define WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_
13
aleloiaed581a2016-10-20 06:32:39 -070014#include "webrtc/api/audio/audio_mixer.h"
solenbergff976312016-03-30 23:28:51 -070015#include "webrtc/base/constructormagic.h"
aleloiaed581a2016-10-20 06:32:39 -070016#include "webrtc/base/race_checker.h"
solenberg358057b2015-11-27 10:46:42 -080017#include "webrtc/base/thread_checker.h"
ossu1ffbd6c2017-04-06 12:05:04 -070018#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
solenberg13725082015-11-25 08:16:52 -080019#include "webrtc/voice_engine/channel_manager.h"
solenberg358057b2015-11-27 10:46:42 -080020#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
solenberg13725082015-11-25 08:16:52 -080021
kwibergb7f89d62016-02-17 10:04:18 -080022#include <memory>
solenberg13725082015-11-25 08:16:52 -080023#include <string>
solenberg358057b2015-11-27 10:46:42 -080024#include <vector>
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;
ivoc14d5dbe2016-07-04 07:06:55 -070030class RtcEventLog;
stefan7de8d642017-02-07 07:14:08 -080031class RtcpBandwidthObserver;
michaelt9332b7d2016-11-30 07:51:13 -080032class RtcpRttStats;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010033class RtpPacketSender;
nisse657bab22017-02-21 06:28:10 -080034class RtpPacketReceived;
solenberg3ebbcb52017-01-31 03:58:40 -080035class RtpReceiver;
36class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070037class RtpTransportControllerSendInterface;
mflodman3d7db262016-04-29 00:57:13 -070038class Transport;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010039class TransportFeedbackObserver;
40
solenberg13725082015-11-25 08:16:52 -080041namespace voe {
42
solenberg358057b2015-11-27 10:46:42 -080043class Channel;
44
solenberg13725082015-11-25 08:16:52 -080045// This class provides the "view" of a voe::Channel that we need to implement
46// webrtc::AudioSendStream and webrtc::AudioReceiveStream. It serves two
47// purposes:
48// 1. Allow mocking just the interfaces used, instead of the entire
49// voe::Channel class.
50// 2. Provide a refined interface for the stream classes, including assumptions
51// on return values and input adaptation.
52class ChannelProxy {
53 public:
54 ChannelProxy();
55 explicit ChannelProxy(const ChannelOwner& channel_owner);
Tommif888bb52015-12-12 01:37:01 +010056 virtual ~ChannelProxy();
solenberg13725082015-11-25 08:16:52 -080057
ossu1ffbd6c2017-04-06 12:05:04 -070058 virtual bool SetEncoder(int payload_type,
59 std::unique_ptr<AudioEncoder> encoder);
60
solenberg13725082015-11-25 08:16:52 -080061 virtual void SetRTCPStatus(bool enable);
62 virtual void SetLocalSSRC(uint32_t ssrc);
63 virtual void SetRTCP_CNAME(const std::string& c_name);
solenberg971cab02016-06-14 10:02:41 -070064 virtual void SetNACKStatus(bool enable, int max_packets);
solenberg358057b2015-11-27 10:46:42 -080065 virtual void SetSendAudioLevelIndicationStatus(bool enable, int id);
solenberg358057b2015-11-27 10:46:42 -080066 virtual void SetReceiveAudioLevelIndicationStatus(bool enable, int id);
stefan3313ec92016-01-21 06:32:43 -080067 virtual void EnableSendTransportSequenceNumber(int id);
68 virtual void EnableReceiveTransportSequenceNumber(int id);
stefanbba9dec2016-02-01 04:39:55 -080069 virtual void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -070070 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -080071 RtcpBandwidthObserver* bandwidth_observer);
stefanbba9dec2016-02-01 04:39:55 -080072 virtual void RegisterReceiverCongestionControlObjects(
73 PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -070074 virtual void ResetSenderCongestionControlObjects();
75 virtual void ResetReceiverCongestionControlObjects();
solenberg358057b2015-11-27 10:46:42 -080076 virtual CallStatistics GetRTCPStatistics() const;
77 virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const;
78 virtual NetworkStatistics GetNetworkStatistics() const;
79 virtual AudioDecodingCallStats GetDecodingCallStatistics() const;
solenberg8d73f8c2017-03-08 01:52:20 -080080 virtual int GetSpeechOutputLevel() const;
81 virtual int GetSpeechOutputLevelFullRange() const;
solenberg358057b2015-11-27 10:46:42 -080082 virtual uint32_t GetDelayEstimate() const;
solenbergffbbcac2016-11-17 05:25:37 -080083 virtual bool SetSendTelephoneEventPayloadType(int payload_type,
84 int payload_frequency);
solenberg8842c3e2016-03-11 03:06:41 -080085 virtual bool SendTelephoneEventOutband(int event, int duration_ms);
minyue78b4d562016-11-30 04:47:39 -080086 virtual void SetBitrate(int bitrate_bps, int64_t probing_interval_ms);
kwibergd32bf752017-01-19 07:03:59 -080087 virtual void SetRecPayloadType(int payload_type,
88 const SdpAudioFormat& format);
kwiberg1c07c702017-03-27 07:15:49 -070089 virtual void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
kwibergb7f89d62016-02-17 10:04:18 -080090 virtual void SetSink(std::unique_ptr<AudioSinkInterface> sink);
solenberg94218532016-06-16 10:53:22 -070091 virtual void SetInputMute(bool muted);
mflodman3d7db262016-04-29 00:57:13 -070092 virtual void RegisterExternalTransport(Transport* transport);
93 virtual void DeRegisterExternalTransport();
nisse657bab22017-02-21 06:28:10 -080094 virtual void OnRtpPacket(const RtpPacketReceived& packet);
mflodman3d7db262016-04-29 00:57:13 -070095 virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length);
ossu29b1a8d2016-06-13 07:34:51 -070096 virtual const rtc::scoped_refptr<AudioDecoderFactory>&
solenberg217fb662016-06-17 08:30:54 -070097 GetAudioDecoderFactory() const;
solenberg217fb662016-06-17 08:30:54 -070098 virtual void SetChannelOutputVolumeScaling(float scaling);
ivoc14d5dbe2016-07-04 07:06:55 -070099 virtual void SetRtcEventLog(RtcEventLog* event_log);
minyue6b825df2016-10-31 04:08:32 -0700100 virtual void EnableAudioNetworkAdaptor(const std::string& config_string);
101 virtual void DisableAudioNetworkAdaptor();
102 virtual void SetReceiverFrameLengthRange(int min_frame_length_ms,
103 int max_frame_length_ms);
aleloi6c278492016-10-20 14:24:39 -0700104 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
105 int sample_rate_hz,
106 AudioFrame* audio_frame);
aleloi051f6782016-10-31 03:26:40 -0700107 virtual int NeededFrequency() const;
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;
117 virtual bool GetSendCodec(CodecInst* codec_inst) const;
118 virtual bool SetVADStatus(bool enable);
119 virtual bool SetCodecFECStatus(bool enable);
120 virtual bool SetOpusDtx(bool enable);
121 virtual bool SetOpusMaxPlaybackRate(int frequency_hz);
122 virtual bool SetSendCodec(const CodecInst& codec_inst);
123 virtual bool SetSendCNPayloadType(int type, PayloadFrequencies frequency);
elad.alond12a8e12017-03-23 11:04:48 -0700124 virtual void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
elad.alondadb4dc2017-03-23 15:29:50 -0700125 virtual void OnRecoverableUplinkPacketLossRate(
126 float recoverable_packet_loss_rate);
kwiberg1c07c702017-03-27 07:15:49 -0700127 virtual void RegisterLegacyReceiveCodecs();
michaelt9332b7d2016-11-30 07:51:13 -0800128
solenberg13725082015-11-25 08:16:52 -0800129 private:
solenberg358057b2015-11-27 10:46:42 -0800130 Channel* channel() const;
131
solenberg08b19df2017-02-15 00:42:31 -0800132 // Thread checkers document and lock usage of some methods on voe::Channel to
133 // specific threads we know about. The goal is to eventually split up
134 // voe::Channel into parts with single-threaded semantics, and thereby reduce
135 // the need for locks.
136 rtc::ThreadChecker worker_thread_checker_;
137 rtc::ThreadChecker module_process_thread_checker_;
138 // Methods accessed from audio and video threads are checked for sequential-
139 // only access. We don't necessarily own and control these threads, so thread
140 // checkers cannot be used. E.g. Chromium may transfer "ownership" from one
141 // audio thread to another, but access is still sequential.
142 rtc::RaceChecker audio_thread_race_checker_;
143 rtc::RaceChecker video_capture_thread_race_checker_;
solenberg13725082015-11-25 08:16:52 -0800144 ChannelOwner channel_owner_;
solenbergff976312016-03-30 23:28:51 -0700145
146 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelProxy);
solenberg13725082015-11-25 08:16:52 -0800147};
148} // namespace voe
149} // namespace webrtc
150
151#endif // WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_