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