blob: 826117b9aa8300a273241d1018c75c7873378264 [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"
ossueb1fde42017-05-02 06:46:30 -070015#include "webrtc/api/audio_codecs/audio_encoder.h"
hbos8d609f62017-04-10 07:39:05 -070016#include "webrtc/api/rtpreceiverinterface.h"
nisse0f15f922017-06-21 01:05:22 -070017#include "webrtc/call/rtp_packet_sink_interface.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/rtc_base/constructormagic.h"
19#include "webrtc/rtc_base/race_checker.h"
20#include "webrtc/rtc_base/thread_checker.h"
solenberg13725082015-11-25 08:16:52 -080021#include "webrtc/voice_engine/channel_manager.h"
solenberg358057b2015-11-27 10:46:42 -080022#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
solenberg13725082015-11-25 08:16:52 -080023
kwibergb7f89d62016-02-17 10:04:18 -080024#include <memory>
solenberg13725082015-11-25 08:16:52 -080025#include <string>
solenberg358057b2015-11-27 10:46:42 -080026#include <vector>
solenberg13725082015-11-25 08:16:52 -080027
28namespace webrtc {
Stefan Holmerb86d4e42015-12-07 10:26:18 +010029
Tommif888bb52015-12-12 01:37:01 +010030class AudioSinkInterface;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010031class PacketRouter;
ivoc14d5dbe2016-07-04 07:06:55 -070032class RtcEventLog;
stefan7de8d642017-02-07 07:14:08 -080033class RtcpBandwidthObserver;
michaelt9332b7d2016-11-30 07:51:13 -080034class RtcpRttStats;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010035class RtpPacketSender;
nisse657bab22017-02-21 06:28:10 -080036class RtpPacketReceived;
solenberg3ebbcb52017-01-31 03:58:40 -080037class RtpReceiver;
38class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070039class RtpTransportControllerSendInterface;
mflodman3d7db262016-04-29 00:57:13 -070040class Transport;
Stefan Holmerb86d4e42015-12-07 10:26:18 +010041class TransportFeedbackObserver;
42
solenberg13725082015-11-25 08:16:52 -080043namespace voe {
44
solenberg358057b2015-11-27 10:46:42 -080045class Channel;
46
solenberg13725082015-11-25 08:16:52 -080047// This class provides the "view" of a voe::Channel that we need to implement
48// webrtc::AudioSendStream and webrtc::AudioReceiveStream. It serves two
49// purposes:
50// 1. Allow mocking just the interfaces used, instead of the entire
51// voe::Channel class.
52// 2. Provide a refined interface for the stream classes, including assumptions
53// on return values and input adaptation.
nisse0f15f922017-06-21 01:05:22 -070054class ChannelProxy : public RtpPacketSinkInterface {
solenberg13725082015-11-25 08:16:52 -080055 public:
56 ChannelProxy();
57 explicit ChannelProxy(const ChannelOwner& channel_owner);
Tommif888bb52015-12-12 01:37:01 +010058 virtual ~ChannelProxy();
solenberg13725082015-11-25 08:16:52 -080059
ossu1ffbd6c2017-04-06 12:05:04 -070060 virtual bool SetEncoder(int payload_type,
61 std::unique_ptr<AudioEncoder> encoder);
ossu20a4b3f2017-04-27 02:08:52 -070062 virtual void ModifyEncoder(
63 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier);
ossu1ffbd6c2017-04-06 12:05:04 -070064
solenberg13725082015-11-25 08:16:52 -080065 virtual void SetRTCPStatus(bool enable);
66 virtual void SetLocalSSRC(uint32_t ssrc);
67 virtual void SetRTCP_CNAME(const std::string& c_name);
solenberg971cab02016-06-14 10:02:41 -070068 virtual void SetNACKStatus(bool enable, int max_packets);
solenberg358057b2015-11-27 10:46:42 -080069 virtual void SetSendAudioLevelIndicationStatus(bool enable, int id);
solenberg358057b2015-11-27 10:46:42 -080070 virtual void SetReceiveAudioLevelIndicationStatus(bool enable, int id);
stefan3313ec92016-01-21 06:32:43 -080071 virtual void EnableSendTransportSequenceNumber(int id);
72 virtual void EnableReceiveTransportSequenceNumber(int id);
stefanbba9dec2016-02-01 04:39:55 -080073 virtual void RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -070074 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -080075 RtcpBandwidthObserver* bandwidth_observer);
stefanbba9dec2016-02-01 04:39:55 -080076 virtual void RegisterReceiverCongestionControlObjects(
77 PacketRouter* packet_router);
nissefdbfdc92017-03-31 05:44:52 -070078 virtual void ResetSenderCongestionControlObjects();
79 virtual void ResetReceiverCongestionControlObjects();
solenberg358057b2015-11-27 10:46:42 -080080 virtual CallStatistics GetRTCPStatistics() const;
81 virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const;
82 virtual NetworkStatistics GetNetworkStatistics() const;
83 virtual AudioDecodingCallStats GetDecodingCallStatistics() const;
ivoce1198e02017-09-08 08:13:19 -070084 virtual ANAStats GetANAStatistics() const;
solenberg8d73f8c2017-03-08 01:52:20 -080085 virtual int GetSpeechOutputLevel() const;
86 virtual int GetSpeechOutputLevelFullRange() const;
zsteine76bd3a2017-07-14 12:17:49 -070087 // See description of "totalAudioEnergy" in the WebRTC stats spec:
88 // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
89 virtual double GetTotalOutputEnergy() const;
90 virtual double GetTotalOutputDuration() const;
solenberg358057b2015-11-27 10:46:42 -080091 virtual uint32_t GetDelayEstimate() const;
solenbergffbbcac2016-11-17 05:25:37 -080092 virtual bool SetSendTelephoneEventPayloadType(int payload_type,
93 int payload_frequency);
solenberg8842c3e2016-03-11 03:06:41 -080094 virtual bool SendTelephoneEventOutband(int event, int duration_ms);
minyue78b4d562016-11-30 04:47:39 -080095 virtual void SetBitrate(int bitrate_bps, int64_t probing_interval_ms);
kwibergd32bf752017-01-19 07:03:59 -080096 virtual void SetRecPayloadType(int payload_type,
97 const SdpAudioFormat& format);
kwiberg1c07c702017-03-27 07:15:49 -070098 virtual void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
kwibergb7f89d62016-02-17 10:04:18 -080099 virtual void SetSink(std::unique_ptr<AudioSinkInterface> sink);
solenberg94218532016-06-16 10:53:22 -0700100 virtual void SetInputMute(bool muted);
mflodman3d7db262016-04-29 00:57:13 -0700101 virtual void RegisterExternalTransport(Transport* transport);
102 virtual void DeRegisterExternalTransport();
nisse0f15f922017-06-21 01:05:22 -0700103
104 // Implements RtpPacketSinkInterface
105 void OnRtpPacket(const RtpPacketReceived& packet) override;
mflodman3d7db262016-04-29 00:57:13 -0700106 virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length);
ossu29b1a8d2016-06-13 07:34:51 -0700107 virtual const rtc::scoped_refptr<AudioDecoderFactory>&
solenberg217fb662016-06-17 08:30:54 -0700108 GetAudioDecoderFactory() const;
solenberg217fb662016-06-17 08:30:54 -0700109 virtual void SetChannelOutputVolumeScaling(float scaling);
ivoc14d5dbe2016-07-04 07:06:55 -0700110 virtual void SetRtcEventLog(RtcEventLog* event_log);
aleloi6c278492016-10-20 14:24:39 -0700111 virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
112 int sample_rate_hz,
113 AudioFrame* audio_frame);
aleloi051f6782016-10-31 03:26:40 -0700114 virtual int NeededFrequency() const;
michaelt79e05882016-11-08 02:50:09 -0800115 virtual void SetTransportOverhead(int transport_overhead_per_packet);
solenberg7602aab2016-11-14 11:30:07 -0800116 virtual void AssociateSendChannel(const ChannelProxy& send_channel_proxy);
117 virtual void DisassociateSendChannel();
solenberg3ebbcb52017-01-31 03:58:40 -0800118 virtual void GetRtpRtcp(RtpRtcp** rtp_rtcp,
119 RtpReceiver** rtp_receiver) const;
solenberg3ebbcb52017-01-31 03:58:40 -0800120 virtual uint32_t GetPlayoutTimestamp() const;
121 virtual void SetMinimumPlayoutDelay(int delay_ms);
michaelt9332b7d2016-11-30 07:51:13 -0800122 virtual void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
solenbergbd9a77f2017-02-06 12:53:57 -0800123 virtual bool GetRecCodec(CodecInst* codec_inst) const;
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();
hbos8d609f62017-04-10 07:39:05 -0700128 virtual std::vector<webrtc::RtpSource> GetSources() const;
michaelt9332b7d2016-11-30 07:51:13 -0800129
solenberg13725082015-11-25 08:16:52 -0800130 private:
solenberg358057b2015-11-27 10:46:42 -0800131 Channel* channel() const;
132
solenberg08b19df2017-02-15 00:42:31 -0800133 // Thread checkers document and lock usage of some methods on voe::Channel to
134 // specific threads we know about. The goal is to eventually split up
135 // voe::Channel into parts with single-threaded semantics, and thereby reduce
136 // the need for locks.
137 rtc::ThreadChecker worker_thread_checker_;
138 rtc::ThreadChecker module_process_thread_checker_;
139 // Methods accessed from audio and video threads are checked for sequential-
140 // only access. We don't necessarily own and control these threads, so thread
141 // checkers cannot be used. E.g. Chromium may transfer "ownership" from one
142 // audio thread to another, but access is still sequential.
143 rtc::RaceChecker audio_thread_race_checker_;
144 rtc::RaceChecker video_capture_thread_race_checker_;
solenberg13725082015-11-25 08:16:52 -0800145 ChannelOwner channel_owner_;
solenbergff976312016-03-30 23:28:51 -0700146
147 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelProxy);
solenberg13725082015-11-25 08:16:52 -0800148};
149} // namespace voe
150} // namespace webrtc
151
152#endif // WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_