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 | #include "webrtc/voice_engine/channel_proxy.h" |
| 12 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 13 | #include <utility> |
| 14 | |
kjellander@webrtc.org | 7ffeab5 | 2016-02-26 22:46:09 +0100 | [diff] [blame] | 15 | #include "webrtc/audio_sink.h" |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
| 17 | #include "webrtc/voice_engine/channel.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | namespace voe { |
| 21 | ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {} |
| 22 | |
| 23 | ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) : |
| 24 | channel_owner_(channel_owner) { |
| 25 | RTC_CHECK(channel_owner_.channel()); |
| 26 | } |
| 27 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 28 | ChannelProxy::~ChannelProxy() {} |
| 29 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 30 | void ChannelProxy::SetRTCPStatus(bool enable) { |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 31 | channel()->SetRTCPStatus(enable); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void ChannelProxy::SetLocalSSRC(uint32_t ssrc) { |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 35 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 | int error = channel()->SetLocalSSRC(ssrc); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 37 | RTC_DCHECK_EQ(0, error); |
| 38 | } |
| 39 | |
| 40 | void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) { |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 41 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 42 | // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array. |
| 43 | std::string c_name_limited = c_name.substr(0, 255); |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 44 | int error = channel()->SetRTCP_CNAME(c_name_limited.c_str()); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 45 | RTC_DCHECK_EQ(0, error); |
| 46 | } |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 47 | |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 48 | void ChannelProxy::SetNACKStatus(bool enable, int max_packets) { |
| 49 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 | channel()->SetNACKStatus(enable, max_packets); |
| 51 | } |
| 52 | |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 53 | void ChannelProxy::SetSendAbsoluteSenderTimeStatus(bool enable, int id) { |
| 54 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 | int error = channel()->SetSendAbsoluteSenderTimeStatus(enable, id); |
| 56 | RTC_DCHECK_EQ(0, error); |
| 57 | } |
| 58 | |
| 59 | void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) { |
| 60 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 | int error = channel()->SetSendAudioLevelIndicationStatus(enable, id); |
| 62 | RTC_DCHECK_EQ(0, error); |
| 63 | } |
| 64 | |
| 65 | void ChannelProxy::SetReceiveAbsoluteSenderTimeStatus(bool enable, int id) { |
| 66 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 | int error = channel()->SetReceiveAbsoluteSenderTimeStatus(enable, id); |
| 68 | RTC_DCHECK_EQ(0, error); |
| 69 | } |
| 70 | |
| 71 | void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id) { |
| 72 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 73 | int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id); |
| 74 | RTC_DCHECK_EQ(0, error); |
| 75 | } |
| 76 | |
stefan | 3313ec9 | 2016-01-21 06:32:43 -0800 | [diff] [blame] | 77 | void ChannelProxy::EnableSendTransportSequenceNumber(int id) { |
| 78 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 79 | channel()->EnableSendTransportSequenceNumber(id); |
| 80 | } |
| 81 | |
| 82 | void ChannelProxy::EnableReceiveTransportSequenceNumber(int id) { |
| 83 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 | channel()->EnableReceiveTransportSequenceNumber(id); |
| 85 | } |
| 86 | |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 87 | void ChannelProxy::RegisterSenderCongestionControlObjects( |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 88 | RtpPacketSender* rtp_packet_sender, |
| 89 | TransportFeedbackObserver* transport_feedback_observer, |
| 90 | PacketRouter* packet_router) { |
| 91 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 92 | channel()->RegisterSenderCongestionControlObjects( |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 93 | rtp_packet_sender, transport_feedback_observer, packet_router); |
| 94 | } |
| 95 | |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 96 | void ChannelProxy::RegisterReceiverCongestionControlObjects( |
| 97 | PacketRouter* packet_router) { |
| 98 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 99 | channel()->RegisterReceiverCongestionControlObjects(packet_router); |
| 100 | } |
| 101 | |
| 102 | void ChannelProxy::ResetCongestionControlObjects() { |
| 103 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 104 | channel()->ResetCongestionControlObjects(); |
| 105 | } |
| 106 | |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 107 | CallStatistics ChannelProxy::GetRTCPStatistics() const { |
| 108 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 109 | CallStatistics stats = {0}; |
| 110 | int error = channel()->GetRTPStatistics(stats); |
| 111 | RTC_DCHECK_EQ(0, error); |
| 112 | return stats; |
| 113 | } |
| 114 | |
| 115 | std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const { |
| 116 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 117 | std::vector<webrtc::ReportBlock> blocks; |
| 118 | int error = channel()->GetRemoteRTCPReportBlocks(&blocks); |
| 119 | RTC_DCHECK_EQ(0, error); |
| 120 | return blocks; |
| 121 | } |
| 122 | |
| 123 | NetworkStatistics ChannelProxy::GetNetworkStatistics() const { |
| 124 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 125 | NetworkStatistics stats = {0}; |
| 126 | int error = channel()->GetNetworkStatistics(stats); |
| 127 | RTC_DCHECK_EQ(0, error); |
| 128 | return stats; |
| 129 | } |
| 130 | |
| 131 | AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const { |
| 132 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 133 | AudioDecodingCallStats stats; |
| 134 | channel()->GetDecodingCallStatistics(&stats); |
| 135 | return stats; |
| 136 | } |
| 137 | |
| 138 | int32_t ChannelProxy::GetSpeechOutputLevelFullRange() const { |
| 139 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 140 | uint32_t level = 0; |
| 141 | int error = channel()->GetSpeechOutputLevelFullRange(level); |
| 142 | RTC_DCHECK_EQ(0, error); |
| 143 | return static_cast<int32_t>(level); |
| 144 | } |
| 145 | |
| 146 | uint32_t ChannelProxy::GetDelayEstimate() const { |
| 147 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 148 | return channel()->GetDelayEstimate(); |
| 149 | } |
| 150 | |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 151 | bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type) { |
| 152 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 153 | return channel()->SetSendTelephoneEventPayloadType(payload_type) == 0; |
| 154 | } |
| 155 | |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 156 | bool ChannelProxy::SendTelephoneEventOutband(int event, int duration_ms) { |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 157 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 158 | return channel()->SendTelephoneEventOutband(event, duration_ms) == 0; |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 159 | } |
| 160 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 161 | void ChannelProxy::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 162 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
deadbeef | 2d110be | 2016-01-13 12:00:26 -0800 | [diff] [blame] | 163 | channel()->SetSink(std::move(sink)); |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 164 | } |
| 165 | |
solenberg | 9421853 | 2016-06-16 10:53:22 -0700 | [diff] [blame] | 166 | void ChannelProxy::SetInputMute(bool muted) { |
| 167 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 168 | int error = channel()->SetInputMute(muted); |
| 169 | RTC_DCHECK_EQ(0, error); |
| 170 | } |
| 171 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 172 | void ChannelProxy::RegisterExternalTransport(Transport* transport) { |
| 173 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 174 | int error = channel()->RegisterExternalTransport(transport); |
| 175 | RTC_DCHECK_EQ(0, error); |
| 176 | } |
| 177 | |
| 178 | void ChannelProxy::DeRegisterExternalTransport() { |
| 179 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 180 | channel()->DeRegisterExternalTransport(); |
| 181 | } |
| 182 | |
| 183 | bool ChannelProxy::ReceivedRTPPacket(const uint8_t* packet, |
| 184 | size_t length, |
| 185 | const PacketTime& packet_time) { |
| 186 | // May be called on either worker thread or network thread. |
| 187 | return channel()->ReceivedRTPPacket(packet, length, packet_time) == 0; |
| 188 | } |
| 189 | |
| 190 | bool ChannelProxy::ReceivedRTCPPacket(const uint8_t* packet, size_t length) { |
| 191 | // May be called on either worker thread or network thread. |
| 192 | return channel()->ReceivedRTCPPacket(packet, length) == 0; |
| 193 | } |
| 194 | |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 195 | const rtc::scoped_refptr<AudioDecoderFactory>& |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame^] | 196 | ChannelProxy::GetAudioDecoderFactory() const { |
| 197 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 198 | return channel()->GetAudioDecoderFactory(); |
| 199 | } |
| 200 | |
solenberg | 217fb66 | 2016-06-17 08:30:54 -0700 | [diff] [blame^] | 201 | void ChannelProxy::SetChannelOutputVolumeScaling(float scaling) { |
| 202 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 203 | int error = channel()->SetChannelOutputVolumeScaling(scaling); |
| 204 | RTC_DCHECK_EQ(0, error); |
| 205 | } |
| 206 | |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 207 | Channel* ChannelProxy::channel() const { |
| 208 | RTC_DCHECK(channel_owner_.channel()); |
| 209 | return channel_owner_.channel(); |
| 210 | } |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 211 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 212 | } // namespace voe |
| 213 | } // namespace webrtc |