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