Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [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 | #include "audio/channel_receive_proxy.h" |
| 12 | |
| 13 | #include <utility> |
| 14 | |
| 15 | #include "api/call/audio_sink.h" |
| 16 | #include "audio/channel_send_proxy.h" |
| 17 | #include "call/rtp_transport_controller_send_interface.h" |
| 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/logging.h" |
| 20 | #include "rtc_base/numerics/safe_minmax.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | namespace voe { |
| 24 | ChannelReceiveProxy::ChannelReceiveProxy() {} |
| 25 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 26 | ChannelReceiveProxy::ChannelReceiveProxy( |
| 27 | std::unique_ptr<ChannelReceive> channel) |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame] | 28 | : channel_(std::move(channel)) { |
| 29 | RTC_DCHECK(channel_); |
| 30 | module_process_thread_checker_.DetachFromThread(); |
| 31 | } |
| 32 | |
| 33 | ChannelReceiveProxy::~ChannelReceiveProxy() {} |
| 34 | |
| 35 | void ChannelReceiveProxy::SetLocalSSRC(uint32_t ssrc) { |
| 36 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 37 | int error = channel_->SetLocalSSRC(ssrc); |
| 38 | RTC_DCHECK_EQ(0, error); |
| 39 | } |
| 40 | |
| 41 | void ChannelReceiveProxy::SetNACKStatus(bool enable, int max_packets) { |
| 42 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 43 | channel_->SetNACKStatus(enable, max_packets); |
| 44 | } |
| 45 | |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 46 | CallReceiveStatistics ChannelReceiveProxy::GetRTCPStatistics() const { |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame] | 47 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
Niels Möller | 530ead4 | 2018-10-04 14:28:39 +0200 | [diff] [blame] | 48 | CallReceiveStatistics stats = {0}; |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame] | 49 | int error = channel_->GetRTPStatistics(stats); |
| 50 | RTC_DCHECK_EQ(0, error); |
| 51 | return stats; |
| 52 | } |
| 53 | |
Niels Möller | b222f49 | 2018-10-03 16:50:08 +0200 | [diff] [blame] | 54 | bool ChannelReceiveProxy::ReceivedRTCPPacket(const uint8_t* packet, |
| 55 | size_t length) { |
| 56 | // May be called on either worker thread or network thread. |
| 57 | return channel_->ReceivedRTCPPacket(packet, length) == 0; |
| 58 | } |
| 59 | |
| 60 | void ChannelReceiveProxy::RegisterReceiverCongestionControlObjects( |
| 61 | PacketRouter* packet_router) { |
| 62 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 63 | channel_->RegisterReceiverCongestionControlObjects(packet_router); |
| 64 | } |
| 65 | |
| 66 | void ChannelReceiveProxy::ResetReceiverCongestionControlObjects() { |
| 67 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 68 | channel_->ResetReceiverCongestionControlObjects(); |
| 69 | } |
| 70 | |
| 71 | NetworkStatistics ChannelReceiveProxy::GetNetworkStatistics() const { |
| 72 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 73 | NetworkStatistics stats = {0}; |
| 74 | int error = channel_->GetNetworkStatistics(stats); |
| 75 | RTC_DCHECK_EQ(0, error); |
| 76 | return stats; |
| 77 | } |
| 78 | |
| 79 | AudioDecodingCallStats ChannelReceiveProxy::GetDecodingCallStatistics() const { |
| 80 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 81 | AudioDecodingCallStats stats; |
| 82 | channel_->GetDecodingCallStatistics(&stats); |
| 83 | return stats; |
| 84 | } |
| 85 | |
| 86 | int ChannelReceiveProxy::GetSpeechOutputLevelFullRange() const { |
| 87 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 88 | return channel_->GetSpeechOutputLevelFullRange(); |
| 89 | } |
| 90 | |
| 91 | double ChannelReceiveProxy::GetTotalOutputEnergy() const { |
| 92 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 93 | return channel_->GetTotalOutputEnergy(); |
| 94 | } |
| 95 | |
| 96 | double ChannelReceiveProxy::GetTotalOutputDuration() const { |
| 97 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 98 | return channel_->GetTotalOutputDuration(); |
| 99 | } |
| 100 | |
| 101 | uint32_t ChannelReceiveProxy::GetDelayEstimate() const { |
| 102 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() || |
| 103 | module_process_thread_checker_.CalledOnValidThread()); |
| 104 | return channel_->GetDelayEstimate(); |
| 105 | } |
| 106 | |
| 107 | void ChannelReceiveProxy::SetReceiveCodecs( |
| 108 | const std::map<int, SdpAudioFormat>& codecs) { |
| 109 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 110 | channel_->SetReceiveCodecs(codecs); |
| 111 | } |
| 112 | |
| 113 | void ChannelReceiveProxy::SetSink(AudioSinkInterface* sink) { |
| 114 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 115 | channel_->SetSink(sink); |
| 116 | } |
| 117 | |
| 118 | void ChannelReceiveProxy::OnRtpPacket(const RtpPacketReceived& packet) { |
| 119 | // May be called on either worker thread or network thread. |
| 120 | channel_->OnRtpPacket(packet); |
| 121 | } |
| 122 | |
| 123 | void ChannelReceiveProxy::SetChannelOutputVolumeScaling(float scaling) { |
| 124 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 125 | channel_->SetChannelOutputVolumeScaling(scaling); |
| 126 | } |
| 127 | |
| 128 | AudioMixer::Source::AudioFrameInfo ChannelReceiveProxy::GetAudioFrameWithInfo( |
| 129 | int sample_rate_hz, |
| 130 | AudioFrame* audio_frame) { |
| 131 | RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_); |
| 132 | return channel_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame); |
| 133 | } |
| 134 | |
| 135 | int ChannelReceiveProxy::PreferredSampleRate() const { |
| 136 | RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_); |
| 137 | return channel_->PreferredSampleRate(); |
| 138 | } |
| 139 | |
| 140 | void ChannelReceiveProxy::AssociateSendChannel( |
| 141 | const ChannelSendProxy& send_channel_proxy) { |
| 142 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 143 | channel_->SetAssociatedSendChannel(send_channel_proxy.GetChannel()); |
| 144 | } |
| 145 | |
| 146 | void ChannelReceiveProxy::DisassociateSendChannel() { |
| 147 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 148 | channel_->SetAssociatedSendChannel(nullptr); |
| 149 | } |
| 150 | |
| 151 | absl::optional<Syncable::Info> ChannelReceiveProxy::GetSyncInfo() const { |
| 152 | RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
| 153 | return channel_->GetSyncInfo(); |
| 154 | } |
| 155 | |
| 156 | uint32_t ChannelReceiveProxy::GetPlayoutTimestamp() const { |
| 157 | RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_); |
| 158 | unsigned int timestamp = 0; |
| 159 | int error = channel_->GetPlayoutTimestamp(timestamp); |
| 160 | RTC_DCHECK(!error || timestamp == 0); |
| 161 | return timestamp; |
| 162 | } |
| 163 | |
| 164 | void ChannelReceiveProxy::SetMinimumPlayoutDelay(int delay_ms) { |
| 165 | RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
| 166 | // Limit to range accepted by both VoE and ACM, so we're at least getting as |
| 167 | // close as possible, instead of failing. |
| 168 | delay_ms = rtc::SafeClamp(delay_ms, 0, 10000); |
| 169 | int error = channel_->SetMinimumPlayoutDelay(delay_ms); |
| 170 | if (0 != error) { |
| 171 | RTC_LOG(LS_WARNING) << "Error setting minimum playout delay."; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | bool ChannelReceiveProxy::GetRecCodec(CodecInst* codec_inst) const { |
| 176 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 177 | return channel_->GetRecCodec(*codec_inst) == 0; |
| 178 | } |
| 179 | |
| 180 | std::vector<RtpSource> ChannelReceiveProxy::GetSources() const { |
| 181 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 182 | return channel_->GetSources(); |
| 183 | } |
| 184 | |
| 185 | void ChannelReceiveProxy::StartPlayout() { |
| 186 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 187 | int error = channel_->StartPlayout(); |
| 188 | RTC_DCHECK_EQ(0, error); |
| 189 | } |
| 190 | |
| 191 | void ChannelReceiveProxy::StopPlayout() { |
| 192 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 193 | int error = channel_->StopPlayout(); |
| 194 | RTC_DCHECK_EQ(0, error); |
| 195 | } |
| 196 | } // namespace voe |
| 197 | } // namespace webrtc |