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