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_send_proxy.h" |
| 12 | |
| 13 | #include <utility> |
| 14 | |
| 15 | #include "api/call/audio_sink.h" |
| 16 | #include "call/rtp_transport_controller_send_interface.h" |
| 17 | #include "rtc_base/checks.h" |
| 18 | #include "rtc_base/logging.h" |
| 19 | #include "rtc_base/numerics/safe_minmax.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | namespace voe { |
| 23 | ChannelSendProxy::ChannelSendProxy() {} |
| 24 | |
| 25 | ChannelSendProxy::ChannelSendProxy(std::unique_ptr<Channel> channel) |
| 26 | : channel_(std::move(channel)) { |
| 27 | RTC_DCHECK(channel_); |
| 28 | module_process_thread_checker_.DetachFromThread(); |
| 29 | } |
| 30 | |
| 31 | ChannelSendProxy::~ChannelSendProxy() {} |
| 32 | |
| 33 | void ChannelSendProxy::SetLocalSSRC(uint32_t ssrc) { |
| 34 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 35 | int error = channel_->SetLocalSSRC(ssrc); |
| 36 | RTC_DCHECK_EQ(0, error); |
| 37 | } |
| 38 | |
| 39 | void ChannelSendProxy::SetNACKStatus(bool enable, int max_packets) { |
| 40 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 41 | channel_->SetNACKStatus(enable, max_packets); |
| 42 | } |
| 43 | |
| 44 | CallStatistics ChannelSendProxy::GetRTCPStatistics() const { |
| 45 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 46 | CallStatistics stats = {0}; |
| 47 | int error = channel_->GetRTPStatistics(stats); |
| 48 | RTC_DCHECK_EQ(0, error); |
| 49 | return stats; |
| 50 | } |
| 51 | |
| 52 | void ChannelSendProxy::RegisterTransport(Transport* transport) { |
| 53 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 54 | channel_->RegisterTransport(transport); |
| 55 | } |
| 56 | |
| 57 | bool ChannelSendProxy::ReceivedRTCPPacket(const uint8_t* packet, |
| 58 | size_t length) { |
| 59 | // May be called on either worker thread or network thread. |
| 60 | return channel_->ReceivedRTCPPacket(packet, length) == 0; |
| 61 | } |
| 62 | |
| 63 | bool ChannelSendProxy::SetEncoder(int payload_type, |
| 64 | std::unique_ptr<AudioEncoder> encoder) { |
| 65 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 66 | return channel_->SetEncoder(payload_type, std::move(encoder)); |
| 67 | } |
| 68 | |
| 69 | void ChannelSendProxy::ModifyEncoder( |
| 70 | rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) { |
| 71 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 72 | channel_->ModifyEncoder(modifier); |
| 73 | } |
| 74 | |
| 75 | void ChannelSendProxy::SetRTCPStatus(bool enable) { |
| 76 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 77 | channel_->SetRTCPStatus(enable); |
| 78 | } |
| 79 | |
| 80 | void ChannelSendProxy::SetMid(const std::string& mid, int extension_id) { |
| 81 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 82 | channel_->SetMid(mid, extension_id); |
| 83 | } |
| 84 | |
| 85 | void ChannelSendProxy::SetRTCP_CNAME(const std::string& c_name) { |
| 86 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 87 | // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array. |
| 88 | std::string c_name_limited = c_name.substr(0, 255); |
| 89 | int error = channel_->SetRTCP_CNAME(c_name_limited.c_str()); |
| 90 | RTC_DCHECK_EQ(0, error); |
| 91 | } |
| 92 | |
| 93 | void ChannelSendProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) { |
| 94 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 95 | int error = channel_->SetSendAudioLevelIndicationStatus(enable, id); |
| 96 | RTC_DCHECK_EQ(0, error); |
| 97 | } |
| 98 | |
| 99 | void ChannelSendProxy::EnableSendTransportSequenceNumber(int id) { |
| 100 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 101 | channel_->EnableSendTransportSequenceNumber(id); |
| 102 | } |
| 103 | |
| 104 | void ChannelSendProxy::RegisterSenderCongestionControlObjects( |
| 105 | RtpTransportControllerSendInterface* transport, |
| 106 | RtcpBandwidthObserver* bandwidth_observer) { |
| 107 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 108 | channel_->RegisterSenderCongestionControlObjects(transport, |
| 109 | bandwidth_observer); |
| 110 | } |
| 111 | |
| 112 | void ChannelSendProxy::ResetSenderCongestionControlObjects() { |
| 113 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 114 | channel_->ResetSenderCongestionControlObjects(); |
| 115 | } |
| 116 | |
| 117 | std::vector<ReportBlock> ChannelSendProxy::GetRemoteRTCPReportBlocks() const { |
| 118 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 119 | std::vector<webrtc::ReportBlock> blocks; |
| 120 | int error = channel_->GetRemoteRTCPReportBlocks(&blocks); |
| 121 | RTC_DCHECK_EQ(0, error); |
| 122 | return blocks; |
| 123 | } |
| 124 | |
| 125 | ANAStats ChannelSendProxy::GetANAStatistics() const { |
| 126 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 127 | return channel_->GetANAStatistics(); |
| 128 | } |
| 129 | |
| 130 | bool ChannelSendProxy::SetSendTelephoneEventPayloadType(int payload_type, |
| 131 | int payload_frequency) { |
| 132 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 133 | return channel_->SetSendTelephoneEventPayloadType(payload_type, |
| 134 | payload_frequency) == 0; |
| 135 | } |
| 136 | |
| 137 | bool ChannelSendProxy::SendTelephoneEventOutband(int event, int duration_ms) { |
| 138 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 139 | return channel_->SendTelephoneEventOutband(event, duration_ms) == 0; |
| 140 | } |
| 141 | |
| 142 | void ChannelSendProxy::SetBitrate(int bitrate_bps, |
| 143 | int64_t probing_interval_ms) { |
| 144 | // This method can be called on the worker thread, module process thread |
| 145 | // or on a TaskQueue via VideoSendStreamImpl::OnEncoderConfigurationChanged. |
| 146 | // TODO(solenberg): Figure out a good way to check this or enforce calling |
| 147 | // rules. |
| 148 | // RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() || |
| 149 | // module_process_thread_checker_.CalledOnValidThread()); |
| 150 | channel_->SetBitRate(bitrate_bps, probing_interval_ms); |
| 151 | } |
| 152 | |
| 153 | void ChannelSendProxy::SetInputMute(bool muted) { |
| 154 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 155 | channel_->SetInputMute(muted); |
| 156 | } |
| 157 | |
| 158 | void ChannelSendProxy::ProcessAndEncodeAudio( |
| 159 | std::unique_ptr<AudioFrame> audio_frame) { |
| 160 | RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_); |
| 161 | return channel_->ProcessAndEncodeAudio(std::move(audio_frame)); |
| 162 | } |
| 163 | |
| 164 | void ChannelSendProxy::SetTransportOverhead(int transport_overhead_per_packet) { |
| 165 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 166 | channel_->SetTransportOverhead(transport_overhead_per_packet); |
| 167 | } |
| 168 | |
| 169 | RtpRtcp* ChannelSendProxy::GetRtpRtcp() const { |
| 170 | RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
| 171 | return channel_->GetRtpRtcp(); |
| 172 | } |
| 173 | |
| 174 | void ChannelSendProxy::OnTwccBasedUplinkPacketLossRate(float packet_loss_rate) { |
| 175 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 176 | channel_->OnTwccBasedUplinkPacketLossRate(packet_loss_rate); |
| 177 | } |
| 178 | |
| 179 | void ChannelSendProxy::OnRecoverableUplinkPacketLossRate( |
| 180 | float recoverable_packet_loss_rate) { |
| 181 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 182 | channel_->OnRecoverableUplinkPacketLossRate(recoverable_packet_loss_rate); |
| 183 | } |
| 184 | |
| 185 | void ChannelSendProxy::StartSend() { |
| 186 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 187 | int error = channel_->StartSend(); |
| 188 | RTC_DCHECK_EQ(0, error); |
| 189 | } |
| 190 | |
| 191 | void ChannelSendProxy::StopSend() { |
| 192 | RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 193 | channel_->StopSend(); |
| 194 | } |
| 195 | |
| 196 | Channel* ChannelSendProxy::GetChannel() const { |
| 197 | return channel_.get(); |
| 198 | } |
| 199 | |
| 200 | } // namespace voe |
| 201 | } // namespace webrtc |