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