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