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 | |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 11 | #ifndef AUDIO_CHANNEL_RECEIVE_PROXY_H_ |
| 12 | #define AUDIO_CHANNEL_RECEIVE_PROXY_H_ |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 13 | |
Fredrik Solenberg | a8b7c7f | 2018-01-17 11:18:31 +0100 | [diff] [blame] | 14 | #include <map> |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 15 | #include <memory> |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/audio/audio_mixer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/rtpreceiverinterface.h" |
Fredrik Solenberg | a8b7c7f | 2018-01-17 11:18:31 +0100 | [diff] [blame] | 20 | #include "audio/channel.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 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" |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 27 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 28 | class AudioSinkInterface; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 29 | class PacketRouter; |
nisse | 657bab2 | 2017-02-21 06:28:10 -0800 | [diff] [blame] | 30 | class RtpPacketReceived; |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 31 | class Transport; |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 32 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 33 | namespace voe { |
| 34 | |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 35 | class ChannelSendProxy; |
| 36 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 37 | // This class provides the "view" of a voe::Channel that we need to implement |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 38 | // webrtc::AudioReceiveStream. It serves two purposes: |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 39 | // 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öller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 43 | class ChannelReceiveProxy : public RtpPacketSinkInterface { |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 44 | public: |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 45 | ChannelReceiveProxy(); |
| 46 | explicit ChannelReceiveProxy(std::unique_ptr<Channel> channel); |
| 47 | virtual ~ChannelReceiveProxy(); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 48 | |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 49 | // Shared with ChannelSendProxy |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 50 | virtual void SetLocalSSRC(uint32_t ssrc); |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 51 | virtual void SetNACKStatus(bool enable, int max_packets); |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 52 | virtual CallStatistics GetRTCPStatistics() const; |
| 53 | virtual void RegisterTransport(Transport* transport); |
| 54 | virtual bool ReceivedRTCPPacket(const uint8_t* packet, size_t length); |
| 55 | |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 56 | virtual void RegisterReceiverCongestionControlObjects( |
| 57 | PacketRouter* packet_router); |
nisse | fdbfdc9 | 2017-03-31 05:44:52 -0700 | [diff] [blame] | 58 | virtual void ResetReceiverCongestionControlObjects(); |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 59 | virtual NetworkStatistics GetNetworkStatistics() const; |
| 60 | virtual AudioDecodingCallStats GetDecodingCallStatistics() const; |
solenberg | 8d73f8c | 2017-03-08 01:52:20 -0800 | [diff] [blame] | 61 | virtual int GetSpeechOutputLevelFullRange() const; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 62 | // 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; |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 66 | virtual uint32_t GetDelayEstimate() const; |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 67 | virtual void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 68 | virtual void SetSink(AudioSinkInterface* sink); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 69 | |
| 70 | // Implements RtpPacketSinkInterface |
| 71 | void OnRtpPacket(const RtpPacketReceived& packet) override; |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 72 | |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame] | 73 | virtual void SetChannelOutputVolumeScaling(float scaling); |
aleloi | 6c27849 | 2016-10-20 14:24:39 -0700 | [diff] [blame] | 74 | virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo( |
| 75 | int sample_rate_hz, |
| 76 | AudioFrame* audio_frame); |
solenberg | 2397b9a | 2017-09-22 06:48:10 -0700 | [diff] [blame] | 77 | virtual int PreferredSampleRate() const; |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 78 | virtual void AssociateSendChannel(const ChannelSendProxy& send_channel_proxy); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 79 | virtual void DisassociateSendChannel(); |
Niels Möller | 848d6d3 | 2018-08-08 10:49:16 +0200 | [diff] [blame] | 80 | |
| 81 | // Produces the transport-related timestamps; current_delay_ms is left unset. |
| 82 | absl::optional<Syncable::Info> GetSyncInfo() const; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 83 | virtual uint32_t GetPlayoutTimestamp() const; |
| 84 | virtual void SetMinimumPlayoutDelay(int delay_ms); |
solenberg | bd9a77f | 2017-02-06 12:53:57 -0800 | [diff] [blame] | 85 | virtual bool GetRecCodec(CodecInst* codec_inst) const; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 86 | virtual std::vector<webrtc::RtpSource> GetSources() const; |
Fredrik Solenberg | d524751 | 2017-12-18 22:41:03 +0100 | [diff] [blame] | 87 | virtual void StartPlayout(); |
| 88 | virtual void StopPlayout(); |
michaelt | 9332b7d | 2016-11-30 07:51:13 -0800 | [diff] [blame] | 89 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 90 | private: |
solenberg | 08b19df | 2017-02-15 00:42:31 -0800 | [diff] [blame] | 91 | // 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 Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 103 | std::unique_ptr<Channel> channel_; |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 104 | |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 105 | RTC_DISALLOW_COPY_AND_ASSIGN(ChannelReceiveProxy); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 106 | }; |
| 107 | } // namespace voe |
| 108 | } // namespace webrtc |
| 109 | |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame^] | 110 | #endif // AUDIO_CHANNEL_RECEIVE_PROXY_H_ |