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