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