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