solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
aleloi | aed581a | 2016-10-20 06:32:39 -0700 | [diff] [blame] | 14 | #include "webrtc/api/audio/audio_mixer.h" |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 15 | #include "webrtc/api/audio_codecs/audio_encoder.h" |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 16 | #include "webrtc/api/rtpreceiverinterface.h" |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 17 | #include "webrtc/call/rtp_packet_sink_interface.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 18 | #include "webrtc/rtc_base/constructormagic.h" |
| 19 | #include "webrtc/rtc_base/race_checker.h" |
| 20 | #include "webrtc/rtc_base/thread_checker.h" |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 21 | #include "webrtc/voice_engine/channel_manager.h" |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 22 | #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 23 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 24 | #include <memory> |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 25 | #include <string> |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 26 | #include <vector> |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 29 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 30 | class AudioSinkInterface; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 31 | class PacketRouter; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 32 | class RtcEventLog; |
stefan | 7de8d64 | 2017-02-07 07:14:08 -0800 | [diff] [blame] | 33 | class RtcpBandwidthObserver; |
michaelt | 9332b7d | 2016-11-30 07:51:13 -0800 | [diff] [blame] | 34 | class RtcpRttStats; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 35 | class RtpPacketSender; |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 36 | class RtpPacketReceived; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 37 | class RtpReceiver; |
| 38 | class RtpRtcp; |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 39 | class RtpTransportControllerSendInterface; |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 40 | class Transport; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 41 | class TransportFeedbackObserver; |
| 42 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 43 | namespace voe { |
| 44 | |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 45 | class Channel; |
| 46 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 47 | // 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. |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 54 | class ChannelProxy : public RtpPacketSinkInterface { |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 55 | public: |
| 56 | ChannelProxy(); |
| 57 | explicit ChannelProxy(const ChannelOwner& channel_owner); |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 58 | virtual ~ChannelProxy(); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 59 | |
ossu | 1ffbd6c | 2017-04-06 12:05:04 -0700 | [diff] [blame] | 60 | virtual bool SetEncoder(int payload_type, |
| 61 | std::unique_ptr<AudioEncoder> encoder); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 62 | virtual void ModifyEncoder( |
| 63 | rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier); |
ossu | 1ffbd6c | 2017-04-06 12:05:04 -0700 | [diff] [blame] | 64 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 65 | virtual void SetRTCPStatus(bool enable); |
| 66 | virtual void SetLocalSSRC(uint32_t ssrc); |
| 67 | virtual void SetRTCP_CNAME(const std::string& c_name); |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 68 | virtual void SetNACKStatus(bool enable, int max_packets); |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 69 | virtual void SetSendAudioLevelIndicationStatus(bool enable, int id); |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 70 | virtual void SetReceiveAudioLevelIndicationStatus(bool enable, int id); |
stefan | 3313ec9 | 2016-01-21 06:32:43 -0800 | [diff] [blame] | 71 | virtual void EnableSendTransportSequenceNumber(int id); |
| 72 | virtual void EnableReceiveTransportSequenceNumber(int id); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 73 | virtual void RegisterSenderCongestionControlObjects( |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 74 | RtpTransportControllerSendInterface* transport, |
stefan | 7de8d64 | 2017-02-07 07:14:08 -0800 | [diff] [blame] | 75 | RtcpBandwidthObserver* bandwidth_observer); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 76 | virtual void RegisterReceiverCongestionControlObjects( |
| 77 | PacketRouter* packet_router); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 78 | virtual void ResetSenderCongestionControlObjects(); |
| 79 | virtual void ResetReceiverCongestionControlObjects(); |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 80 | virtual CallStatistics GetRTCPStatistics() const; |
| 81 | virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const; |
| 82 | virtual NetworkStatistics GetNetworkStatistics() const; |
| 83 | virtual AudioDecodingCallStats GetDecodingCallStatistics() const; |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 84 | virtual ANAStats GetANAStatistics() const; |
solenberg | 8d73f8c | 2017-03-08 01:52:20 -0800 | [diff] [blame] | 85 | virtual int GetSpeechOutputLevel() const; |
| 86 | virtual int GetSpeechOutputLevelFullRange() const; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 87 | // 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; |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 91 | virtual uint32_t GetDelayEstimate() const; |
solenberg | ffbbcac | 2016-11-17 05:25:37 -0800 | [diff] [blame] | 92 | virtual bool SetSendTelephoneEventPayloadType(int payload_type, |
| 93 | int payload_frequency); |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 94 | virtual bool SendTelephoneEventOutband(int event, int duration_ms); |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 95 | virtual void SetBitrate(int bitrate_bps, int64_t probing_interval_ms); |
kwiberg | d32bf75 | 2017-01-19 07:03:59 -0800 | [diff] [blame] | 96 | virtual void SetRecPayloadType(int payload_type, |
| 97 | const SdpAudioFormat& format); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 98 | virtual void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs); |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 99 | virtual void SetSink(std::unique_ptr<AudioSinkInterface> sink); |
solenberg | 9421853 | 2016-06-16 10:53:22 -0700 | [diff] [blame] | 100 | virtual void SetInputMute(bool muted); |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 101 | virtual void RegisterExternalTransport(Transport* transport); |
| 102 | virtual void DeRegisterExternalTransport(); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 103 | |
| 104 | // Implements RtpPacketSinkInterface |
| 105 | void OnRtpPacket(const RtpPacketReceived& packet) override; |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 106 | virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length); |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 107 | virtual const rtc::scoped_refptr<AudioDecoderFactory>& |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame] | 108 | GetAudioDecoderFactory() const; |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame] | 109 | virtual void SetChannelOutputVolumeScaling(float scaling); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 110 | virtual void SetRtcEventLog(RtcEventLog* event_log); |
aleloi | 6c27849 | 2016-10-20 14:24:39 -0700 | [diff] [blame] | 111 | virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( |
| 112 | int sample_rate_hz, |
| 113 | AudioFrame* audio_frame); |
aleloi | 051f678 | 2016-10-31 03:26:40 -0700 | [diff] [blame] | 114 | virtual int NeededFrequency() const; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 115 | virtual void SetTransportOverhead(int transport_overhead_per_packet); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 116 | virtual void AssociateSendChannel(const ChannelProxy& send_channel_proxy); |
| 117 | virtual void DisassociateSendChannel(); |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 118 | virtual void GetRtpRtcp(RtpRtcp** rtp_rtcp, |
| 119 | RtpReceiver** rtp_receiver) const; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 120 | virtual uint32_t GetPlayoutTimestamp() const; |
| 121 | virtual void SetMinimumPlayoutDelay(int delay_ms); |
michaelt | 9332b7d | 2016-11-30 07:51:13 -0800 | [diff] [blame] | 122 | virtual void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); |
solenberg | bd9a77f | 2017-02-06 12:53:57 -0800 | [diff] [blame] | 123 | virtual bool GetRecCodec(CodecInst* codec_inst) const; |
elad.alon | d12a8e1 | 2017-03-23 11:04:48 -0700 | [diff] [blame] | 124 | virtual void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate); |
elad.alon | dadb4dc | 2017-03-23 15:29:50 -0700 | [diff] [blame] | 125 | virtual void OnRecoverableUplinkPacketLossRate( |
| 126 | float recoverable_packet_loss_rate); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 127 | virtual void RegisterLegacyReceiveCodecs(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 128 | virtual std::vector<webrtc::RtpSource> GetSources() const; |
michaelt | 9332b7d | 2016-11-30 07:51:13 -0800 | [diff] [blame] | 129 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 130 | private: |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 131 | Channel* channel() const; |
| 132 | |
solenberg | 08b19df | 2017-02-15 00:42:31 -0800 | [diff] [blame] | 133 | // 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_; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 145 | ChannelOwner channel_owner_; |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 146 | |
| 147 | RTC_DISALLOW_COPY_AND_ASSIGN(ChannelProxy); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 148 | }; |
| 149 | } // namespace voe |
| 150 | } // namespace webrtc |
| 151 | |
| 152 | #endif // WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_ |