niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
henrika@webrtc.org | 2919e95 | 2012-01-31 08:45:03 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/channel.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 13 | #include <algorithm> |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 14 | #include <utility> |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 15 | |
Ivo Creusen | ae856f2 | 2015-09-17 16:30:16 +0200 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 17 | #include "webrtc/base/format_macros.h" |
pbos | ad85622 | 2015-11-27 09:48:36 -0800 | [diff] [blame] | 18 | #include "webrtc/base/logging.h" |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 19 | #include "webrtc/base/thread_checker.h" |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 20 | #include "webrtc/base/timeutils.h" |
minyue@webrtc.org | e509f94 | 2013-09-12 17:03:00 +0000 | [diff] [blame] | 21 | #include "webrtc/common.h" |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 22 | #include "webrtc/config.h" |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 23 | #include "webrtc/modules/audio_device/include/audio_device.h" |
| 24 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 25 | #include "webrtc/modules/include/module_common_types.h" |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 26 | #include "webrtc/modules/pacing/packet_router.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 27 | #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
| 28 | #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 29 | #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 30 | #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 31 | #include "webrtc/modules/utility/include/audio_frame_operations.h" |
| 32 | #include "webrtc/modules/utility/include/process_thread.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 33 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 34 | #include "webrtc/system_wrappers/include/trace.h" |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 35 | #include "webrtc/voice_engine/include/voe_base.h" |
| 36 | #include "webrtc/voice_engine/include/voe_external_media.h" |
| 37 | #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
| 38 | #include "webrtc/voice_engine/output_mixer.h" |
| 39 | #include "webrtc/voice_engine/statistics.h" |
| 40 | #include "webrtc/voice_engine/transmit_mixer.h" |
| 41 | #include "webrtc/voice_engine/utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
| 43 | #if defined(_WIN32) |
| 44 | #include <Qos.h> |
| 45 | #endif |
| 46 | |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 47 | namespace webrtc { |
| 48 | namespace voe { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 50 | class TransportFeedbackProxy : public TransportFeedbackObserver { |
| 51 | public: |
| 52 | TransportFeedbackProxy() : feedback_observer_(nullptr) { |
| 53 | pacer_thread_.DetachFromThread(); |
| 54 | network_thread_.DetachFromThread(); |
| 55 | } |
| 56 | |
| 57 | void SetTransportFeedbackObserver( |
| 58 | TransportFeedbackObserver* feedback_observer) { |
| 59 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 60 | rtc::CritScope lock(&crit_); |
| 61 | feedback_observer_ = feedback_observer; |
| 62 | } |
| 63 | |
| 64 | // Implements TransportFeedbackObserver. |
| 65 | void AddPacket(uint16_t sequence_number, |
| 66 | size_t length, |
| 67 | bool was_paced) override { |
| 68 | RTC_DCHECK(pacer_thread_.CalledOnValidThread()); |
| 69 | rtc::CritScope lock(&crit_); |
| 70 | if (feedback_observer_) |
| 71 | feedback_observer_->AddPacket(sequence_number, length, was_paced); |
| 72 | } |
| 73 | void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override { |
| 74 | RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 75 | rtc::CritScope lock(&crit_); |
| 76 | if (feedback_observer_) |
| 77 | feedback_observer_->OnTransportFeedback(feedback); |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | rtc::CriticalSection crit_; |
| 82 | rtc::ThreadChecker thread_checker_; |
| 83 | rtc::ThreadChecker pacer_thread_; |
| 84 | rtc::ThreadChecker network_thread_; |
| 85 | TransportFeedbackObserver* feedback_observer_ GUARDED_BY(&crit_); |
| 86 | }; |
| 87 | |
| 88 | class TransportSequenceNumberProxy : public TransportSequenceNumberAllocator { |
| 89 | public: |
| 90 | TransportSequenceNumberProxy() : seq_num_allocator_(nullptr) { |
| 91 | pacer_thread_.DetachFromThread(); |
| 92 | } |
| 93 | |
| 94 | void SetSequenceNumberAllocator( |
| 95 | TransportSequenceNumberAllocator* seq_num_allocator) { |
| 96 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 | rtc::CritScope lock(&crit_); |
| 98 | seq_num_allocator_ = seq_num_allocator; |
| 99 | } |
| 100 | |
| 101 | // Implements TransportSequenceNumberAllocator. |
| 102 | uint16_t AllocateSequenceNumber() override { |
| 103 | RTC_DCHECK(pacer_thread_.CalledOnValidThread()); |
| 104 | rtc::CritScope lock(&crit_); |
| 105 | if (!seq_num_allocator_) |
| 106 | return 0; |
| 107 | return seq_num_allocator_->AllocateSequenceNumber(); |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | rtc::CriticalSection crit_; |
| 112 | rtc::ThreadChecker thread_checker_; |
| 113 | rtc::ThreadChecker pacer_thread_; |
| 114 | TransportSequenceNumberAllocator* seq_num_allocator_ GUARDED_BY(&crit_); |
| 115 | }; |
| 116 | |
| 117 | class RtpPacketSenderProxy : public RtpPacketSender { |
| 118 | public: |
| 119 | RtpPacketSenderProxy() : rtp_packet_sender_(nullptr) { |
| 120 | } |
| 121 | |
| 122 | void SetPacketSender(RtpPacketSender* rtp_packet_sender) { |
| 123 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 124 | rtc::CritScope lock(&crit_); |
| 125 | rtp_packet_sender_ = rtp_packet_sender; |
| 126 | } |
| 127 | |
| 128 | // Implements RtpPacketSender. |
| 129 | void InsertPacket(Priority priority, |
| 130 | uint32_t ssrc, |
| 131 | uint16_t sequence_number, |
| 132 | int64_t capture_time_ms, |
| 133 | size_t bytes, |
| 134 | bool retransmission) override { |
| 135 | rtc::CritScope lock(&crit_); |
| 136 | if (rtp_packet_sender_) { |
| 137 | rtp_packet_sender_->InsertPacket(priority, ssrc, sequence_number, |
| 138 | capture_time_ms, bytes, retransmission); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private: |
| 143 | rtc::ThreadChecker thread_checker_; |
| 144 | rtc::CriticalSection crit_; |
| 145 | RtpPacketSender* rtp_packet_sender_ GUARDED_BY(&crit_); |
| 146 | }; |
| 147 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 148 | // Extend the default RTCP statistics struct with max_jitter, defined as the |
| 149 | // maximum jitter value seen in an RTCP report block. |
| 150 | struct ChannelStatistics : public RtcpStatistics { |
| 151 | ChannelStatistics() : rtcp(), max_jitter(0) {} |
| 152 | |
| 153 | RtcpStatistics rtcp; |
| 154 | uint32_t max_jitter; |
| 155 | }; |
| 156 | |
| 157 | // Statistics callback, called at each generation of a new RTCP report block. |
| 158 | class StatisticsProxy : public RtcpStatisticsCallback { |
| 159 | public: |
| 160 | StatisticsProxy(uint32_t ssrc) |
| 161 | : stats_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
| 162 | ssrc_(ssrc) {} |
| 163 | virtual ~StatisticsProxy() {} |
| 164 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 165 | void StatisticsUpdated(const RtcpStatistics& statistics, |
| 166 | uint32_t ssrc) override { |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 167 | if (ssrc != ssrc_) |
| 168 | return; |
| 169 | |
| 170 | CriticalSectionScoped cs(stats_lock_.get()); |
| 171 | stats_.rtcp = statistics; |
| 172 | if (statistics.jitter > stats_.max_jitter) { |
| 173 | stats_.max_jitter = statistics.jitter; |
| 174 | } |
| 175 | } |
| 176 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 177 | void CNameChanged(const char* cname, uint32_t ssrc) override {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 178 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 179 | ChannelStatistics GetStats() { |
| 180 | CriticalSectionScoped cs(stats_lock_.get()); |
| 181 | return stats_; |
| 182 | } |
| 183 | |
| 184 | private: |
| 185 | // StatisticsUpdated calls are triggered from threads in the RTP module, |
| 186 | // while GetStats calls can be triggered from the public voice engine API, |
| 187 | // hence synchronization is needed. |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 188 | rtc::scoped_ptr<CriticalSectionWrapper> stats_lock_; |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 189 | const uint32_t ssrc_; |
| 190 | ChannelStatistics stats_; |
| 191 | }; |
| 192 | |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 193 | class VoERtcpObserver : public RtcpBandwidthObserver { |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 194 | public: |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 195 | explicit VoERtcpObserver(Channel* owner) : owner_(owner) {} |
| 196 | virtual ~VoERtcpObserver() {} |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 197 | |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 198 | void OnReceivedEstimatedBitrate(uint32_t bitrate) override { |
| 199 | // Not used for Voice Engine. |
| 200 | } |
| 201 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 202 | void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, |
| 203 | int64_t rtt, |
| 204 | int64_t now_ms) override { |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 205 | // TODO(mflodman): Do we need to aggregate reports here or can we jut send |
| 206 | // what we get? I.e. do we ever get multiple reports bundled into one RTCP |
| 207 | // report for VoiceEngine? |
| 208 | if (report_blocks.empty()) |
| 209 | return; |
| 210 | |
| 211 | int fraction_lost_aggregate = 0; |
| 212 | int total_number_of_packets = 0; |
| 213 | |
| 214 | // If receiving multiple report blocks, calculate the weighted average based |
| 215 | // on the number of packets a report refers to. |
| 216 | for (ReportBlockList::const_iterator block_it = report_blocks.begin(); |
| 217 | block_it != report_blocks.end(); ++block_it) { |
| 218 | // Find the previous extended high sequence number for this remote SSRC, |
| 219 | // to calculate the number of RTP packets this report refers to. Ignore if |
| 220 | // we haven't seen this SSRC before. |
| 221 | std::map<uint32_t, uint32_t>::iterator seq_num_it = |
| 222 | extended_max_sequence_number_.find(block_it->sourceSSRC); |
| 223 | int number_of_packets = 0; |
| 224 | if (seq_num_it != extended_max_sequence_number_.end()) { |
| 225 | number_of_packets = block_it->extendedHighSeqNum - seq_num_it->second; |
| 226 | } |
| 227 | fraction_lost_aggregate += number_of_packets * block_it->fractionLost; |
| 228 | total_number_of_packets += number_of_packets; |
| 229 | |
| 230 | extended_max_sequence_number_[block_it->sourceSSRC] = |
| 231 | block_it->extendedHighSeqNum; |
| 232 | } |
| 233 | int weighted_fraction_lost = 0; |
| 234 | if (total_number_of_packets > 0) { |
| 235 | weighted_fraction_lost = (fraction_lost_aggregate + |
| 236 | total_number_of_packets / 2) / total_number_of_packets; |
| 237 | } |
| 238 | owner_->OnIncomingFractionLoss(weighted_fraction_lost); |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | private: |
| 242 | Channel* owner_; |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 243 | // Maps remote side ssrc to extended highest sequence number received. |
| 244 | std::map<uint32_t, uint32_t> extended_max_sequence_number_; |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 247 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 248 | Channel::SendData(FrameType frameType, |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 249 | uint8_t payloadType, |
| 250 | uint32_t timeStamp, |
| 251 | const uint8_t* payloadData, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 252 | size_t payloadSize, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | const RTPFragmentationHeader* fragmentation) |
| 254 | { |
| 255 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 256 | "Channel::SendData(frameType=%u, payloadType=%u, timeStamp=%u," |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 257 | " payloadSize=%" PRIuS ", fragmentation=0x%x)", |
| 258 | frameType, payloadType, timeStamp, |
| 259 | payloadSize, fragmentation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 260 | |
| 261 | if (_includeAudioLevelIndication) |
| 262 | { |
| 263 | // Store current audio level in the RTP/RTCP module. |
| 264 | // The level will be used in combination with voice-activity state |
| 265 | // (frameType) to add an RTP header extension |
andrew@webrtc.org | 382c0c2 | 2014-05-05 18:22:21 +0000 | [diff] [blame] | 266 | _rtpRtcpModule->SetAudioLevel(rms_level_.RMS()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | // Push data from ACM to RTP/RTCP-module to deliver audio frame for |
| 270 | // packetization. |
| 271 | // This call will trigger Transport::SendPacket() from the RTP/RTCP module. |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 272 | if (_rtpRtcpModule->SendOutgoingData((FrameType&)frameType, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | payloadType, |
| 274 | timeStamp, |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 275 | // Leaving the time when this frame was |
| 276 | // received from the capture device as |
| 277 | // undefined for voice for now. |
| 278 | -1, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 279 | payloadData, |
| 280 | payloadSize, |
| 281 | fragmentation) == -1) |
| 282 | { |
| 283 | _engineStatisticsPtr->SetLastError( |
| 284 | VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
| 285 | "Channel::SendData() failed to send data to RTP/RTCP module"); |
| 286 | return -1; |
| 287 | } |
| 288 | |
| 289 | _lastLocalTimeStamp = timeStamp; |
| 290 | _lastPayloadType = payloadType; |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 295 | int32_t |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 296 | Channel::InFrameType(FrameType frame_type) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | { |
| 298 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 299 | "Channel::InFrameType(frame_type=%d)", frame_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 300 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 301 | CriticalSectionScoped cs(&_callbackCritSect); |
henrik.lundin@webrtc.org | e9217b4 | 2015-03-06 07:50:34 +0000 | [diff] [blame] | 302 | _sendFrameType = (frame_type == kAudioFrameSpeech); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 306 | int32_t |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 307 | Channel::OnRxVadDetected(int vadDecision) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 309 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | if (_rxVadObserverPtr) |
| 311 | { |
| 312 | _rxVadObserverPtr->OnRxVad(_channelId, vadDecision); |
| 313 | } |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 318 | bool Channel::SendRtp(const uint8_t* data, |
| 319 | size_t len, |
| 320 | const PacketOptions& options) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 321 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 322 | "Channel::SendPacket(channel=%d, len=%" PRIuS ")", len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 323 | |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 324 | CriticalSectionScoped cs(&_callbackCritSect); |
| 325 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 326 | if (_transportPtr == NULL) |
| 327 | { |
| 328 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,_channelId), |
| 329 | "Channel::SendPacket() failed to send RTP packet due to" |
| 330 | " invalid transport object"); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 331 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 332 | } |
| 333 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 334 | uint8_t* bufferToSendPtr = (uint8_t*)data; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 335 | size_t bufferLength = len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 336 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 337 | if (!_transportPtr->SendRtp(bufferToSendPtr, bufferLength, options)) { |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 338 | std::string transport_name = |
| 339 | _externalTransport ? "external transport" : "WebRtc sockets"; |
| 340 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 341 | VoEId(_instanceId,_channelId), |
| 342 | "Channel::SendPacket() RTP transmission using %s failed", |
| 343 | transport_name.c_str()); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 344 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 345 | } |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 346 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | } |
| 348 | |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 349 | bool |
| 350 | Channel::SendRtcp(const uint8_t *data, size_t len) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 352 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 353 | "Channel::SendRtcp(len=%" PRIuS ")", len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 355 | CriticalSectionScoped cs(&_callbackCritSect); |
| 356 | if (_transportPtr == NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 357 | { |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 358 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 359 | VoEId(_instanceId,_channelId), |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 360 | "Channel::SendRtcp() failed to send RTCP packet" |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 361 | " due to invalid transport object"); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 362 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 363 | } |
| 364 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 365 | uint8_t* bufferToSendPtr = (uint8_t*)data; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 366 | size_t bufferLength = len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 367 | |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 368 | int n = _transportPtr->SendRtcp(bufferToSendPtr, bufferLength); |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 369 | if (n < 0) { |
| 370 | std::string transport_name = |
| 371 | _externalTransport ? "external transport" : "WebRtc sockets"; |
| 372 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 373 | VoEId(_instanceId,_channelId), |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 374 | "Channel::SendRtcp() transmission using %s failed", |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 375 | transport_name.c_str()); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 376 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 377 | } |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 378 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 381 | void Channel::OnPlayTelephoneEvent(uint8_t event, |
| 382 | uint16_t lengthMs, |
| 383 | uint8_t volume) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 384 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 385 | "Channel::OnPlayTelephoneEvent(event=%u, lengthMs=%u," |
| 386 | " volume=%u)", event, lengthMs, volume); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 387 | |
| 388 | if (!_playOutbandDtmfEvent || (event > 15)) |
| 389 | { |
| 390 | // Ignore callback since feedback is disabled or event is not a |
| 391 | // Dtmf tone event. |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | assert(_outputMixerPtr != NULL); |
| 396 | |
| 397 | // Start playing out the Dtmf tone (if playout is enabled). |
| 398 | // Reduce length of tone with 80ms to the reduce risk of echo. |
| 399 | _outputMixerPtr->PlayDtmfTone(event, lengthMs - 80, volume); |
| 400 | } |
| 401 | |
| 402 | void |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 403 | Channel::OnIncomingSSRCChanged(uint32_t ssrc) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | { |
| 405 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 406 | "Channel::OnIncomingSSRCChanged(SSRC=%d)", ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 407 | |
dwkang@webrtc.org | b295a3f | 2013-08-29 07:34:12 +0000 | [diff] [blame] | 408 | // Update ssrc so that NTP for AV sync can be updated. |
| 409 | _rtpRtcpModule->SetRemoteSSRC(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 412 | void Channel::OnIncomingCSRCChanged(uint32_t CSRC, bool added) { |
| 413 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 414 | "Channel::OnIncomingCSRCChanged(CSRC=%d, added=%d)", CSRC, |
| 415 | added); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 418 | int32_t Channel::OnInitializeDecoder( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 419 | int8_t payloadType, |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 420 | const char payloadName[RTP_PAYLOAD_NAME_SIZE], |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 421 | int frequency, |
| 422 | uint8_t channels, |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 423 | uint32_t rate) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 424 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 425 | "Channel::OnInitializeDecoder(payloadType=%d, " |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 426 | "payloadName=%s, frequency=%u, channels=%u, rate=%u)", |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 427 | payloadType, payloadName, frequency, channels, rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 428 | |
henrika@webrtc.org | f75901f | 2012-01-16 08:45:42 +0000 | [diff] [blame] | 429 | CodecInst receiveCodec = {0}; |
| 430 | CodecInst dummyCodec = {0}; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 431 | |
| 432 | receiveCodec.pltype = payloadType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | receiveCodec.plfreq = frequency; |
| 434 | receiveCodec.channels = channels; |
| 435 | receiveCodec.rate = rate; |
henrika@webrtc.org | f75901f | 2012-01-16 08:45:42 +0000 | [diff] [blame] | 436 | strncpy(receiveCodec.plname, payloadName, RTP_PAYLOAD_NAME_SIZE - 1); |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 437 | |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 438 | audio_coding_->Codec(payloadName, &dummyCodec, frequency, channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | receiveCodec.pacsize = dummyCodec.pacsize; |
| 440 | |
| 441 | // Register the new codec to the ACM |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 442 | if (audio_coding_->RegisterReceiveCodec(receiveCodec) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 443 | { |
| 444 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
andrew@webrtc.org | ceb148c | 2011-08-23 17:53:54 +0000 | [diff] [blame] | 445 | VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 446 | "Channel::OnInitializeDecoder() invalid codec (" |
| 447 | "pt=%d, name=%s) received - 1", payloadType, payloadName); |
| 448 | _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR); |
| 449 | return -1; |
| 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 455 | int32_t |
| 456 | Channel::OnReceivedPayloadData(const uint8_t* payloadData, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 457 | size_t payloadSize, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 458 | const WebRtcRTPHeader* rtpHeader) |
| 459 | { |
| 460 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 461 | "Channel::OnReceivedPayloadData(payloadSize=%" PRIuS "," |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 462 | " payloadType=%u, audioChannel=%u)", |
| 463 | payloadSize, |
| 464 | rtpHeader->header.payloadType, |
| 465 | rtpHeader->type.Audio.channel); |
| 466 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 467 | if (!channel_state_.Get().playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 468 | { |
| 469 | // Avoid inserting into NetEQ when we are not playing. Count the |
| 470 | // packet as discarded. |
| 471 | WEBRTC_TRACE(kTraceStream, kTraceVoice, |
| 472 | VoEId(_instanceId, _channelId), |
| 473 | "received packet is discarded since playing is not" |
| 474 | " activated"); |
| 475 | _numberOfDiscardedPackets++; |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | // Push the incoming payload (parsed and ready for decoding) into the ACM |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 480 | if (audio_coding_->IncomingPacket(payloadData, |
| 481 | payloadSize, |
| 482 | *rtpHeader) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 483 | { |
| 484 | _engineStatisticsPtr->SetLastError( |
| 485 | VE_AUDIO_CODING_MODULE_ERROR, kTraceWarning, |
| 486 | "Channel::OnReceivedPayloadData() unable to push data to the ACM"); |
| 487 | return -1; |
| 488 | } |
| 489 | |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 490 | // Update the packet delay. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 491 | UpdatePacketDelay(rtpHeader->header.timestamp, |
| 492 | rtpHeader->header.sequenceNumber); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 493 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 494 | int64_t round_trip_time = 0; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 495 | _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, |
| 496 | NULL, NULL, NULL); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 497 | |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 498 | std::vector<uint16_t> nack_list = audio_coding_->GetNackList( |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 499 | round_trip_time); |
| 500 | if (!nack_list.empty()) { |
| 501 | // Can't use nack_list.data() since it's not supported by all |
| 502 | // compilers. |
| 503 | ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size())); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 504 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 508 | bool Channel::OnRecoveredPacket(const uint8_t* rtp_packet, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 509 | size_t rtp_packet_length) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 510 | RTPHeader header; |
| 511 | if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { |
| 512 | WEBRTC_TRACE(kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 513 | "IncomingPacket invalid RTP header"); |
| 514 | return false; |
| 515 | } |
| 516 | header.payload_type_frequency = |
| 517 | rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); |
| 518 | if (header.payload_type_frequency < 0) |
| 519 | return false; |
| 520 | return ReceivePacket(rtp_packet, rtp_packet_length, header, false); |
| 521 | } |
| 522 | |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 523 | int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 524 | { |
Ivo Creusen | ae856f2 | 2015-09-17 16:30:16 +0200 | [diff] [blame] | 525 | if (event_log_) { |
| 526 | unsigned int ssrc; |
| 527 | RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); |
| 528 | event_log_->LogAudioPlayout(ssrc); |
| 529 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 530 | // Get 10ms raw PCM data from the ACM (mixer limits output frequency) |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 531 | if (audio_coding_->PlayoutData10Ms(audioFrame->sample_rate_hz_, |
| 532 | audioFrame) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 533 | { |
| 534 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 535 | VoEId(_instanceId,_channelId), |
| 536 | "Channel::GetAudioFrame() PlayoutData10Ms() failed!"); |
andrew@webrtc.org | 7859e10 | 2012-01-13 00:30:11 +0000 | [diff] [blame] | 537 | // In all likelihood, the audio in this frame is garbage. We return an |
| 538 | // error so that the audio mixer module doesn't add it to the mix. As |
| 539 | // a result, it won't be played out and the actions skipped here are |
| 540 | // irrelevant. |
| 541 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if (_RxVadDetection) |
| 545 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 546 | UpdateRxVadDetection(*audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | // Convert module ID to internal VoE channel ID |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 550 | audioFrame->id_ = VoEChannelId(audioFrame->id_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 551 | // Store speech type for dead-or-alive detection |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 552 | _outputSpeechType = audioFrame->speech_type_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 553 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 554 | ChannelState::State state = channel_state_.Get(); |
| 555 | |
| 556 | if (state.rx_apm_is_enabled) { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 557 | int err = rx_audioproc_->ProcessStream(audioFrame); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 558 | if (err) { |
| 559 | LOG(LS_ERROR) << "ProcessStream() error: " << err; |
| 560 | assert(false); |
| 561 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 564 | { |
| 565 | // Pass the audio buffers to an optional sink callback, before applying |
| 566 | // scaling/panning, as that applies to the mix operation. |
| 567 | // External recipients of the audio (e.g. via AudioTrack), will do their |
| 568 | // own mixing/dynamic processing. |
| 569 | CriticalSectionScoped cs(&_callbackCritSect); |
| 570 | if (audio_sink_) { |
| 571 | AudioSinkInterface::Data data( |
| 572 | &audioFrame->data_[0], |
| 573 | audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_, |
| 574 | audioFrame->num_channels_, audioFrame->timestamp_); |
| 575 | audio_sink_->OnData(data); |
| 576 | } |
| 577 | } |
| 578 | |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 579 | float output_gain = 1.0f; |
| 580 | float left_pan = 1.0f; |
| 581 | float right_pan = 1.0f; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 582 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 583 | CriticalSectionScoped cs(&volume_settings_critsect_); |
| 584 | output_gain = _outputGain; |
| 585 | left_pan = _panLeft; |
| 586 | right_pan= _panRight; |
| 587 | } |
| 588 | |
| 589 | // Output volume scaling |
| 590 | if (output_gain < 0.99f || output_gain > 1.01f) |
| 591 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 592 | AudioFrameOperations::ScaleWithSat(output_gain, *audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | // Scale left and/or right channel(s) if stereo and master balance is |
| 596 | // active |
| 597 | |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 598 | if (left_pan != 1.0f || right_pan != 1.0f) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 599 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 600 | if (audioFrame->num_channels_ == 1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 601 | { |
| 602 | // Emulate stereo mode since panning is active. |
| 603 | // The mono signal is copied to both left and right channels here. |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 604 | AudioFrameOperations::MonoToStereo(audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 605 | } |
| 606 | // For true stereo mode (when we are receiving a stereo signal), no |
| 607 | // action is needed. |
| 608 | |
| 609 | // Do the panning operation (the audio frame contains stereo at this |
| 610 | // stage) |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 611 | AudioFrameOperations::Scale(left_pan, right_pan, *audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // Mix decoded PCM output with file if file mixing is enabled |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 615 | if (state.output_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 616 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 617 | MixAudioWithFile(*audioFrame, audioFrame->sample_rate_hz_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 618 | } |
| 619 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 620 | // External media |
| 621 | if (_outputExternalMedia) |
| 622 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 623 | CriticalSectionScoped cs(&_callbackCritSect); |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 624 | const bool isStereo = (audioFrame->num_channels_ == 2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 625 | if (_outputExternalMediaCallbackPtr) |
| 626 | { |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 627 | _outputExternalMediaCallbackPtr->Process( |
| 628 | _channelId, kPlaybackPerChannel, (int16_t*)audioFrame->data_, |
| 629 | audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_, |
| 630 | isStereo); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
| 634 | // Record playout if enabled |
| 635 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 636 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 637 | |
| 638 | if (_outputFileRecording && _outputFileRecorderPtr) |
| 639 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 640 | _outputFileRecorderPtr->RecordAudioToFile(*audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | // Measure audio level (0-9) |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 645 | _outputAudioLevel.ComputeLevel(*audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 646 | |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 647 | if (capture_start_rtp_time_stamp_ < 0 && audioFrame->timestamp_ != 0) { |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 648 | // The first frame with a valid rtp timestamp. |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 649 | capture_start_rtp_time_stamp_ = audioFrame->timestamp_; |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | if (capture_start_rtp_time_stamp_ >= 0) { |
| 653 | // audioFrame.timestamp_ should be valid from now on. |
| 654 | |
| 655 | // Compute elapsed time. |
| 656 | int64_t unwrap_timestamp = |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 657 | rtp_ts_wraparound_handler_->Unwrap(audioFrame->timestamp_); |
| 658 | audioFrame->elapsed_time_ms_ = |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 659 | (unwrap_timestamp - capture_start_rtp_time_stamp_) / |
| 660 | (GetPlayoutFrequency() / 1000); |
| 661 | |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 662 | { |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 663 | CriticalSectionScoped lock(ts_stats_lock_.get()); |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 664 | // Compute ntp time. |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 665 | audioFrame->ntp_time_ms_ = ntp_estimator_.Estimate( |
| 666 | audioFrame->timestamp_); |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 667 | // |ntp_time_ms_| won't be valid until at least 2 RTCP SRs are received. |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 668 | if (audioFrame->ntp_time_ms_ > 0) { |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 669 | // Compute |capture_start_ntp_time_ms_| so that |
| 670 | // |capture_start_ntp_time_ms_| + |elapsed_time_ms_| == |ntp_time_ms_| |
| 671 | capture_start_ntp_time_ms_ = |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 672 | audioFrame->ntp_time_ms_ - audioFrame->elapsed_time_ms_; |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 673 | } |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 680 | int32_t |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 681 | Channel::NeededFrequency(int32_t id) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 682 | { |
| 683 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 684 | "Channel::NeededFrequency(id=%d)", id); |
| 685 | |
| 686 | int highestNeeded = 0; |
| 687 | |
| 688 | // Determine highest needed receive frequency |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 689 | int32_t receiveFrequency = audio_coding_->ReceiveFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 690 | |
| 691 | // Return the bigger of playout and receive frequency in the ACM. |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 692 | if (audio_coding_->PlayoutFrequency() > receiveFrequency) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 693 | { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 694 | highestNeeded = audio_coding_->PlayoutFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 695 | } |
| 696 | else |
| 697 | { |
| 698 | highestNeeded = receiveFrequency; |
| 699 | } |
| 700 | |
| 701 | // Special case, if we're playing a file on the playout side |
| 702 | // we take that frequency into consideration as well |
| 703 | // This is not needed on sending side, since the codec will |
| 704 | // limit the spectrum anyway. |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 705 | if (channel_state_.Get().output_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 706 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 707 | CriticalSectionScoped cs(&_fileCritSect); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 708 | if (_outputFilePlayerPtr) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 709 | { |
| 710 | if(_outputFilePlayerPtr->Frequency()>highestNeeded) |
| 711 | { |
| 712 | highestNeeded=_outputFilePlayerPtr->Frequency(); |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | return(highestNeeded); |
| 718 | } |
| 719 | |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 720 | int32_t Channel::CreateChannel(Channel*& channel, |
| 721 | int32_t channelId, |
| 722 | uint32_t instanceId, |
| 723 | RtcEventLog* const event_log, |
| 724 | const Config& config) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 725 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId,channelId), |
| 726 | "Channel::CreateChannel(channelId=%d, instanceId=%d)", |
| 727 | channelId, instanceId); |
| 728 | |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 729 | channel = new Channel(channelId, instanceId, event_log, config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 730 | if (channel == NULL) |
| 731 | { |
| 732 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, |
| 733 | VoEId(instanceId,channelId), |
| 734 | "Channel::CreateChannel() unable to allocate memory for" |
| 735 | " channel"); |
| 736 | return -1; |
| 737 | } |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | void |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 742 | Channel::PlayNotification(int32_t id, uint32_t durationMs) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 743 | { |
| 744 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 745 | "Channel::PlayNotification(id=%d, durationMs=%d)", |
| 746 | id, durationMs); |
| 747 | |
| 748 | // Not implement yet |
| 749 | } |
| 750 | |
| 751 | void |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 752 | Channel::RecordNotification(int32_t id, uint32_t durationMs) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 753 | { |
| 754 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 755 | "Channel::RecordNotification(id=%d, durationMs=%d)", |
| 756 | id, durationMs); |
| 757 | |
| 758 | // Not implement yet |
| 759 | } |
| 760 | |
| 761 | void |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 762 | Channel::PlayFileEnded(int32_t id) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 763 | { |
| 764 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 765 | "Channel::PlayFileEnded(id=%d)", id); |
| 766 | |
| 767 | if (id == _inputFilePlayerId) |
| 768 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 769 | channel_state_.SetInputFilePlaying(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 770 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 771 | VoEId(_instanceId,_channelId), |
| 772 | "Channel::PlayFileEnded() => input file player module is" |
| 773 | " shutdown"); |
| 774 | } |
| 775 | else if (id == _outputFilePlayerId) |
| 776 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 777 | channel_state_.SetOutputFilePlaying(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 778 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 779 | VoEId(_instanceId,_channelId), |
| 780 | "Channel::PlayFileEnded() => output file player module is" |
| 781 | " shutdown"); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | void |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 786 | Channel::RecordFileEnded(int32_t id) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 787 | { |
| 788 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 789 | "Channel::RecordFileEnded(id=%d)", id); |
| 790 | |
| 791 | assert(id == _outputFileRecorderId); |
| 792 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 793 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 794 | |
| 795 | _outputFileRecording = false; |
| 796 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, |
| 797 | VoEId(_instanceId,_channelId), |
| 798 | "Channel::RecordFileEnded() => output file recorder module is" |
| 799 | " shutdown"); |
| 800 | } |
| 801 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 802 | Channel::Channel(int32_t channelId, |
minyue@webrtc.org | e509f94 | 2013-09-12 17:03:00 +0000 | [diff] [blame] | 803 | uint32_t instanceId, |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 804 | RtcEventLog* const event_log, |
| 805 | const Config& config) |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 806 | : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()), |
| 807 | _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), |
| 808 | volume_settings_critsect_( |
| 809 | *CriticalSectionWrapper::CreateCriticalSection()), |
| 810 | _instanceId(instanceId), |
| 811 | _channelId(channelId), |
| 812 | event_log_(event_log), |
| 813 | rtp_header_parser_(RtpHeaderParser::Create()), |
| 814 | rtp_payload_registry_( |
| 815 | new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), |
| 816 | rtp_receive_statistics_( |
| 817 | ReceiveStatistics::Create(Clock::GetRealTimeClock())), |
| 818 | rtp_receiver_( |
| 819 | RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), |
| 820 | this, |
| 821 | this, |
| 822 | this, |
| 823 | rtp_payload_registry_.get())), |
| 824 | telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), |
| 825 | _outputAudioLevel(), |
| 826 | _externalTransport(false), |
| 827 | _inputFilePlayerPtr(NULL), |
| 828 | _outputFilePlayerPtr(NULL), |
| 829 | _outputFileRecorderPtr(NULL), |
| 830 | // Avoid conflict with other channels by adding 1024 - 1026, |
| 831 | // won't use as much as 1024 channels. |
| 832 | _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024), |
| 833 | _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025), |
| 834 | _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026), |
| 835 | _outputFileRecording(false), |
| 836 | _inbandDtmfQueue(VoEModuleId(instanceId, channelId)), |
| 837 | _inbandDtmfGenerator(VoEModuleId(instanceId, channelId)), |
| 838 | _outputExternalMedia(false), |
| 839 | _inputExternalMediaCallbackPtr(NULL), |
| 840 | _outputExternalMediaCallbackPtr(NULL), |
| 841 | _timeStamp(0), // This is just an offset, RTP module will add it's own |
| 842 | // random offset |
| 843 | _sendTelephoneEventPayloadType(106), |
| 844 | ntp_estimator_(Clock::GetRealTimeClock()), |
| 845 | jitter_buffer_playout_timestamp_(0), |
| 846 | playout_timestamp_rtp_(0), |
| 847 | playout_timestamp_rtcp_(0), |
| 848 | playout_delay_ms_(0), |
| 849 | _numberOfDiscardedPackets(0), |
| 850 | send_sequence_number_(0), |
| 851 | ts_stats_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
| 852 | rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()), |
| 853 | capture_start_rtp_time_stamp_(-1), |
| 854 | capture_start_ntp_time_ms_(-1), |
| 855 | _engineStatisticsPtr(NULL), |
| 856 | _outputMixerPtr(NULL), |
| 857 | _transmitMixerPtr(NULL), |
| 858 | _moduleProcessThreadPtr(NULL), |
| 859 | _audioDeviceModulePtr(NULL), |
| 860 | _voiceEngineObserverPtr(NULL), |
| 861 | _callbackCritSectPtr(NULL), |
| 862 | _transportPtr(NULL), |
| 863 | _rxVadObserverPtr(NULL), |
| 864 | _oldVadDecision(-1), |
| 865 | _sendFrameType(0), |
| 866 | _externalMixing(false), |
| 867 | _mixFileWithMicrophone(false), |
| 868 | _mute(false), |
| 869 | _panLeft(1.0f), |
| 870 | _panRight(1.0f), |
| 871 | _outputGain(1.0f), |
| 872 | _playOutbandDtmfEvent(false), |
| 873 | _playInbandDtmfEvent(false), |
| 874 | _lastLocalTimeStamp(0), |
| 875 | _lastPayloadType(0), |
| 876 | _includeAudioLevelIndication(false), |
| 877 | _outputSpeechType(AudioFrame::kNormalSpeech), |
| 878 | video_sync_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
| 879 | _average_jitter_buffer_delay_us(0), |
| 880 | _previousTimestamp(0), |
| 881 | _recPacketDelayMs(20), |
| 882 | _RxVadDetection(false), |
| 883 | _rxAgcIsEnabled(false), |
| 884 | _rxNsIsEnabled(false), |
| 885 | restored_packet_in_use_(false), |
| 886 | rtcp_observer_(new VoERtcpObserver(this)), |
| 887 | network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), |
| 888 | assoc_send_channel_lock_(CriticalSectionWrapper::CreateCriticalSection()), |
| 889 | associate_send_channel_(ChannelOwner(nullptr)), |
| 890 | pacing_enabled_(config.Get<VoicePacing>().enabled), |
| 891 | feedback_observer_proxy_(pacing_enabled_ ? new TransportFeedbackProxy() |
| 892 | : nullptr), |
| 893 | seq_num_allocator_proxy_( |
| 894 | pacing_enabled_ ? new TransportSequenceNumberProxy() : nullptr), |
| 895 | rtp_packet_sender_proxy_(pacing_enabled_ ? new RtpPacketSenderProxy() |
| 896 | : nullptr) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 897 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId), |
| 898 | "Channel::Channel() - ctor"); |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 899 | AudioCodingModule::Config acm_config; |
| 900 | acm_config.id = VoEModuleId(instanceId, channelId); |
| 901 | if (config.Get<NetEqCapacityConfig>().enabled) { |
| 902 | // Clamping the buffer capacity at 20 packets. While going lower will |
| 903 | // probably work, it makes little sense. |
| 904 | acm_config.neteq_config.max_packets_in_buffer = |
| 905 | std::max(20, config.Get<NetEqCapacityConfig>().capacity); |
| 906 | } |
Henrik Lundin | 5263b3c | 2015-06-01 10:29:41 +0200 | [diff] [blame] | 907 | acm_config.neteq_config.enable_fast_accelerate = |
| 908 | config.Get<NetEqFastAccelerate>().enabled; |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 909 | audio_coding_.reset(AudioCodingModule::Create(acm_config)); |
| 910 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 911 | _inbandDtmfQueue.ResetDtmf(); |
| 912 | _inbandDtmfGenerator.Init(); |
| 913 | _outputAudioLevel.Clear(); |
| 914 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 915 | RtpRtcp::Configuration configuration; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 916 | configuration.audio = true; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 917 | configuration.outgoing_transport = this; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 918 | configuration.audio_messages = this; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 919 | configuration.receive_statistics = rtp_receive_statistics_.get(); |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 920 | configuration.bandwidth_callback = rtcp_observer_.get(); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 921 | configuration.paced_sender = rtp_packet_sender_proxy_.get(); |
| 922 | configuration.transport_sequence_number_allocator = |
| 923 | seq_num_allocator_proxy_.get(); |
| 924 | configuration.transport_feedback_callback = feedback_observer_proxy_.get(); |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 925 | |
| 926 | _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 927 | |
| 928 | statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); |
| 929 | rtp_receive_statistics_->RegisterRtcpStatisticsCallback( |
| 930 | statistics_proxy_.get()); |
aluebs@webrtc.org | f927fd6 | 2014-04-16 11:58:18 +0000 | [diff] [blame] | 931 | |
| 932 | Config audioproc_config; |
| 933 | audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
| 934 | rx_audioproc_.reset(AudioProcessing::Create(audioproc_config)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | Channel::~Channel() |
| 938 | { |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 939 | rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 940 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId), |
| 941 | "Channel::~Channel() - dtor"); |
| 942 | |
| 943 | if (_outputExternalMedia) |
| 944 | { |
| 945 | DeRegisterExternalMediaProcessing(kPlaybackPerChannel); |
| 946 | } |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 947 | if (channel_state_.Get().input_external_media) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 948 | { |
| 949 | DeRegisterExternalMediaProcessing(kRecordingPerChannel); |
| 950 | } |
| 951 | StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 952 | StopPlayout(); |
| 953 | |
| 954 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 955 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 956 | if (_inputFilePlayerPtr) |
| 957 | { |
| 958 | _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 959 | _inputFilePlayerPtr->StopPlayingFile(); |
| 960 | FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); |
| 961 | _inputFilePlayerPtr = NULL; |
| 962 | } |
| 963 | if (_outputFilePlayerPtr) |
| 964 | { |
| 965 | _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 966 | _outputFilePlayerPtr->StopPlayingFile(); |
| 967 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 968 | _outputFilePlayerPtr = NULL; |
| 969 | } |
| 970 | if (_outputFileRecorderPtr) |
| 971 | { |
| 972 | _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
| 973 | _outputFileRecorderPtr->StopRecording(); |
| 974 | FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
| 975 | _outputFileRecorderPtr = NULL; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | // The order to safely shutdown modules in a channel is: |
| 980 | // 1. De-register callbacks in modules |
| 981 | // 2. De-register modules in process thread |
| 982 | // 3. Destroy modules |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 983 | if (audio_coding_->RegisterTransportCallback(NULL) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 984 | { |
| 985 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 986 | VoEId(_instanceId,_channelId), |
| 987 | "~Channel() failed to de-register transport callback" |
| 988 | " (Audio coding module)"); |
| 989 | } |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 990 | if (audio_coding_->RegisterVADCallback(NULL) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 991 | { |
| 992 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 993 | VoEId(_instanceId,_channelId), |
| 994 | "~Channel() failed to de-register VAD callback" |
| 995 | " (Audio coding module)"); |
| 996 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 997 | // De-register modules in process thread |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 998 | _moduleProcessThreadPtr->DeRegisterModule(_rtpRtcpModule.get()); |
| 999 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1000 | // End of modules shutdown |
| 1001 | |
| 1002 | // Delete other objects |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1003 | delete &_callbackCritSect; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1004 | delete &_fileCritSect; |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 1005 | delete &volume_settings_critsect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1008 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1009 | Channel::Init() |
| 1010 | { |
| 1011 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1012 | "Channel::Init()"); |
| 1013 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1014 | channel_state_.Reset(); |
| 1015 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1016 | // --- Initial sanity |
| 1017 | |
| 1018 | if ((_engineStatisticsPtr == NULL) || |
| 1019 | (_moduleProcessThreadPtr == NULL)) |
| 1020 | { |
| 1021 | WEBRTC_TRACE(kTraceError, kTraceVoice, |
| 1022 | VoEId(_instanceId,_channelId), |
| 1023 | "Channel::Init() must call SetEngineInformation() first"); |
| 1024 | return -1; |
| 1025 | } |
| 1026 | |
| 1027 | // --- Add modules to process thread (for periodic schedulation) |
| 1028 | |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 1029 | _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get()); |
| 1030 | |
pwestin@webrtc.org | c450a19 | 2012-01-04 15:00:12 +0000 | [diff] [blame] | 1031 | // --- ACM initialization |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1032 | |
henrik.lundin | 061b79a | 2015-09-18 01:29:11 -0700 | [diff] [blame] | 1033 | if (audio_coding_->InitializeReceiver() == -1) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1034 | _engineStatisticsPtr->SetLastError( |
| 1035 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1036 | "Channel::Init() unable to initialize the ACM - 1"); |
| 1037 | return -1; |
| 1038 | } |
| 1039 | |
| 1040 | // --- RTP/RTCP module initialization |
| 1041 | |
| 1042 | // Ensure that RTCP is enabled by default for the created channel. |
| 1043 | // Note that, the module will keep generating RTCP until it is explicitly |
| 1044 | // disabled by the user. |
| 1045 | // After StopListen (when no sockets exists), RTCP packets will no longer |
| 1046 | // be transmitted since the Transport object will then be invalid. |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1047 | telephone_event_handler_->SetTelephoneEventForwardToDecoder(true); |
| 1048 | // RTCP is enabled by default. |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 1049 | _rtpRtcpModule->SetRTCPStatus(RtcpMode::kCompound); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 1050 | // --- Register all permanent callbacks |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1051 | const bool fail = |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1052 | (audio_coding_->RegisterTransportCallback(this) == -1) || |
| 1053 | (audio_coding_->RegisterVADCallback(this) == -1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1054 | |
| 1055 | if (fail) |
| 1056 | { |
| 1057 | _engineStatisticsPtr->SetLastError( |
| 1058 | VE_CANNOT_INIT_CHANNEL, kTraceError, |
| 1059 | "Channel::Init() callbacks not registered"); |
| 1060 | return -1; |
| 1061 | } |
| 1062 | |
| 1063 | // --- Register all supported codecs to the receiving side of the |
| 1064 | // RTP/RTCP module |
| 1065 | |
| 1066 | CodecInst codec; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1067 | const uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1068 | |
| 1069 | for (int idx = 0; idx < nSupportedCodecs; idx++) |
| 1070 | { |
| 1071 | // Open up the RTP/RTCP receiver for all supported codecs |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1072 | if ((audio_coding_->Codec(idx, &codec) == -1) || |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1073 | (rtp_receiver_->RegisterReceivePayload( |
| 1074 | codec.plname, |
| 1075 | codec.pltype, |
| 1076 | codec.plfreq, |
| 1077 | codec.channels, |
| 1078 | (codec.rate < 0) ? 0 : codec.rate) == -1)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1079 | { |
| 1080 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 1081 | VoEId(_instanceId,_channelId), |
| 1082 | "Channel::Init() unable to register %s (%d/%d/%d/%d) " |
| 1083 | "to RTP/RTCP receiver", |
| 1084 | codec.plname, codec.pltype, codec.plfreq, |
| 1085 | codec.channels, codec.rate); |
| 1086 | } |
| 1087 | else |
| 1088 | { |
| 1089 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, |
| 1090 | VoEId(_instanceId,_channelId), |
| 1091 | "Channel::Init() %s (%d/%d/%d/%d) has been added to " |
| 1092 | "the RTP/RTCP receiver", |
| 1093 | codec.plname, codec.pltype, codec.plfreq, |
| 1094 | codec.channels, codec.rate); |
| 1095 | } |
| 1096 | |
| 1097 | // Ensure that PCMU is used as default codec on the sending side |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 1098 | if (!STR_CASE_CMP(codec.plname, "PCMU") && (codec.channels == 1)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1099 | { |
| 1100 | SetSendCodec(codec); |
| 1101 | } |
| 1102 | |
| 1103 | // Register default PT for outband 'telephone-event' |
| 1104 | if (!STR_CASE_CMP(codec.plname, "telephone-event")) |
| 1105 | { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1106 | if ((_rtpRtcpModule->RegisterSendPayload(codec) == -1) || |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1107 | (audio_coding_->RegisterReceiveCodec(codec) == -1)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1108 | { |
| 1109 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 1110 | VoEId(_instanceId,_channelId), |
| 1111 | "Channel::Init() failed to register outband " |
| 1112 | "'telephone-event' (%d/%d) correctly", |
| 1113 | codec.pltype, codec.plfreq); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (!STR_CASE_CMP(codec.plname, "CN")) |
| 1118 | { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1119 | if ((audio_coding_->RegisterSendCodec(codec) == -1) || |
| 1120 | (audio_coding_->RegisterReceiveCodec(codec) == -1) || |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1121 | (_rtpRtcpModule->RegisterSendPayload(codec) == -1)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1122 | { |
| 1123 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 1124 | VoEId(_instanceId,_channelId), |
| 1125 | "Channel::Init() failed to register CN (%d/%d) " |
| 1126 | "correctly - 1", |
| 1127 | codec.pltype, codec.plfreq); |
| 1128 | } |
| 1129 | } |
| 1130 | #ifdef WEBRTC_CODEC_RED |
| 1131 | // Register RED to the receiving side of the ACM. |
| 1132 | // We will not receive an OnInitializeDecoder() callback for RED. |
| 1133 | if (!STR_CASE_CMP(codec.plname, "RED")) |
| 1134 | { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1135 | if (audio_coding_->RegisterReceiveCodec(codec) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1136 | { |
| 1137 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 1138 | VoEId(_instanceId,_channelId), |
| 1139 | "Channel::Init() failed to register RED (%d/%d) " |
| 1140 | "correctly", |
| 1141 | codec.pltype, codec.plfreq); |
| 1142 | } |
| 1143 | } |
| 1144 | #endif |
| 1145 | } |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 1146 | |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 1147 | if (rx_audioproc_->noise_suppression()->set_level(kDefaultNsMode) != 0) { |
pbos | ad85622 | 2015-11-27 09:48:36 -0800 | [diff] [blame] | 1148 | LOG(LS_ERROR) << "noise_suppression()->set_level(kDefaultNsMode) failed."; |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 1149 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1150 | } |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 1151 | if (rx_audioproc_->gain_control()->set_mode(kDefaultRxAgcMode) != 0) { |
pbos | ad85622 | 2015-11-27 09:48:36 -0800 | [diff] [blame] | 1152 | LOG(LS_ERROR) << "gain_control()->set_mode(kDefaultRxAgcMode) failed."; |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 1153 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1159 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1160 | Channel::SetEngineInformation(Statistics& engineStatistics, |
| 1161 | OutputMixer& outputMixer, |
| 1162 | voe::TransmitMixer& transmitMixer, |
| 1163 | ProcessThread& moduleProcessThread, |
| 1164 | AudioDeviceModule& audioDeviceModule, |
| 1165 | VoiceEngineObserver* voiceEngineObserver, |
| 1166 | CriticalSectionWrapper* callbackCritSect) |
| 1167 | { |
| 1168 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1169 | "Channel::SetEngineInformation()"); |
| 1170 | _engineStatisticsPtr = &engineStatistics; |
| 1171 | _outputMixerPtr = &outputMixer; |
| 1172 | _transmitMixerPtr = &transmitMixer, |
| 1173 | _moduleProcessThreadPtr = &moduleProcessThread; |
| 1174 | _audioDeviceModulePtr = &audioDeviceModule; |
| 1175 | _voiceEngineObserverPtr = voiceEngineObserver; |
| 1176 | _callbackCritSectPtr = callbackCritSect; |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1180 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1181 | Channel::UpdateLocalTimeStamp() |
| 1182 | { |
| 1183 | |
Peter Kasting | b7e5054 | 2015-06-11 12:55:50 -0700 | [diff] [blame] | 1184 | _timeStamp += static_cast<uint32_t>(_audioFrame.samples_per_channel_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1185 | return 0; |
| 1186 | } |
| 1187 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 1188 | void Channel::SetSink(rtc::scoped_ptr<AudioSinkInterface> sink) { |
| 1189 | CriticalSectionScoped cs(&_callbackCritSect); |
| 1190 | audio_sink_ = std::move(sink); |
| 1191 | } |
| 1192 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1193 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1194 | Channel::StartPlayout() |
| 1195 | { |
| 1196 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1197 | "Channel::StartPlayout()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1198 | if (channel_state_.Get().playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1199 | { |
| 1200 | return 0; |
| 1201 | } |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 1202 | |
| 1203 | if (!_externalMixing) { |
| 1204 | // Add participant as candidates for mixing. |
| 1205 | if (_outputMixerPtr->SetMixabilityStatus(*this, true) != 0) |
| 1206 | { |
| 1207 | _engineStatisticsPtr->SetLastError( |
| 1208 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 1209 | "StartPlayout() failed to add participant to mixer"); |
| 1210 | return -1; |
| 1211 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1214 | channel_state_.SetPlaying(true); |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1215 | if (RegisterFilePlayingToMixer() != 0) |
| 1216 | return -1; |
| 1217 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1221 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1222 | Channel::StopPlayout() |
| 1223 | { |
| 1224 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1225 | "Channel::StopPlayout()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1226 | if (!channel_state_.Get().playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1227 | { |
| 1228 | return 0; |
| 1229 | } |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 1230 | |
| 1231 | if (!_externalMixing) { |
| 1232 | // Remove participant as candidates for mixing |
| 1233 | if (_outputMixerPtr->SetMixabilityStatus(*this, false) != 0) |
| 1234 | { |
| 1235 | _engineStatisticsPtr->SetLastError( |
| 1236 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 1237 | "StopPlayout() failed to remove participant from mixer"); |
| 1238 | return -1; |
| 1239 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1242 | channel_state_.SetPlaying(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1243 | _outputAudioLevel.Clear(); |
| 1244 | |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1248 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1249 | Channel::StartSend() |
| 1250 | { |
| 1251 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1252 | "Channel::StartSend()"); |
xians@webrtc.org | 09e8c47 | 2013-07-31 16:30:19 +0000 | [diff] [blame] | 1253 | // Resume the previous sequence number which was reset by StopSend(). |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1254 | // This needs to be done before |sending| is set to true. |
xians@webrtc.org | 09e8c47 | 2013-07-31 16:30:19 +0000 | [diff] [blame] | 1255 | if (send_sequence_number_) |
| 1256 | SetInitSequenceNumber(send_sequence_number_); |
| 1257 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1258 | if (channel_state_.Get().sending) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1259 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1260 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1261 | } |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1262 | channel_state_.SetSending(true); |
xians@webrtc.org | e07247a | 2011-11-28 16:31:28 +0000 | [diff] [blame] | 1263 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1264 | if (_rtpRtcpModule->SetSendingStatus(true) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1265 | { |
| 1266 | _engineStatisticsPtr->SetLastError( |
| 1267 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1268 | "StartSend() RTP/RTCP failed to start sending"); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1269 | CriticalSectionScoped cs(&_callbackCritSect); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1270 | channel_state_.SetSending(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1271 | return -1; |
| 1272 | } |
xians@webrtc.org | e07247a | 2011-11-28 16:31:28 +0000 | [diff] [blame] | 1273 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1274 | return 0; |
| 1275 | } |
| 1276 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1277 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1278 | Channel::StopSend() |
| 1279 | { |
| 1280 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1281 | "Channel::StopSend()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1282 | if (!channel_state_.Get().sending) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1283 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1284 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1285 | } |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1286 | channel_state_.SetSending(false); |
xians@webrtc.org | e07247a | 2011-11-28 16:31:28 +0000 | [diff] [blame] | 1287 | |
xians@webrtc.org | 09e8c47 | 2013-07-31 16:30:19 +0000 | [diff] [blame] | 1288 | // Store the sequence number to be able to pick up the same sequence for |
| 1289 | // the next StartSend(). This is needed for restarting device, otherwise |
| 1290 | // it might cause libSRTP to complain about packets being replayed. |
| 1291 | // TODO(xians): Remove this workaround after RtpRtcpModule's refactoring |
| 1292 | // CL is landed. See issue |
| 1293 | // https://code.google.com/p/webrtc/issues/detail?id=2111 . |
| 1294 | send_sequence_number_ = _rtpRtcpModule->SequenceNumber(); |
| 1295 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1296 | // Reset sending SSRC and sequence number and triggers direct transmission |
| 1297 | // of RTCP BYE |
pbos | d436298 | 2015-07-07 08:32:48 -0700 | [diff] [blame] | 1298 | if (_rtpRtcpModule->SetSendingStatus(false) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1299 | { |
| 1300 | _engineStatisticsPtr->SetLastError( |
| 1301 | VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
| 1302 | "StartSend() RTP/RTCP failed to stop sending"); |
| 1303 | } |
| 1304 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1305 | return 0; |
| 1306 | } |
| 1307 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1308 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1309 | Channel::StartReceiving() |
| 1310 | { |
| 1311 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1312 | "Channel::StartReceiving()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1313 | if (channel_state_.Get().receiving) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1314 | { |
| 1315 | return 0; |
| 1316 | } |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1317 | channel_state_.SetReceiving(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1318 | _numberOfDiscardedPackets = 0; |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1322 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1323 | Channel::StopReceiving() |
| 1324 | { |
| 1325 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1326 | "Channel::StopReceiving()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1327 | if (!channel_state_.Get().receiving) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1328 | { |
| 1329 | return 0; |
| 1330 | } |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 1331 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1332 | channel_state_.SetReceiving(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1333 | return 0; |
| 1334 | } |
| 1335 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1336 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1337 | Channel::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) |
| 1338 | { |
| 1339 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1340 | "Channel::RegisterVoiceEngineObserver()"); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1341 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1342 | |
| 1343 | if (_voiceEngineObserverPtr) |
| 1344 | { |
| 1345 | _engineStatisticsPtr->SetLastError( |
| 1346 | VE_INVALID_OPERATION, kTraceError, |
| 1347 | "RegisterVoiceEngineObserver() observer already enabled"); |
| 1348 | return -1; |
| 1349 | } |
| 1350 | _voiceEngineObserverPtr = &observer; |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1354 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1355 | Channel::DeRegisterVoiceEngineObserver() |
| 1356 | { |
| 1357 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1358 | "Channel::DeRegisterVoiceEngineObserver()"); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1359 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1360 | |
| 1361 | if (!_voiceEngineObserverPtr) |
| 1362 | { |
| 1363 | _engineStatisticsPtr->SetLastError( |
| 1364 | VE_INVALID_OPERATION, kTraceWarning, |
| 1365 | "DeRegisterVoiceEngineObserver() observer already disabled"); |
| 1366 | return 0; |
| 1367 | } |
| 1368 | _voiceEngineObserverPtr = NULL; |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1372 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1373 | Channel::GetSendCodec(CodecInst& codec) |
| 1374 | { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 1375 | auto send_codec = audio_coding_->SendCodec(); |
| 1376 | if (send_codec) { |
| 1377 | codec = *send_codec; |
| 1378 | return 0; |
| 1379 | } |
| 1380 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1383 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1384 | Channel::GetRecCodec(CodecInst& codec) |
| 1385 | { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1386 | return (audio_coding_->ReceiveCodec(&codec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1389 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1390 | Channel::SetSendCodec(const CodecInst& codec) |
| 1391 | { |
| 1392 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1393 | "Channel::SetSendCodec()"); |
| 1394 | |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1395 | if (audio_coding_->RegisterSendCodec(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1396 | { |
| 1397 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1398 | "SetSendCodec() failed to register codec to ACM"); |
| 1399 | return -1; |
| 1400 | } |
| 1401 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1402 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1403 | { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1404 | _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 1405 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1406 | { |
| 1407 | WEBRTC_TRACE( |
| 1408 | kTraceError, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1409 | "SetSendCodec() failed to register codec to" |
| 1410 | " RTP/RTCP module"); |
| 1411 | return -1; |
| 1412 | } |
| 1413 | } |
| 1414 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1415 | if (_rtpRtcpModule->SetAudioPacketSize(codec.pacsize) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1416 | { |
| 1417 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1418 | "SetSendCodec() failed to set audio packet size"); |
| 1419 | return -1; |
| 1420 | } |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 1425 | void Channel::SetBitRate(int bitrate_bps) { |
| 1426 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1427 | "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); |
| 1428 | audio_coding_->SetBitRate(bitrate_bps); |
| 1429 | } |
| 1430 | |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 1431 | void Channel::OnIncomingFractionLoss(int fraction_lost) { |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 1432 | network_predictor_->UpdatePacketLossRate(fraction_lost); |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 1433 | uint8_t average_fraction_loss = network_predictor_->GetLossRate(); |
| 1434 | |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 1435 | // Normalizes rate to 0 - 100. |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 1436 | if (audio_coding_->SetPacketLossRate( |
| 1437 | 100 * average_fraction_loss / 255) != 0) { |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 1438 | assert(false); // This should not happen. |
| 1439 | } |
| 1440 | } |
| 1441 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1442 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1443 | Channel::SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX) |
| 1444 | { |
| 1445 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1446 | "Channel::SetVADStatus(mode=%d)", mode); |
henrik.lundin@webrtc.org | 664ccb7 | 2015-01-28 14:49:05 +0000 | [diff] [blame] | 1447 | assert(!(disableDTX && enableVAD)); // disableDTX mode is deprecated. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1448 | // To disable VAD, DTX must be disabled too |
| 1449 | disableDTX = ((enableVAD == false) ? true : disableDTX); |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1450 | if (audio_coding_->SetVAD(!disableDTX, enableVAD, mode) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1451 | { |
| 1452 | _engineStatisticsPtr->SetLastError( |
| 1453 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1454 | "SetVADStatus() failed to set VAD"); |
| 1455 | return -1; |
| 1456 | } |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1460 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1461 | Channel::GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX) |
| 1462 | { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1463 | if (audio_coding_->VAD(&disabledDTX, &enabledVAD, &mode) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1464 | { |
| 1465 | _engineStatisticsPtr->SetLastError( |
| 1466 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1467 | "GetVADStatus() failed to get VAD status"); |
| 1468 | return -1; |
| 1469 | } |
| 1470 | disabledDTX = !disabledDTX; |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1474 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1475 | Channel::SetRecPayloadType(const CodecInst& codec) |
| 1476 | { |
| 1477 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1478 | "Channel::SetRecPayloadType()"); |
| 1479 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1480 | if (channel_state_.Get().playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1481 | { |
| 1482 | _engineStatisticsPtr->SetLastError( |
| 1483 | VE_ALREADY_PLAYING, kTraceError, |
| 1484 | "SetRecPayloadType() unable to set PT while playing"); |
| 1485 | return -1; |
| 1486 | } |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1487 | if (channel_state_.Get().receiving) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1488 | { |
| 1489 | _engineStatisticsPtr->SetLastError( |
| 1490 | VE_ALREADY_LISTENING, kTraceError, |
| 1491 | "SetRecPayloadType() unable to set PT while listening"); |
| 1492 | return -1; |
| 1493 | } |
| 1494 | |
| 1495 | if (codec.pltype == -1) |
| 1496 | { |
| 1497 | // De-register the selected codec (RTP/RTCP module and ACM) |
| 1498 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1499 | int8_t pltype(-1); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1500 | CodecInst rxCodec = codec; |
| 1501 | |
| 1502 | // Get payload type for the given codec |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1503 | rtp_payload_registry_->ReceivePayloadType( |
| 1504 | rxCodec.plname, |
| 1505 | rxCodec.plfreq, |
| 1506 | rxCodec.channels, |
| 1507 | (rxCodec.rate < 0) ? 0 : rxCodec.rate, |
| 1508 | &pltype); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1509 | rxCodec.pltype = pltype; |
| 1510 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1511 | if (rtp_receiver_->DeRegisterReceivePayload(pltype) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1512 | { |
| 1513 | _engineStatisticsPtr->SetLastError( |
| 1514 | VE_RTP_RTCP_MODULE_ERROR, |
| 1515 | kTraceError, |
| 1516 | "SetRecPayloadType() RTP/RTCP-module deregistration " |
| 1517 | "failed"); |
| 1518 | return -1; |
| 1519 | } |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1520 | if (audio_coding_->UnregisterReceiveCodec(rxCodec.pltype) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1521 | { |
| 1522 | _engineStatisticsPtr->SetLastError( |
| 1523 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1524 | "SetRecPayloadType() ACM deregistration failed - 1"); |
| 1525 | return -1; |
| 1526 | } |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1530 | if (rtp_receiver_->RegisterReceivePayload( |
| 1531 | codec.plname, |
| 1532 | codec.pltype, |
| 1533 | codec.plfreq, |
| 1534 | codec.channels, |
| 1535 | (codec.rate < 0) ? 0 : codec.rate) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1536 | { |
| 1537 | // First attempt to register failed => de-register and try again |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1538 | rtp_receiver_->DeRegisterReceivePayload(codec.pltype); |
| 1539 | if (rtp_receiver_->RegisterReceivePayload( |
| 1540 | codec.plname, |
| 1541 | codec.pltype, |
| 1542 | codec.plfreq, |
| 1543 | codec.channels, |
| 1544 | (codec.rate < 0) ? 0 : codec.rate) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1545 | { |
| 1546 | _engineStatisticsPtr->SetLastError( |
| 1547 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1548 | "SetRecPayloadType() RTP/RTCP-module registration failed"); |
| 1549 | return -1; |
| 1550 | } |
| 1551 | } |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1552 | if (audio_coding_->RegisterReceiveCodec(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1553 | { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1554 | audio_coding_->UnregisterReceiveCodec(codec.pltype); |
| 1555 | if (audio_coding_->RegisterReceiveCodec(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1556 | { |
| 1557 | _engineStatisticsPtr->SetLastError( |
| 1558 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1559 | "SetRecPayloadType() ACM registration failed - 1"); |
| 1560 | return -1; |
| 1561 | } |
| 1562 | } |
| 1563 | return 0; |
| 1564 | } |
| 1565 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1566 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1567 | Channel::GetRecPayloadType(CodecInst& codec) |
| 1568 | { |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1569 | int8_t payloadType(-1); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1570 | if (rtp_payload_registry_->ReceivePayloadType( |
| 1571 | codec.plname, |
| 1572 | codec.plfreq, |
| 1573 | codec.channels, |
| 1574 | (codec.rate < 0) ? 0 : codec.rate, |
| 1575 | &payloadType) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1576 | { |
| 1577 | _engineStatisticsPtr->SetLastError( |
henrika@webrtc.org | 3719800 | 2012-06-18 11:00:12 +0000 | [diff] [blame] | 1578 | VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1579 | "GetRecPayloadType() failed to retrieve RX payload type"); |
| 1580 | return -1; |
| 1581 | } |
| 1582 | codec.pltype = payloadType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1583 | return 0; |
| 1584 | } |
| 1585 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1586 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1587 | Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency) |
| 1588 | { |
| 1589 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1590 | "Channel::SetSendCNPayloadType()"); |
| 1591 | |
| 1592 | CodecInst codec; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1593 | int32_t samplingFreqHz(-1); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 1594 | const int kMono = 1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1595 | if (frequency == kFreq32000Hz) |
| 1596 | samplingFreqHz = 32000; |
| 1597 | else if (frequency == kFreq16000Hz) |
| 1598 | samplingFreqHz = 16000; |
| 1599 | |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1600 | if (audio_coding_->Codec("CN", &codec, samplingFreqHz, kMono) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1601 | { |
| 1602 | _engineStatisticsPtr->SetLastError( |
| 1603 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1604 | "SetSendCNPayloadType() failed to retrieve default CN codec " |
| 1605 | "settings"); |
| 1606 | return -1; |
| 1607 | } |
| 1608 | |
| 1609 | // Modify the payload type (must be set to dynamic range) |
| 1610 | codec.pltype = type; |
| 1611 | |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 1612 | if (audio_coding_->RegisterSendCodec(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1613 | { |
| 1614 | _engineStatisticsPtr->SetLastError( |
| 1615 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1616 | "SetSendCNPayloadType() failed to register CN to ACM"); |
| 1617 | return -1; |
| 1618 | } |
| 1619 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1620 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1621 | { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 1622 | _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 1623 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1624 | { |
| 1625 | _engineStatisticsPtr->SetLastError( |
| 1626 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1627 | "SetSendCNPayloadType() failed to register CN to RTP/RTCP " |
| 1628 | "module"); |
| 1629 | return -1; |
| 1630 | } |
| 1631 | } |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1635 | int Channel::SetOpusMaxPlaybackRate(int frequency_hz) { |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1636 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1637 | "Channel::SetOpusMaxPlaybackRate()"); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1638 | |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1639 | if (audio_coding_->SetOpusMaxPlaybackRate(frequency_hz) != 0) { |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1640 | _engineStatisticsPtr->SetLastError( |
| 1641 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1642 | "SetOpusMaxPlaybackRate() failed to set maximum playback rate"); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1643 | return -1; |
| 1644 | } |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 1648 | int Channel::SetOpusDtx(bool enable_dtx) { |
| 1649 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1650 | "Channel::SetOpusDtx(%d)", enable_dtx); |
Minyue Li | 092041c | 2015-05-11 12:19:35 +0200 | [diff] [blame] | 1651 | int ret = enable_dtx ? audio_coding_->EnableOpusDtx() |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 1652 | : audio_coding_->DisableOpusDtx(); |
| 1653 | if (ret != 0) { |
| 1654 | _engineStatisticsPtr->SetLastError( |
| 1655 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, "SetOpusDtx() failed"); |
| 1656 | return -1; |
| 1657 | } |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1661 | int32_t Channel::RegisterExternalTransport(Transport& transport) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1662 | { |
| 1663 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1664 | "Channel::RegisterExternalTransport()"); |
| 1665 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1666 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1667 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1668 | if (_externalTransport) |
| 1669 | { |
| 1670 | _engineStatisticsPtr->SetLastError(VE_INVALID_OPERATION, |
| 1671 | kTraceError, |
| 1672 | "RegisterExternalTransport() external transport already enabled"); |
| 1673 | return -1; |
| 1674 | } |
| 1675 | _externalTransport = true; |
| 1676 | _transportPtr = &transport; |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1680 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1681 | Channel::DeRegisterExternalTransport() |
| 1682 | { |
| 1683 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1684 | "Channel::DeRegisterExternalTransport()"); |
| 1685 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1686 | CriticalSectionScoped cs(&_callbackCritSect); |
xians@webrtc.org | 83661f5 | 2011-11-25 10:58:15 +0000 | [diff] [blame] | 1687 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1688 | if (!_transportPtr) |
| 1689 | { |
| 1690 | _engineStatisticsPtr->SetLastError( |
| 1691 | VE_INVALID_OPERATION, kTraceWarning, |
| 1692 | "DeRegisterExternalTransport() external transport already " |
| 1693 | "disabled"); |
| 1694 | return 0; |
| 1695 | } |
| 1696 | _externalTransport = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1697 | _transportPtr = NULL; |
| 1698 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1699 | "DeRegisterExternalTransport() all transport is disabled"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1700 | return 0; |
| 1701 | } |
| 1702 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1703 | int32_t Channel::ReceivedRTPPacket(const int8_t* data, size_t length, |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 1704 | const PacketTime& packet_time) { |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1705 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1706 | "Channel::ReceivedRTPPacket()"); |
| 1707 | |
| 1708 | // Store playout timestamp for the received RTP packet |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 1709 | UpdatePlayoutTimestamp(false); |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1710 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1711 | const uint8_t* received_packet = reinterpret_cast<const uint8_t*>(data); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 1712 | RTPHeader header; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1713 | if (!rtp_header_parser_->Parse(received_packet, length, &header)) { |
| 1714 | WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 1715 | "Incoming packet: invalid RTP header"); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 1716 | return -1; |
| 1717 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1718 | header.payload_type_frequency = |
| 1719 | rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1720 | if (header.payload_type_frequency < 0) |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1721 | return -1; |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1722 | bool in_order = IsPacketInOrder(header); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1723 | rtp_receive_statistics_->IncomingPacket(header, length, |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1724 | IsPacketRetransmitted(header, in_order)); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1725 | rtp_payload_registry_->SetIncomingPayloadType(header); |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 1726 | |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1727 | return ReceivePacket(received_packet, length, header, in_order) ? 0 : -1; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | bool Channel::ReceivePacket(const uint8_t* packet, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1731 | size_t packet_length, |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1732 | const RTPHeader& header, |
| 1733 | bool in_order) { |
minyue@webrtc.org | 456f014 | 2015-01-23 11:58:42 +0000 | [diff] [blame] | 1734 | if (rtp_payload_registry_->IsRtx(header)) { |
| 1735 | return HandleRtxPacket(packet, packet_length, header); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1736 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1737 | const uint8_t* payload = packet + header.headerLength; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1738 | assert(packet_length >= header.headerLength); |
| 1739 | size_t payload_length = packet_length - header.headerLength; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1740 | PayloadUnion payload_specific; |
| 1741 | if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1742 | &payload_specific)) { |
| 1743 | return false; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1744 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1745 | return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, |
| 1746 | payload_specific, in_order); |
| 1747 | } |
| 1748 | |
minyue@webrtc.org | 456f014 | 2015-01-23 11:58:42 +0000 | [diff] [blame] | 1749 | bool Channel::HandleRtxPacket(const uint8_t* packet, |
| 1750 | size_t packet_length, |
| 1751 | const RTPHeader& header) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1752 | if (!rtp_payload_registry_->IsRtx(header)) |
| 1753 | return false; |
| 1754 | |
| 1755 | // Remove the RTX header and parse the original RTP header. |
| 1756 | if (packet_length < header.headerLength) |
| 1757 | return false; |
| 1758 | if (packet_length > kVoiceEngineMaxIpPacketSizeBytes) |
| 1759 | return false; |
| 1760 | if (restored_packet_in_use_) { |
| 1761 | WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 1762 | "Multiple RTX headers detected, dropping packet"); |
| 1763 | return false; |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1764 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1765 | if (!rtp_payload_registry_->RestoreOriginalPacket( |
noahric | 65220a7 | 2015-10-14 11:29:49 -0700 | [diff] [blame] | 1766 | restored_packet_, packet, &packet_length, rtp_receiver_->SSRC(), |
| 1767 | header)) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1768 | WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 1769 | "Incoming RTX packet: invalid RTP header"); |
| 1770 | return false; |
| 1771 | } |
| 1772 | restored_packet_in_use_ = true; |
noahric | 65220a7 | 2015-10-14 11:29:49 -0700 | [diff] [blame] | 1773 | bool ret = OnRecoveredPacket(restored_packet_, packet_length); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1774 | restored_packet_in_use_ = false; |
| 1775 | return ret; |
| 1776 | } |
| 1777 | |
| 1778 | bool Channel::IsPacketInOrder(const RTPHeader& header) const { |
| 1779 | StreamStatistician* statistician = |
| 1780 | rtp_receive_statistics_->GetStatistician(header.ssrc); |
| 1781 | if (!statistician) |
| 1782 | return false; |
| 1783 | return statistician->IsPacketInOrder(header.sequenceNumber); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1786 | bool Channel::IsPacketRetransmitted(const RTPHeader& header, |
| 1787 | bool in_order) const { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1788 | // Retransmissions are handled separately if RTX is enabled. |
| 1789 | if (rtp_payload_registry_->RtxEnabled()) |
| 1790 | return false; |
| 1791 | StreamStatistician* statistician = |
| 1792 | rtp_receive_statistics_->GetStatistician(header.ssrc); |
| 1793 | if (!statistician) |
| 1794 | return false; |
| 1795 | // Check if this is a retransmission. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 1796 | int64_t min_rtt = 0; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1797 | _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL); |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1798 | return !in_order && |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1799 | statistician->IsRetransmitOfOldPacket(header, min_rtt); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1802 | int32_t Channel::ReceivedRTCPPacket(const int8_t* data, size_t length) { |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1803 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1804 | "Channel::ReceivedRTCPPacket()"); |
| 1805 | // Store playout timestamp for the received RTCP packet |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 1806 | UpdatePlayoutTimestamp(true); |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1807 | |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1808 | // Deliver RTCP packet to RTP/RTCP module for parsing |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1809 | if (_rtpRtcpModule->IncomingRtcpPacket((const uint8_t*)data, length) == -1) { |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1810 | _engineStatisticsPtr->SetLastError( |
| 1811 | VE_SOCKET_TRANSPORT_MODULE_ERROR, kTraceWarning, |
| 1812 | "Channel::IncomingRTPPacket() RTCP packet is invalid"); |
| 1813 | } |
wu@webrtc.org | 82c4b85 | 2014-05-20 22:55:01 +0000 | [diff] [blame] | 1814 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 1815 | int64_t rtt = GetRTT(true); |
| 1816 | if (rtt == 0) { |
| 1817 | // Waiting for valid RTT. |
| 1818 | return 0; |
| 1819 | } |
| 1820 | uint32_t ntp_secs = 0; |
| 1821 | uint32_t ntp_frac = 0; |
| 1822 | uint32_t rtp_timestamp = 0; |
| 1823 | if (0 != _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, |
| 1824 | &rtp_timestamp)) { |
| 1825 | // Waiting for RTCP. |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 1829 | { |
| 1830 | CriticalSectionScoped lock(ts_stats_lock_.get()); |
minyue@webrtc.org | 2c0cdbc | 2014-10-09 10:52:43 +0000 | [diff] [blame] | 1831 | ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 1832 | } |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1833 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1836 | int Channel::StartPlayingFileLocally(const char* fileName, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 1837 | bool loop, |
| 1838 | FileFormats format, |
| 1839 | int startPosition, |
| 1840 | float volumeScaling, |
| 1841 | int stopPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1842 | const CodecInst* codecInst) |
| 1843 | { |
| 1844 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1845 | "Channel::StartPlayingFileLocally(fileNameUTF8[]=%s, loop=%d," |
| 1846 | " format=%d, volumeScaling=%5.3f, startPosition=%d, " |
| 1847 | "stopPosition=%d)", fileName, loop, format, volumeScaling, |
| 1848 | startPosition, stopPosition); |
| 1849 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1850 | if (channel_state_.Get().output_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1851 | { |
| 1852 | _engineStatisticsPtr->SetLastError( |
| 1853 | VE_ALREADY_PLAYING, kTraceError, |
| 1854 | "StartPlayingFileLocally() is already playing"); |
| 1855 | return -1; |
| 1856 | } |
| 1857 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1858 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1859 | CriticalSectionScoped cs(&_fileCritSect); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1860 | |
| 1861 | if (_outputFilePlayerPtr) |
| 1862 | { |
| 1863 | _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 1864 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 1865 | _outputFilePlayerPtr = NULL; |
| 1866 | } |
| 1867 | |
| 1868 | _outputFilePlayerPtr = FilePlayer::CreateFilePlayer( |
| 1869 | _outputFilePlayerId, (const FileFormats)format); |
| 1870 | |
| 1871 | if (_outputFilePlayerPtr == NULL) |
| 1872 | { |
| 1873 | _engineStatisticsPtr->SetLastError( |
| 1874 | VE_INVALID_ARGUMENT, kTraceError, |
henrike@webrtc.org | 31d3070 | 2011-11-18 19:59:32 +0000 | [diff] [blame] | 1875 | "StartPlayingFileLocally() filePlayer format is not correct"); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1876 | return -1; |
| 1877 | } |
| 1878 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1879 | const uint32_t notificationTime(0); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1880 | |
| 1881 | if (_outputFilePlayerPtr->StartPlayingFile( |
| 1882 | fileName, |
| 1883 | loop, |
| 1884 | startPosition, |
| 1885 | volumeScaling, |
| 1886 | notificationTime, |
| 1887 | stopPosition, |
| 1888 | (const CodecInst*)codecInst) != 0) |
| 1889 | { |
| 1890 | _engineStatisticsPtr->SetLastError( |
| 1891 | VE_BAD_FILE, kTraceError, |
| 1892 | "StartPlayingFile() failed to start file playout"); |
| 1893 | _outputFilePlayerPtr->StopPlayingFile(); |
| 1894 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 1895 | _outputFilePlayerPtr = NULL; |
| 1896 | return -1; |
| 1897 | } |
| 1898 | _outputFilePlayerPtr->RegisterModuleFileCallback(this); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1899 | channel_state_.SetOutputFilePlaying(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1900 | } |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1901 | |
| 1902 | if (RegisterFilePlayingToMixer() != 0) |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 1903 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1904 | |
| 1905 | return 0; |
| 1906 | } |
| 1907 | |
| 1908 | int Channel::StartPlayingFileLocally(InStream* stream, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 1909 | FileFormats format, |
| 1910 | int startPosition, |
| 1911 | float volumeScaling, |
| 1912 | int stopPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1913 | const CodecInst* codecInst) |
| 1914 | { |
| 1915 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1916 | "Channel::StartPlayingFileLocally(format=%d," |
| 1917 | " volumeScaling=%5.3f, startPosition=%d, stopPosition=%d)", |
| 1918 | format, volumeScaling, startPosition, stopPosition); |
| 1919 | |
| 1920 | if(stream == NULL) |
| 1921 | { |
| 1922 | _engineStatisticsPtr->SetLastError( |
| 1923 | VE_BAD_FILE, kTraceError, |
| 1924 | "StartPlayingFileLocally() NULL as input stream"); |
| 1925 | return -1; |
| 1926 | } |
| 1927 | |
| 1928 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1929 | if (channel_state_.Get().output_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1930 | { |
| 1931 | _engineStatisticsPtr->SetLastError( |
| 1932 | VE_ALREADY_PLAYING, kTraceError, |
| 1933 | "StartPlayingFileLocally() is already playing"); |
| 1934 | return -1; |
| 1935 | } |
| 1936 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1937 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1938 | CriticalSectionScoped cs(&_fileCritSect); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1939 | |
| 1940 | // Destroy the old instance |
| 1941 | if (_outputFilePlayerPtr) |
| 1942 | { |
| 1943 | _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 1944 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 1945 | _outputFilePlayerPtr = NULL; |
| 1946 | } |
| 1947 | |
| 1948 | // Create the instance |
| 1949 | _outputFilePlayerPtr = FilePlayer::CreateFilePlayer( |
| 1950 | _outputFilePlayerId, |
| 1951 | (const FileFormats)format); |
| 1952 | |
| 1953 | if (_outputFilePlayerPtr == NULL) |
| 1954 | { |
| 1955 | _engineStatisticsPtr->SetLastError( |
| 1956 | VE_INVALID_ARGUMENT, kTraceError, |
| 1957 | "StartPlayingFileLocally() filePlayer format isnot correct"); |
| 1958 | return -1; |
| 1959 | } |
| 1960 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 1961 | const uint32_t notificationTime(0); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1962 | |
| 1963 | if (_outputFilePlayerPtr->StartPlayingFile(*stream, startPosition, |
| 1964 | volumeScaling, |
| 1965 | notificationTime, |
| 1966 | stopPosition, codecInst) != 0) |
| 1967 | { |
| 1968 | _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, |
| 1969 | "StartPlayingFile() failed to " |
| 1970 | "start file playout"); |
| 1971 | _outputFilePlayerPtr->StopPlayingFile(); |
| 1972 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 1973 | _outputFilePlayerPtr = NULL; |
| 1974 | return -1; |
| 1975 | } |
| 1976 | _outputFilePlayerPtr->RegisterModuleFileCallback(this); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1977 | channel_state_.SetOutputFilePlaying(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1978 | } |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1979 | |
| 1980 | if (RegisterFilePlayingToMixer() != 0) |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 1981 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1982 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | int Channel::StopPlayingFileLocally() |
| 1987 | { |
| 1988 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 1989 | "Channel::StopPlayingFileLocally()"); |
| 1990 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1991 | if (!channel_state_.Get().output_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1992 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1993 | return 0; |
| 1994 | } |
| 1995 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1996 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 1997 | CriticalSectionScoped cs(&_fileCritSect); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1998 | |
| 1999 | if (_outputFilePlayerPtr->StopPlayingFile() != 0) |
| 2000 | { |
| 2001 | _engineStatisticsPtr->SetLastError( |
| 2002 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 2003 | "StopPlayingFile() could not stop playing"); |
| 2004 | return -1; |
| 2005 | } |
| 2006 | _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 2007 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 2008 | _outputFilePlayerPtr = NULL; |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2009 | channel_state_.SetOutputFilePlaying(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2010 | } |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 2011 | // _fileCritSect cannot be taken while calling |
| 2012 | // SetAnonymousMixibilityStatus. Refer to comments in |
| 2013 | // StartPlayingFileLocally(const char* ...) for more details. |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 2014 | if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, false) != 0) |
| 2015 | { |
| 2016 | _engineStatisticsPtr->SetLastError( |
| 2017 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 2018 | "StopPlayingFile() failed to stop participant from playing as" |
| 2019 | "file in the mixer"); |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 2020 | return -1; |
| 2021 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2022 | |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
| 2026 | int Channel::IsPlayingFileLocally() const |
| 2027 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2028 | return channel_state_.Get().output_file_playing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 2031 | int Channel::RegisterFilePlayingToMixer() |
| 2032 | { |
| 2033 | // Return success for not registering for file playing to mixer if: |
| 2034 | // 1. playing file before playout is started on that channel. |
| 2035 | // 2. starting playout without file playing on that channel. |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2036 | if (!channel_state_.Get().playing || |
| 2037 | !channel_state_.Get().output_file_playing) |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 2038 | { |
| 2039 | return 0; |
| 2040 | } |
| 2041 | |
| 2042 | // |_fileCritSect| cannot be taken while calling |
| 2043 | // SetAnonymousMixabilityStatus() since as soon as the participant is added |
| 2044 | // frames can be pulled by the mixer. Since the frames are generated from |
| 2045 | // the file, _fileCritSect will be taken. This would result in a deadlock. |
| 2046 | if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, true) != 0) |
| 2047 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2048 | channel_state_.SetOutputFilePlaying(false); |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 2049 | CriticalSectionScoped cs(&_fileCritSect); |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 2050 | _engineStatisticsPtr->SetLastError( |
| 2051 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 2052 | "StartPlayingFile() failed to add participant as file to mixer"); |
| 2053 | _outputFilePlayerPtr->StopPlayingFile(); |
| 2054 | FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); |
| 2055 | _outputFilePlayerPtr = NULL; |
| 2056 | return -1; |
| 2057 | } |
| 2058 | |
| 2059 | return 0; |
| 2060 | } |
| 2061 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2062 | int Channel::StartPlayingFileAsMicrophone(const char* fileName, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 2063 | bool loop, |
| 2064 | FileFormats format, |
| 2065 | int startPosition, |
| 2066 | float volumeScaling, |
| 2067 | int stopPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2068 | const CodecInst* codecInst) |
| 2069 | { |
| 2070 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2071 | "Channel::StartPlayingFileAsMicrophone(fileNameUTF8[]=%s, " |
| 2072 | "loop=%d, format=%d, volumeScaling=%5.3f, startPosition=%d, " |
| 2073 | "stopPosition=%d)", fileName, loop, format, volumeScaling, |
| 2074 | startPosition, stopPosition); |
| 2075 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2076 | CriticalSectionScoped cs(&_fileCritSect); |
| 2077 | |
| 2078 | if (channel_state_.Get().input_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2079 | { |
| 2080 | _engineStatisticsPtr->SetLastError( |
| 2081 | VE_ALREADY_PLAYING, kTraceWarning, |
| 2082 | "StartPlayingFileAsMicrophone() filePlayer is playing"); |
| 2083 | return 0; |
| 2084 | } |
| 2085 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2086 | // Destroy the old instance |
| 2087 | if (_inputFilePlayerPtr) |
| 2088 | { |
| 2089 | _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 2090 | FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); |
| 2091 | _inputFilePlayerPtr = NULL; |
| 2092 | } |
| 2093 | |
| 2094 | // Create the instance |
| 2095 | _inputFilePlayerPtr = FilePlayer::CreateFilePlayer( |
| 2096 | _inputFilePlayerId, (const FileFormats)format); |
| 2097 | |
| 2098 | if (_inputFilePlayerPtr == NULL) |
| 2099 | { |
| 2100 | _engineStatisticsPtr->SetLastError( |
| 2101 | VE_INVALID_ARGUMENT, kTraceError, |
| 2102 | "StartPlayingFileAsMicrophone() filePlayer format isnot correct"); |
| 2103 | return -1; |
| 2104 | } |
| 2105 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2106 | const uint32_t notificationTime(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2107 | |
| 2108 | if (_inputFilePlayerPtr->StartPlayingFile( |
| 2109 | fileName, |
| 2110 | loop, |
| 2111 | startPosition, |
| 2112 | volumeScaling, |
| 2113 | notificationTime, |
| 2114 | stopPosition, |
| 2115 | (const CodecInst*)codecInst) != 0) |
| 2116 | { |
| 2117 | _engineStatisticsPtr->SetLastError( |
| 2118 | VE_BAD_FILE, kTraceError, |
| 2119 | "StartPlayingFile() failed to start file playout"); |
| 2120 | _inputFilePlayerPtr->StopPlayingFile(); |
| 2121 | FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); |
| 2122 | _inputFilePlayerPtr = NULL; |
| 2123 | return -1; |
| 2124 | } |
| 2125 | _inputFilePlayerPtr->RegisterModuleFileCallback(this); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2126 | channel_state_.SetInputFilePlaying(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2127 | |
| 2128 | return 0; |
| 2129 | } |
| 2130 | |
| 2131 | int Channel::StartPlayingFileAsMicrophone(InStream* stream, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 2132 | FileFormats format, |
| 2133 | int startPosition, |
| 2134 | float volumeScaling, |
| 2135 | int stopPosition, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2136 | const CodecInst* codecInst) |
| 2137 | { |
| 2138 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2139 | "Channel::StartPlayingFileAsMicrophone(format=%d, " |
| 2140 | "volumeScaling=%5.3f, startPosition=%d, stopPosition=%d)", |
| 2141 | format, volumeScaling, startPosition, stopPosition); |
| 2142 | |
| 2143 | if(stream == NULL) |
| 2144 | { |
| 2145 | _engineStatisticsPtr->SetLastError( |
| 2146 | VE_BAD_FILE, kTraceError, |
| 2147 | "StartPlayingFileAsMicrophone NULL as input stream"); |
| 2148 | return -1; |
| 2149 | } |
| 2150 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2151 | CriticalSectionScoped cs(&_fileCritSect); |
| 2152 | |
| 2153 | if (channel_state_.Get().input_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2154 | { |
| 2155 | _engineStatisticsPtr->SetLastError( |
| 2156 | VE_ALREADY_PLAYING, kTraceWarning, |
| 2157 | "StartPlayingFileAsMicrophone() is playing"); |
| 2158 | return 0; |
| 2159 | } |
| 2160 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2161 | // Destroy the old instance |
| 2162 | if (_inputFilePlayerPtr) |
| 2163 | { |
| 2164 | _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 2165 | FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); |
| 2166 | _inputFilePlayerPtr = NULL; |
| 2167 | } |
| 2168 | |
| 2169 | // Create the instance |
| 2170 | _inputFilePlayerPtr = FilePlayer::CreateFilePlayer( |
| 2171 | _inputFilePlayerId, (const FileFormats)format); |
| 2172 | |
| 2173 | if (_inputFilePlayerPtr == NULL) |
| 2174 | { |
| 2175 | _engineStatisticsPtr->SetLastError( |
| 2176 | VE_INVALID_ARGUMENT, kTraceError, |
| 2177 | "StartPlayingInputFile() filePlayer format isnot correct"); |
| 2178 | return -1; |
| 2179 | } |
| 2180 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2181 | const uint32_t notificationTime(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2182 | |
| 2183 | if (_inputFilePlayerPtr->StartPlayingFile(*stream, startPosition, |
| 2184 | volumeScaling, notificationTime, |
| 2185 | stopPosition, codecInst) != 0) |
| 2186 | { |
| 2187 | _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, |
| 2188 | "StartPlayingFile() failed to start " |
| 2189 | "file playout"); |
| 2190 | _inputFilePlayerPtr->StopPlayingFile(); |
| 2191 | FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); |
| 2192 | _inputFilePlayerPtr = NULL; |
| 2193 | return -1; |
| 2194 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 2195 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2196 | _inputFilePlayerPtr->RegisterModuleFileCallback(this); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2197 | channel_state_.SetInputFilePlaying(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2198 | |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
| 2202 | int Channel::StopPlayingFileAsMicrophone() |
| 2203 | { |
| 2204 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2205 | "Channel::StopPlayingFileAsMicrophone()"); |
| 2206 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2207 | CriticalSectionScoped cs(&_fileCritSect); |
| 2208 | |
| 2209 | if (!channel_state_.Get().input_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2210 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2211 | return 0; |
| 2212 | } |
| 2213 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2214 | if (_inputFilePlayerPtr->StopPlayingFile() != 0) |
| 2215 | { |
| 2216 | _engineStatisticsPtr->SetLastError( |
| 2217 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 2218 | "StopPlayingFile() could not stop playing"); |
| 2219 | return -1; |
| 2220 | } |
| 2221 | _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); |
| 2222 | FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); |
| 2223 | _inputFilePlayerPtr = NULL; |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2224 | channel_state_.SetInputFilePlaying(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2225 | |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
| 2229 | int Channel::IsPlayingFileAsMicrophone() const |
| 2230 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2231 | return channel_state_.Get().input_file_playing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 2234 | int Channel::StartRecordingPlayout(const char* fileName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2235 | const CodecInst* codecInst) |
| 2236 | { |
| 2237 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2238 | "Channel::StartRecordingPlayout(fileName=%s)", fileName); |
| 2239 | |
| 2240 | if (_outputFileRecording) |
| 2241 | { |
| 2242 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,-1), |
| 2243 | "StartRecordingPlayout() is already recording"); |
| 2244 | return 0; |
| 2245 | } |
| 2246 | |
| 2247 | FileFormats format; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2248 | const uint32_t notificationTime(0); // Not supported in VoE |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2249 | CodecInst dummyCodec={100,"L16",16000,320,1,320000}; |
| 2250 | |
niklas.enbom@webrtc.org | 40197d7 | 2012-03-26 08:45:47 +0000 | [diff] [blame] | 2251 | if ((codecInst != NULL) && |
| 2252 | ((codecInst->channels < 1) || (codecInst->channels > 2))) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2253 | { |
| 2254 | _engineStatisticsPtr->SetLastError( |
| 2255 | VE_BAD_ARGUMENT, kTraceError, |
| 2256 | "StartRecordingPlayout() invalid compression"); |
| 2257 | return(-1); |
| 2258 | } |
| 2259 | if(codecInst == NULL) |
| 2260 | { |
| 2261 | format = kFileFormatPcm16kHzFile; |
| 2262 | codecInst=&dummyCodec; |
| 2263 | } |
| 2264 | else if((STR_CASE_CMP(codecInst->plname,"L16") == 0) || |
| 2265 | (STR_CASE_CMP(codecInst->plname,"PCMU") == 0) || |
| 2266 | (STR_CASE_CMP(codecInst->plname,"PCMA") == 0)) |
| 2267 | { |
| 2268 | format = kFileFormatWavFile; |
| 2269 | } |
| 2270 | else |
| 2271 | { |
| 2272 | format = kFileFormatCompressedFile; |
| 2273 | } |
| 2274 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2275 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2276 | |
| 2277 | // Destroy the old instance |
| 2278 | if (_outputFileRecorderPtr) |
| 2279 | { |
| 2280 | _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
| 2281 | FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
| 2282 | _outputFileRecorderPtr = NULL; |
| 2283 | } |
| 2284 | |
| 2285 | _outputFileRecorderPtr = FileRecorder::CreateFileRecorder( |
| 2286 | _outputFileRecorderId, (const FileFormats)format); |
| 2287 | if (_outputFileRecorderPtr == NULL) |
| 2288 | { |
| 2289 | _engineStatisticsPtr->SetLastError( |
| 2290 | VE_INVALID_ARGUMENT, kTraceError, |
| 2291 | "StartRecordingPlayout() fileRecorder format isnot correct"); |
| 2292 | return -1; |
| 2293 | } |
| 2294 | |
| 2295 | if (_outputFileRecorderPtr->StartRecordingAudioFile( |
| 2296 | fileName, (const CodecInst&)*codecInst, notificationTime) != 0) |
| 2297 | { |
| 2298 | _engineStatisticsPtr->SetLastError( |
| 2299 | VE_BAD_FILE, kTraceError, |
| 2300 | "StartRecordingAudioFile() failed to start file recording"); |
| 2301 | _outputFileRecorderPtr->StopRecording(); |
| 2302 | FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
| 2303 | _outputFileRecorderPtr = NULL; |
| 2304 | return -1; |
| 2305 | } |
| 2306 | _outputFileRecorderPtr->RegisterModuleFileCallback(this); |
| 2307 | _outputFileRecording = true; |
| 2308 | |
| 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | int Channel::StartRecordingPlayout(OutStream* stream, |
| 2313 | const CodecInst* codecInst) |
| 2314 | { |
| 2315 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2316 | "Channel::StartRecordingPlayout()"); |
| 2317 | |
| 2318 | if (_outputFileRecording) |
| 2319 | { |
| 2320 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,-1), |
| 2321 | "StartRecordingPlayout() is already recording"); |
| 2322 | return 0; |
| 2323 | } |
| 2324 | |
| 2325 | FileFormats format; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2326 | const uint32_t notificationTime(0); // Not supported in VoE |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2327 | CodecInst dummyCodec={100,"L16",16000,320,1,320000}; |
| 2328 | |
| 2329 | if (codecInst != NULL && codecInst->channels != 1) |
| 2330 | { |
| 2331 | _engineStatisticsPtr->SetLastError( |
| 2332 | VE_BAD_ARGUMENT, kTraceError, |
| 2333 | "StartRecordingPlayout() invalid compression"); |
| 2334 | return(-1); |
| 2335 | } |
| 2336 | if(codecInst == NULL) |
| 2337 | { |
| 2338 | format = kFileFormatPcm16kHzFile; |
| 2339 | codecInst=&dummyCodec; |
| 2340 | } |
| 2341 | else if((STR_CASE_CMP(codecInst->plname,"L16") == 0) || |
| 2342 | (STR_CASE_CMP(codecInst->plname,"PCMU") == 0) || |
| 2343 | (STR_CASE_CMP(codecInst->plname,"PCMA") == 0)) |
| 2344 | { |
| 2345 | format = kFileFormatWavFile; |
| 2346 | } |
| 2347 | else |
| 2348 | { |
| 2349 | format = kFileFormatCompressedFile; |
| 2350 | } |
| 2351 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2352 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2353 | |
| 2354 | // Destroy the old instance |
| 2355 | if (_outputFileRecorderPtr) |
| 2356 | { |
| 2357 | _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
| 2358 | FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
| 2359 | _outputFileRecorderPtr = NULL; |
| 2360 | } |
| 2361 | |
| 2362 | _outputFileRecorderPtr = FileRecorder::CreateFileRecorder( |
| 2363 | _outputFileRecorderId, (const FileFormats)format); |
| 2364 | if (_outputFileRecorderPtr == NULL) |
| 2365 | { |
| 2366 | _engineStatisticsPtr->SetLastError( |
| 2367 | VE_INVALID_ARGUMENT, kTraceError, |
| 2368 | "StartRecordingPlayout() fileRecorder format isnot correct"); |
| 2369 | return -1; |
| 2370 | } |
| 2371 | |
| 2372 | if (_outputFileRecorderPtr->StartRecordingAudioFile(*stream, *codecInst, |
| 2373 | notificationTime) != 0) |
| 2374 | { |
| 2375 | _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, |
| 2376 | "StartRecordingPlayout() failed to " |
| 2377 | "start file recording"); |
| 2378 | _outputFileRecorderPtr->StopRecording(); |
| 2379 | FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
| 2380 | _outputFileRecorderPtr = NULL; |
| 2381 | return -1; |
| 2382 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 2383 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2384 | _outputFileRecorderPtr->RegisterModuleFileCallback(this); |
| 2385 | _outputFileRecording = true; |
| 2386 | |
| 2387 | return 0; |
| 2388 | } |
| 2389 | |
| 2390 | int Channel::StopRecordingPlayout() |
| 2391 | { |
| 2392 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 2393 | "Channel::StopRecordingPlayout()"); |
| 2394 | |
| 2395 | if (!_outputFileRecording) |
| 2396 | { |
| 2397 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,-1), |
| 2398 | "StopRecordingPlayout() isnot recording"); |
| 2399 | return -1; |
| 2400 | } |
| 2401 | |
| 2402 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2403 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2404 | |
| 2405 | if (_outputFileRecorderPtr->StopRecording() != 0) |
| 2406 | { |
| 2407 | _engineStatisticsPtr->SetLastError( |
| 2408 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 2409 | "StopRecording() could not stop recording"); |
| 2410 | return(-1); |
| 2411 | } |
| 2412 | _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
| 2413 | FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
| 2414 | _outputFileRecorderPtr = NULL; |
| 2415 | _outputFileRecording = false; |
| 2416 | |
| 2417 | return 0; |
| 2418 | } |
| 2419 | |
| 2420 | void |
| 2421 | Channel::SetMixWithMicStatus(bool mix) |
| 2422 | { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2423 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2424 | _mixFileWithMicrophone=mix; |
| 2425 | } |
| 2426 | |
| 2427 | int |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2428 | Channel::GetSpeechOutputLevel(uint32_t& level) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2429 | { |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2430 | int8_t currentLevel = _outputAudioLevel.Level(); |
| 2431 | level = static_cast<int32_t> (currentLevel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2432 | return 0; |
| 2433 | } |
| 2434 | |
| 2435 | int |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2436 | Channel::GetSpeechOutputLevelFullRange(uint32_t& level) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2437 | { |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 2438 | int16_t currentLevel = _outputAudioLevel.LevelFullRange(); |
| 2439 | level = static_cast<int32_t> (currentLevel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2440 | return 0; |
| 2441 | } |
| 2442 | |
| 2443 | int |
| 2444 | Channel::SetMute(bool enable) |
| 2445 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 2446 | CriticalSectionScoped cs(&volume_settings_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2447 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2448 | "Channel::SetMute(enable=%d)", enable); |
| 2449 | _mute = enable; |
| 2450 | return 0; |
| 2451 | } |
| 2452 | |
| 2453 | bool |
| 2454 | Channel::Mute() const |
| 2455 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 2456 | CriticalSectionScoped cs(&volume_settings_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2457 | return _mute; |
| 2458 | } |
| 2459 | |
| 2460 | int |
| 2461 | Channel::SetOutputVolumePan(float left, float right) |
| 2462 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 2463 | CriticalSectionScoped cs(&volume_settings_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2464 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2465 | "Channel::SetOutputVolumePan()"); |
| 2466 | _panLeft = left; |
| 2467 | _panRight = right; |
| 2468 | return 0; |
| 2469 | } |
| 2470 | |
| 2471 | int |
| 2472 | Channel::GetOutputVolumePan(float& left, float& right) const |
| 2473 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 2474 | CriticalSectionScoped cs(&volume_settings_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2475 | left = _panLeft; |
| 2476 | right = _panRight; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2477 | return 0; |
| 2478 | } |
| 2479 | |
| 2480 | int |
| 2481 | Channel::SetChannelOutputVolumeScaling(float scaling) |
| 2482 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 2483 | CriticalSectionScoped cs(&volume_settings_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2484 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2485 | "Channel::SetChannelOutputVolumeScaling()"); |
| 2486 | _outputGain = scaling; |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
| 2490 | int |
| 2491 | Channel::GetChannelOutputVolumeScaling(float& scaling) const |
| 2492 | { |
wu@webrtc.org | 6342066 | 2013-10-17 18:28:55 +0000 | [diff] [blame] | 2493 | CriticalSectionScoped cs(&volume_settings_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2494 | scaling = _outputGain; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2495 | return 0; |
| 2496 | } |
| 2497 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2498 | int Channel::SendTelephoneEventOutband(unsigned char eventCode, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 2499 | int lengthMs, int attenuationDb, |
| 2500 | bool playDtmfEvent) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2501 | { |
| 2502 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2503 | "Channel::SendTelephoneEventOutband(..., playDtmfEvent=%d)", |
| 2504 | playDtmfEvent); |
Fredrik Solenberg | b572768 | 2015-12-04 15:22:19 +0100 | [diff] [blame] | 2505 | if (!Sending()) { |
| 2506 | return -1; |
| 2507 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2508 | |
| 2509 | _playOutbandDtmfEvent = playDtmfEvent; |
| 2510 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 2511 | if (_rtpRtcpModule->SendTelephoneEventOutband(eventCode, lengthMs, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2512 | attenuationDb) != 0) |
| 2513 | { |
| 2514 | _engineStatisticsPtr->SetLastError( |
| 2515 | VE_SEND_DTMF_FAILED, |
| 2516 | kTraceWarning, |
| 2517 | "SendTelephoneEventOutband() failed to send event"); |
| 2518 | return -1; |
| 2519 | } |
| 2520 | return 0; |
| 2521 | } |
| 2522 | |
| 2523 | int Channel::SendTelephoneEventInband(unsigned char eventCode, |
| 2524 | int lengthMs, |
| 2525 | int attenuationDb, |
| 2526 | bool playDtmfEvent) |
| 2527 | { |
| 2528 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2529 | "Channel::SendTelephoneEventInband(..., playDtmfEvent=%d)", |
| 2530 | playDtmfEvent); |
| 2531 | |
| 2532 | _playInbandDtmfEvent = playDtmfEvent; |
| 2533 | _inbandDtmfQueue.AddDtmf(eventCode, lengthMs, attenuationDb); |
| 2534 | |
| 2535 | return 0; |
| 2536 | } |
| 2537 | |
| 2538 | int |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2539 | Channel::SetSendTelephoneEventPayloadType(unsigned char type) |
| 2540 | { |
| 2541 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2542 | "Channel::SetSendTelephoneEventPayloadType()"); |
andrew@webrtc.org | f81f9f8 | 2011-08-19 22:56:22 +0000 | [diff] [blame] | 2543 | if (type > 127) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2544 | { |
| 2545 | _engineStatisticsPtr->SetLastError( |
| 2546 | VE_INVALID_ARGUMENT, kTraceError, |
| 2547 | "SetSendTelephoneEventPayloadType() invalid type"); |
| 2548 | return -1; |
| 2549 | } |
pbos@webrtc.org | 5b10d8f | 2013-07-11 15:50:07 +0000 | [diff] [blame] | 2550 | CodecInst codec = {}; |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 2551 | codec.plfreq = 8000; |
| 2552 | codec.pltype = type; |
| 2553 | memcpy(codec.plname, "telephone-event", 16); |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 2554 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2555 | { |
henrika@webrtc.org | 4392d5f | 2013-04-17 07:34:25 +0000 | [diff] [blame] | 2556 | _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 2557 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 2558 | _engineStatisticsPtr->SetLastError( |
| 2559 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 2560 | "SetSendTelephoneEventPayloadType() failed to register send" |
| 2561 | "payload type"); |
| 2562 | return -1; |
| 2563 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2564 | } |
| 2565 | _sendTelephoneEventPayloadType = type; |
| 2566 | return 0; |
| 2567 | } |
| 2568 | |
| 2569 | int |
| 2570 | Channel::GetSendTelephoneEventPayloadType(unsigned char& type) |
| 2571 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2572 | type = _sendTelephoneEventPayloadType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2573 | return 0; |
| 2574 | } |
| 2575 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2576 | int |
| 2577 | Channel::UpdateRxVadDetection(AudioFrame& audioFrame) |
| 2578 | { |
| 2579 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2580 | "Channel::UpdateRxVadDetection()"); |
| 2581 | |
| 2582 | int vadDecision = 1; |
| 2583 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 2584 | vadDecision = (audioFrame.vad_activity_ == AudioFrame::kVadActive)? 1 : 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2585 | |
| 2586 | if ((vadDecision != _oldVadDecision) && _rxVadObserverPtr) |
| 2587 | { |
| 2588 | OnRxVadDetected(vadDecision); |
| 2589 | _oldVadDecision = vadDecision; |
| 2590 | } |
| 2591 | |
| 2592 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2593 | "Channel::UpdateRxVadDetection() => vadDecision=%d", |
| 2594 | vadDecision); |
| 2595 | return 0; |
| 2596 | } |
| 2597 | |
| 2598 | int |
| 2599 | Channel::RegisterRxVadObserver(VoERxVadCallback &observer) |
| 2600 | { |
| 2601 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2602 | "Channel::RegisterRxVadObserver()"); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2603 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2604 | |
| 2605 | if (_rxVadObserverPtr) |
| 2606 | { |
| 2607 | _engineStatisticsPtr->SetLastError( |
| 2608 | VE_INVALID_OPERATION, kTraceError, |
| 2609 | "RegisterRxVadObserver() observer already enabled"); |
| 2610 | return -1; |
| 2611 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2612 | _rxVadObserverPtr = &observer; |
| 2613 | _RxVadDetection = true; |
| 2614 | return 0; |
| 2615 | } |
| 2616 | |
| 2617 | int |
| 2618 | Channel::DeRegisterRxVadObserver() |
| 2619 | { |
| 2620 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2621 | "Channel::DeRegisterRxVadObserver()"); |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2622 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2623 | |
| 2624 | if (!_rxVadObserverPtr) |
| 2625 | { |
| 2626 | _engineStatisticsPtr->SetLastError( |
| 2627 | VE_INVALID_OPERATION, kTraceWarning, |
| 2628 | "DeRegisterRxVadObserver() observer already disabled"); |
| 2629 | return 0; |
| 2630 | } |
| 2631 | _rxVadObserverPtr = NULL; |
| 2632 | _RxVadDetection = false; |
| 2633 | return 0; |
| 2634 | } |
| 2635 | |
| 2636 | int |
| 2637 | Channel::VoiceActivityIndicator(int &activity) |
| 2638 | { |
| 2639 | activity = _sendFrameType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2640 | return 0; |
| 2641 | } |
| 2642 | |
| 2643 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
| 2644 | |
| 2645 | int |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 2646 | Channel::SetRxAgcStatus(bool enable, AgcModes mode) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2647 | { |
| 2648 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2649 | "Channel::SetRxAgcStatus(enable=%d, mode=%d)", |
| 2650 | (int)enable, (int)mode); |
| 2651 | |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 2652 | GainControl::Mode agcMode = kDefaultRxAgcMode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2653 | switch (mode) |
| 2654 | { |
| 2655 | case kAgcDefault: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2656 | break; |
| 2657 | case kAgcUnchanged: |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2658 | agcMode = rx_audioproc_->gain_control()->mode(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2659 | break; |
| 2660 | case kAgcFixedDigital: |
| 2661 | agcMode = GainControl::kFixedDigital; |
| 2662 | break; |
| 2663 | case kAgcAdaptiveDigital: |
| 2664 | agcMode =GainControl::kAdaptiveDigital; |
| 2665 | break; |
| 2666 | default: |
| 2667 | _engineStatisticsPtr->SetLastError( |
| 2668 | VE_INVALID_ARGUMENT, kTraceError, |
| 2669 | "SetRxAgcStatus() invalid Agc mode"); |
| 2670 | return -1; |
| 2671 | } |
| 2672 | |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2673 | if (rx_audioproc_->gain_control()->set_mode(agcMode) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2674 | { |
| 2675 | _engineStatisticsPtr->SetLastError( |
| 2676 | VE_APM_ERROR, kTraceError, |
| 2677 | "SetRxAgcStatus() failed to set Agc mode"); |
| 2678 | return -1; |
| 2679 | } |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2680 | if (rx_audioproc_->gain_control()->Enable(enable) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2681 | { |
| 2682 | _engineStatisticsPtr->SetLastError( |
| 2683 | VE_APM_ERROR, kTraceError, |
| 2684 | "SetRxAgcStatus() failed to set Agc state"); |
| 2685 | return -1; |
| 2686 | } |
| 2687 | |
| 2688 | _rxAgcIsEnabled = enable; |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2689 | channel_state_.SetRxApmIsEnabled(_rxAgcIsEnabled || _rxNsIsEnabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2690 | |
| 2691 | return 0; |
| 2692 | } |
| 2693 | |
| 2694 | int |
| 2695 | Channel::GetRxAgcStatus(bool& enabled, AgcModes& mode) |
| 2696 | { |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2697 | bool enable = rx_audioproc_->gain_control()->is_enabled(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2698 | GainControl::Mode agcMode = |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2699 | rx_audioproc_->gain_control()->mode(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2700 | |
| 2701 | enabled = enable; |
| 2702 | |
| 2703 | switch (agcMode) |
| 2704 | { |
| 2705 | case GainControl::kFixedDigital: |
| 2706 | mode = kAgcFixedDigital; |
| 2707 | break; |
| 2708 | case GainControl::kAdaptiveDigital: |
| 2709 | mode = kAgcAdaptiveDigital; |
| 2710 | break; |
| 2711 | default: |
| 2712 | _engineStatisticsPtr->SetLastError( |
| 2713 | VE_APM_ERROR, kTraceError, |
| 2714 | "GetRxAgcStatus() invalid Agc mode"); |
| 2715 | return -1; |
| 2716 | } |
| 2717 | |
| 2718 | return 0; |
| 2719 | } |
| 2720 | |
| 2721 | int |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 2722 | Channel::SetRxAgcConfig(AgcConfig config) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2723 | { |
| 2724 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2725 | "Channel::SetRxAgcConfig()"); |
| 2726 | |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2727 | if (rx_audioproc_->gain_control()->set_target_level_dbfs( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2728 | config.targetLeveldBOv) != 0) |
| 2729 | { |
| 2730 | _engineStatisticsPtr->SetLastError( |
| 2731 | VE_APM_ERROR, kTraceError, |
| 2732 | "SetRxAgcConfig() failed to set target peak |level|" |
| 2733 | "(or envelope) of the Agc"); |
| 2734 | return -1; |
| 2735 | } |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2736 | if (rx_audioproc_->gain_control()->set_compression_gain_db( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2737 | config.digitalCompressionGaindB) != 0) |
| 2738 | { |
| 2739 | _engineStatisticsPtr->SetLastError( |
| 2740 | VE_APM_ERROR, kTraceError, |
| 2741 | "SetRxAgcConfig() failed to set the range in |gain| the" |
| 2742 | " digital compression stage may apply"); |
| 2743 | return -1; |
| 2744 | } |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2745 | if (rx_audioproc_->gain_control()->enable_limiter( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2746 | config.limiterEnable) != 0) |
| 2747 | { |
| 2748 | _engineStatisticsPtr->SetLastError( |
| 2749 | VE_APM_ERROR, kTraceError, |
| 2750 | "SetRxAgcConfig() failed to set hard limiter to the signal"); |
| 2751 | return -1; |
| 2752 | } |
| 2753 | |
| 2754 | return 0; |
| 2755 | } |
| 2756 | |
| 2757 | int |
| 2758 | Channel::GetRxAgcConfig(AgcConfig& config) |
| 2759 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2760 | config.targetLeveldBOv = |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2761 | rx_audioproc_->gain_control()->target_level_dbfs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2762 | config.digitalCompressionGaindB = |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2763 | rx_audioproc_->gain_control()->compression_gain_db(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2764 | config.limiterEnable = |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2765 | rx_audioproc_->gain_control()->is_limiter_enabled(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2766 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2767 | return 0; |
| 2768 | } |
| 2769 | |
| 2770 | #endif // #ifdef WEBRTC_VOICE_ENGINE_AGC |
| 2771 | |
| 2772 | #ifdef WEBRTC_VOICE_ENGINE_NR |
| 2773 | |
| 2774 | int |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 2775 | Channel::SetRxNsStatus(bool enable, NsModes mode) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2776 | { |
| 2777 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 2778 | "Channel::SetRxNsStatus(enable=%d, mode=%d)", |
| 2779 | (int)enable, (int)mode); |
| 2780 | |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 2781 | NoiseSuppression::Level nsLevel = kDefaultNsMode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2782 | switch (mode) |
| 2783 | { |
| 2784 | |
| 2785 | case kNsDefault: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2786 | break; |
| 2787 | case kNsUnchanged: |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2788 | nsLevel = rx_audioproc_->noise_suppression()->level(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2789 | break; |
| 2790 | case kNsConference: |
| 2791 | nsLevel = NoiseSuppression::kHigh; |
| 2792 | break; |
| 2793 | case kNsLowSuppression: |
| 2794 | nsLevel = NoiseSuppression::kLow; |
| 2795 | break; |
| 2796 | case kNsModerateSuppression: |
| 2797 | nsLevel = NoiseSuppression::kModerate; |
| 2798 | break; |
| 2799 | case kNsHighSuppression: |
| 2800 | nsLevel = NoiseSuppression::kHigh; |
| 2801 | break; |
| 2802 | case kNsVeryHighSuppression: |
| 2803 | nsLevel = NoiseSuppression::kVeryHigh; |
| 2804 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2807 | if (rx_audioproc_->noise_suppression()->set_level(nsLevel) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2808 | != 0) |
| 2809 | { |
| 2810 | _engineStatisticsPtr->SetLastError( |
| 2811 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 2812 | "SetRxNsStatus() failed to set NS level"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2813 | return -1; |
| 2814 | } |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2815 | if (rx_audioproc_->noise_suppression()->Enable(enable) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2816 | { |
| 2817 | _engineStatisticsPtr->SetLastError( |
| 2818 | VE_APM_ERROR, kTraceError, |
andrew@webrtc.org | 6c264cc | 2013-10-04 17:54:09 +0000 | [diff] [blame] | 2819 | "SetRxNsStatus() failed to set NS state"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2820 | return -1; |
| 2821 | } |
| 2822 | |
| 2823 | _rxNsIsEnabled = enable; |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2824 | channel_state_.SetRxApmIsEnabled(_rxAgcIsEnabled || _rxNsIsEnabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2825 | |
| 2826 | return 0; |
| 2827 | } |
| 2828 | |
| 2829 | int |
| 2830 | Channel::GetRxNsStatus(bool& enabled, NsModes& mode) |
| 2831 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2832 | bool enable = |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2833 | rx_audioproc_->noise_suppression()->is_enabled(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2834 | NoiseSuppression::Level ncLevel = |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2835 | rx_audioproc_->noise_suppression()->level(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2836 | |
| 2837 | enabled = enable; |
| 2838 | |
| 2839 | switch (ncLevel) |
| 2840 | { |
| 2841 | case NoiseSuppression::kLow: |
| 2842 | mode = kNsLowSuppression; |
| 2843 | break; |
| 2844 | case NoiseSuppression::kModerate: |
| 2845 | mode = kNsModerateSuppression; |
| 2846 | break; |
| 2847 | case NoiseSuppression::kHigh: |
| 2848 | mode = kNsHighSuppression; |
| 2849 | break; |
| 2850 | case NoiseSuppression::kVeryHigh: |
| 2851 | mode = kNsVeryHighSuppression; |
| 2852 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2853 | } |
| 2854 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2855 | return 0; |
| 2856 | } |
| 2857 | |
| 2858 | #endif // #ifdef WEBRTC_VOICE_ENGINE_NR |
| 2859 | |
| 2860 | int |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2861 | Channel::SetLocalSSRC(unsigned int ssrc) |
| 2862 | { |
| 2863 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2864 | "Channel::SetLocalSSRC()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 2865 | if (channel_state_.Get().sending) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2866 | { |
| 2867 | _engineStatisticsPtr->SetLastError( |
| 2868 | VE_ALREADY_SENDING, kTraceError, |
| 2869 | "SetLocalSSRC() already sending"); |
| 2870 | return -1; |
| 2871 | } |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 2872 | _rtpRtcpModule->SetSSRC(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2873 | return 0; |
| 2874 | } |
| 2875 | |
| 2876 | int |
| 2877 | Channel::GetLocalSSRC(unsigned int& ssrc) |
| 2878 | { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 2879 | ssrc = _rtpRtcpModule->SSRC(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2880 | return 0; |
| 2881 | } |
| 2882 | |
| 2883 | int |
| 2884 | Channel::GetRemoteSSRC(unsigned int& ssrc) |
| 2885 | { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 2886 | ssrc = rtp_receiver_->SSRC(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2887 | return 0; |
| 2888 | } |
| 2889 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2890 | int Channel::SetSendAudioLevelIndicationStatus(bool enable, unsigned char id) { |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2891 | _includeAudioLevelIndication = enable; |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2892 | return SetSendRtpHeaderExtension(enable, kRtpExtensionAudioLevel, id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2893 | } |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2894 | |
wu@webrtc.org | 93fd25c | 2014-04-24 20:33:08 +0000 | [diff] [blame] | 2895 | int Channel::SetReceiveAudioLevelIndicationStatus(bool enable, |
| 2896 | unsigned char id) { |
| 2897 | rtp_header_parser_->DeregisterRtpHeaderExtension( |
| 2898 | kRtpExtensionAudioLevel); |
| 2899 | if (enable && !rtp_header_parser_->RegisterRtpHeaderExtension( |
| 2900 | kRtpExtensionAudioLevel, id)) { |
| 2901 | return -1; |
| 2902 | } |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2906 | int Channel::SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id) { |
| 2907 | return SetSendRtpHeaderExtension(enable, kRtpExtensionAbsoluteSendTime, id); |
| 2908 | } |
| 2909 | |
| 2910 | int Channel::SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id) { |
| 2911 | rtp_header_parser_->DeregisterRtpHeaderExtension( |
| 2912 | kRtpExtensionAbsoluteSendTime); |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 2913 | if (enable && !rtp_header_parser_->RegisterRtpHeaderExtension( |
| 2914 | kRtpExtensionAbsoluteSendTime, id)) { |
| 2915 | return -1; |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2916 | } |
| 2917 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2918 | } |
| 2919 | |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 2920 | void Channel::EnableSendTransportSequenceNumber(int id) { |
| 2921 | int ret = |
| 2922 | SetSendRtpHeaderExtension(true, kRtpExtensionTransportSequenceNumber, id); |
| 2923 | RTC_DCHECK_EQ(0, ret); |
| 2924 | } |
| 2925 | |
| 2926 | void Channel::SetCongestionControlObjects( |
| 2927 | RtpPacketSender* rtp_packet_sender, |
| 2928 | TransportFeedbackObserver* transport_feedback_observer, |
| 2929 | PacketRouter* packet_router) { |
| 2930 | RTC_DCHECK(feedback_observer_proxy_.get()); |
| 2931 | RTC_DCHECK(seq_num_allocator_proxy_.get()); |
| 2932 | RTC_DCHECK(rtp_packet_sender_proxy_.get()); |
| 2933 | RTC_DCHECK(packet_router != nullptr || packet_router_ != nullptr); |
| 2934 | feedback_observer_proxy_->SetTransportFeedbackObserver( |
| 2935 | transport_feedback_observer); |
| 2936 | seq_num_allocator_proxy_->SetSequenceNumberAllocator(packet_router); |
| 2937 | rtp_packet_sender_proxy_->SetPacketSender(rtp_packet_sender); |
| 2938 | _rtpRtcpModule->SetStorePacketsStatus(rtp_packet_sender != nullptr, 600); |
| 2939 | if (packet_router != nullptr) { |
| 2940 | packet_router->AddRtpModule(_rtpRtcpModule.get()); |
| 2941 | } else { |
| 2942 | packet_router_->RemoveRtpModule(_rtpRtcpModule.get()); |
| 2943 | } |
| 2944 | packet_router_ = packet_router; |
| 2945 | } |
| 2946 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 2947 | void Channel::SetRTCPStatus(bool enable) { |
| 2948 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2949 | "Channel::SetRTCPStatus()"); |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 2950 | _rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | int |
| 2954 | Channel::GetRTCPStatus(bool& enabled) |
| 2955 | { |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 2956 | RtcpMode method = _rtpRtcpModule->RTCP(); |
| 2957 | enabled = (method != RtcpMode::kOff); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2958 | return 0; |
| 2959 | } |
| 2960 | |
| 2961 | int |
| 2962 | Channel::SetRTCP_CNAME(const char cName[256]) |
| 2963 | { |
| 2964 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2965 | "Channel::SetRTCP_CNAME()"); |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 2966 | if (_rtpRtcpModule->SetCNAME(cName) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2967 | { |
| 2968 | _engineStatisticsPtr->SetLastError( |
| 2969 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 2970 | "SetRTCP_CNAME() failed to set RTCP CNAME"); |
| 2971 | return -1; |
| 2972 | } |
| 2973 | return 0; |
| 2974 | } |
| 2975 | |
| 2976 | int |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2977 | Channel::GetRemoteRTCP_CNAME(char cName[256]) |
| 2978 | { |
| 2979 | if (cName == NULL) |
| 2980 | { |
| 2981 | _engineStatisticsPtr->SetLastError( |
| 2982 | VE_INVALID_ARGUMENT, kTraceError, |
| 2983 | "GetRemoteRTCP_CNAME() invalid CNAME input buffer"); |
| 2984 | return -1; |
| 2985 | } |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 2986 | char cname[RTCP_CNAME_SIZE]; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 2987 | const uint32_t remoteSSRC = rtp_receiver_->SSRC(); |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 2988 | if (_rtpRtcpModule->RemoteCNAME(remoteSSRC, cname) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2989 | { |
| 2990 | _engineStatisticsPtr->SetLastError( |
| 2991 | VE_CANNOT_RETRIEVE_CNAME, kTraceError, |
| 2992 | "GetRemoteRTCP_CNAME() failed to retrieve remote RTCP CNAME"); |
| 2993 | return -1; |
| 2994 | } |
| 2995 | strcpy(cName, cname); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2996 | return 0; |
| 2997 | } |
| 2998 | |
| 2999 | int |
| 3000 | Channel::GetRemoteRTCPData( |
| 3001 | unsigned int& NTPHigh, |
| 3002 | unsigned int& NTPLow, |
| 3003 | unsigned int& timestamp, |
| 3004 | unsigned int& playoutTimestamp, |
| 3005 | unsigned int* jitter, |
| 3006 | unsigned short* fractionLost) |
| 3007 | { |
| 3008 | // --- Information from sender info in received Sender Reports |
| 3009 | |
| 3010 | RTCPSenderInfo senderInfo; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 3011 | if (_rtpRtcpModule->RemoteRTCPStat(&senderInfo) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3012 | { |
| 3013 | _engineStatisticsPtr->SetLastError( |
| 3014 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
wu@webrtc.org | fcd12b3 | 2011-09-15 20:49:50 +0000 | [diff] [blame] | 3015 | "GetRemoteRTCPData() failed to retrieve sender info for remote " |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3016 | "side"); |
| 3017 | return -1; |
| 3018 | } |
| 3019 | |
| 3020 | // We only utilize 12 out of 20 bytes in the sender info (ignores packet |
| 3021 | // and octet count) |
| 3022 | NTPHigh = senderInfo.NTPseconds; |
| 3023 | NTPLow = senderInfo.NTPfraction; |
| 3024 | timestamp = senderInfo.RTPtimeStamp; |
| 3025 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3026 | // --- Locally derived information |
| 3027 | |
| 3028 | // This value is updated on each incoming RTCP packet (0 when no packet |
| 3029 | // has been received) |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3030 | playoutTimestamp = playout_timestamp_rtcp_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3031 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3032 | if (NULL != jitter || NULL != fractionLost) |
| 3033 | { |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3034 | // Get all RTCP receiver report blocks that have been received on this |
| 3035 | // channel. If we receive RTP packets from a remote source we know the |
| 3036 | // remote SSRC and use the report block from him. |
| 3037 | // Otherwise use the first report block. |
| 3038 | std::vector<RTCPReportBlock> remote_stats; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 3039 | if (_rtpRtcpModule->RemoteRTCPStat(&remote_stats) != 0 || |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3040 | remote_stats.empty()) { |
| 3041 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3042 | VoEId(_instanceId, _channelId), |
| 3043 | "GetRemoteRTCPData() failed to measure statistics due" |
| 3044 | " to lack of received RTP and/or RTCP packets"); |
| 3045 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3046 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3047 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3048 | uint32_t remoteSSRC = rtp_receiver_->SSRC(); |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3049 | std::vector<RTCPReportBlock>::const_iterator it = remote_stats.begin(); |
| 3050 | for (; it != remote_stats.end(); ++it) { |
| 3051 | if (it->remoteSSRC == remoteSSRC) |
| 3052 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3053 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3054 | |
| 3055 | if (it == remote_stats.end()) { |
| 3056 | // If we have not received any RTCP packets from this SSRC it probably |
| 3057 | // means that we have not received any RTP packets. |
| 3058 | // Use the first received report block instead. |
| 3059 | it = remote_stats.begin(); |
| 3060 | remoteSSRC = it->remoteSSRC; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3061 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3062 | |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 3063 | if (jitter) { |
| 3064 | *jitter = it->jitter; |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 3065 | } |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 3066 | |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 3067 | if (fractionLost) { |
| 3068 | *fractionLost = it->fractionLost; |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 3069 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3070 | } |
| 3071 | return 0; |
| 3072 | } |
| 3073 | |
| 3074 | int |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 3075 | Channel::SendApplicationDefinedRTCPPacket(unsigned char subType, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3076 | unsigned int name, |
| 3077 | const char* data, |
| 3078 | unsigned short dataLengthInBytes) |
| 3079 | { |
| 3080 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3081 | "Channel::SendApplicationDefinedRTCPPacket()"); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 3082 | if (!channel_state_.Get().sending) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3083 | { |
| 3084 | _engineStatisticsPtr->SetLastError( |
| 3085 | VE_NOT_SENDING, kTraceError, |
| 3086 | "SendApplicationDefinedRTCPPacket() not sending"); |
| 3087 | return -1; |
| 3088 | } |
| 3089 | if (NULL == data) |
| 3090 | { |
| 3091 | _engineStatisticsPtr->SetLastError( |
| 3092 | VE_INVALID_ARGUMENT, kTraceError, |
| 3093 | "SendApplicationDefinedRTCPPacket() invalid data value"); |
| 3094 | return -1; |
| 3095 | } |
| 3096 | if (dataLengthInBytes % 4 != 0) |
| 3097 | { |
| 3098 | _engineStatisticsPtr->SetLastError( |
| 3099 | VE_INVALID_ARGUMENT, kTraceError, |
| 3100 | "SendApplicationDefinedRTCPPacket() invalid length value"); |
| 3101 | return -1; |
| 3102 | } |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 3103 | RtcpMode status = _rtpRtcpModule->RTCP(); |
| 3104 | if (status == RtcpMode::kOff) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3105 | _engineStatisticsPtr->SetLastError( |
| 3106 | VE_RTCP_ERROR, kTraceError, |
| 3107 | "SendApplicationDefinedRTCPPacket() RTCP is disabled"); |
| 3108 | return -1; |
| 3109 | } |
| 3110 | |
| 3111 | // Create and schedule the RTCP APP packet for transmission |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 3112 | if (_rtpRtcpModule->SetRTCPApplicationSpecificData( |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3113 | subType, |
| 3114 | name, |
| 3115 | (const unsigned char*) data, |
| 3116 | dataLengthInBytes) != 0) |
| 3117 | { |
| 3118 | _engineStatisticsPtr->SetLastError( |
| 3119 | VE_SEND_ERROR, kTraceError, |
| 3120 | "SendApplicationDefinedRTCPPacket() failed to send RTCP packet"); |
| 3121 | return -1; |
| 3122 | } |
| 3123 | return 0; |
| 3124 | } |
| 3125 | |
| 3126 | int |
| 3127 | Channel::GetRTPStatistics( |
| 3128 | unsigned int& averageJitterMs, |
| 3129 | unsigned int& maxJitterMs, |
| 3130 | unsigned int& discardedPackets) |
| 3131 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3132 | // The jitter statistics is updated for each received RTP packet and is |
| 3133 | // based on received packets. |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 3134 | if (_rtpRtcpModule->RTCP() == RtcpMode::kOff) { |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 3135 | // If RTCP is off, there is no timed thread in the RTCP module regularly |
| 3136 | // generating new stats, trigger the update manually here instead. |
| 3137 | StreamStatistician* statistician = |
| 3138 | rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC()); |
| 3139 | if (statistician) { |
| 3140 | // Don't use returned statistics, use data from proxy instead so that |
| 3141 | // max jitter can be fetched atomically. |
| 3142 | RtcpStatistics s; |
| 3143 | statistician->GetStatistics(&s, true); |
| 3144 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3145 | } |
| 3146 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 3147 | ChannelStatistics stats = statistics_proxy_->GetStats(); |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 3148 | const int32_t playoutFrequency = audio_coding_->PlayoutFrequency(); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 3149 | if (playoutFrequency > 0) { |
| 3150 | // Scale RTP statistics given the current playout frequency |
| 3151 | maxJitterMs = stats.max_jitter / (playoutFrequency / 1000); |
| 3152 | averageJitterMs = stats.rtcp.jitter / (playoutFrequency / 1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | discardedPackets = _numberOfDiscardedPackets; |
| 3156 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3157 | return 0; |
| 3158 | } |
| 3159 | |
henrika@webrtc.org | 8a2fc88 | 2012-08-22 08:53:55 +0000 | [diff] [blame] | 3160 | int Channel::GetRemoteRTCPReportBlocks( |
| 3161 | std::vector<ReportBlock>* report_blocks) { |
| 3162 | if (report_blocks == NULL) { |
| 3163 | _engineStatisticsPtr->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
| 3164 | "GetRemoteRTCPReportBlock()s invalid report_blocks."); |
| 3165 | return -1; |
| 3166 | } |
| 3167 | |
| 3168 | // Get the report blocks from the latest received RTCP Sender or Receiver |
| 3169 | // Report. Each element in the vector contains the sender's SSRC and a |
| 3170 | // report block according to RFC 3550. |
| 3171 | std::vector<RTCPReportBlock> rtcp_report_blocks; |
| 3172 | if (_rtpRtcpModule->RemoteRTCPStat(&rtcp_report_blocks) != 0) { |
henrika@webrtc.org | 8a2fc88 | 2012-08-22 08:53:55 +0000 | [diff] [blame] | 3173 | return -1; |
| 3174 | } |
| 3175 | |
| 3176 | if (rtcp_report_blocks.empty()) |
| 3177 | return 0; |
| 3178 | |
| 3179 | std::vector<RTCPReportBlock>::const_iterator it = rtcp_report_blocks.begin(); |
| 3180 | for (; it != rtcp_report_blocks.end(); ++it) { |
| 3181 | ReportBlock report_block; |
| 3182 | report_block.sender_SSRC = it->remoteSSRC; |
| 3183 | report_block.source_SSRC = it->sourceSSRC; |
| 3184 | report_block.fraction_lost = it->fractionLost; |
| 3185 | report_block.cumulative_num_packets_lost = it->cumulativeLost; |
| 3186 | report_block.extended_highest_sequence_number = it->extendedHighSeqNum; |
| 3187 | report_block.interarrival_jitter = it->jitter; |
| 3188 | report_block.last_SR_timestamp = it->lastSR; |
| 3189 | report_block.delay_since_last_SR = it->delaySinceLastSR; |
| 3190 | report_blocks->push_back(report_block); |
| 3191 | } |
| 3192 | return 0; |
| 3193 | } |
| 3194 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3195 | int |
| 3196 | Channel::GetRTPStatistics(CallStatistics& stats) |
| 3197 | { |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 3198 | // --- RtcpStatistics |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3199 | |
| 3200 | // The jitter statistics is updated for each received RTP packet and is |
| 3201 | // based on received packets. |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 3202 | RtcpStatistics statistics; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 3203 | StreamStatistician* statistician = |
| 3204 | rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC()); |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 3205 | if (!statistician || |
| 3206 | !statistician->GetStatistics( |
| 3207 | &statistics, _rtpRtcpModule->RTCP() == RtcpMode::kOff)) { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3208 | _engineStatisticsPtr->SetLastError( |
| 3209 | VE_CANNOT_RETRIEVE_RTP_STAT, kTraceWarning, |
| 3210 | "GetRTPStatistics() failed to read RTP statistics from the " |
| 3211 | "RTP/RTCP module"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3214 | stats.fractionLost = statistics.fraction_lost; |
| 3215 | stats.cumulativeLost = statistics.cumulative_lost; |
| 3216 | stats.extendedMax = statistics.extended_max_sequence_number; |
| 3217 | stats.jitterSamples = statistics.jitter; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3218 | |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 3219 | // --- RTT |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3220 | stats.rttMs = GetRTT(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3221 | |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 3222 | // --- Data counters |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3223 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 3224 | size_t bytesSent(0); |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3225 | uint32_t packetsSent(0); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 3226 | size_t bytesReceived(0); |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3227 | uint32_t packetsReceived(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3228 | |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 3229 | if (statistician) { |
| 3230 | statistician->GetDataCounters(&bytesReceived, &packetsReceived); |
| 3231 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3232 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 3233 | if (_rtpRtcpModule->DataCountersRTP(&bytesSent, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3234 | &packetsSent) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3235 | { |
| 3236 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3237 | VoEId(_instanceId, _channelId), |
| 3238 | "GetRTPStatistics() failed to retrieve RTP datacounters =>" |
wu@webrtc.org | fcd12b3 | 2011-09-15 20:49:50 +0000 | [diff] [blame] | 3239 | " output will not be complete"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | stats.bytesSent = bytesSent; |
| 3243 | stats.packetsSent = packetsSent; |
| 3244 | stats.bytesReceived = bytesReceived; |
| 3245 | stats.packetsReceived = packetsReceived; |
| 3246 | |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 3247 | // --- Timestamps |
| 3248 | { |
| 3249 | CriticalSectionScoped lock(ts_stats_lock_.get()); |
| 3250 | stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_; |
| 3251 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3252 | return 0; |
| 3253 | } |
| 3254 | |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3255 | int Channel::SetREDStatus(bool enable, int redPayloadtype) { |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 3256 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3257 | "Channel::SetREDStatus()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3258 | |
turaj@webrtc.org | 8c8ad85 | 2013-01-31 18:20:17 +0000 | [diff] [blame] | 3259 | if (enable) { |
| 3260 | if (redPayloadtype < 0 || redPayloadtype > 127) { |
| 3261 | _engineStatisticsPtr->SetLastError( |
| 3262 | VE_PLTYPE_ERROR, kTraceError, |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3263 | "SetREDStatus() invalid RED payload type"); |
turaj@webrtc.org | 8c8ad85 | 2013-01-31 18:20:17 +0000 | [diff] [blame] | 3264 | return -1; |
| 3265 | } |
| 3266 | |
| 3267 | if (SetRedPayloadType(redPayloadtype) < 0) { |
| 3268 | _engineStatisticsPtr->SetLastError( |
| 3269 | VE_CODEC_ERROR, kTraceError, |
| 3270 | "SetSecondarySendCodec() Failed to register RED ACM"); |
| 3271 | return -1; |
| 3272 | } |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 3273 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3274 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 3275 | if (audio_coding_->SetREDStatus(enable) != 0) { |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 3276 | _engineStatisticsPtr->SetLastError( |
| 3277 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 3278 | "SetREDStatus() failed to set RED state in the ACM"); |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 3279 | return -1; |
| 3280 | } |
| 3281 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | int |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3285 | Channel::GetREDStatus(bool& enabled, int& redPayloadtype) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3286 | { |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 3287 | enabled = audio_coding_->REDStatus(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3288 | if (enabled) |
| 3289 | { |
danilchap | 5c1def8 | 2015-12-10 09:51:54 -0800 | [diff] [blame] | 3290 | int8_t payloadType = 0; |
| 3291 | if (_rtpRtcpModule->SendREDPayloadType(&payloadType) != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3292 | _engineStatisticsPtr->SetLastError( |
| 3293 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3294 | "GetREDStatus() failed to retrieve RED PT from RTP/RTCP " |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3295 | "module"); |
| 3296 | return -1; |
| 3297 | } |
pkasting@chromium.org | df9a41d | 2015-01-26 22:35:29 +0000 | [diff] [blame] | 3298 | redPayloadtype = payloadType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3299 | return 0; |
| 3300 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3301 | return 0; |
| 3302 | } |
| 3303 | |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3304 | int Channel::SetCodecFECStatus(bool enable) { |
| 3305 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3306 | "Channel::SetCodecFECStatus()"); |
| 3307 | |
| 3308 | if (audio_coding_->SetCodecFEC(enable) != 0) { |
| 3309 | _engineStatisticsPtr->SetLastError( |
| 3310 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 3311 | "SetCodecFECStatus() failed to set FEC state"); |
| 3312 | return -1; |
| 3313 | } |
| 3314 | return 0; |
| 3315 | } |
| 3316 | |
| 3317 | bool Channel::GetCodecFECStatus() { |
| 3318 | bool enabled = audio_coding_->CodecFEC(); |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3319 | return enabled; |
| 3320 | } |
| 3321 | |
pwestin@webrtc.org | db24995 | 2013-06-05 15:33:20 +0000 | [diff] [blame] | 3322 | void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) { |
| 3323 | // None of these functions can fail. |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 3324 | // If pacing is enabled we always store packets. |
| 3325 | if (!pacing_enabled_) |
| 3326 | _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 3327 | rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets); |
| 3328 | rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 3329 | if (enable) |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 3330 | audio_coding_->EnableNack(maxNumberOfPackets); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 3331 | else |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 3332 | audio_coding_->DisableNack(); |
pwestin@webrtc.org | db24995 | 2013-06-05 15:33:20 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 3335 | // Called when we are missing one or more packets. |
| 3336 | int Channel::ResendPackets(const uint16_t* sequence_numbers, int length) { |
pwestin@webrtc.org | db24995 | 2013-06-05 15:33:20 +0000 | [diff] [blame] | 3337 | return _rtpRtcpModule->SendNACK(sequence_numbers, length); |
| 3338 | } |
| 3339 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3340 | uint32_t |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 3341 | Channel::Demultiplex(const AudioFrame& audioFrame) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3342 | { |
| 3343 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 3344 | "Channel::Demultiplex()"); |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 3345 | _audioFrame.CopyFrom(audioFrame); |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3346 | _audioFrame.id_ = _channelId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3347 | return 0; |
| 3348 | } |
| 3349 | |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 3350 | void Channel::Demultiplex(const int16_t* audio_data, |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 3351 | int sample_rate, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3352 | size_t number_of_frames, |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 3353 | int number_of_channels) { |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 3354 | CodecInst codec; |
| 3355 | GetSendCodec(codec); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 3356 | |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 3357 | // Never upsample or upmix the capture signal here. This should be done at the |
| 3358 | // end of the send chain. |
| 3359 | _audioFrame.sample_rate_hz_ = std::min(codec.plfreq, sample_rate); |
| 3360 | _audioFrame.num_channels_ = std::min(number_of_channels, codec.channels); |
| 3361 | RemixAndResample(audio_data, number_of_frames, number_of_channels, |
| 3362 | sample_rate, &input_resampler_, &_audioFrame); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 3363 | } |
| 3364 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3365 | uint32_t |
xians@google.com | 0b0665a | 2011-08-08 08:18:44 +0000 | [diff] [blame] | 3366 | Channel::PrepareEncodeAndSend(int mixingFrequency) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3367 | { |
| 3368 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3369 | "Channel::PrepareEncodeAndSend()"); |
| 3370 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3371 | if (_audioFrame.samples_per_channel_ == 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3372 | { |
| 3373 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3374 | "Channel::PrepareEncodeAndSend() invalid audio frame"); |
tommi@webrtc.org | eec6ecd | 2014-07-11 19:09:59 +0000 | [diff] [blame] | 3375 | return 0xFFFFFFFF; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3376 | } |
| 3377 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 3378 | if (channel_state_.Get().input_file_playing) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3379 | { |
| 3380 | MixOrReplaceAudioWithFile(mixingFrequency); |
| 3381 | } |
| 3382 | |
andrew@webrtc.org | 21299d4 | 2014-05-14 19:00:59 +0000 | [diff] [blame] | 3383 | bool is_muted = Mute(); // Cache locally as Mute() takes a lock. |
| 3384 | if (is_muted) { |
| 3385 | AudioFrameOperations::Mute(_audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 3388 | if (channel_state_.Get().input_external_media) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3389 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 3390 | CriticalSectionScoped cs(&_callbackCritSect); |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3391 | const bool isStereo = (_audioFrame.num_channels_ == 2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3392 | if (_inputExternalMediaCallbackPtr) |
| 3393 | { |
| 3394 | _inputExternalMediaCallbackPtr->Process( |
| 3395 | _channelId, |
| 3396 | kRecordingPerChannel, |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3397 | (int16_t*)_audioFrame.data_, |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3398 | _audioFrame.samples_per_channel_, |
| 3399 | _audioFrame.sample_rate_hz_, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3400 | isStereo); |
| 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | InsertInbandDtmfTone(); |
| 3405 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 3406 | if (_includeAudioLevelIndication) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3407 | size_t length = |
| 3408 | _audioFrame.samples_per_channel_ * _audioFrame.num_channels_; |
andrew@webrtc.org | 21299d4 | 2014-05-14 19:00:59 +0000 | [diff] [blame] | 3409 | if (is_muted) { |
| 3410 | rms_level_.ProcessMuted(length); |
| 3411 | } else { |
| 3412 | rms_level_.Process(_audioFrame.data_, length); |
| 3413 | } |
andrew@webrtc.org | 755b04a | 2011-11-15 16:57:56 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3416 | return 0; |
| 3417 | } |
| 3418 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3419 | uint32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3420 | Channel::EncodeAndSend() |
| 3421 | { |
| 3422 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3423 | "Channel::EncodeAndSend()"); |
| 3424 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3425 | assert(_audioFrame.num_channels_ <= 2); |
| 3426 | if (_audioFrame.samples_per_channel_ == 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3427 | { |
| 3428 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3429 | "Channel::EncodeAndSend() invalid audio frame"); |
tommi@webrtc.org | eec6ecd | 2014-07-11 19:09:59 +0000 | [diff] [blame] | 3430 | return 0xFFFFFFFF; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3433 | _audioFrame.id_ = _channelId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3434 | |
| 3435 | // --- Add 10ms of raw (PCM) audio data to the encoder @ 32kHz. |
| 3436 | |
| 3437 | // The ACM resamples internally. |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3438 | _audioFrame.timestamp_ = _timeStamp; |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 3439 | // This call will trigger AudioPacketizationCallback::SendData if encoding |
| 3440 | // is done and payload is ready for packetization and transmission. |
| 3441 | // Otherwise, it will return without invoking the callback. |
| 3442 | if (audio_coding_->Add10MsData((AudioFrame&)_audioFrame) < 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3443 | { |
| 3444 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3445 | "Channel::EncodeAndSend() ACM encoding failed"); |
tommi@webrtc.org | eec6ecd | 2014-07-11 19:09:59 +0000 | [diff] [blame] | 3446 | return 0xFFFFFFFF; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
Peter Kasting | b7e5054 | 2015-06-11 12:55:50 -0700 | [diff] [blame] | 3449 | _timeStamp += static_cast<uint32_t>(_audioFrame.samples_per_channel_); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 3450 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3453 | void Channel::DisassociateSendChannel(int channel_id) { |
| 3454 | CriticalSectionScoped lock(assoc_send_channel_lock_.get()); |
| 3455 | Channel* channel = associate_send_channel_.channel(); |
| 3456 | if (channel && channel->ChannelId() == channel_id) { |
| 3457 | // If this channel is associated with a send channel of the specified |
| 3458 | // Channel ID, disassociate with it. |
| 3459 | ChannelOwner ref(NULL); |
| 3460 | associate_send_channel_ = ref; |
| 3461 | } |
| 3462 | } |
| 3463 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3464 | int Channel::RegisterExternalMediaProcessing( |
| 3465 | ProcessingTypes type, |
| 3466 | VoEMediaProcess& processObject) |
| 3467 | { |
| 3468 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3469 | "Channel::RegisterExternalMediaProcessing()"); |
| 3470 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 3471 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3472 | |
| 3473 | if (kPlaybackPerChannel == type) |
| 3474 | { |
| 3475 | if (_outputExternalMediaCallbackPtr) |
| 3476 | { |
| 3477 | _engineStatisticsPtr->SetLastError( |
| 3478 | VE_INVALID_OPERATION, kTraceError, |
| 3479 | "Channel::RegisterExternalMediaProcessing() " |
| 3480 | "output external media already enabled"); |
| 3481 | return -1; |
| 3482 | } |
| 3483 | _outputExternalMediaCallbackPtr = &processObject; |
| 3484 | _outputExternalMedia = true; |
| 3485 | } |
| 3486 | else if (kRecordingPerChannel == type) |
| 3487 | { |
| 3488 | if (_inputExternalMediaCallbackPtr) |
| 3489 | { |
| 3490 | _engineStatisticsPtr->SetLastError( |
| 3491 | VE_INVALID_OPERATION, kTraceError, |
| 3492 | "Channel::RegisterExternalMediaProcessing() " |
| 3493 | "output external media already enabled"); |
| 3494 | return -1; |
| 3495 | } |
| 3496 | _inputExternalMediaCallbackPtr = &processObject; |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 3497 | channel_state_.SetInputExternalMedia(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3498 | } |
| 3499 | return 0; |
| 3500 | } |
| 3501 | |
| 3502 | int Channel::DeRegisterExternalMediaProcessing(ProcessingTypes type) |
| 3503 | { |
| 3504 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3505 | "Channel::DeRegisterExternalMediaProcessing()"); |
| 3506 | |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 3507 | CriticalSectionScoped cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3508 | |
| 3509 | if (kPlaybackPerChannel == type) |
| 3510 | { |
| 3511 | if (!_outputExternalMediaCallbackPtr) |
| 3512 | { |
| 3513 | _engineStatisticsPtr->SetLastError( |
| 3514 | VE_INVALID_OPERATION, kTraceWarning, |
| 3515 | "Channel::DeRegisterExternalMediaProcessing() " |
| 3516 | "output external media already disabled"); |
| 3517 | return 0; |
| 3518 | } |
| 3519 | _outputExternalMedia = false; |
| 3520 | _outputExternalMediaCallbackPtr = NULL; |
| 3521 | } |
| 3522 | else if (kRecordingPerChannel == type) |
| 3523 | { |
| 3524 | if (!_inputExternalMediaCallbackPtr) |
| 3525 | { |
| 3526 | _engineStatisticsPtr->SetLastError( |
| 3527 | VE_INVALID_OPERATION, kTraceWarning, |
| 3528 | "Channel::DeRegisterExternalMediaProcessing() " |
| 3529 | "input external media already disabled"); |
| 3530 | return 0; |
| 3531 | } |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 3532 | channel_state_.SetInputExternalMedia(false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3533 | _inputExternalMediaCallbackPtr = NULL; |
| 3534 | } |
| 3535 | |
| 3536 | return 0; |
| 3537 | } |
| 3538 | |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 3539 | int Channel::SetExternalMixing(bool enabled) { |
| 3540 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3541 | "Channel::SetExternalMixing(enabled=%d)", enabled); |
| 3542 | |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 3543 | if (channel_state_.Get().playing) |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 3544 | { |
| 3545 | _engineStatisticsPtr->SetLastError( |
| 3546 | VE_INVALID_OPERATION, kTraceError, |
| 3547 | "Channel::SetExternalMixing() " |
| 3548 | "external mixing cannot be changed while playing."); |
| 3549 | return -1; |
| 3550 | } |
| 3551 | |
| 3552 | _externalMixing = enabled; |
| 3553 | |
| 3554 | return 0; |
| 3555 | } |
| 3556 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3557 | int |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3558 | Channel::GetNetworkStatistics(NetworkStatistics& stats) |
| 3559 | { |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 3560 | return audio_coding_->GetNetworkStatistics(&stats); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 +0000 | [diff] [blame] | 3563 | void Channel::GetDecodingCallStatistics(AudioDecodingCallStats* stats) const { |
| 3564 | audio_coding_->GetDecodingCallStatistics(stats); |
| 3565 | } |
| 3566 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3567 | bool Channel::GetDelayEstimate(int* jitter_buffer_delay_ms, |
| 3568 | int* playout_buffer_delay_ms) const { |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3569 | CriticalSectionScoped cs(video_sync_lock_.get()); |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3570 | if (_average_jitter_buffer_delay_us == 0) { |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3571 | return false; |
| 3572 | } |
| 3573 | *jitter_buffer_delay_ms = (_average_jitter_buffer_delay_us + 500) / 1000 + |
| 3574 | _recPacketDelayMs; |
| 3575 | *playout_buffer_delay_ms = playout_delay_ms_; |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3576 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3577 | } |
| 3578 | |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 3579 | uint32_t Channel::GetDelayEstimate() const { |
| 3580 | int jitter_buffer_delay_ms = 0; |
| 3581 | int playout_buffer_delay_ms = 0; |
| 3582 | GetDelayEstimate(&jitter_buffer_delay_ms, &playout_buffer_delay_ms); |
| 3583 | return jitter_buffer_delay_ms + playout_buffer_delay_ms; |
| 3584 | } |
| 3585 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3586 | int Channel::LeastRequiredDelayMs() const { |
| 3587 | return audio_coding_->LeastRequiredDelayMs(); |
| 3588 | } |
| 3589 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3590 | int |
| 3591 | Channel::SetMinimumPlayoutDelay(int delayMs) |
| 3592 | { |
| 3593 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3594 | "Channel::SetMinimumPlayoutDelay()"); |
| 3595 | if ((delayMs < kVoiceEngineMinMinPlayoutDelayMs) || |
| 3596 | (delayMs > kVoiceEngineMaxMinPlayoutDelayMs)) |
| 3597 | { |
| 3598 | _engineStatisticsPtr->SetLastError( |
| 3599 | VE_INVALID_ARGUMENT, kTraceError, |
| 3600 | "SetMinimumPlayoutDelay() invalid min delay"); |
| 3601 | return -1; |
| 3602 | } |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 3603 | if (audio_coding_->SetMinimumPlayoutDelay(delayMs) != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3604 | { |
| 3605 | _engineStatisticsPtr->SetLastError( |
| 3606 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 3607 | "SetMinimumPlayoutDelay() failed to set min playout delay"); |
| 3608 | return -1; |
| 3609 | } |
| 3610 | return 0; |
| 3611 | } |
| 3612 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3613 | int Channel::GetPlayoutTimestamp(unsigned int& timestamp) { |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3614 | uint32_t playout_timestamp_rtp = 0; |
| 3615 | { |
| 3616 | CriticalSectionScoped cs(video_sync_lock_.get()); |
| 3617 | playout_timestamp_rtp = playout_timestamp_rtp_; |
| 3618 | } |
| 3619 | if (playout_timestamp_rtp == 0) { |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3620 | _engineStatisticsPtr->SetLastError( |
| 3621 | VE_CANNOT_RETRIEVE_VALUE, kTraceError, |
| 3622 | "GetPlayoutTimestamp() failed to retrieve timestamp"); |
| 3623 | return -1; |
| 3624 | } |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3625 | timestamp = playout_timestamp_rtp; |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3626 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 3629 | int Channel::SetInitTimestamp(unsigned int timestamp) { |
| 3630 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3631 | "Channel::SetInitTimestamp()"); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 3632 | if (channel_state_.Get().sending) { |
| 3633 | _engineStatisticsPtr->SetLastError(VE_SENDING, kTraceError, |
| 3634 | "SetInitTimestamp() already sending"); |
| 3635 | return -1; |
| 3636 | } |
| 3637 | _rtpRtcpModule->SetStartTimestamp(timestamp); |
| 3638 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 3641 | int Channel::SetInitSequenceNumber(short sequenceNumber) { |
| 3642 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3643 | "Channel::SetInitSequenceNumber()"); |
| 3644 | if (channel_state_.Get().sending) { |
| 3645 | _engineStatisticsPtr->SetLastError( |
| 3646 | VE_SENDING, kTraceError, "SetInitSequenceNumber() already sending"); |
| 3647 | return -1; |
| 3648 | } |
| 3649 | _rtpRtcpModule->SetSequenceNumber(sequenceNumber); |
| 3650 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | int |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3654 | Channel::GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3655 | { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3656 | *rtpRtcpModule = _rtpRtcpModule.get(); |
| 3657 | *rtp_receiver = rtp_receiver_.get(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3658 | return 0; |
| 3659 | } |
| 3660 | |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 3661 | // TODO(andrew): refactor Mix functions here and in transmit_mixer.cc to use |
| 3662 | // a shared helper. |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3663 | int32_t |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 3664 | Channel::MixOrReplaceAudioWithFile(int mixingFrequency) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3665 | { |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 3666 | rtc::scoped_ptr<int16_t[]> fileBuffer(new int16_t[640]); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3667 | size_t fileSamples(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3668 | |
| 3669 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 3670 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3671 | |
| 3672 | if (_inputFilePlayerPtr == NULL) |
| 3673 | { |
| 3674 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3675 | VoEId(_instanceId, _channelId), |
| 3676 | "Channel::MixOrReplaceAudioWithFile() fileplayer" |
| 3677 | " doesnt exist"); |
| 3678 | return -1; |
| 3679 | } |
| 3680 | |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 3681 | if (_inputFilePlayerPtr->Get10msAudioFromFile(fileBuffer.get(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3682 | fileSamples, |
| 3683 | mixingFrequency) == -1) |
| 3684 | { |
| 3685 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3686 | VoEId(_instanceId, _channelId), |
| 3687 | "Channel::MixOrReplaceAudioWithFile() file mixing " |
| 3688 | "failed"); |
| 3689 | return -1; |
| 3690 | } |
| 3691 | if (fileSamples == 0) |
| 3692 | { |
| 3693 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3694 | VoEId(_instanceId, _channelId), |
| 3695 | "Channel::MixOrReplaceAudioWithFile() file is ended"); |
| 3696 | return 0; |
| 3697 | } |
| 3698 | } |
| 3699 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3700 | assert(_audioFrame.samples_per_channel_ == fileSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3701 | |
| 3702 | if (_mixFileWithMicrophone) |
| 3703 | { |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 3704 | // Currently file stream is always mono. |
| 3705 | // TODO(xians): Change the code when FilePlayer supports real stereo. |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 3706 | MixWithSat(_audioFrame.data_, |
| 3707 | _audioFrame.num_channels_, |
| 3708 | fileBuffer.get(), |
| 3709 | 1, |
| 3710 | fileSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3711 | } |
| 3712 | else |
| 3713 | { |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 3714 | // Replace ACM audio with file. |
| 3715 | // Currently file stream is always mono. |
| 3716 | // TODO(xians): Change the code when FilePlayer supports real stereo. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3717 | _audioFrame.UpdateFrame(_channelId, |
tommi@webrtc.org | eec6ecd | 2014-07-11 19:09:59 +0000 | [diff] [blame] | 3718 | 0xFFFFFFFF, |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 3719 | fileBuffer.get(), |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 3720 | fileSamples, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3721 | mixingFrequency, |
| 3722 | AudioFrame::kNormalSpeech, |
| 3723 | AudioFrame::kVadUnknown, |
| 3724 | 1); |
| 3725 | |
| 3726 | } |
| 3727 | return 0; |
| 3728 | } |
| 3729 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3730 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3731 | Channel::MixAudioWithFile(AudioFrame& audioFrame, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 3732 | int mixingFrequency) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3733 | { |
minyue@webrtc.org | 2a8df7c | 2014-08-06 10:05:19 +0000 | [diff] [blame] | 3734 | assert(mixingFrequency <= 48000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3735 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 3736 | rtc::scoped_ptr<int16_t[]> fileBuffer(new int16_t[960]); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3737 | size_t fileSamples(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3738 | |
| 3739 | { |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 3740 | CriticalSectionScoped cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3741 | |
| 3742 | if (_outputFilePlayerPtr == NULL) |
| 3743 | { |
| 3744 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3745 | VoEId(_instanceId, _channelId), |
| 3746 | "Channel::MixAudioWithFile() file mixing failed"); |
| 3747 | return -1; |
| 3748 | } |
| 3749 | |
| 3750 | // We should get the frequency we ask for. |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 3751 | if (_outputFilePlayerPtr->Get10msAudioFromFile(fileBuffer.get(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3752 | fileSamples, |
| 3753 | mixingFrequency) == -1) |
| 3754 | { |
| 3755 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3756 | VoEId(_instanceId, _channelId), |
| 3757 | "Channel::MixAudioWithFile() file mixing failed"); |
| 3758 | return -1; |
| 3759 | } |
| 3760 | } |
| 3761 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3762 | if (audioFrame.samples_per_channel_ == fileSamples) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3763 | { |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 3764 | // Currently file stream is always mono. |
| 3765 | // TODO(xians): Change the code when FilePlayer supports real stereo. |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 3766 | MixWithSat(audioFrame.data_, |
| 3767 | audioFrame.num_channels_, |
| 3768 | fileBuffer.get(), |
| 3769 | 1, |
| 3770 | fileSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3771 | } |
| 3772 | else |
| 3773 | { |
| 3774 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,_channelId), |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3775 | "Channel::MixAudioWithFile() samples_per_channel_(%" PRIuS ") != " |
| 3776 | "fileSamples(%" PRIuS ")", |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3777 | audioFrame.samples_per_channel_, fileSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3778 | return -1; |
| 3779 | } |
| 3780 | |
| 3781 | return 0; |
| 3782 | } |
| 3783 | |
| 3784 | int |
| 3785 | Channel::InsertInbandDtmfTone() |
| 3786 | { |
niklas.enbom@webrtc.org | af26f64 | 2011-11-16 12:41:36 +0000 | [diff] [blame] | 3787 | // Check if we should start a new tone. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3788 | if (_inbandDtmfQueue.PendingDtmf() && |
| 3789 | !_inbandDtmfGenerator.IsAddingTone() && |
| 3790 | _inbandDtmfGenerator.DelaySinceLastTone() > |
| 3791 | kMinTelephoneEventSeparationMs) |
| 3792 | { |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3793 | int8_t eventCode(0); |
| 3794 | uint16_t lengthMs(0); |
| 3795 | uint8_t attenuationDb(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3796 | |
| 3797 | eventCode = _inbandDtmfQueue.NextDtmf(&lengthMs, &attenuationDb); |
| 3798 | _inbandDtmfGenerator.AddTone(eventCode, lengthMs, attenuationDb); |
| 3799 | if (_playInbandDtmfEvent) |
| 3800 | { |
| 3801 | // Add tone to output mixer using a reduced length to minimize |
| 3802 | // risk of echo. |
| 3803 | _outputMixerPtr->PlayDtmfTone(eventCode, lengthMs - 80, |
| 3804 | attenuationDb); |
| 3805 | } |
| 3806 | } |
| 3807 | |
| 3808 | if (_inbandDtmfGenerator.IsAddingTone()) |
| 3809 | { |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3810 | uint16_t frequency(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3811 | _inbandDtmfGenerator.GetSampleRate(frequency); |
| 3812 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3813 | if (frequency != _audioFrame.sample_rate_hz_) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3814 | { |
| 3815 | // Update sample rate of Dtmf tone since the mixing frequency |
| 3816 | // has changed. |
| 3817 | _inbandDtmfGenerator.SetSampleRate( |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3818 | (uint16_t) (_audioFrame.sample_rate_hz_)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3819 | // Reset the tone to be added taking the new sample rate into |
| 3820 | // account. |
| 3821 | _inbandDtmfGenerator.ResetTone(); |
| 3822 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 3823 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3824 | int16_t toneBuffer[320]; |
| 3825 | uint16_t toneSamples(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3826 | // Get 10ms tone segment and set time since last tone to zero |
| 3827 | if (_inbandDtmfGenerator.Get10msTone(toneBuffer, toneSamples) == -1) |
| 3828 | { |
| 3829 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, |
| 3830 | VoEId(_instanceId, _channelId), |
| 3831 | "Channel::EncodeAndSend() inserting Dtmf failed"); |
| 3832 | return -1; |
| 3833 | } |
| 3834 | |
niklas.enbom@webrtc.org | af26f64 | 2011-11-16 12:41:36 +0000 | [diff] [blame] | 3835 | // Replace mixed audio with DTMF tone. |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3836 | for (size_t sample = 0; |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3837 | sample < _audioFrame.samples_per_channel_; |
niklas.enbom@webrtc.org | af26f64 | 2011-11-16 12:41:36 +0000 | [diff] [blame] | 3838 | sample++) |
| 3839 | { |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 3840 | for (int channel = 0; |
| 3841 | channel < _audioFrame.num_channels_; |
niklas.enbom@webrtc.org | af26f64 | 2011-11-16 12:41:36 +0000 | [diff] [blame] | 3842 | channel++) |
| 3843 | { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 3844 | const size_t index = |
| 3845 | sample * _audioFrame.num_channels_ + channel; |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 3846 | _audioFrame.data_[index] = toneBuffer[sample]; |
niklas.enbom@webrtc.org | af26f64 | 2011-11-16 12:41:36 +0000 | [diff] [blame] | 3847 | } |
| 3848 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 3849 | |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 3850 | assert(_audioFrame.samples_per_channel_ == toneSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3851 | } else |
| 3852 | { |
| 3853 | // Add 10ms to "delay-since-last-tone" counter |
| 3854 | _inbandDtmfGenerator.UpdateDelaySinceLastTone(); |
| 3855 | } |
| 3856 | return 0; |
| 3857 | } |
| 3858 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3859 | void Channel::UpdatePlayoutTimestamp(bool rtcp) { |
| 3860 | uint32_t playout_timestamp = 0; |
| 3861 | |
| 3862 | if (audio_coding_->PlayoutTimestamp(&playout_timestamp) == -1) { |
| 3863 | // This can happen if this channel has not been received any RTP packet. In |
| 3864 | // this case, NetEq is not capable of computing playout timestamp. |
| 3865 | return; |
| 3866 | } |
| 3867 | |
| 3868 | uint16_t delay_ms = 0; |
| 3869 | if (_audioDeviceModulePtr->PlayoutDelay(&delay_ms) == -1) { |
| 3870 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3871 | "Channel::UpdatePlayoutTimestamp() failed to read playout" |
| 3872 | " delay from the ADM"); |
| 3873 | _engineStatisticsPtr->SetLastError( |
| 3874 | VE_CANNOT_RETRIEVE_VALUE, kTraceError, |
| 3875 | "UpdatePlayoutTimestamp() failed to retrieve playout delay"); |
| 3876 | return; |
| 3877 | } |
| 3878 | |
| 3879 | jitter_buffer_playout_timestamp_ = playout_timestamp; |
| 3880 | |
| 3881 | // Remove the playout delay. |
| 3882 | playout_timestamp -= (delay_ms * (GetPlayoutFrequency() / 1000)); |
| 3883 | |
| 3884 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3885 | "Channel::UpdatePlayoutTimestamp() => playoutTimestamp = %lu", |
| 3886 | playout_timestamp); |
| 3887 | |
| 3888 | { |
| 3889 | CriticalSectionScoped cs(video_sync_lock_.get()); |
| 3890 | if (rtcp) { |
| 3891 | playout_timestamp_rtcp_ = playout_timestamp; |
| 3892 | } else { |
| 3893 | playout_timestamp_rtp_ = playout_timestamp; |
| 3894 | } |
| 3895 | playout_delay_ms_ = delay_ms; |
| 3896 | } |
| 3897 | } |
| 3898 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3899 | // Called for incoming RTP packets after successful RTP header parsing. |
| 3900 | void Channel::UpdatePacketDelay(uint32_t rtp_timestamp, |
| 3901 | uint16_t sequence_number) { |
| 3902 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3903 | "Channel::UpdatePacketDelay(timestamp=%lu, sequenceNumber=%u)", |
| 3904 | rtp_timestamp, sequence_number); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3905 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3906 | // Get frequency of last received payload |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 3907 | int rtp_receive_frequency = GetPlayoutFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3908 | |
turaj@webrtc.org | 167b6df | 2013-12-13 21:05:07 +0000 | [diff] [blame] | 3909 | // |jitter_buffer_playout_timestamp_| updated in UpdatePlayoutTimestamp for |
| 3910 | // every incoming packet. |
| 3911 | uint32_t timestamp_diff_ms = (rtp_timestamp - |
| 3912 | jitter_buffer_playout_timestamp_) / (rtp_receive_frequency / 1000); |
henrik.lundin@webrtc.org | d669299 | 2014-03-20 12:04:09 +0000 | [diff] [blame] | 3913 | if (!IsNewerTimestamp(rtp_timestamp, jitter_buffer_playout_timestamp_) || |
| 3914 | timestamp_diff_ms > (2 * kVoiceEngineMaxMinPlayoutDelayMs)) { |
| 3915 | // If |jitter_buffer_playout_timestamp_| is newer than the incoming RTP |
| 3916 | // timestamp, the resulting difference is negative, but is set to zero. |
| 3917 | // This can happen when a network glitch causes a packet to arrive late, |
| 3918 | // and during long comfort noise periods with clock drift. |
| 3919 | timestamp_diff_ms = 0; |
| 3920 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3921 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3922 | uint16_t packet_delay_ms = (rtp_timestamp - _previousTimestamp) / |
| 3923 | (rtp_receive_frequency / 1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3924 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3925 | _previousTimestamp = rtp_timestamp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3926 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3927 | if (timestamp_diff_ms == 0) return; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3928 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3929 | { |
| 3930 | CriticalSectionScoped cs(video_sync_lock_.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3931 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3932 | if (packet_delay_ms >= 10 && packet_delay_ms <= 60) { |
| 3933 | _recPacketDelayMs = packet_delay_ms; |
| 3934 | } |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 3935 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3936 | if (_average_jitter_buffer_delay_us == 0) { |
| 3937 | _average_jitter_buffer_delay_us = timestamp_diff_ms * 1000; |
| 3938 | return; |
| 3939 | } |
| 3940 | |
| 3941 | // Filter average delay value using exponential filter (alpha is |
| 3942 | // 7/8). We derive 1000 *_average_jitter_buffer_delay_us here (reduces |
| 3943 | // risk of rounding error) and compensate for it in GetDelayEstimate() |
| 3944 | // later. |
| 3945 | _average_jitter_buffer_delay_us = (_average_jitter_buffer_delay_us * 7 + |
| 3946 | 1000 * timestamp_diff_ms + 500) / 8; |
| 3947 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | void |
| 3951 | Channel::RegisterReceiveCodecsToRTPModule() |
| 3952 | { |
| 3953 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), |
| 3954 | "Channel::RegisterReceiveCodecsToRTPModule()"); |
| 3955 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3956 | CodecInst codec; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 3957 | const uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3958 | |
| 3959 | for (int idx = 0; idx < nSupportedCodecs; idx++) |
| 3960 | { |
| 3961 | // Open up the RTP/RTCP receiver for all supported codecs |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 3962 | if ((audio_coding_->Codec(idx, &codec) == -1) || |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 3963 | (rtp_receiver_->RegisterReceivePayload( |
| 3964 | codec.plname, |
| 3965 | codec.pltype, |
| 3966 | codec.plfreq, |
| 3967 | codec.channels, |
| 3968 | (codec.rate < 0) ? 0 : codec.rate) == -1)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3969 | { |
Peter Boström | d5c75b1 | 2015-09-23 13:24:32 +0200 | [diff] [blame] | 3970 | WEBRTC_TRACE(kTraceWarning, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3971 | kTraceVoice, |
| 3972 | VoEId(_instanceId, _channelId), |
| 3973 | "Channel::RegisterReceiveCodecsToRTPModule() unable" |
| 3974 | " to register %s (%d/%d/%d/%d) to RTP/RTCP receiver", |
| 3975 | codec.plname, codec.pltype, codec.plfreq, |
| 3976 | codec.channels, codec.rate); |
| 3977 | } |
| 3978 | else |
| 3979 | { |
Peter Boström | d5c75b1 | 2015-09-23 13:24:32 +0200 | [diff] [blame] | 3980 | WEBRTC_TRACE(kTraceInfo, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3981 | kTraceVoice, |
| 3982 | VoEId(_instanceId, _channelId), |
| 3983 | "Channel::RegisterReceiveCodecsToRTPModule() %s " |
wu@webrtc.org | fcd12b3 | 2011-09-15 20:49:50 +0000 | [diff] [blame] | 3984 | "(%d/%d/%d/%d) has been added to the RTP/RTCP " |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3985 | "receiver", |
| 3986 | codec.plname, codec.pltype, codec.plfreq, |
| 3987 | codec.channels, codec.rate); |
| 3988 | } |
| 3989 | } |
| 3990 | } |
| 3991 | |
turaj@webrtc.org | 8c8ad85 | 2013-01-31 18:20:17 +0000 | [diff] [blame] | 3992 | // Assuming this method is called with valid payload type. |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 3993 | int Channel::SetRedPayloadType(int red_payload_type) { |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 3994 | CodecInst codec; |
| 3995 | bool found_red = false; |
| 3996 | |
| 3997 | // Get default RED settings from the ACM database |
| 3998 | const int num_codecs = AudioCodingModule::NumberOfCodecs(); |
| 3999 | for (int idx = 0; idx < num_codecs; idx++) { |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 4000 | audio_coding_->Codec(idx, &codec); |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 4001 | if (!STR_CASE_CMP(codec.plname, "RED")) { |
| 4002 | found_red = true; |
| 4003 | break; |
| 4004 | } |
| 4005 | } |
| 4006 | |
| 4007 | if (!found_red) { |
| 4008 | _engineStatisticsPtr->SetLastError( |
| 4009 | VE_CODEC_ERROR, kTraceError, |
| 4010 | "SetRedPayloadType() RED is not supported"); |
| 4011 | return -1; |
| 4012 | } |
| 4013 | |
turaj@webrtc.org | 9d532fd | 2013-01-31 18:34:19 +0000 | [diff] [blame] | 4014 | codec.pltype = red_payload_type; |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 4015 | if (audio_coding_->RegisterSendCodec(codec) < 0) { |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 4016 | _engineStatisticsPtr->SetLastError( |
| 4017 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 4018 | "SetRedPayloadType() RED registration in ACM module failed"); |
| 4019 | return -1; |
| 4020 | } |
| 4021 | |
| 4022 | if (_rtpRtcpModule->SetSendREDPayloadType(red_payload_type) != 0) { |
| 4023 | _engineStatisticsPtr->SetLastError( |
| 4024 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 4025 | "SetRedPayloadType() RED registration in RTP/RTCP module failed"); |
| 4026 | return -1; |
| 4027 | } |
| 4028 | return 0; |
| 4029 | } |
| 4030 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 4031 | int Channel::SetSendRtpHeaderExtension(bool enable, RTPExtensionType type, |
| 4032 | unsigned char id) { |
| 4033 | int error = 0; |
| 4034 | _rtpRtcpModule->DeregisterSendRtpHeaderExtension(type); |
| 4035 | if (enable) { |
| 4036 | error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id); |
| 4037 | } |
| 4038 | return error; |
| 4039 | } |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 4040 | |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 4041 | int32_t Channel::GetPlayoutFrequency() { |
| 4042 | int32_t playout_frequency = audio_coding_->PlayoutFrequency(); |
| 4043 | CodecInst current_recive_codec; |
| 4044 | if (audio_coding_->ReceiveCodec(¤t_recive_codec) == 0) { |
| 4045 | if (STR_CASE_CMP("G722", current_recive_codec.plname) == 0) { |
| 4046 | // Even though the actual sampling rate for G.722 audio is |
| 4047 | // 16,000 Hz, the RTP clock rate for the G722 payload format is |
| 4048 | // 8,000 Hz because that value was erroneously assigned in |
| 4049 | // RFC 1890 and must remain unchanged for backward compatibility. |
| 4050 | playout_frequency = 8000; |
| 4051 | } else if (STR_CASE_CMP("opus", current_recive_codec.plname) == 0) { |
| 4052 | // We are resampling Opus internally to 32,000 Hz until all our |
| 4053 | // DSP routines can operate at 48,000 Hz, but the RTP clock |
| 4054 | // rate for the Opus payload format is standardized to 48,000 Hz, |
| 4055 | // because that is the maximum supported decoding sampling rate. |
| 4056 | playout_frequency = 48000; |
| 4057 | } |
| 4058 | } |
| 4059 | return playout_frequency; |
| 4060 | } |
| 4061 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 4062 | int64_t Channel::GetRTT(bool allow_associate_channel) const { |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 4063 | RtcpMode method = _rtpRtcpModule->RTCP(); |
| 4064 | if (method == RtcpMode::kOff) { |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 4065 | return 0; |
| 4066 | } |
| 4067 | std::vector<RTCPReportBlock> report_blocks; |
| 4068 | _rtpRtcpModule->RemoteRTCPStat(&report_blocks); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 4069 | |
| 4070 | int64_t rtt = 0; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 4071 | if (report_blocks.empty()) { |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 4072 | if (allow_associate_channel) { |
| 4073 | CriticalSectionScoped lock(assoc_send_channel_lock_.get()); |
| 4074 | Channel* channel = associate_send_channel_.channel(); |
| 4075 | // Tries to get RTT from an associated channel. This is important for |
| 4076 | // receive-only channels. |
| 4077 | if (channel) { |
| 4078 | // To prevent infinite recursion and deadlock, calling GetRTT of |
| 4079 | // associate channel should always use "false" for argument: |
| 4080 | // |allow_associate_channel|. |
| 4081 | rtt = channel->GetRTT(false); |
| 4082 | } |
| 4083 | } |
| 4084 | return rtt; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | uint32_t remoteSSRC = rtp_receiver_->SSRC(); |
| 4088 | std::vector<RTCPReportBlock>::const_iterator it = report_blocks.begin(); |
| 4089 | for (; it != report_blocks.end(); ++it) { |
| 4090 | if (it->remoteSSRC == remoteSSRC) |
| 4091 | break; |
| 4092 | } |
| 4093 | if (it == report_blocks.end()) { |
| 4094 | // We have not received packets with SSRC matching the report blocks. |
| 4095 | // To calculate RTT we try with the SSRC of the first report block. |
| 4096 | // This is very important for send-only channels where we don't know |
| 4097 | // the SSRC of the other end. |
| 4098 | remoteSSRC = report_blocks[0].remoteSSRC; |
| 4099 | } |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 4100 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 4101 | int64_t avg_rtt = 0; |
| 4102 | int64_t max_rtt= 0; |
| 4103 | int64_t min_rtt = 0; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 4104 | if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) |
| 4105 | != 0) { |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 4106 | return 0; |
| 4107 | } |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 4108 | return rtt; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 4111 | } // namespace voe |
| 4112 | } // namespace webrtc |