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 | |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 13 | #include <algorithm> |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 14 | #include <utility> |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 15 | |
Ivo Creusen | ae856f2 | 2015-09-17 16:30:16 +0200 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 17 | #include "webrtc/base/criticalsection.h" |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 18 | #include "webrtc/base/format_macros.h" |
pbos | ad85622 | 2015-11-27 09:48:36 -0800 | [diff] [blame] | 19 | #include "webrtc/base/logging.h" |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 20 | #include "webrtc/base/rate_limiter.h" |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 21 | #include "webrtc/base/thread_checker.h" |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 22 | #include "webrtc/base/timeutils.h" |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 23 | #include "webrtc/call/rtc_event_log.h" |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 24 | #include "webrtc/config.h" |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 25 | #include "webrtc/modules/audio_device/include/audio_device.h" |
| 26 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 27 | #include "webrtc/modules/include/module_common_types.h" |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 28 | #include "webrtc/modules/pacing/packet_router.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 29 | #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
| 30 | #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 31 | #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 32 | #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 33 | #include "webrtc/modules/utility/include/audio_frame_operations.h" |
| 34 | #include "webrtc/modules/utility/include/process_thread.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 35 | #include "webrtc/system_wrappers/include/trace.h" |
turaj@webrtc.org | 6388c3e | 2013-02-12 21:42:18 +0000 | [diff] [blame] | 36 | #include "webrtc/voice_engine/include/voe_external_media.h" |
| 37 | #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
| 38 | #include "webrtc/voice_engine/output_mixer.h" |
| 39 | #include "webrtc/voice_engine/statistics.h" |
| 40 | #include "webrtc/voice_engine/transmit_mixer.h" |
| 41 | #include "webrtc/voice_engine/utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 43 | namespace webrtc { |
| 44 | namespace voe { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 46 | namespace { |
| 47 | |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 48 | constexpr int64_t kMaxRetransmissionWindowMs = 1000; |
| 49 | constexpr int64_t kMinRetransmissionWindowMs = 30; |
| 50 | |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 51 | bool RegisterReceiveCodec(std::unique_ptr<AudioCodingModule>* acm, |
| 52 | acm2::RentACodec* rac, |
| 53 | const CodecInst& ci) { |
kwiberg | abe95ba | 2016-06-02 02:58:59 -0700 | [diff] [blame] | 54 | const int result = (*acm)->RegisterReceiveCodec( |
| 55 | ci, [&] { return rac->RentIsacDecoder(ci.plfreq); }); |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 56 | return result == 0; |
| 57 | } |
| 58 | |
| 59 | } // namespace |
| 60 | |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 61 | const int kTelephoneEventAttenuationdB = 10; |
| 62 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 63 | class RtcEventLogProxy final : public webrtc::RtcEventLog { |
| 64 | public: |
| 65 | RtcEventLogProxy() : event_log_(nullptr) {} |
| 66 | |
| 67 | bool StartLogging(const std::string& file_name, |
| 68 | int64_t max_size_bytes) override { |
| 69 | RTC_NOTREACHED(); |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | bool StartLogging(rtc::PlatformFile log_file, |
| 74 | int64_t max_size_bytes) override { |
| 75 | RTC_NOTREACHED(); |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | void StopLogging() override { RTC_NOTREACHED(); } |
| 80 | |
| 81 | void LogVideoReceiveStreamConfig( |
| 82 | const webrtc::VideoReceiveStream::Config& config) override { |
| 83 | rtc::CritScope lock(&crit_); |
| 84 | if (event_log_) { |
| 85 | event_log_->LogVideoReceiveStreamConfig(config); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | void LogVideoSendStreamConfig( |
| 90 | const webrtc::VideoSendStream::Config& config) override { |
| 91 | rtc::CritScope lock(&crit_); |
| 92 | if (event_log_) { |
| 93 | event_log_->LogVideoSendStreamConfig(config); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void LogRtpHeader(webrtc::PacketDirection direction, |
| 98 | webrtc::MediaType media_type, |
| 99 | const uint8_t* header, |
| 100 | size_t packet_length) override { |
| 101 | rtc::CritScope lock(&crit_); |
| 102 | if (event_log_) { |
| 103 | event_log_->LogRtpHeader(direction, media_type, header, packet_length); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | void LogRtcpPacket(webrtc::PacketDirection direction, |
| 108 | webrtc::MediaType media_type, |
| 109 | const uint8_t* packet, |
| 110 | size_t length) override { |
| 111 | rtc::CritScope lock(&crit_); |
| 112 | if (event_log_) { |
| 113 | event_log_->LogRtcpPacket(direction, media_type, packet, length); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | void LogAudioPlayout(uint32_t ssrc) override { |
| 118 | rtc::CritScope lock(&crit_); |
| 119 | if (event_log_) { |
| 120 | event_log_->LogAudioPlayout(ssrc); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void LogBwePacketLossEvent(int32_t bitrate, |
| 125 | uint8_t fraction_loss, |
| 126 | int32_t total_packets) override { |
| 127 | rtc::CritScope lock(&crit_); |
| 128 | if (event_log_) { |
| 129 | event_log_->LogBwePacketLossEvent(bitrate, fraction_loss, total_packets); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void SetEventLog(RtcEventLog* event_log) { |
| 134 | rtc::CritScope lock(&crit_); |
| 135 | event_log_ = event_log; |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | rtc::CriticalSection crit_; |
| 140 | RtcEventLog* event_log_ GUARDED_BY(crit_); |
| 141 | RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogProxy); |
| 142 | }; |
| 143 | |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 144 | class TransportFeedbackProxy : public TransportFeedbackObserver { |
| 145 | public: |
| 146 | TransportFeedbackProxy() : feedback_observer_(nullptr) { |
| 147 | pacer_thread_.DetachFromThread(); |
| 148 | network_thread_.DetachFromThread(); |
| 149 | } |
| 150 | |
| 151 | void SetTransportFeedbackObserver( |
| 152 | TransportFeedbackObserver* feedback_observer) { |
| 153 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 154 | rtc::CritScope lock(&crit_); |
| 155 | feedback_observer_ = feedback_observer; |
| 156 | } |
| 157 | |
| 158 | // Implements TransportFeedbackObserver. |
| 159 | void AddPacket(uint16_t sequence_number, |
| 160 | size_t length, |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 161 | int probe_cluster_id) override { |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 162 | RTC_DCHECK(pacer_thread_.CalledOnValidThread()); |
| 163 | rtc::CritScope lock(&crit_); |
| 164 | if (feedback_observer_) |
pbos | 2169d8b | 2016-06-20 11:53:02 -0700 | [diff] [blame] | 165 | feedback_observer_->AddPacket(sequence_number, length, probe_cluster_id); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 166 | } |
| 167 | void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override { |
| 168 | RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 169 | rtc::CritScope lock(&crit_); |
Stefan Holmer | 60e4346 | 2016-09-07 09:58:20 +0200 | [diff] [blame] | 170 | feedback_observer_->OnTransportFeedback(feedback); |
| 171 | } |
| 172 | std::vector<PacketInfo> GetTransportFeedbackVector() const override { |
| 173 | RTC_NOTREACHED(); |
| 174 | return std::vector<PacketInfo>(); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | private: |
| 178 | rtc::CriticalSection crit_; |
| 179 | rtc::ThreadChecker thread_checker_; |
| 180 | rtc::ThreadChecker pacer_thread_; |
| 181 | rtc::ThreadChecker network_thread_; |
| 182 | TransportFeedbackObserver* feedback_observer_ GUARDED_BY(&crit_); |
| 183 | }; |
| 184 | |
| 185 | class TransportSequenceNumberProxy : public TransportSequenceNumberAllocator { |
| 186 | public: |
| 187 | TransportSequenceNumberProxy() : seq_num_allocator_(nullptr) { |
| 188 | pacer_thread_.DetachFromThread(); |
| 189 | } |
| 190 | |
| 191 | void SetSequenceNumberAllocator( |
| 192 | TransportSequenceNumberAllocator* seq_num_allocator) { |
| 193 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 194 | rtc::CritScope lock(&crit_); |
| 195 | seq_num_allocator_ = seq_num_allocator; |
| 196 | } |
| 197 | |
| 198 | // Implements TransportSequenceNumberAllocator. |
| 199 | uint16_t AllocateSequenceNumber() override { |
| 200 | RTC_DCHECK(pacer_thread_.CalledOnValidThread()); |
| 201 | rtc::CritScope lock(&crit_); |
| 202 | if (!seq_num_allocator_) |
| 203 | return 0; |
| 204 | return seq_num_allocator_->AllocateSequenceNumber(); |
| 205 | } |
| 206 | |
| 207 | private: |
| 208 | rtc::CriticalSection crit_; |
| 209 | rtc::ThreadChecker thread_checker_; |
| 210 | rtc::ThreadChecker pacer_thread_; |
| 211 | TransportSequenceNumberAllocator* seq_num_allocator_ GUARDED_BY(&crit_); |
| 212 | }; |
| 213 | |
| 214 | class RtpPacketSenderProxy : public RtpPacketSender { |
| 215 | public: |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 216 | RtpPacketSenderProxy() : rtp_packet_sender_(nullptr) {} |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 217 | |
| 218 | void SetPacketSender(RtpPacketSender* rtp_packet_sender) { |
| 219 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 220 | rtc::CritScope lock(&crit_); |
| 221 | rtp_packet_sender_ = rtp_packet_sender; |
| 222 | } |
| 223 | |
| 224 | // Implements RtpPacketSender. |
| 225 | void InsertPacket(Priority priority, |
| 226 | uint32_t ssrc, |
| 227 | uint16_t sequence_number, |
| 228 | int64_t capture_time_ms, |
| 229 | size_t bytes, |
| 230 | bool retransmission) override { |
| 231 | rtc::CritScope lock(&crit_); |
| 232 | if (rtp_packet_sender_) { |
| 233 | rtp_packet_sender_->InsertPacket(priority, ssrc, sequence_number, |
| 234 | capture_time_ms, bytes, retransmission); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | private: |
| 239 | rtc::ThreadChecker thread_checker_; |
| 240 | rtc::CriticalSection crit_; |
| 241 | RtpPacketSender* rtp_packet_sender_ GUARDED_BY(&crit_); |
| 242 | }; |
| 243 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 244 | // Extend the default RTCP statistics struct with max_jitter, defined as the |
| 245 | // maximum jitter value seen in an RTCP report block. |
| 246 | struct ChannelStatistics : public RtcpStatistics { |
| 247 | ChannelStatistics() : rtcp(), max_jitter(0) {} |
| 248 | |
| 249 | RtcpStatistics rtcp; |
| 250 | uint32_t max_jitter; |
| 251 | }; |
| 252 | |
| 253 | // Statistics callback, called at each generation of a new RTCP report block. |
| 254 | class StatisticsProxy : public RtcpStatisticsCallback { |
| 255 | public: |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 256 | StatisticsProxy(uint32_t ssrc) : ssrc_(ssrc) {} |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 257 | virtual ~StatisticsProxy() {} |
| 258 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 259 | void StatisticsUpdated(const RtcpStatistics& statistics, |
| 260 | uint32_t ssrc) override { |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 261 | if (ssrc != ssrc_) |
| 262 | return; |
| 263 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 264 | rtc::CritScope cs(&stats_lock_); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 265 | stats_.rtcp = statistics; |
| 266 | if (statistics.jitter > stats_.max_jitter) { |
| 267 | stats_.max_jitter = statistics.jitter; |
| 268 | } |
| 269 | } |
| 270 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 271 | void CNameChanged(const char* cname, uint32_t ssrc) override {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 272 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 273 | ChannelStatistics GetStats() { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 274 | rtc::CritScope cs(&stats_lock_); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 275 | return stats_; |
| 276 | } |
| 277 | |
| 278 | private: |
| 279 | // StatisticsUpdated calls are triggered from threads in the RTP module, |
| 280 | // while GetStats calls can be triggered from the public voice engine API, |
| 281 | // hence synchronization is needed. |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 282 | rtc::CriticalSection stats_lock_; |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 283 | const uint32_t ssrc_; |
| 284 | ChannelStatistics stats_; |
| 285 | }; |
| 286 | |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 287 | class VoERtcpObserver : public RtcpBandwidthObserver { |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 288 | public: |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 289 | explicit VoERtcpObserver(Channel* owner) : owner_(owner) {} |
| 290 | virtual ~VoERtcpObserver() {} |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 291 | |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 292 | void OnReceivedEstimatedBitrate(uint32_t bitrate) override { |
| 293 | // Not used for Voice Engine. |
| 294 | } |
| 295 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 296 | void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, |
| 297 | int64_t rtt, |
| 298 | int64_t now_ms) override { |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 299 | // TODO(mflodman): Do we need to aggregate reports here or can we jut send |
| 300 | // what we get? I.e. do we ever get multiple reports bundled into one RTCP |
| 301 | // report for VoiceEngine? |
| 302 | if (report_blocks.empty()) |
| 303 | return; |
| 304 | |
| 305 | int fraction_lost_aggregate = 0; |
| 306 | int total_number_of_packets = 0; |
| 307 | |
| 308 | // If receiving multiple report blocks, calculate the weighted average based |
| 309 | // on the number of packets a report refers to. |
| 310 | for (ReportBlockList::const_iterator block_it = report_blocks.begin(); |
| 311 | block_it != report_blocks.end(); ++block_it) { |
| 312 | // Find the previous extended high sequence number for this remote SSRC, |
| 313 | // to calculate the number of RTP packets this report refers to. Ignore if |
| 314 | // we haven't seen this SSRC before. |
| 315 | std::map<uint32_t, uint32_t>::iterator seq_num_it = |
| 316 | extended_max_sequence_number_.find(block_it->sourceSSRC); |
| 317 | int number_of_packets = 0; |
| 318 | if (seq_num_it != extended_max_sequence_number_.end()) { |
| 319 | number_of_packets = block_it->extendedHighSeqNum - seq_num_it->second; |
| 320 | } |
| 321 | fraction_lost_aggregate += number_of_packets * block_it->fractionLost; |
| 322 | total_number_of_packets += number_of_packets; |
| 323 | |
| 324 | extended_max_sequence_number_[block_it->sourceSSRC] = |
| 325 | block_it->extendedHighSeqNum; |
| 326 | } |
| 327 | int weighted_fraction_lost = 0; |
| 328 | if (total_number_of_packets > 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 329 | weighted_fraction_lost = |
| 330 | (fraction_lost_aggregate + total_number_of_packets / 2) / |
| 331 | total_number_of_packets; |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 332 | } |
| 333 | owner_->OnIncomingFractionLoss(weighted_fraction_lost); |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | private: |
| 337 | Channel* owner_; |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 338 | // Maps remote side ssrc to extended highest sequence number received. |
| 339 | std::map<uint32_t, uint32_t> extended_max_sequence_number_; |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 340 | }; |
| 341 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 342 | int32_t Channel::SendData(FrameType frameType, |
| 343 | uint8_t payloadType, |
| 344 | uint32_t timeStamp, |
| 345 | const uint8_t* payloadData, |
| 346 | size_t payloadSize, |
| 347 | const RTPFragmentationHeader* fragmentation) { |
| 348 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 349 | "Channel::SendData(frameType=%u, payloadType=%u, timeStamp=%u," |
| 350 | " payloadSize=%" PRIuS ", fragmentation=0x%x)", |
| 351 | frameType, payloadType, timeStamp, payloadSize, fragmentation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 352 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 353 | if (_includeAudioLevelIndication) { |
| 354 | // Store current audio level in the RTP/RTCP module. |
| 355 | // The level will be used in combination with voice-activity state |
| 356 | // (frameType) to add an RTP header extension |
| 357 | _rtpRtcpModule->SetAudioLevel(rms_level_.RMS()); |
| 358 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 359 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 360 | // Push data from ACM to RTP/RTCP-module to deliver audio frame for |
| 361 | // packetization. |
| 362 | // This call will trigger Transport::SendPacket() from the RTP/RTCP module. |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 363 | if (!_rtpRtcpModule->SendOutgoingData( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 364 | (FrameType&)frameType, payloadType, timeStamp, |
| 365 | // Leaving the time when this frame was |
| 366 | // received from the capture device as |
| 367 | // undefined for voice for now. |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 368 | -1, payloadData, payloadSize, fragmentation, nullptr, nullptr)) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 369 | _engineStatisticsPtr->SetLastError( |
| 370 | VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
| 371 | "Channel::SendData() failed to send data to RTP/RTCP module"); |
| 372 | return -1; |
| 373 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 374 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 375 | _lastLocalTimeStamp = timeStamp; |
| 376 | _lastPayloadType = payloadType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 377 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 378 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 379 | } |
| 380 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 381 | int32_t Channel::InFrameType(FrameType frame_type) { |
| 382 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 383 | "Channel::InFrameType(frame_type=%d)", frame_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 384 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 385 | rtc::CritScope cs(&_callbackCritSect); |
| 386 | _sendFrameType = (frame_type == kAudioFrameSpeech); |
| 387 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 388 | } |
| 389 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 390 | bool Channel::SendRtp(const uint8_t* data, |
| 391 | size_t len, |
| 392 | const PacketOptions& options) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 393 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 394 | "Channel::SendPacket(channel=%d, len=%" PRIuS ")", len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 396 | rtc::CritScope cs(&_callbackCritSect); |
wu@webrtc.org | fb648da | 2013-10-18 21:10:51 +0000 | [diff] [blame] | 397 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 398 | if (_transportPtr == NULL) { |
| 399 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 400 | "Channel::SendPacket() failed to send RTP packet due to" |
| 401 | " invalid transport object"); |
| 402 | return false; |
| 403 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 405 | uint8_t* bufferToSendPtr = (uint8_t*)data; |
| 406 | size_t bufferLength = len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 407 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 408 | if (!_transportPtr->SendRtp(bufferToSendPtr, bufferLength, options)) { |
| 409 | std::string transport_name = |
| 410 | _externalTransport ? "external transport" : "WebRtc sockets"; |
| 411 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 412 | "Channel::SendPacket() RTP transmission using %s failed", |
| 413 | transport_name.c_str()); |
| 414 | return false; |
| 415 | } |
| 416 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 417 | } |
| 418 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 419 | bool Channel::SendRtcp(const uint8_t* data, size_t len) { |
| 420 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 421 | "Channel::SendRtcp(len=%" PRIuS ")", len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 422 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 423 | rtc::CritScope cs(&_callbackCritSect); |
| 424 | if (_transportPtr == NULL) { |
| 425 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 426 | "Channel::SendRtcp() failed to send RTCP packet" |
| 427 | " due to invalid transport object"); |
| 428 | return false; |
| 429 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 430 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 431 | uint8_t* bufferToSendPtr = (uint8_t*)data; |
| 432 | size_t bufferLength = len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 434 | int n = _transportPtr->SendRtcp(bufferToSendPtr, bufferLength); |
| 435 | if (n < 0) { |
| 436 | std::string transport_name = |
| 437 | _externalTransport ? "external transport" : "WebRtc sockets"; |
| 438 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 439 | "Channel::SendRtcp() transmission using %s failed", |
| 440 | transport_name.c_str()); |
| 441 | return false; |
| 442 | } |
| 443 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 444 | } |
| 445 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 446 | void Channel::OnIncomingSSRCChanged(uint32_t ssrc) { |
| 447 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 448 | "Channel::OnIncomingSSRCChanged(SSRC=%d)", ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 449 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 450 | // Update ssrc so that NTP for AV sync can be updated. |
| 451 | _rtpRtcpModule->SetRemoteSSRC(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 454 | void Channel::OnIncomingCSRCChanged(uint32_t CSRC, bool added) { |
| 455 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 456 | "Channel::OnIncomingCSRCChanged(CSRC=%d, added=%d)", CSRC, |
| 457 | added); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 460 | int32_t Channel::OnInitializeDecoder( |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 461 | int8_t payloadType, |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 462 | const char payloadName[RTP_PAYLOAD_NAME_SIZE], |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 463 | int frequency, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 464 | size_t channels, |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 465 | uint32_t rate) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 466 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 467 | "Channel::OnInitializeDecoder(payloadType=%d, " |
| 468 | "payloadName=%s, frequency=%u, channels=%" PRIuS ", rate=%u)", |
| 469 | payloadType, payloadName, frequency, channels, rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 470 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 471 | CodecInst receiveCodec = {0}; |
| 472 | CodecInst dummyCodec = {0}; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 473 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 474 | receiveCodec.pltype = payloadType; |
| 475 | receiveCodec.plfreq = frequency; |
| 476 | receiveCodec.channels = channels; |
| 477 | receiveCodec.rate = rate; |
| 478 | strncpy(receiveCodec.plname, payloadName, RTP_PAYLOAD_NAME_SIZE - 1); |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 479 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 480 | audio_coding_->Codec(payloadName, &dummyCodec, frequency, channels); |
| 481 | receiveCodec.pacsize = dummyCodec.pacsize; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 482 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 483 | // Register the new codec to the ACM |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 484 | if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, receiveCodec)) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 485 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 486 | "Channel::OnInitializeDecoder() invalid codec (" |
| 487 | "pt=%d, name=%s) received - 1", |
| 488 | payloadType, payloadName); |
| 489 | _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR); |
| 490 | return -1; |
| 491 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 492 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 493 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 494 | } |
| 495 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 496 | int32_t Channel::OnReceivedPayloadData(const uint8_t* payloadData, |
| 497 | size_t payloadSize, |
| 498 | const WebRtcRTPHeader* rtpHeader) { |
| 499 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 500 | "Channel::OnReceivedPayloadData(payloadSize=%" PRIuS |
| 501 | "," |
| 502 | " payloadType=%u, audioChannel=%" PRIuS ")", |
| 503 | payloadSize, rtpHeader->header.payloadType, |
| 504 | rtpHeader->type.Audio.channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 505 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 506 | if (!channel_state_.Get().playing) { |
| 507 | // Avoid inserting into NetEQ when we are not playing. Count the |
| 508 | // packet as discarded. |
| 509 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 510 | "received packet is discarded since playing is not" |
| 511 | " activated"); |
| 512 | _numberOfDiscardedPackets++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 513 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | // Push the incoming payload (parsed and ready for decoding) into the ACM |
| 517 | if (audio_coding_->IncomingPacket(payloadData, payloadSize, *rtpHeader) != |
| 518 | 0) { |
| 519 | _engineStatisticsPtr->SetLastError( |
| 520 | VE_AUDIO_CODING_MODULE_ERROR, kTraceWarning, |
| 521 | "Channel::OnReceivedPayloadData() unable to push data to the ACM"); |
| 522 | return -1; |
| 523 | } |
| 524 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 525 | int64_t round_trip_time = 0; |
| 526 | _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL, |
| 527 | NULL); |
| 528 | |
| 529 | std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time); |
| 530 | if (!nack_list.empty()) { |
| 531 | // Can't use nack_list.data() since it's not supported by all |
| 532 | // compilers. |
| 533 | ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size())); |
| 534 | } |
| 535 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 536 | } |
| 537 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 538 | bool Channel::OnRecoveredPacket(const uint8_t* rtp_packet, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 539 | size_t rtp_packet_length) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 540 | RTPHeader header; |
| 541 | if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) { |
| 542 | WEBRTC_TRACE(kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 543 | "IncomingPacket invalid RTP header"); |
| 544 | return false; |
| 545 | } |
| 546 | header.payload_type_frequency = |
| 547 | rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); |
| 548 | if (header.payload_type_frequency < 0) |
| 549 | return false; |
| 550 | return ReceivePacket(rtp_packet, rtp_packet_length, header, false); |
| 551 | } |
| 552 | |
henrik.lundin | 42dda50 | 2016-05-18 05:36:01 -0700 | [diff] [blame] | 553 | MixerParticipant::AudioFrameInfo Channel::GetAudioFrameWithMuted( |
| 554 | int32_t id, |
| 555 | AudioFrame* audioFrame) { |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 556 | unsigned int ssrc; |
| 557 | RTC_CHECK_EQ(GetLocalSSRC(ssrc), 0); |
| 558 | event_log_proxy_->LogAudioPlayout(ssrc); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 559 | // Get 10ms raw PCM data from the ACM (mixer limits output frequency) |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 560 | bool muted; |
| 561 | if (audio_coding_->PlayoutData10Ms(audioFrame->sample_rate_hz_, audioFrame, |
| 562 | &muted) == -1) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 563 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 564 | "Channel::GetAudioFrame() PlayoutData10Ms() failed!"); |
| 565 | // In all likelihood, the audio in this frame is garbage. We return an |
| 566 | // error so that the audio mixer module doesn't add it to the mix. As |
| 567 | // a result, it won't be played out and the actions skipped here are |
| 568 | // irrelevant. |
henrik.lundin | 42dda50 | 2016-05-18 05:36:01 -0700 | [diff] [blame] | 569 | return MixerParticipant::AudioFrameInfo::kError; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 570 | } |
henrik.lundin | a89ab96 | 2016-05-18 08:52:45 -0700 | [diff] [blame] | 571 | |
| 572 | if (muted) { |
| 573 | // TODO(henrik.lundin): We should be able to do better than this. But we |
| 574 | // will have to go through all the cases below where the audio samples may |
| 575 | // be used, and handle the muted case in some way. |
| 576 | audioFrame->Mute(); |
| 577 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 578 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 579 | // Convert module ID to internal VoE channel ID |
| 580 | audioFrame->id_ = VoEChannelId(audioFrame->id_); |
| 581 | // Store speech type for dead-or-alive detection |
| 582 | _outputSpeechType = audioFrame->speech_type_; |
| 583 | |
| 584 | ChannelState::State state = channel_state_.Get(); |
| 585 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 586 | { |
| 587 | // Pass the audio buffers to an optional sink callback, before applying |
| 588 | // scaling/panning, as that applies to the mix operation. |
| 589 | // External recipients of the audio (e.g. via AudioTrack), will do their |
| 590 | // own mixing/dynamic processing. |
| 591 | rtc::CritScope cs(&_callbackCritSect); |
| 592 | if (audio_sink_) { |
| 593 | AudioSinkInterface::Data data( |
| 594 | &audioFrame->data_[0], audioFrame->samples_per_channel_, |
| 595 | audioFrame->sample_rate_hz_, audioFrame->num_channels_, |
| 596 | audioFrame->timestamp_); |
| 597 | audio_sink_->OnData(data); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | float output_gain = 1.0f; |
| 602 | float left_pan = 1.0f; |
| 603 | float right_pan = 1.0f; |
| 604 | { |
| 605 | rtc::CritScope cs(&volume_settings_critsect_); |
| 606 | output_gain = _outputGain; |
| 607 | left_pan = _panLeft; |
| 608 | right_pan = _panRight; |
| 609 | } |
| 610 | |
| 611 | // Output volume scaling |
| 612 | if (output_gain < 0.99f || output_gain > 1.01f) { |
| 613 | AudioFrameOperations::ScaleWithSat(output_gain, *audioFrame); |
| 614 | } |
| 615 | |
| 616 | // Scale left and/or right channel(s) if stereo and master balance is |
| 617 | // active |
| 618 | |
| 619 | if (left_pan != 1.0f || right_pan != 1.0f) { |
| 620 | if (audioFrame->num_channels_ == 1) { |
| 621 | // Emulate stereo mode since panning is active. |
| 622 | // The mono signal is copied to both left and right channels here. |
| 623 | AudioFrameOperations::MonoToStereo(audioFrame); |
| 624 | } |
| 625 | // For true stereo mode (when we are receiving a stereo signal), no |
| 626 | // action is needed. |
| 627 | |
| 628 | // Do the panning operation (the audio frame contains stereo at this |
| 629 | // stage) |
| 630 | AudioFrameOperations::Scale(left_pan, right_pan, *audioFrame); |
| 631 | } |
| 632 | |
| 633 | // Mix decoded PCM output with file if file mixing is enabled |
| 634 | if (state.output_file_playing) { |
| 635 | MixAudioWithFile(*audioFrame, audioFrame->sample_rate_hz_); |
henrik.lundin | a89ab96 | 2016-05-18 08:52:45 -0700 | [diff] [blame] | 636 | muted = false; // We may have added non-zero samples. |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | // External media |
| 640 | if (_outputExternalMedia) { |
| 641 | rtc::CritScope cs(&_callbackCritSect); |
| 642 | const bool isStereo = (audioFrame->num_channels_ == 2); |
| 643 | if (_outputExternalMediaCallbackPtr) { |
| 644 | _outputExternalMediaCallbackPtr->Process( |
| 645 | _channelId, kPlaybackPerChannel, (int16_t*)audioFrame->data_, |
| 646 | audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_, |
| 647 | isStereo); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | // Record playout if enabled |
| 652 | { |
| 653 | rtc::CritScope cs(&_fileCritSect); |
| 654 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 655 | if (_outputFileRecording && output_file_recorder_) { |
| 656 | output_file_recorder_->RecordAudioToFile(*audioFrame); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
| 660 | // Measure audio level (0-9) |
henrik.lundin | a89ab96 | 2016-05-18 08:52:45 -0700 | [diff] [blame] | 661 | // TODO(henrik.lundin) Use the |muted| information here too. |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 662 | _outputAudioLevel.ComputeLevel(*audioFrame); |
| 663 | |
| 664 | if (capture_start_rtp_time_stamp_ < 0 && audioFrame->timestamp_ != 0) { |
| 665 | // The first frame with a valid rtp timestamp. |
| 666 | capture_start_rtp_time_stamp_ = audioFrame->timestamp_; |
| 667 | } |
| 668 | |
| 669 | if (capture_start_rtp_time_stamp_ >= 0) { |
| 670 | // audioFrame.timestamp_ should be valid from now on. |
| 671 | |
| 672 | // Compute elapsed time. |
| 673 | int64_t unwrap_timestamp = |
| 674 | rtp_ts_wraparound_handler_->Unwrap(audioFrame->timestamp_); |
| 675 | audioFrame->elapsed_time_ms_ = |
| 676 | (unwrap_timestamp - capture_start_rtp_time_stamp_) / |
| 677 | (GetPlayoutFrequency() / 1000); |
| 678 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 679 | { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 680 | rtc::CritScope lock(&ts_stats_lock_); |
| 681 | // Compute ntp time. |
| 682 | audioFrame->ntp_time_ms_ = |
| 683 | ntp_estimator_.Estimate(audioFrame->timestamp_); |
| 684 | // |ntp_time_ms_| won't be valid until at least 2 RTCP SRs are received. |
| 685 | if (audioFrame->ntp_time_ms_ > 0) { |
| 686 | // Compute |capture_start_ntp_time_ms_| so that |
| 687 | // |capture_start_ntp_time_ms_| + |elapsed_time_ms_| == |ntp_time_ms_| |
| 688 | capture_start_ntp_time_ms_ = |
| 689 | audioFrame->ntp_time_ms_ - audioFrame->elapsed_time_ms_; |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 690 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 691 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 692 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 693 | |
henrik.lundin | 42dda50 | 2016-05-18 05:36:01 -0700 | [diff] [blame] | 694 | return muted ? MixerParticipant::AudioFrameInfo::kMuted |
| 695 | : MixerParticipant::AudioFrameInfo::kNormal; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 696 | } |
| 697 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 698 | int32_t Channel::NeededFrequency(int32_t id) const { |
| 699 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 700 | "Channel::NeededFrequency(id=%d)", id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 701 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 702 | int highestNeeded = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 703 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 704 | // Determine highest needed receive frequency |
| 705 | int32_t receiveFrequency = audio_coding_->ReceiveFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 706 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 707 | // Return the bigger of playout and receive frequency in the ACM. |
| 708 | if (audio_coding_->PlayoutFrequency() > receiveFrequency) { |
| 709 | highestNeeded = audio_coding_->PlayoutFrequency(); |
| 710 | } else { |
| 711 | highestNeeded = receiveFrequency; |
| 712 | } |
| 713 | |
| 714 | // Special case, if we're playing a file on the playout side |
| 715 | // we take that frequency into consideration as well |
| 716 | // This is not needed on sending side, since the codec will |
| 717 | // limit the spectrum anyway. |
| 718 | if (channel_state_.Get().output_file_playing) { |
| 719 | rtc::CritScope cs(&_fileCritSect); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 720 | if (output_file_player_) { |
| 721 | if (output_file_player_->Frequency() > highestNeeded) { |
| 722 | highestNeeded = output_file_player_->Frequency(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 723 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 724 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 725 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 726 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 727 | return (highestNeeded); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 728 | } |
| 729 | |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 730 | int32_t Channel::CreateChannel( |
| 731 | Channel*& channel, |
| 732 | int32_t channelId, |
| 733 | uint32_t instanceId, |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 734 | const VoEBase::ChannelConfig& config) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 735 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), |
| 736 | "Channel::CreateChannel(channelId=%d, instanceId=%d)", channelId, |
| 737 | instanceId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 738 | |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 739 | channel = new Channel(channelId, instanceId, config); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 740 | if (channel == NULL) { |
| 741 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(instanceId, channelId), |
| 742 | "Channel::CreateChannel() unable to allocate memory for" |
| 743 | " channel"); |
| 744 | return -1; |
| 745 | } |
| 746 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 747 | } |
| 748 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 749 | void Channel::PlayNotification(int32_t id, uint32_t durationMs) { |
| 750 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 751 | "Channel::PlayNotification(id=%d, durationMs=%d)", id, |
| 752 | durationMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 753 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 754 | // Not implement yet |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 755 | } |
| 756 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 757 | void Channel::RecordNotification(int32_t id, uint32_t durationMs) { |
| 758 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 759 | "Channel::RecordNotification(id=%d, durationMs=%d)", id, |
| 760 | durationMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 761 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 762 | // Not implement yet |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 763 | } |
| 764 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 765 | void Channel::PlayFileEnded(int32_t id) { |
| 766 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 767 | "Channel::PlayFileEnded(id=%d)", id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 768 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 769 | if (id == _inputFilePlayerId) { |
| 770 | channel_state_.SetInputFilePlaying(false); |
| 771 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 772 | "Channel::PlayFileEnded() => input file player module is" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 773 | " shutdown"); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 774 | } else if (id == _outputFilePlayerId) { |
| 775 | channel_state_.SetOutputFilePlaying(false); |
| 776 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 777 | "Channel::PlayFileEnded() => output file player module is" |
| 778 | " shutdown"); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | void Channel::RecordFileEnded(int32_t id) { |
| 783 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 784 | "Channel::RecordFileEnded(id=%d)", id); |
| 785 | |
| 786 | assert(id == _outputFileRecorderId); |
| 787 | |
| 788 | rtc::CritScope cs(&_fileCritSect); |
| 789 | |
| 790 | _outputFileRecording = false; |
| 791 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 792 | "Channel::RecordFileEnded() => output file recorder module is" |
| 793 | " shutdown"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 794 | } |
| 795 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 796 | Channel::Channel(int32_t channelId, |
minyue@webrtc.org | e509f94 | 2013-09-12 17:03:00 +0000 | [diff] [blame] | 797 | uint32_t instanceId, |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 798 | const VoEBase::ChannelConfig& config) |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 799 | : _instanceId(instanceId), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 800 | _channelId(channelId), |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 801 | event_log_proxy_(new RtcEventLogProxy()), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 802 | rtp_header_parser_(RtpHeaderParser::Create()), |
| 803 | rtp_payload_registry_( |
| 804 | new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), |
| 805 | rtp_receive_statistics_( |
| 806 | ReceiveStatistics::Create(Clock::GetRealTimeClock())), |
| 807 | rtp_receiver_( |
| 808 | RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 809 | this, |
| 810 | this, |
| 811 | rtp_payload_registry_.get())), |
danilchap | 799a9d0 | 2016-09-22 03:36:27 -0700 | [diff] [blame] | 812 | telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 813 | _outputAudioLevel(), |
| 814 | _externalTransport(false), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 815 | // Avoid conflict with other channels by adding 1024 - 1026, |
| 816 | // won't use as much as 1024 channels. |
| 817 | _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024), |
| 818 | _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025), |
| 819 | _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026), |
| 820 | _outputFileRecording(false), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 821 | _outputExternalMedia(false), |
| 822 | _inputExternalMediaCallbackPtr(NULL), |
| 823 | _outputExternalMediaCallbackPtr(NULL), |
| 824 | _timeStamp(0), // This is just an offset, RTP module will add it's own |
| 825 | // random offset |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 826 | ntp_estimator_(Clock::GetRealTimeClock()), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 827 | playout_timestamp_rtp_(0), |
| 828 | playout_timestamp_rtcp_(0), |
| 829 | playout_delay_ms_(0), |
| 830 | _numberOfDiscardedPackets(0), |
| 831 | send_sequence_number_(0), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 832 | rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()), |
| 833 | capture_start_rtp_time_stamp_(-1), |
| 834 | capture_start_ntp_time_ms_(-1), |
| 835 | _engineStatisticsPtr(NULL), |
| 836 | _outputMixerPtr(NULL), |
| 837 | _transmitMixerPtr(NULL), |
| 838 | _moduleProcessThreadPtr(NULL), |
| 839 | _audioDeviceModulePtr(NULL), |
| 840 | _voiceEngineObserverPtr(NULL), |
| 841 | _callbackCritSectPtr(NULL), |
| 842 | _transportPtr(NULL), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 843 | _sendFrameType(0), |
| 844 | _externalMixing(false), |
| 845 | _mixFileWithMicrophone(false), |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 846 | input_mute_(false), |
| 847 | previous_frame_muted_(false), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 848 | _panLeft(1.0f), |
| 849 | _panRight(1.0f), |
| 850 | _outputGain(1.0f), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 851 | _lastLocalTimeStamp(0), |
| 852 | _lastPayloadType(0), |
| 853 | _includeAudioLevelIndication(false), |
| 854 | _outputSpeechType(AudioFrame::kNormalSpeech), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 855 | restored_packet_in_use_(false), |
| 856 | rtcp_observer_(new VoERtcpObserver(this)), |
| 857 | network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 858 | associate_send_channel_(ChannelOwner(nullptr)), |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 859 | pacing_enabled_(config.enable_voice_pacing), |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 860 | feedback_observer_proxy_(new TransportFeedbackProxy()), |
| 861 | seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 862 | rtp_packet_sender_proxy_(new RtpPacketSenderProxy()), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 863 | retransmission_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(), |
| 864 | kMaxRetransmissionWindowMs)), |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 865 | decoder_factory_(config.acm_config.decoder_factory) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 866 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), |
| 867 | "Channel::Channel() - ctor"); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 868 | AudioCodingModule::Config acm_config(config.acm_config); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 869 | acm_config.id = VoEModuleId(instanceId, channelId); |
henrik.lundin | a89ab96 | 2016-05-18 08:52:45 -0700 | [diff] [blame] | 870 | acm_config.neteq_config.enable_muted_state = true; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 871 | audio_coding_.reset(AudioCodingModule::Create(acm_config)); |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 872 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 873 | _outputAudioLevel.Clear(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 874 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 875 | RtpRtcp::Configuration configuration; |
| 876 | configuration.audio = true; |
| 877 | configuration.outgoing_transport = this; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 878 | configuration.receive_statistics = rtp_receive_statistics_.get(); |
| 879 | configuration.bandwidth_callback = rtcp_observer_.get(); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 880 | if (pacing_enabled_) { |
| 881 | configuration.paced_sender = rtp_packet_sender_proxy_.get(); |
| 882 | configuration.transport_sequence_number_allocator = |
| 883 | seq_num_allocator_proxy_.get(); |
| 884 | configuration.transport_feedback_callback = feedback_observer_proxy_.get(); |
| 885 | } |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 886 | configuration.event_log = &(*event_log_proxy_); |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 887 | configuration.retransmission_rate_limiter = |
| 888 | retransmission_rate_limiter_.get(); |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 889 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 890 | _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 891 | _rtpRtcpModule->SetSendingMediaStatus(false); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 892 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 893 | statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); |
| 894 | rtp_receive_statistics_->RegisterRtcpStatisticsCallback( |
| 895 | statistics_proxy_.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 896 | } |
| 897 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 898 | Channel::~Channel() { |
| 899 | rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); |
| 900 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), |
| 901 | "Channel::~Channel() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 902 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 903 | if (_outputExternalMedia) { |
| 904 | DeRegisterExternalMediaProcessing(kPlaybackPerChannel); |
| 905 | } |
| 906 | if (channel_state_.Get().input_external_media) { |
| 907 | DeRegisterExternalMediaProcessing(kRecordingPerChannel); |
| 908 | } |
| 909 | StopSend(); |
| 910 | StopPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 911 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 912 | { |
| 913 | rtc::CritScope cs(&_fileCritSect); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 914 | if (input_file_player_) { |
| 915 | input_file_player_->RegisterModuleFileCallback(NULL); |
| 916 | input_file_player_->StopPlayingFile(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 917 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 918 | if (output_file_player_) { |
| 919 | output_file_player_->RegisterModuleFileCallback(NULL); |
| 920 | output_file_player_->StopPlayingFile(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 921 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 922 | if (output_file_recorder_) { |
| 923 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 924 | output_file_recorder_->StopRecording(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 925 | } |
| 926 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 927 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 928 | // The order to safely shutdown modules in a channel is: |
| 929 | // 1. De-register callbacks in modules |
| 930 | // 2. De-register modules in process thread |
| 931 | // 3. Destroy modules |
| 932 | if (audio_coding_->RegisterTransportCallback(NULL) == -1) { |
| 933 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 934 | "~Channel() failed to de-register transport callback" |
| 935 | " (Audio coding module)"); |
| 936 | } |
| 937 | if (audio_coding_->RegisterVADCallback(NULL) == -1) { |
| 938 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 939 | "~Channel() failed to de-register VAD callback" |
| 940 | " (Audio coding module)"); |
| 941 | } |
| 942 | // De-register modules in process thread |
| 943 | _moduleProcessThreadPtr->DeRegisterModule(_rtpRtcpModule.get()); |
tommi@webrtc.org | 3985f01 | 2015-02-27 13:36:34 +0000 | [diff] [blame] | 944 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 945 | // End of modules shutdown |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 946 | } |
| 947 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 948 | int32_t Channel::Init() { |
| 949 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 950 | "Channel::Init()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 951 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 952 | channel_state_.Reset(); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 953 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 954 | // --- Initial sanity |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 955 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 956 | if ((_engineStatisticsPtr == NULL) || (_moduleProcessThreadPtr == NULL)) { |
| 957 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 958 | "Channel::Init() must call SetEngineInformation() first"); |
| 959 | return -1; |
| 960 | } |
| 961 | |
| 962 | // --- Add modules to process thread (for periodic schedulation) |
| 963 | |
| 964 | _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get()); |
| 965 | |
| 966 | // --- ACM initialization |
| 967 | |
| 968 | if (audio_coding_->InitializeReceiver() == -1) { |
| 969 | _engineStatisticsPtr->SetLastError( |
| 970 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 971 | "Channel::Init() unable to initialize the ACM - 1"); |
| 972 | return -1; |
| 973 | } |
| 974 | |
| 975 | // --- RTP/RTCP module initialization |
| 976 | |
| 977 | // Ensure that RTCP is enabled by default for the created channel. |
| 978 | // Note that, the module will keep generating RTCP until it is explicitly |
| 979 | // disabled by the user. |
| 980 | // After StopListen (when no sockets exists), RTCP packets will no longer |
| 981 | // be transmitted since the Transport object will then be invalid. |
danilchap | 799a9d0 | 2016-09-22 03:36:27 -0700 | [diff] [blame] | 982 | telephone_event_handler_->SetTelephoneEventForwardToDecoder(true); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 983 | // RTCP is enabled by default. |
| 984 | _rtpRtcpModule->SetRTCPStatus(RtcpMode::kCompound); |
| 985 | // --- Register all permanent callbacks |
| 986 | const bool fail = (audio_coding_->RegisterTransportCallback(this) == -1) || |
| 987 | (audio_coding_->RegisterVADCallback(this) == -1); |
| 988 | |
| 989 | if (fail) { |
| 990 | _engineStatisticsPtr->SetLastError( |
| 991 | VE_CANNOT_INIT_CHANNEL, kTraceError, |
| 992 | "Channel::Init() callbacks not registered"); |
| 993 | return -1; |
| 994 | } |
| 995 | |
| 996 | // --- Register all supported codecs to the receiving side of the |
| 997 | // RTP/RTCP module |
| 998 | |
| 999 | CodecInst codec; |
| 1000 | const uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
| 1001 | |
| 1002 | for (int idx = 0; idx < nSupportedCodecs; idx++) { |
| 1003 | // Open up the RTP/RTCP receiver for all supported codecs |
| 1004 | if ((audio_coding_->Codec(idx, &codec) == -1) || |
| 1005 | (rtp_receiver_->RegisterReceivePayload( |
| 1006 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 1007 | (codec.rate < 0) ? 0 : codec.rate) == -1)) { |
| 1008 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1009 | "Channel::Init() unable to register %s " |
| 1010 | "(%d/%d/%" PRIuS "/%d) to RTP/RTCP receiver", |
| 1011 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 1012 | codec.rate); |
| 1013 | } else { |
| 1014 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1015 | "Channel::Init() %s (%d/%d/%" PRIuS |
| 1016 | "/%d) has been " |
| 1017 | "added to the RTP/RTCP receiver", |
| 1018 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 1019 | codec.rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1022 | // Ensure that PCMU is used as default codec on the sending side |
| 1023 | if (!STR_CASE_CMP(codec.plname, "PCMU") && (codec.channels == 1)) { |
| 1024 | SetSendCodec(codec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1027 | // Register default PT for outband 'telephone-event' |
| 1028 | if (!STR_CASE_CMP(codec.plname, "telephone-event")) { |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1029 | if (_rtpRtcpModule->RegisterSendPayload(codec) == -1 || |
| 1030 | !RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1031 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1032 | "Channel::Init() failed to register outband " |
| 1033 | "'telephone-event' (%d/%d) correctly", |
| 1034 | codec.pltype, codec.plfreq); |
| 1035 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1038 | if (!STR_CASE_CMP(codec.plname, "CN")) { |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1039 | if (!codec_manager_.RegisterEncoder(codec) || |
| 1040 | !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get()) || |
| 1041 | !RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec) || |
| 1042 | _rtpRtcpModule->RegisterSendPayload(codec) == -1) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1043 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1044 | "Channel::Init() failed to register CN (%d/%d) " |
| 1045 | "correctly - 1", |
| 1046 | codec.pltype, codec.plfreq); |
| 1047 | } |
| 1048 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1049 | } |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 1050 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1051 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1054 | int32_t Channel::SetEngineInformation(Statistics& engineStatistics, |
| 1055 | OutputMixer& outputMixer, |
| 1056 | voe::TransmitMixer& transmitMixer, |
| 1057 | ProcessThread& moduleProcessThread, |
| 1058 | AudioDeviceModule& audioDeviceModule, |
| 1059 | VoiceEngineObserver* voiceEngineObserver, |
| 1060 | rtc::CriticalSection* callbackCritSect) { |
| 1061 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1062 | "Channel::SetEngineInformation()"); |
| 1063 | _engineStatisticsPtr = &engineStatistics; |
| 1064 | _outputMixerPtr = &outputMixer; |
| 1065 | _transmitMixerPtr = &transmitMixer, |
| 1066 | _moduleProcessThreadPtr = &moduleProcessThread; |
| 1067 | _audioDeviceModulePtr = &audioDeviceModule; |
| 1068 | _voiceEngineObserverPtr = voiceEngineObserver; |
| 1069 | _callbackCritSectPtr = callbackCritSect; |
| 1070 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1073 | int32_t Channel::UpdateLocalTimeStamp() { |
| 1074 | _timeStamp += static_cast<uint32_t>(_audioFrame.samples_per_channel_); |
| 1075 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 1078 | void Channel::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 1079 | rtc::CritScope cs(&_callbackCritSect); |
deadbeef | 2d110be | 2016-01-13 12:00:26 -0800 | [diff] [blame] | 1080 | audio_sink_ = std::move(sink); |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 1083 | const rtc::scoped_refptr<AudioDecoderFactory>& |
| 1084 | Channel::GetAudioDecoderFactory() const { |
| 1085 | return decoder_factory_; |
| 1086 | } |
| 1087 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1088 | int32_t Channel::StartPlayout() { |
| 1089 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1090 | "Channel::StartPlayout()"); |
| 1091 | if (channel_state_.Get().playing) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1092 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | if (!_externalMixing) { |
| 1096 | // Add participant as candidates for mixing. |
| 1097 | if (_outputMixerPtr->SetMixabilityStatus(*this, true) != 0) { |
| 1098 | _engineStatisticsPtr->SetLastError( |
| 1099 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 1100 | "StartPlayout() failed to add participant to mixer"); |
| 1101 | return -1; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | channel_state_.SetPlaying(true); |
| 1106 | if (RegisterFilePlayingToMixer() != 0) |
| 1107 | return -1; |
| 1108 | |
| 1109 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1112 | int32_t Channel::StopPlayout() { |
| 1113 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1114 | "Channel::StopPlayout()"); |
| 1115 | if (!channel_state_.Get().playing) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1116 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | if (!_externalMixing) { |
| 1120 | // Remove participant as candidates for mixing |
| 1121 | if (_outputMixerPtr->SetMixabilityStatus(*this, false) != 0) { |
| 1122 | _engineStatisticsPtr->SetLastError( |
| 1123 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 1124 | "StopPlayout() failed to remove participant from mixer"); |
| 1125 | return -1; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | channel_state_.SetPlaying(false); |
| 1130 | _outputAudioLevel.Clear(); |
| 1131 | |
| 1132 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1135 | int32_t Channel::StartSend() { |
| 1136 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1137 | "Channel::StartSend()"); |
| 1138 | // Resume the previous sequence number which was reset by StopSend(). |
| 1139 | // This needs to be done before |sending| is set to true. |
| 1140 | if (send_sequence_number_) |
| 1141 | SetInitSequenceNumber(send_sequence_number_); |
xians@webrtc.org | 09e8c47 | 2013-07-31 16:30:19 +0000 | [diff] [blame] | 1142 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1143 | if (channel_state_.Get().sending) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1144 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1145 | } |
| 1146 | channel_state_.SetSending(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1147 | |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 1148 | _rtpRtcpModule->SetSendingMediaStatus(true); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1149 | if (_rtpRtcpModule->SetSendingStatus(true) != 0) { |
| 1150 | _engineStatisticsPtr->SetLastError( |
| 1151 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1152 | "StartSend() RTP/RTCP failed to start sending"); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 1153 | _rtpRtcpModule->SetSendingMediaStatus(false); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1154 | rtc::CritScope cs(&_callbackCritSect); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1155 | channel_state_.SetSending(false); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1156 | return -1; |
| 1157 | } |
xians@webrtc.org | e07247a | 2011-11-28 16:31:28 +0000 | [diff] [blame] | 1158 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1159 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1162 | int32_t Channel::StopSend() { |
| 1163 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1164 | "Channel::StopSend()"); |
| 1165 | if (!channel_state_.Get().sending) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1166 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1167 | } |
| 1168 | channel_state_.SetSending(false); |
| 1169 | |
| 1170 | // Store the sequence number to be able to pick up the same sequence for |
| 1171 | // the next StartSend(). This is needed for restarting device, otherwise |
| 1172 | // it might cause libSRTP to complain about packets being replayed. |
| 1173 | // TODO(xians): Remove this workaround after RtpRtcpModule's refactoring |
| 1174 | // CL is landed. See issue |
| 1175 | // https://code.google.com/p/webrtc/issues/detail?id=2111 . |
| 1176 | send_sequence_number_ = _rtpRtcpModule->SequenceNumber(); |
| 1177 | |
| 1178 | // Reset sending SSRC and sequence number and triggers direct transmission |
| 1179 | // of RTCP BYE |
| 1180 | if (_rtpRtcpModule->SetSendingStatus(false) == -1) { |
| 1181 | _engineStatisticsPtr->SetLastError( |
| 1182 | VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
| 1183 | "StartSend() RTP/RTCP failed to stop sending"); |
| 1184 | } |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 1185 | _rtpRtcpModule->SetSendingMediaStatus(false); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1186 | |
| 1187 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1190 | int32_t Channel::StartReceiving() { |
| 1191 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1192 | "Channel::StartReceiving()"); |
| 1193 | if (channel_state_.Get().receiving) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1194 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1195 | } |
| 1196 | channel_state_.SetReceiving(true); |
| 1197 | _numberOfDiscardedPackets = 0; |
| 1198 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1201 | int32_t Channel::StopReceiving() { |
| 1202 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1203 | "Channel::StopReceiving()"); |
| 1204 | if (!channel_state_.Get().receiving) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1205 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | channel_state_.SetReceiving(false); |
| 1209 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1212 | int32_t Channel::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) { |
| 1213 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1214 | "Channel::RegisterVoiceEngineObserver()"); |
| 1215 | rtc::CritScope cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1216 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1217 | if (_voiceEngineObserverPtr) { |
| 1218 | _engineStatisticsPtr->SetLastError( |
| 1219 | VE_INVALID_OPERATION, kTraceError, |
| 1220 | "RegisterVoiceEngineObserver() observer already enabled"); |
| 1221 | return -1; |
| 1222 | } |
| 1223 | _voiceEngineObserverPtr = &observer; |
| 1224 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1227 | int32_t Channel::DeRegisterVoiceEngineObserver() { |
| 1228 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1229 | "Channel::DeRegisterVoiceEngineObserver()"); |
| 1230 | rtc::CritScope cs(&_callbackCritSect); |
| 1231 | |
| 1232 | if (!_voiceEngineObserverPtr) { |
| 1233 | _engineStatisticsPtr->SetLastError( |
| 1234 | VE_INVALID_OPERATION, kTraceWarning, |
| 1235 | "DeRegisterVoiceEngineObserver() observer already disabled"); |
| 1236 | return 0; |
| 1237 | } |
| 1238 | _voiceEngineObserverPtr = NULL; |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | int32_t Channel::GetSendCodec(CodecInst& codec) { |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1243 | auto send_codec = codec_manager_.GetCodecInst(); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 1244 | if (send_codec) { |
| 1245 | codec = *send_codec; |
| 1246 | return 0; |
| 1247 | } |
| 1248 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1251 | int32_t Channel::GetRecCodec(CodecInst& codec) { |
| 1252 | return (audio_coding_->ReceiveCodec(&codec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1255 | int32_t Channel::SetSendCodec(const CodecInst& codec) { |
| 1256 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1257 | "Channel::SetSendCodec()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1258 | |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1259 | if (!codec_manager_.RegisterEncoder(codec) || |
| 1260 | !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1261 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1262 | "SetSendCodec() failed to register codec to ACM"); |
| 1263 | return -1; |
| 1264 | } |
| 1265 | |
| 1266 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 1267 | _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 1268 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 1269 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1270 | "SetSendCodec() failed to register codec to" |
| 1271 | " RTP/RTCP module"); |
| 1272 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1273 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1274 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1275 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1276 | if (_rtpRtcpModule->SetAudioPacketSize(codec.pacsize) != 0) { |
| 1277 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1278 | "SetSendCodec() failed to set audio packet size"); |
| 1279 | return -1; |
| 1280 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1281 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1282 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 1285 | void Channel::SetBitRate(int bitrate_bps) { |
| 1286 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1287 | "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); |
| 1288 | audio_coding_->SetBitRate(bitrate_bps); |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1289 | retransmission_rate_limiter_->SetMaxRate(bitrate_bps); |
Ivo Creusen | adf89b7 | 2015-04-29 16:03:33 +0200 | [diff] [blame] | 1290 | } |
| 1291 | |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 1292 | void Channel::OnIncomingFractionLoss(int fraction_lost) { |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 1293 | network_predictor_->UpdatePacketLossRate(fraction_lost); |
mflodman@webrtc.org | 0a7d4ee | 2015-02-17 12:57:14 +0000 | [diff] [blame] | 1294 | uint8_t average_fraction_loss = network_predictor_->GetLossRate(); |
| 1295 | |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 1296 | // Normalizes rate to 0 - 100. |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1297 | if (audio_coding_->SetPacketLossRate(100 * average_fraction_loss / 255) != |
| 1298 | 0) { |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 1299 | assert(false); // This should not happen. |
| 1300 | } |
| 1301 | } |
| 1302 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1303 | int32_t Channel::SetVADStatus(bool enableVAD, |
| 1304 | ACMVADMode mode, |
| 1305 | bool disableDTX) { |
| 1306 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1307 | "Channel::SetVADStatus(mode=%d)", mode); |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1308 | RTC_DCHECK(!(disableDTX && enableVAD)); // disableDTX mode is deprecated. |
| 1309 | if (!codec_manager_.SetVAD(enableVAD, mode) || |
| 1310 | !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1311 | _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR, |
| 1312 | kTraceError, |
| 1313 | "SetVADStatus() failed to set VAD"); |
| 1314 | return -1; |
| 1315 | } |
| 1316 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1319 | int32_t Channel::GetVADStatus(bool& enabledVAD, |
| 1320 | ACMVADMode& mode, |
| 1321 | bool& disabledDTX) { |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1322 | const auto* params = codec_manager_.GetStackParams(); |
| 1323 | enabledVAD = params->use_cng; |
| 1324 | mode = params->vad_mode; |
| 1325 | disabledDTX = !params->use_cng; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1326 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1329 | int32_t Channel::SetRecPayloadType(const CodecInst& codec) { |
| 1330 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1331 | "Channel::SetRecPayloadType()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1332 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1333 | if (channel_state_.Get().playing) { |
| 1334 | _engineStatisticsPtr->SetLastError( |
| 1335 | VE_ALREADY_PLAYING, kTraceError, |
| 1336 | "SetRecPayloadType() unable to set PT while playing"); |
| 1337 | return -1; |
| 1338 | } |
| 1339 | if (channel_state_.Get().receiving) { |
| 1340 | _engineStatisticsPtr->SetLastError( |
| 1341 | VE_ALREADY_LISTENING, kTraceError, |
| 1342 | "SetRecPayloadType() unable to set PT while listening"); |
| 1343 | return -1; |
| 1344 | } |
| 1345 | |
| 1346 | if (codec.pltype == -1) { |
| 1347 | // De-register the selected codec (RTP/RTCP module and ACM) |
| 1348 | |
| 1349 | int8_t pltype(-1); |
| 1350 | CodecInst rxCodec = codec; |
| 1351 | |
| 1352 | // Get payload type for the given codec |
| 1353 | rtp_payload_registry_->ReceivePayloadType( |
| 1354 | rxCodec.plname, rxCodec.plfreq, rxCodec.channels, |
| 1355 | (rxCodec.rate < 0) ? 0 : rxCodec.rate, &pltype); |
| 1356 | rxCodec.pltype = pltype; |
| 1357 | |
| 1358 | if (rtp_receiver_->DeRegisterReceivePayload(pltype) != 0) { |
| 1359 | _engineStatisticsPtr->SetLastError( |
| 1360 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1361 | "SetRecPayloadType() RTP/RTCP-module deregistration " |
| 1362 | "failed"); |
| 1363 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1364 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1365 | if (audio_coding_->UnregisterReceiveCodec(rxCodec.pltype) != 0) { |
| 1366 | _engineStatisticsPtr->SetLastError( |
| 1367 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1368 | "SetRecPayloadType() ACM deregistration failed - 1"); |
| 1369 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1370 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1371 | return 0; |
| 1372 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1373 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1374 | if (rtp_receiver_->RegisterReceivePayload( |
| 1375 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 1376 | (codec.rate < 0) ? 0 : codec.rate) != 0) { |
| 1377 | // First attempt to register failed => de-register and try again |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1378 | // TODO(kwiberg): Retrying is probably not necessary, since |
| 1379 | // AcmReceiver::AddCodec also retries. |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1380 | rtp_receiver_->DeRegisterReceivePayload(codec.pltype); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1381 | if (rtp_receiver_->RegisterReceivePayload( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1382 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 1383 | (codec.rate < 0) ? 0 : codec.rate) != 0) { |
| 1384 | _engineStatisticsPtr->SetLastError( |
| 1385 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1386 | "SetRecPayloadType() RTP/RTCP-module registration failed"); |
| 1387 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1388 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1389 | } |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1390 | if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1391 | audio_coding_->UnregisterReceiveCodec(codec.pltype); |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1392 | if (!RegisterReceiveCodec(&audio_coding_, &rent_a_codec_, codec)) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1393 | _engineStatisticsPtr->SetLastError( |
| 1394 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1395 | "SetRecPayloadType() ACM registration failed - 1"); |
| 1396 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1397 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1398 | } |
| 1399 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1402 | int32_t Channel::GetRecPayloadType(CodecInst& codec) { |
| 1403 | int8_t payloadType(-1); |
| 1404 | if (rtp_payload_registry_->ReceivePayloadType( |
| 1405 | codec.plname, codec.plfreq, codec.channels, |
| 1406 | (codec.rate < 0) ? 0 : codec.rate, &payloadType) != 0) { |
| 1407 | _engineStatisticsPtr->SetLastError( |
| 1408 | VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, |
| 1409 | "GetRecPayloadType() failed to retrieve RX payload type"); |
| 1410 | return -1; |
| 1411 | } |
| 1412 | codec.pltype = payloadType; |
| 1413 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1416 | int32_t Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency) { |
| 1417 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1418 | "Channel::SetSendCNPayloadType()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1419 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1420 | CodecInst codec; |
| 1421 | int32_t samplingFreqHz(-1); |
| 1422 | const size_t kMono = 1; |
| 1423 | if (frequency == kFreq32000Hz) |
| 1424 | samplingFreqHz = 32000; |
| 1425 | else if (frequency == kFreq16000Hz) |
| 1426 | samplingFreqHz = 16000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1427 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1428 | if (audio_coding_->Codec("CN", &codec, samplingFreqHz, kMono) == -1) { |
| 1429 | _engineStatisticsPtr->SetLastError( |
| 1430 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1431 | "SetSendCNPayloadType() failed to retrieve default CN codec " |
| 1432 | "settings"); |
| 1433 | return -1; |
| 1434 | } |
| 1435 | |
| 1436 | // Modify the payload type (must be set to dynamic range) |
| 1437 | codec.pltype = type; |
| 1438 | |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 1439 | if (!codec_manager_.RegisterEncoder(codec) || |
| 1440 | !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1441 | _engineStatisticsPtr->SetLastError( |
| 1442 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 1443 | "SetSendCNPayloadType() failed to register CN to ACM"); |
| 1444 | return -1; |
| 1445 | } |
| 1446 | |
| 1447 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 1448 | _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 1449 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 1450 | _engineStatisticsPtr->SetLastError( |
| 1451 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 1452 | "SetSendCNPayloadType() failed to register CN to RTP/RTCP " |
| 1453 | "module"); |
| 1454 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1455 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1456 | } |
| 1457 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1460 | int Channel::SetOpusMaxPlaybackRate(int frequency_hz) { |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1461 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1462 | "Channel::SetOpusMaxPlaybackRate()"); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1463 | |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1464 | if (audio_coding_->SetOpusMaxPlaybackRate(frequency_hz) != 0) { |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1465 | _engineStatisticsPtr->SetLastError( |
| 1466 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
minyue@webrtc.org | adee8f9 | 2014-09-03 12:28:06 +0000 | [diff] [blame] | 1467 | "SetOpusMaxPlaybackRate() failed to set maximum playback rate"); |
minyue@webrtc.org | 6aac93b | 2014-08-12 08:13:33 +0000 | [diff] [blame] | 1468 | return -1; |
| 1469 | } |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 1473 | int Channel::SetOpusDtx(bool enable_dtx) { |
| 1474 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1475 | "Channel::SetOpusDtx(%d)", enable_dtx); |
Minyue Li | 092041c | 2015-05-11 12:19:35 +0200 | [diff] [blame] | 1476 | int ret = enable_dtx ? audio_coding_->EnableOpusDtx() |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 1477 | : audio_coding_->DisableOpusDtx(); |
| 1478 | if (ret != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1479 | _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR, |
| 1480 | kTraceError, "SetOpusDtx() failed"); |
minyue@webrtc.org | 9b2e114 | 2015-03-13 09:38:07 +0000 | [diff] [blame] | 1481 | return -1; |
| 1482 | } |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
ivoc | 85228d6 | 2016-07-27 04:53:47 -0700 | [diff] [blame] | 1486 | int Channel::GetOpusDtx(bool* enabled) { |
| 1487 | int success = -1; |
| 1488 | audio_coding_->QueryEncoder([&](AudioEncoder const* encoder) { |
| 1489 | if (encoder) { |
| 1490 | *enabled = encoder->GetDtx(); |
| 1491 | success = 0; |
| 1492 | } |
| 1493 | }); |
| 1494 | return success; |
| 1495 | } |
| 1496 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 1497 | int32_t Channel::RegisterExternalTransport(Transport* transport) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1498 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1499 | "Channel::RegisterExternalTransport()"); |
| 1500 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1501 | rtc::CritScope cs(&_callbackCritSect); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1502 | if (_externalTransport) { |
| 1503 | _engineStatisticsPtr->SetLastError( |
| 1504 | VE_INVALID_OPERATION, kTraceError, |
| 1505 | "RegisterExternalTransport() external transport already enabled"); |
| 1506 | return -1; |
| 1507 | } |
| 1508 | _externalTransport = true; |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 1509 | _transportPtr = transport; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1510 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1513 | int32_t Channel::DeRegisterExternalTransport() { |
| 1514 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1515 | "Channel::DeRegisterExternalTransport()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1516 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1517 | rtc::CritScope cs(&_callbackCritSect); |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 1518 | if (_transportPtr) { |
| 1519 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1520 | "DeRegisterExternalTransport() all transport is disabled"); |
| 1521 | } else { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1522 | _engineStatisticsPtr->SetLastError( |
| 1523 | VE_INVALID_OPERATION, kTraceWarning, |
| 1524 | "DeRegisterExternalTransport() external transport already " |
| 1525 | "disabled"); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1526 | } |
| 1527 | _externalTransport = false; |
| 1528 | _transportPtr = NULL; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1529 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 1532 | int32_t Channel::ReceivedRTPPacket(const uint8_t* received_packet, |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1533 | size_t length, |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 1534 | const PacketTime& packet_time) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1535 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1536 | "Channel::ReceivedRTPPacket()"); |
| 1537 | |
| 1538 | // Store playout timestamp for the received RTP packet |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 1539 | UpdatePlayoutTimestamp(false); |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1540 | |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 1541 | RTPHeader header; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1542 | if (!rtp_header_parser_->Parse(received_packet, length, &header)) { |
| 1543 | WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 1544 | "Incoming packet: invalid RTP header"); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 1545 | return -1; |
| 1546 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1547 | header.payload_type_frequency = |
| 1548 | rtp_payload_registry_->GetPayloadTypeFrequency(header.payloadType); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1549 | if (header.payload_type_frequency < 0) |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1550 | return -1; |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1551 | bool in_order = IsPacketInOrder(header); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1552 | rtp_receive_statistics_->IncomingPacket( |
| 1553 | header, length, IsPacketRetransmitted(header, in_order)); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1554 | rtp_payload_registry_->SetIncomingPayloadType(header); |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 1555 | |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1556 | return ReceivePacket(received_packet, length, header, in_order) ? 0 : -1; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | bool Channel::ReceivePacket(const uint8_t* packet, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1560 | size_t packet_length, |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1561 | const RTPHeader& header, |
| 1562 | bool in_order) { |
minyue@webrtc.org | 456f014 | 2015-01-23 11:58:42 +0000 | [diff] [blame] | 1563 | if (rtp_payload_registry_->IsRtx(header)) { |
| 1564 | return HandleRtxPacket(packet, packet_length, header); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1565 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1566 | const uint8_t* payload = packet + header.headerLength; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1567 | assert(packet_length >= header.headerLength); |
| 1568 | size_t payload_length = packet_length - header.headerLength; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1569 | PayloadUnion payload_specific; |
| 1570 | if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1571 | &payload_specific)) { |
| 1572 | return false; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1573 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1574 | return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, |
| 1575 | payload_specific, in_order); |
| 1576 | } |
| 1577 | |
minyue@webrtc.org | 456f014 | 2015-01-23 11:58:42 +0000 | [diff] [blame] | 1578 | bool Channel::HandleRtxPacket(const uint8_t* packet, |
| 1579 | size_t packet_length, |
| 1580 | const RTPHeader& header) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1581 | if (!rtp_payload_registry_->IsRtx(header)) |
| 1582 | return false; |
| 1583 | |
| 1584 | // Remove the RTX header and parse the original RTP header. |
| 1585 | if (packet_length < header.headerLength) |
| 1586 | return false; |
| 1587 | if (packet_length > kVoiceEngineMaxIpPacketSizeBytes) |
| 1588 | return false; |
| 1589 | if (restored_packet_in_use_) { |
| 1590 | WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 1591 | "Multiple RTX headers detected, dropping packet"); |
| 1592 | return false; |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1593 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1594 | if (!rtp_payload_registry_->RestoreOriginalPacket( |
noahric | 65220a7 | 2015-10-14 11:29:49 -0700 | [diff] [blame] | 1595 | restored_packet_, packet, &packet_length, rtp_receiver_->SSRC(), |
| 1596 | header)) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1597 | WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVoice, _channelId, |
| 1598 | "Incoming RTX packet: invalid RTP header"); |
| 1599 | return false; |
| 1600 | } |
| 1601 | restored_packet_in_use_ = true; |
noahric | 65220a7 | 2015-10-14 11:29:49 -0700 | [diff] [blame] | 1602 | bool ret = OnRecoveredPacket(restored_packet_, packet_length); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1603 | restored_packet_in_use_ = false; |
| 1604 | return ret; |
| 1605 | } |
| 1606 | |
| 1607 | bool Channel::IsPacketInOrder(const RTPHeader& header) const { |
| 1608 | StreamStatistician* statistician = |
| 1609 | rtp_receive_statistics_->GetStatistician(header.ssrc); |
| 1610 | if (!statistician) |
| 1611 | return false; |
| 1612 | return statistician->IsPacketInOrder(header.sequenceNumber); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 1615 | bool Channel::IsPacketRetransmitted(const RTPHeader& header, |
| 1616 | bool in_order) const { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1617 | // Retransmissions are handled separately if RTX is enabled. |
| 1618 | if (rtp_payload_registry_->RtxEnabled()) |
| 1619 | return false; |
| 1620 | StreamStatistician* statistician = |
| 1621 | rtp_receive_statistics_->GetStatistician(header.ssrc); |
| 1622 | if (!statistician) |
| 1623 | return false; |
| 1624 | // Check if this is a retransmission. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 1625 | int64_t min_rtt = 0; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 1626 | _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1627 | return !in_order && statistician->IsRetransmitOfOldPacket(header, min_rtt); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 1630 | int32_t Channel::ReceivedRTCPPacket(const uint8_t* data, size_t length) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1631 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1632 | "Channel::ReceivedRTCPPacket()"); |
| 1633 | // Store playout timestamp for the received RTCP packet |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 1634 | UpdatePlayoutTimestamp(true); |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1635 | |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1636 | // Deliver RTCP packet to RTP/RTCP module for parsing |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 1637 | if (_rtpRtcpModule->IncomingRtcpPacket(data, length) == -1) { |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1638 | _engineStatisticsPtr->SetLastError( |
| 1639 | VE_SOCKET_TRANSPORT_MODULE_ERROR, kTraceWarning, |
| 1640 | "Channel::IncomingRTPPacket() RTCP packet is invalid"); |
| 1641 | } |
wu@webrtc.org | 82c4b85 | 2014-05-20 22:55:01 +0000 | [diff] [blame] | 1642 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 1643 | int64_t rtt = GetRTT(true); |
| 1644 | if (rtt == 0) { |
| 1645 | // Waiting for valid RTT. |
| 1646 | return 0; |
| 1647 | } |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1648 | |
| 1649 | int64_t nack_window_ms = rtt; |
| 1650 | if (nack_window_ms < kMinRetransmissionWindowMs) { |
| 1651 | nack_window_ms = kMinRetransmissionWindowMs; |
| 1652 | } else if (nack_window_ms > kMaxRetransmissionWindowMs) { |
| 1653 | nack_window_ms = kMaxRetransmissionWindowMs; |
| 1654 | } |
| 1655 | retransmission_rate_limiter_->SetWindowSize(nack_window_ms); |
| 1656 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 1657 | uint32_t ntp_secs = 0; |
| 1658 | uint32_t ntp_frac = 0; |
| 1659 | uint32_t rtp_timestamp = 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1660 | if (0 != |
| 1661 | _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, |
| 1662 | &rtp_timestamp)) { |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 1663 | // Waiting for RTCP. |
| 1664 | return 0; |
| 1665 | } |
| 1666 | |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 1667 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 1668 | rtc::CritScope lock(&ts_stats_lock_); |
minyue@webrtc.org | 2c0cdbc | 2014-10-09 10:52:43 +0000 | [diff] [blame] | 1669 | ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); |
stefan@webrtc.org | 8e24d87 | 2014-09-02 18:58:24 +0000 | [diff] [blame] | 1670 | } |
pwestin@webrtc.org | 0c45957 | 2013-04-03 15:43:57 +0000 | [diff] [blame] | 1671 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1674 | int Channel::StartPlayingFileLocally(const char* fileName, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 1675 | bool loop, |
| 1676 | FileFormats format, |
| 1677 | int startPosition, |
| 1678 | float volumeScaling, |
| 1679 | int stopPosition, |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1680 | const CodecInst* codecInst) { |
| 1681 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1682 | "Channel::StartPlayingFileLocally(fileNameUTF8[]=%s, loop=%d," |
| 1683 | " format=%d, volumeScaling=%5.3f, startPosition=%d, " |
| 1684 | "stopPosition=%d)", |
| 1685 | fileName, loop, format, volumeScaling, startPosition, |
| 1686 | stopPosition); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1687 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1688 | if (channel_state_.Get().output_file_playing) { |
| 1689 | _engineStatisticsPtr->SetLastError( |
| 1690 | VE_ALREADY_PLAYING, kTraceError, |
| 1691 | "StartPlayingFileLocally() is already playing"); |
| 1692 | return -1; |
| 1693 | } |
| 1694 | |
| 1695 | { |
| 1696 | rtc::CritScope cs(&_fileCritSect); |
| 1697 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1698 | if (output_file_player_) { |
| 1699 | output_file_player_->RegisterModuleFileCallback(NULL); |
| 1700 | output_file_player_.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
kwiberg | 5b356f4 | 2016-09-08 04:32:33 -0700 | [diff] [blame] | 1703 | output_file_player_ = FilePlayer::CreateFilePlayer( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1704 | _outputFilePlayerId, (const FileFormats)format); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1705 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1706 | if (!output_file_player_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1707 | _engineStatisticsPtr->SetLastError( |
| 1708 | VE_INVALID_ARGUMENT, kTraceError, |
| 1709 | "StartPlayingFileLocally() filePlayer format is not correct"); |
| 1710 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1711 | } |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1712 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1713 | const uint32_t notificationTime(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1714 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1715 | if (output_file_player_->StartPlayingFile( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1716 | fileName, loop, startPosition, volumeScaling, notificationTime, |
| 1717 | stopPosition, (const CodecInst*)codecInst) != 0) { |
| 1718 | _engineStatisticsPtr->SetLastError( |
| 1719 | VE_BAD_FILE, kTraceError, |
| 1720 | "StartPlayingFile() failed to start file playout"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1721 | output_file_player_->StopPlayingFile(); |
| 1722 | output_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1723 | return -1; |
| 1724 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1725 | output_file_player_->RegisterModuleFileCallback(this); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1726 | channel_state_.SetOutputFilePlaying(true); |
| 1727 | } |
| 1728 | |
| 1729 | if (RegisterFilePlayingToMixer() != 0) |
| 1730 | return -1; |
| 1731 | |
| 1732 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | int Channel::StartPlayingFileLocally(InStream* stream, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 1736 | FileFormats format, |
| 1737 | int startPosition, |
| 1738 | float volumeScaling, |
| 1739 | int stopPosition, |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1740 | const CodecInst* codecInst) { |
| 1741 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1742 | "Channel::StartPlayingFileLocally(format=%d," |
| 1743 | " volumeScaling=%5.3f, startPosition=%d, stopPosition=%d)", |
| 1744 | format, volumeScaling, startPosition, stopPosition); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1745 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1746 | if (stream == NULL) { |
| 1747 | _engineStatisticsPtr->SetLastError( |
| 1748 | VE_BAD_FILE, kTraceError, |
| 1749 | "StartPlayingFileLocally() NULL as input stream"); |
| 1750 | return -1; |
| 1751 | } |
| 1752 | |
| 1753 | if (channel_state_.Get().output_file_playing) { |
| 1754 | _engineStatisticsPtr->SetLastError( |
| 1755 | VE_ALREADY_PLAYING, kTraceError, |
| 1756 | "StartPlayingFileLocally() is already playing"); |
| 1757 | return -1; |
| 1758 | } |
| 1759 | |
| 1760 | { |
| 1761 | rtc::CritScope cs(&_fileCritSect); |
| 1762 | |
| 1763 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1764 | if (output_file_player_) { |
| 1765 | output_file_player_->RegisterModuleFileCallback(NULL); |
| 1766 | output_file_player_.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1769 | // Create the instance |
kwiberg | 5b356f4 | 2016-09-08 04:32:33 -0700 | [diff] [blame] | 1770 | output_file_player_ = FilePlayer::CreateFilePlayer( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1771 | _outputFilePlayerId, (const FileFormats)format); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1772 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1773 | if (!output_file_player_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1774 | _engineStatisticsPtr->SetLastError( |
| 1775 | VE_INVALID_ARGUMENT, kTraceError, |
| 1776 | "StartPlayingFileLocally() filePlayer format isnot correct"); |
| 1777 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1780 | const uint32_t notificationTime(0); |
henrike@webrtc.org | b37c628 | 2011-10-31 23:53:04 +0000 | [diff] [blame] | 1781 | |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 1782 | if (output_file_player_->StartPlayingFile(stream, startPosition, |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1783 | volumeScaling, notificationTime, |
| 1784 | stopPosition, codecInst) != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1785 | _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, |
| 1786 | "StartPlayingFile() failed to " |
| 1787 | "start file playout"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1788 | output_file_player_->StopPlayingFile(); |
| 1789 | output_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1790 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1791 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1792 | output_file_player_->RegisterModuleFileCallback(this); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1793 | channel_state_.SetOutputFilePlaying(true); |
| 1794 | } |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1795 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1796 | if (RegisterFilePlayingToMixer() != 0) |
| 1797 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1798 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1799 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1802 | int Channel::StopPlayingFileLocally() { |
| 1803 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1804 | "Channel::StopPlayingFileLocally()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1805 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1806 | if (!channel_state_.Get().output_file_playing) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1807 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | { |
| 1811 | rtc::CritScope cs(&_fileCritSect); |
| 1812 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1813 | if (output_file_player_->StopPlayingFile() != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1814 | _engineStatisticsPtr->SetLastError( |
| 1815 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 1816 | "StopPlayingFile() could not stop playing"); |
| 1817 | return -1; |
| 1818 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1819 | output_file_player_->RegisterModuleFileCallback(NULL); |
| 1820 | output_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1821 | channel_state_.SetOutputFilePlaying(false); |
| 1822 | } |
| 1823 | // _fileCritSect cannot be taken while calling |
| 1824 | // SetAnonymousMixibilityStatus. Refer to comments in |
| 1825 | // StartPlayingFileLocally(const char* ...) for more details. |
| 1826 | if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, false) != 0) { |
| 1827 | _engineStatisticsPtr->SetLastError( |
| 1828 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 1829 | "StopPlayingFile() failed to stop participant from playing as" |
| 1830 | "file in the mixer"); |
| 1831 | return -1; |
| 1832 | } |
| 1833 | |
| 1834 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1837 | int Channel::IsPlayingFileLocally() const { |
| 1838 | return channel_state_.Get().output_file_playing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1841 | int Channel::RegisterFilePlayingToMixer() { |
| 1842 | // Return success for not registering for file playing to mixer if: |
| 1843 | // 1. playing file before playout is started on that channel. |
| 1844 | // 2. starting playout without file playing on that channel. |
| 1845 | if (!channel_state_.Get().playing || |
| 1846 | !channel_state_.Get().output_file_playing) { |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1847 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | // |_fileCritSect| cannot be taken while calling |
| 1851 | // SetAnonymousMixabilityStatus() since as soon as the participant is added |
| 1852 | // frames can be pulled by the mixer. Since the frames are generated from |
| 1853 | // the file, _fileCritSect will be taken. This would result in a deadlock. |
| 1854 | if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, true) != 0) { |
| 1855 | channel_state_.SetOutputFilePlaying(false); |
| 1856 | rtc::CritScope cs(&_fileCritSect); |
| 1857 | _engineStatisticsPtr->SetLastError( |
| 1858 | VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, |
| 1859 | "StartPlayingFile() failed to add participant as file to mixer"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1860 | output_file_player_->StopPlayingFile(); |
| 1861 | output_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1862 | return -1; |
| 1863 | } |
| 1864 | |
| 1865 | return 0; |
braveyao@webrtc.org | ab12990 | 2012-06-04 03:26:39 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1868 | int Channel::StartPlayingFileAsMicrophone(const char* fileName, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 1869 | bool loop, |
| 1870 | FileFormats format, |
| 1871 | int startPosition, |
| 1872 | float volumeScaling, |
| 1873 | int stopPosition, |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1874 | const CodecInst* codecInst) { |
| 1875 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1876 | "Channel::StartPlayingFileAsMicrophone(fileNameUTF8[]=%s, " |
| 1877 | "loop=%d, format=%d, volumeScaling=%5.3f, startPosition=%d, " |
| 1878 | "stopPosition=%d)", |
| 1879 | fileName, loop, format, volumeScaling, startPosition, |
| 1880 | stopPosition); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1881 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1882 | rtc::CritScope cs(&_fileCritSect); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1883 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1884 | if (channel_state_.Get().input_file_playing) { |
| 1885 | _engineStatisticsPtr->SetLastError( |
| 1886 | VE_ALREADY_PLAYING, kTraceWarning, |
| 1887 | "StartPlayingFileAsMicrophone() filePlayer is playing"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1888 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1892 | if (input_file_player_) { |
| 1893 | input_file_player_->RegisterModuleFileCallback(NULL); |
| 1894 | input_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | // Create the instance |
kwiberg | 5b356f4 | 2016-09-08 04:32:33 -0700 | [diff] [blame] | 1898 | input_file_player_ = FilePlayer::CreateFilePlayer(_inputFilePlayerId, |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1899 | (const FileFormats)format); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1900 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1901 | if (!input_file_player_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1902 | _engineStatisticsPtr->SetLastError( |
| 1903 | VE_INVALID_ARGUMENT, kTraceError, |
| 1904 | "StartPlayingFileAsMicrophone() filePlayer format isnot correct"); |
| 1905 | return -1; |
| 1906 | } |
| 1907 | |
| 1908 | const uint32_t notificationTime(0); |
| 1909 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1910 | if (input_file_player_->StartPlayingFile( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1911 | fileName, loop, startPosition, volumeScaling, notificationTime, |
| 1912 | stopPosition, (const CodecInst*)codecInst) != 0) { |
| 1913 | _engineStatisticsPtr->SetLastError( |
| 1914 | VE_BAD_FILE, kTraceError, |
| 1915 | "StartPlayingFile() failed to start file playout"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1916 | input_file_player_->StopPlayingFile(); |
| 1917 | input_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1918 | return -1; |
| 1919 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1920 | input_file_player_->RegisterModuleFileCallback(this); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1921 | channel_state_.SetInputFilePlaying(true); |
| 1922 | |
| 1923 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | int Channel::StartPlayingFileAsMicrophone(InStream* stream, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 1927 | FileFormats format, |
| 1928 | int startPosition, |
| 1929 | float volumeScaling, |
| 1930 | int stopPosition, |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1931 | const CodecInst* codecInst) { |
| 1932 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1933 | "Channel::StartPlayingFileAsMicrophone(format=%d, " |
| 1934 | "volumeScaling=%5.3f, startPosition=%d, stopPosition=%d)", |
| 1935 | format, volumeScaling, startPosition, stopPosition); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1936 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1937 | if (stream == NULL) { |
| 1938 | _engineStatisticsPtr->SetLastError( |
| 1939 | VE_BAD_FILE, kTraceError, |
| 1940 | "StartPlayingFileAsMicrophone NULL as input stream"); |
| 1941 | return -1; |
| 1942 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1943 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1944 | rtc::CritScope cs(&_fileCritSect); |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 1945 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1946 | if (channel_state_.Get().input_file_playing) { |
| 1947 | _engineStatisticsPtr->SetLastError( |
| 1948 | VE_ALREADY_PLAYING, kTraceWarning, |
| 1949 | "StartPlayingFileAsMicrophone() is playing"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1950 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1951 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1952 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1953 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1954 | if (input_file_player_) { |
| 1955 | input_file_player_->RegisterModuleFileCallback(NULL); |
| 1956 | input_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1957 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1958 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1959 | // Create the instance |
kwiberg | 5b356f4 | 2016-09-08 04:32:33 -0700 | [diff] [blame] | 1960 | input_file_player_ = FilePlayer::CreateFilePlayer(_inputFilePlayerId, |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1961 | (const FileFormats)format); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1962 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1963 | if (!input_file_player_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1964 | _engineStatisticsPtr->SetLastError( |
| 1965 | VE_INVALID_ARGUMENT, kTraceError, |
| 1966 | "StartPlayingInputFile() filePlayer format isnot correct"); |
| 1967 | return -1; |
| 1968 | } |
| 1969 | |
| 1970 | const uint32_t notificationTime(0); |
| 1971 | |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 1972 | if (input_file_player_->StartPlayingFile(stream, startPosition, volumeScaling, |
| 1973 | notificationTime, stopPosition, |
| 1974 | codecInst) != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1975 | _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, |
| 1976 | "StartPlayingFile() failed to start " |
| 1977 | "file playout"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1978 | input_file_player_->StopPlayingFile(); |
| 1979 | input_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1980 | return -1; |
| 1981 | } |
| 1982 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1983 | input_file_player_->RegisterModuleFileCallback(this); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1984 | channel_state_.SetInputFilePlaying(true); |
| 1985 | |
| 1986 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 1989 | int Channel::StopPlayingFileAsMicrophone() { |
| 1990 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 1991 | "Channel::StopPlayingFileAsMicrophone()"); |
| 1992 | |
| 1993 | rtc::CritScope cs(&_fileCritSect); |
| 1994 | |
| 1995 | if (!channel_state_.Get().input_file_playing) { |
| 1996 | return 0; |
| 1997 | } |
| 1998 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 1999 | if (input_file_player_->StopPlayingFile() != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2000 | _engineStatisticsPtr->SetLastError( |
| 2001 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 2002 | "StopPlayingFile() could not stop playing"); |
| 2003 | return -1; |
| 2004 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2005 | input_file_player_->RegisterModuleFileCallback(NULL); |
| 2006 | input_file_player_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2007 | channel_state_.SetInputFilePlaying(false); |
| 2008 | |
| 2009 | return 0; |
| 2010 | } |
| 2011 | |
| 2012 | int Channel::IsPlayingFileAsMicrophone() const { |
| 2013 | return channel_state_.Get().input_file_playing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
leozwang@webrtc.org | 813e4b0 | 2012-03-01 18:34:25 +0000 | [diff] [blame] | 2016 | int Channel::StartRecordingPlayout(const char* fileName, |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2017 | const CodecInst* codecInst) { |
| 2018 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2019 | "Channel::StartRecordingPlayout(fileName=%s)", fileName); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2020 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2021 | if (_outputFileRecording) { |
| 2022 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), |
| 2023 | "StartRecordingPlayout() is already recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2024 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2025 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2026 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2027 | FileFormats format; |
| 2028 | const uint32_t notificationTime(0); // Not supported in VoE |
| 2029 | CodecInst dummyCodec = {100, "L16", 16000, 320, 1, 320000}; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2030 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2031 | if ((codecInst != NULL) && |
| 2032 | ((codecInst->channels < 1) || (codecInst->channels > 2))) { |
| 2033 | _engineStatisticsPtr->SetLastError( |
| 2034 | VE_BAD_ARGUMENT, kTraceError, |
| 2035 | "StartRecordingPlayout() invalid compression"); |
| 2036 | return (-1); |
| 2037 | } |
| 2038 | if (codecInst == NULL) { |
| 2039 | format = kFileFormatPcm16kHzFile; |
| 2040 | codecInst = &dummyCodec; |
| 2041 | } else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) || |
| 2042 | (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || |
| 2043 | (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { |
| 2044 | format = kFileFormatWavFile; |
| 2045 | } else { |
| 2046 | format = kFileFormatCompressedFile; |
| 2047 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2048 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2049 | rtc::CritScope cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2050 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2051 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2052 | if (output_file_recorder_) { |
| 2053 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 2054 | output_file_recorder_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2055 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2056 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2057 | output_file_recorder_ = FileRecorder::CreateFileRecorder( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2058 | _outputFileRecorderId, (const FileFormats)format); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2059 | if (!output_file_recorder_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2060 | _engineStatisticsPtr->SetLastError( |
| 2061 | VE_INVALID_ARGUMENT, kTraceError, |
| 2062 | "StartRecordingPlayout() fileRecorder format isnot correct"); |
| 2063 | return -1; |
| 2064 | } |
| 2065 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2066 | if (output_file_recorder_->StartRecordingAudioFile( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2067 | fileName, (const CodecInst&)*codecInst, notificationTime) != 0) { |
| 2068 | _engineStatisticsPtr->SetLastError( |
| 2069 | VE_BAD_FILE, kTraceError, |
| 2070 | "StartRecordingAudioFile() failed to start file recording"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2071 | output_file_recorder_->StopRecording(); |
| 2072 | output_file_recorder_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2073 | return -1; |
| 2074 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2075 | output_file_recorder_->RegisterModuleFileCallback(this); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2076 | _outputFileRecording = true; |
| 2077 | |
| 2078 | return 0; |
| 2079 | } |
| 2080 | |
| 2081 | int Channel::StartRecordingPlayout(OutStream* stream, |
| 2082 | const CodecInst* codecInst) { |
| 2083 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2084 | "Channel::StartRecordingPlayout()"); |
| 2085 | |
| 2086 | if (_outputFileRecording) { |
| 2087 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), |
| 2088 | "StartRecordingPlayout() is already recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2089 | return 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | FileFormats format; |
| 2093 | const uint32_t notificationTime(0); // Not supported in VoE |
| 2094 | CodecInst dummyCodec = {100, "L16", 16000, 320, 1, 320000}; |
| 2095 | |
| 2096 | if (codecInst != NULL && codecInst->channels != 1) { |
| 2097 | _engineStatisticsPtr->SetLastError( |
| 2098 | VE_BAD_ARGUMENT, kTraceError, |
| 2099 | "StartRecordingPlayout() invalid compression"); |
| 2100 | return (-1); |
| 2101 | } |
| 2102 | if (codecInst == NULL) { |
| 2103 | format = kFileFormatPcm16kHzFile; |
| 2104 | codecInst = &dummyCodec; |
| 2105 | } else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) || |
| 2106 | (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || |
| 2107 | (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { |
| 2108 | format = kFileFormatWavFile; |
| 2109 | } else { |
| 2110 | format = kFileFormatCompressedFile; |
| 2111 | } |
| 2112 | |
| 2113 | rtc::CritScope cs(&_fileCritSect); |
| 2114 | |
| 2115 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2116 | if (output_file_recorder_) { |
| 2117 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 2118 | output_file_recorder_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2119 | } |
| 2120 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2121 | output_file_recorder_ = FileRecorder::CreateFileRecorder( |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2122 | _outputFileRecorderId, (const FileFormats)format); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2123 | if (!output_file_recorder_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2124 | _engineStatisticsPtr->SetLastError( |
| 2125 | VE_INVALID_ARGUMENT, kTraceError, |
| 2126 | "StartRecordingPlayout() fileRecorder format isnot correct"); |
| 2127 | return -1; |
| 2128 | } |
| 2129 | |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 2130 | if (output_file_recorder_->StartRecordingAudioFile(stream, *codecInst, |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2131 | notificationTime) != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2132 | _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, |
| 2133 | "StartRecordingPlayout() failed to " |
| 2134 | "start file recording"); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2135 | output_file_recorder_->StopRecording(); |
| 2136 | output_file_recorder_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2137 | return -1; |
| 2138 | } |
| 2139 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2140 | output_file_recorder_->RegisterModuleFileCallback(this); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2141 | _outputFileRecording = true; |
| 2142 | |
| 2143 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2146 | int Channel::StopRecordingPlayout() { |
| 2147 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
| 2148 | "Channel::StopRecordingPlayout()"); |
| 2149 | |
| 2150 | if (!_outputFileRecording) { |
| 2151 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), |
| 2152 | "StopRecordingPlayout() isnot recording"); |
| 2153 | return -1; |
| 2154 | } |
| 2155 | |
| 2156 | rtc::CritScope cs(&_fileCritSect); |
| 2157 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2158 | if (output_file_recorder_->StopRecording() != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2159 | _engineStatisticsPtr->SetLastError( |
| 2160 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 2161 | "StopRecording() could not stop recording"); |
| 2162 | return (-1); |
| 2163 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2164 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 2165 | output_file_recorder_.reset(); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2166 | _outputFileRecording = false; |
| 2167 | |
| 2168 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2171 | void Channel::SetMixWithMicStatus(bool mix) { |
| 2172 | rtc::CritScope cs(&_fileCritSect); |
| 2173 | _mixFileWithMicrophone = mix; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2176 | int Channel::GetSpeechOutputLevel(uint32_t& level) const { |
| 2177 | int8_t currentLevel = _outputAudioLevel.Level(); |
| 2178 | level = static_cast<int32_t>(currentLevel); |
| 2179 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2182 | int Channel::GetSpeechOutputLevelFullRange(uint32_t& level) const { |
| 2183 | int16_t currentLevel = _outputAudioLevel.LevelFullRange(); |
| 2184 | level = static_cast<int32_t>(currentLevel); |
| 2185 | return 0; |
| 2186 | } |
| 2187 | |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2188 | int Channel::SetInputMute(bool enable) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2189 | rtc::CritScope cs(&volume_settings_critsect_); |
| 2190 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2191 | "Channel::SetMute(enable=%d)", enable); |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2192 | input_mute_ = enable; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2193 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2196 | bool Channel::InputMute() const { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2197 | rtc::CritScope cs(&volume_settings_critsect_); |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2198 | return input_mute_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2201 | int Channel::SetOutputVolumePan(float left, float right) { |
| 2202 | rtc::CritScope cs(&volume_settings_critsect_); |
| 2203 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2204 | "Channel::SetOutputVolumePan()"); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2205 | _panLeft = left; |
| 2206 | _panRight = right; |
| 2207 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2210 | int Channel::GetOutputVolumePan(float& left, float& right) const { |
| 2211 | rtc::CritScope cs(&volume_settings_critsect_); |
| 2212 | left = _panLeft; |
| 2213 | right = _panRight; |
| 2214 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2217 | int Channel::SetChannelOutputVolumeScaling(float scaling) { |
| 2218 | rtc::CritScope cs(&volume_settings_critsect_); |
| 2219 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2220 | "Channel::SetChannelOutputVolumeScaling()"); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2221 | _outputGain = scaling; |
| 2222 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2225 | int Channel::GetChannelOutputVolumeScaling(float& scaling) const { |
| 2226 | rtc::CritScope cs(&volume_settings_critsect_); |
| 2227 | scaling = _outputGain; |
| 2228 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 2231 | int Channel::SendTelephoneEventOutband(int event, int duration_ms) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2232 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 2233 | "Channel::SendTelephoneEventOutband(...)"); |
| 2234 | RTC_DCHECK_LE(0, event); |
| 2235 | RTC_DCHECK_GE(255, event); |
| 2236 | RTC_DCHECK_LE(0, duration_ms); |
| 2237 | RTC_DCHECK_GE(65535, duration_ms); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2238 | if (!Sending()) { |
| 2239 | return -1; |
| 2240 | } |
solenberg | 8842c3e | 2016-03-11 03:06:41 -0800 | [diff] [blame] | 2241 | if (_rtpRtcpModule->SendTelephoneEventOutband( |
| 2242 | event, duration_ms, kTelephoneEventAttenuationdB) != 0) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2243 | _engineStatisticsPtr->SetLastError( |
| 2244 | VE_SEND_DTMF_FAILED, kTraceWarning, |
| 2245 | "SendTelephoneEventOutband() failed to send event"); |
| 2246 | return -1; |
| 2247 | } |
| 2248 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
solenberg | 31642aa | 2016-03-14 08:00:37 -0700 | [diff] [blame] | 2251 | int Channel::SetSendTelephoneEventPayloadType(int payload_type) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2252 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2253 | "Channel::SetSendTelephoneEventPayloadType()"); |
solenberg | 31642aa | 2016-03-14 08:00:37 -0700 | [diff] [blame] | 2254 | RTC_DCHECK_LE(0, payload_type); |
| 2255 | RTC_DCHECK_GE(127, payload_type); |
| 2256 | CodecInst codec = {0}; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2257 | codec.plfreq = 8000; |
solenberg | 31642aa | 2016-03-14 08:00:37 -0700 | [diff] [blame] | 2258 | codec.pltype = payload_type; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2259 | memcpy(codec.plname, "telephone-event", 16); |
| 2260 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 2261 | _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); |
| 2262 | if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { |
| 2263 | _engineStatisticsPtr->SetLastError( |
| 2264 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 2265 | "SetSendTelephoneEventPayloadType() failed to register send" |
| 2266 | "payload type"); |
| 2267 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2268 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2269 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2270 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2273 | int Channel::VoiceActivityIndicator(int& activity) { |
| 2274 | activity = _sendFrameType; |
| 2275 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2278 | int Channel::SetLocalSSRC(unsigned int ssrc) { |
| 2279 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2280 | "Channel::SetLocalSSRC()"); |
| 2281 | if (channel_state_.Get().sending) { |
| 2282 | _engineStatisticsPtr->SetLastError(VE_ALREADY_SENDING, kTraceError, |
| 2283 | "SetLocalSSRC() already sending"); |
| 2284 | return -1; |
| 2285 | } |
| 2286 | _rtpRtcpModule->SetSSRC(ssrc); |
| 2287 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2290 | int Channel::GetLocalSSRC(unsigned int& ssrc) { |
| 2291 | ssrc = _rtpRtcpModule->SSRC(); |
| 2292 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2295 | int Channel::GetRemoteSSRC(unsigned int& ssrc) { |
| 2296 | ssrc = rtp_receiver_->SSRC(); |
| 2297 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2300 | int Channel::SetSendAudioLevelIndicationStatus(bool enable, unsigned char id) { |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2301 | _includeAudioLevelIndication = enable; |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2302 | return SetSendRtpHeaderExtension(enable, kRtpExtensionAudioLevel, id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2303 | } |
andrew@webrtc.org | f3930e9 | 2013-09-18 22:37:32 +0000 | [diff] [blame] | 2304 | |
wu@webrtc.org | 93fd25c | 2014-04-24 20:33:08 +0000 | [diff] [blame] | 2305 | int Channel::SetReceiveAudioLevelIndicationStatus(bool enable, |
| 2306 | unsigned char id) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2307 | rtp_header_parser_->DeregisterRtpHeaderExtension(kRtpExtensionAudioLevel); |
| 2308 | if (enable && |
| 2309 | !rtp_header_parser_->RegisterRtpHeaderExtension(kRtpExtensionAudioLevel, |
| 2310 | id)) { |
wu@webrtc.org | 93fd25c | 2014-04-24 20:33:08 +0000 | [diff] [blame] | 2311 | return -1; |
| 2312 | } |
| 2313 | return 0; |
| 2314 | } |
| 2315 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2316 | int Channel::SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id) { |
| 2317 | return SetSendRtpHeaderExtension(enable, kRtpExtensionAbsoluteSendTime, id); |
| 2318 | } |
| 2319 | |
| 2320 | int Channel::SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id) { |
| 2321 | rtp_header_parser_->DeregisterRtpHeaderExtension( |
| 2322 | kRtpExtensionAbsoluteSendTime); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2323 | if (enable && |
| 2324 | !rtp_header_parser_->RegisterRtpHeaderExtension( |
| 2325 | kRtpExtensionAbsoluteSendTime, id)) { |
solenberg@webrtc.org | b1f5010 | 2014-03-24 10:38:25 +0000 | [diff] [blame] | 2326 | return -1; |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 2327 | } |
| 2328 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 2331 | void Channel::EnableSendTransportSequenceNumber(int id) { |
| 2332 | int ret = |
| 2333 | SetSendRtpHeaderExtension(true, kRtpExtensionTransportSequenceNumber, id); |
| 2334 | RTC_DCHECK_EQ(0, ret); |
| 2335 | } |
| 2336 | |
stefan | 3313ec9 | 2016-01-21 06:32:43 -0800 | [diff] [blame] | 2337 | void Channel::EnableReceiveTransportSequenceNumber(int id) { |
| 2338 | rtp_header_parser_->DeregisterRtpHeaderExtension( |
| 2339 | kRtpExtensionTransportSequenceNumber); |
| 2340 | bool ret = rtp_header_parser_->RegisterRtpHeaderExtension( |
| 2341 | kRtpExtensionTransportSequenceNumber, id); |
| 2342 | RTC_DCHECK(ret); |
| 2343 | } |
| 2344 | |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 2345 | void Channel::RegisterSenderCongestionControlObjects( |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 2346 | RtpPacketSender* rtp_packet_sender, |
| 2347 | TransportFeedbackObserver* transport_feedback_observer, |
| 2348 | PacketRouter* packet_router) { |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 2349 | RTC_DCHECK(rtp_packet_sender); |
| 2350 | RTC_DCHECK(transport_feedback_observer); |
| 2351 | RTC_DCHECK(packet_router && !packet_router_); |
| 2352 | feedback_observer_proxy_->SetTransportFeedbackObserver( |
| 2353 | transport_feedback_observer); |
| 2354 | seq_num_allocator_proxy_->SetSequenceNumberAllocator(packet_router); |
| 2355 | rtp_packet_sender_proxy_->SetPacketSender(rtp_packet_sender); |
| 2356 | _rtpRtcpModule->SetStorePacketsStatus(true, 600); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 2357 | packet_router->AddRtpModule(_rtpRtcpModule.get()); |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 2358 | packet_router_ = packet_router; |
| 2359 | } |
| 2360 | |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 2361 | void Channel::RegisterReceiverCongestionControlObjects( |
| 2362 | PacketRouter* packet_router) { |
| 2363 | RTC_DCHECK(packet_router && !packet_router_); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 2364 | packet_router->AddRtpModule(_rtpRtcpModule.get()); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 2365 | packet_router_ = packet_router; |
| 2366 | } |
| 2367 | |
| 2368 | void Channel::ResetCongestionControlObjects() { |
| 2369 | RTC_DCHECK(packet_router_); |
| 2370 | _rtpRtcpModule->SetStorePacketsStatus(false, 600); |
| 2371 | feedback_observer_proxy_->SetTransportFeedbackObserver(nullptr); |
| 2372 | seq_num_allocator_proxy_->SetSequenceNumberAllocator(nullptr); |
Peter Boström | 3dd5d1d | 2016-02-25 16:56:48 +0100 | [diff] [blame] | 2373 | packet_router_->RemoveRtpModule(_rtpRtcpModule.get()); |
stefan | bba9dec | 2016-02-01 04:39:55 -0800 | [diff] [blame] | 2374 | packet_router_ = nullptr; |
| 2375 | rtp_packet_sender_proxy_->SetPacketSender(nullptr); |
| 2376 | } |
| 2377 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 2378 | void Channel::SetRTCPStatus(bool enable) { |
| 2379 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2380 | "Channel::SetRTCPStatus()"); |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 2381 | _rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2384 | int Channel::GetRTCPStatus(bool& enabled) { |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 2385 | RtcpMode method = _rtpRtcpModule->RTCP(); |
| 2386 | enabled = (method != RtcpMode::kOff); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2387 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2390 | int Channel::SetRTCP_CNAME(const char cName[256]) { |
| 2391 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2392 | "Channel::SetRTCP_CNAME()"); |
| 2393 | if (_rtpRtcpModule->SetCNAME(cName) != 0) { |
| 2394 | _engineStatisticsPtr->SetLastError( |
| 2395 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 2396 | "SetRTCP_CNAME() failed to set RTCP CNAME"); |
| 2397 | return -1; |
| 2398 | } |
| 2399 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2400 | } |
| 2401 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2402 | int Channel::GetRemoteRTCP_CNAME(char cName[256]) { |
| 2403 | if (cName == NULL) { |
| 2404 | _engineStatisticsPtr->SetLastError( |
| 2405 | VE_INVALID_ARGUMENT, kTraceError, |
| 2406 | "GetRemoteRTCP_CNAME() invalid CNAME input buffer"); |
| 2407 | return -1; |
| 2408 | } |
| 2409 | char cname[RTCP_CNAME_SIZE]; |
| 2410 | const uint32_t remoteSSRC = rtp_receiver_->SSRC(); |
| 2411 | if (_rtpRtcpModule->RemoteCNAME(remoteSSRC, cname) != 0) { |
| 2412 | _engineStatisticsPtr->SetLastError( |
| 2413 | VE_CANNOT_RETRIEVE_CNAME, kTraceError, |
| 2414 | "GetRemoteRTCP_CNAME() failed to retrieve remote RTCP CNAME"); |
| 2415 | return -1; |
| 2416 | } |
| 2417 | strcpy(cName, cname); |
| 2418 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2421 | int Channel::GetRemoteRTCPData(unsigned int& NTPHigh, |
| 2422 | unsigned int& NTPLow, |
| 2423 | unsigned int& timestamp, |
| 2424 | unsigned int& playoutTimestamp, |
| 2425 | unsigned int* jitter, |
| 2426 | unsigned short* fractionLost) { |
| 2427 | // --- Information from sender info in received Sender Reports |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2428 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2429 | RTCPSenderInfo senderInfo; |
| 2430 | if (_rtpRtcpModule->RemoteRTCPStat(&senderInfo) != 0) { |
| 2431 | _engineStatisticsPtr->SetLastError( |
| 2432 | VE_RTP_RTCP_MODULE_ERROR, kTraceError, |
| 2433 | "GetRemoteRTCPData() failed to retrieve sender info for remote " |
| 2434 | "side"); |
| 2435 | return -1; |
| 2436 | } |
| 2437 | |
| 2438 | // We only utilize 12 out of 20 bytes in the sender info (ignores packet |
| 2439 | // and octet count) |
| 2440 | NTPHigh = senderInfo.NTPseconds; |
| 2441 | NTPLow = senderInfo.NTPfraction; |
| 2442 | timestamp = senderInfo.RTPtimeStamp; |
| 2443 | |
| 2444 | // --- Locally derived information |
| 2445 | |
| 2446 | // This value is updated on each incoming RTCP packet (0 when no packet |
| 2447 | // has been received) |
| 2448 | playoutTimestamp = playout_timestamp_rtcp_; |
| 2449 | |
| 2450 | if (NULL != jitter || NULL != fractionLost) { |
| 2451 | // Get all RTCP receiver report blocks that have been received on this |
| 2452 | // channel. If we receive RTP packets from a remote source we know the |
| 2453 | // remote SSRC and use the report block from him. |
| 2454 | // Otherwise use the first report block. |
| 2455 | std::vector<RTCPReportBlock> remote_stats; |
| 2456 | if (_rtpRtcpModule->RemoteRTCPStat(&remote_stats) != 0 || |
| 2457 | remote_stats.empty()) { |
| 2458 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2459 | "GetRemoteRTCPData() failed to measure statistics due" |
| 2460 | " to lack of received RTP and/or RTCP packets"); |
| 2461 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2464 | uint32_t remoteSSRC = rtp_receiver_->SSRC(); |
| 2465 | std::vector<RTCPReportBlock>::const_iterator it = remote_stats.begin(); |
| 2466 | for (; it != remote_stats.end(); ++it) { |
| 2467 | if (it->remoteSSRC == remoteSSRC) |
| 2468 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2469 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2470 | |
| 2471 | if (it == remote_stats.end()) { |
| 2472 | // If we have not received any RTCP packets from this SSRC it probably |
| 2473 | // means that we have not received any RTP packets. |
| 2474 | // Use the first received report block instead. |
| 2475 | it = remote_stats.begin(); |
| 2476 | remoteSSRC = it->remoteSSRC; |
| 2477 | } |
| 2478 | |
| 2479 | if (jitter) { |
| 2480 | *jitter = it->jitter; |
| 2481 | } |
| 2482 | |
| 2483 | if (fractionLost) { |
| 2484 | *fractionLost = it->fractionLost; |
| 2485 | } |
| 2486 | } |
| 2487 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2490 | int Channel::SendApplicationDefinedRTCPPacket( |
| 2491 | unsigned char subType, |
| 2492 | unsigned int name, |
| 2493 | const char* data, |
| 2494 | unsigned short dataLengthInBytes) { |
| 2495 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2496 | "Channel::SendApplicationDefinedRTCPPacket()"); |
| 2497 | if (!channel_state_.Get().sending) { |
| 2498 | _engineStatisticsPtr->SetLastError( |
| 2499 | VE_NOT_SENDING, kTraceError, |
| 2500 | "SendApplicationDefinedRTCPPacket() not sending"); |
| 2501 | return -1; |
| 2502 | } |
| 2503 | if (NULL == data) { |
| 2504 | _engineStatisticsPtr->SetLastError( |
| 2505 | VE_INVALID_ARGUMENT, kTraceError, |
| 2506 | "SendApplicationDefinedRTCPPacket() invalid data value"); |
| 2507 | return -1; |
| 2508 | } |
| 2509 | if (dataLengthInBytes % 4 != 0) { |
| 2510 | _engineStatisticsPtr->SetLastError( |
| 2511 | VE_INVALID_ARGUMENT, kTraceError, |
| 2512 | "SendApplicationDefinedRTCPPacket() invalid length value"); |
| 2513 | return -1; |
| 2514 | } |
| 2515 | RtcpMode status = _rtpRtcpModule->RTCP(); |
| 2516 | if (status == RtcpMode::kOff) { |
| 2517 | _engineStatisticsPtr->SetLastError( |
| 2518 | VE_RTCP_ERROR, kTraceError, |
| 2519 | "SendApplicationDefinedRTCPPacket() RTCP is disabled"); |
| 2520 | return -1; |
| 2521 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2522 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2523 | // Create and schedule the RTCP APP packet for transmission |
| 2524 | if (_rtpRtcpModule->SetRTCPApplicationSpecificData( |
| 2525 | subType, name, (const unsigned char*)data, dataLengthInBytes) != 0) { |
| 2526 | _engineStatisticsPtr->SetLastError( |
| 2527 | VE_SEND_ERROR, kTraceError, |
| 2528 | "SendApplicationDefinedRTCPPacket() failed to send RTCP packet"); |
| 2529 | return -1; |
| 2530 | } |
| 2531 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2534 | int Channel::GetRTPStatistics(unsigned int& averageJitterMs, |
| 2535 | unsigned int& maxJitterMs, |
| 2536 | unsigned int& discardedPackets) { |
| 2537 | // The jitter statistics is updated for each received RTP packet and is |
| 2538 | // based on received packets. |
| 2539 | if (_rtpRtcpModule->RTCP() == RtcpMode::kOff) { |
| 2540 | // If RTCP is off, there is no timed thread in the RTCP module regularly |
| 2541 | // generating new stats, trigger the update manually here instead. |
| 2542 | StreamStatistician* statistician = |
| 2543 | rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC()); |
| 2544 | if (statistician) { |
| 2545 | // Don't use returned statistics, use data from proxy instead so that |
| 2546 | // max jitter can be fetched atomically. |
| 2547 | RtcpStatistics s; |
| 2548 | statistician->GetStatistics(&s, true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2549 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2550 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2551 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2552 | ChannelStatistics stats = statistics_proxy_->GetStats(); |
| 2553 | const int32_t playoutFrequency = audio_coding_->PlayoutFrequency(); |
| 2554 | if (playoutFrequency > 0) { |
| 2555 | // Scale RTP statistics given the current playout frequency |
| 2556 | maxJitterMs = stats.max_jitter / (playoutFrequency / 1000); |
| 2557 | averageJitterMs = stats.rtcp.jitter / (playoutFrequency / 1000); |
| 2558 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2559 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2560 | discardedPackets = _numberOfDiscardedPackets; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2561 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2562 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
henrika@webrtc.org | 8a2fc88 | 2012-08-22 08:53:55 +0000 | [diff] [blame] | 2565 | int Channel::GetRemoteRTCPReportBlocks( |
| 2566 | std::vector<ReportBlock>* report_blocks) { |
| 2567 | if (report_blocks == NULL) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2568 | _engineStatisticsPtr->SetLastError( |
| 2569 | VE_INVALID_ARGUMENT, kTraceError, |
| 2570 | "GetRemoteRTCPReportBlock()s invalid report_blocks."); |
henrika@webrtc.org | 8a2fc88 | 2012-08-22 08:53:55 +0000 | [diff] [blame] | 2571 | return -1; |
| 2572 | } |
| 2573 | |
| 2574 | // Get the report blocks from the latest received RTCP Sender or Receiver |
| 2575 | // Report. Each element in the vector contains the sender's SSRC and a |
| 2576 | // report block according to RFC 3550. |
| 2577 | std::vector<RTCPReportBlock> rtcp_report_blocks; |
| 2578 | if (_rtpRtcpModule->RemoteRTCPStat(&rtcp_report_blocks) != 0) { |
henrika@webrtc.org | 8a2fc88 | 2012-08-22 08:53:55 +0000 | [diff] [blame] | 2579 | return -1; |
| 2580 | } |
| 2581 | |
| 2582 | if (rtcp_report_blocks.empty()) |
| 2583 | return 0; |
| 2584 | |
| 2585 | std::vector<RTCPReportBlock>::const_iterator it = rtcp_report_blocks.begin(); |
| 2586 | for (; it != rtcp_report_blocks.end(); ++it) { |
| 2587 | ReportBlock report_block; |
| 2588 | report_block.sender_SSRC = it->remoteSSRC; |
| 2589 | report_block.source_SSRC = it->sourceSSRC; |
| 2590 | report_block.fraction_lost = it->fractionLost; |
| 2591 | report_block.cumulative_num_packets_lost = it->cumulativeLost; |
| 2592 | report_block.extended_highest_sequence_number = it->extendedHighSeqNum; |
| 2593 | report_block.interarrival_jitter = it->jitter; |
| 2594 | report_block.last_SR_timestamp = it->lastSR; |
| 2595 | report_block.delay_since_last_SR = it->delaySinceLastSR; |
| 2596 | report_blocks->push_back(report_block); |
| 2597 | } |
| 2598 | return 0; |
| 2599 | } |
| 2600 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2601 | int Channel::GetRTPStatistics(CallStatistics& stats) { |
| 2602 | // --- RtcpStatistics |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2603 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2604 | // The jitter statistics is updated for each received RTP packet and is |
| 2605 | // based on received packets. |
| 2606 | RtcpStatistics statistics; |
| 2607 | StreamStatistician* statistician = |
| 2608 | rtp_receive_statistics_->GetStatistician(rtp_receiver_->SSRC()); |
Peter Boström | 59013bc | 2016-02-12 11:35:08 +0100 | [diff] [blame] | 2609 | if (statistician) { |
| 2610 | statistician->GetStatistics(&statistics, |
| 2611 | _rtpRtcpModule->RTCP() == RtcpMode::kOff); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2612 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2613 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2614 | stats.fractionLost = statistics.fraction_lost; |
| 2615 | stats.cumulativeLost = statistics.cumulative_lost; |
| 2616 | stats.extendedMax = statistics.extended_max_sequence_number; |
| 2617 | stats.jitterSamples = statistics.jitter; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2618 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2619 | // --- RTT |
| 2620 | stats.rttMs = GetRTT(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2621 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2622 | // --- Data counters |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2623 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2624 | size_t bytesSent(0); |
| 2625 | uint32_t packetsSent(0); |
| 2626 | size_t bytesReceived(0); |
| 2627 | uint32_t packetsReceived(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2628 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2629 | if (statistician) { |
| 2630 | statistician->GetDataCounters(&bytesReceived, &packetsReceived); |
| 2631 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 2632 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2633 | if (_rtpRtcpModule->DataCountersRTP(&bytesSent, &packetsSent) != 0) { |
| 2634 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2635 | "GetRTPStatistics() failed to retrieve RTP datacounters =>" |
| 2636 | " output will not be complete"); |
| 2637 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2638 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2639 | stats.bytesSent = bytesSent; |
| 2640 | stats.packetsSent = packetsSent; |
| 2641 | stats.bytesReceived = bytesReceived; |
| 2642 | stats.packetsReceived = packetsReceived; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2643 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2644 | // --- Timestamps |
| 2645 | { |
| 2646 | rtc::CritScope lock(&ts_stats_lock_); |
| 2647 | stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_; |
| 2648 | } |
| 2649 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2650 | } |
| 2651 | |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 2652 | int Channel::SetCodecFECStatus(bool enable) { |
| 2653 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2654 | "Channel::SetCodecFECStatus()"); |
| 2655 | |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 2656 | if (!codec_manager_.SetCodecFEC(enable) || |
| 2657 | !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 2658 | _engineStatisticsPtr->SetLastError( |
| 2659 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 2660 | "SetCodecFECStatus() failed to set FEC state"); |
| 2661 | return -1; |
| 2662 | } |
| 2663 | return 0; |
| 2664 | } |
| 2665 | |
| 2666 | bool Channel::GetCodecFECStatus() { |
kwiberg | c8d071e | 2016-04-06 12:22:38 -0700 | [diff] [blame] | 2667 | return codec_manager_.GetStackParams()->use_codec_fec; |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
pwestin@webrtc.org | db24995 | 2013-06-05 15:33:20 +0000 | [diff] [blame] | 2670 | void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) { |
| 2671 | // None of these functions can fail. |
Stefan Holmer | b86d4e4 | 2015-12-07 10:26:18 +0100 | [diff] [blame] | 2672 | // If pacing is enabled we always store packets. |
| 2673 | if (!pacing_enabled_) |
| 2674 | _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 2675 | rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 2676 | if (enable) |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 2677 | audio_coding_->EnableNack(maxNumberOfPackets); |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 2678 | else |
andrew@webrtc.org | eb524d9 | 2013-09-23 23:02:24 +0000 | [diff] [blame] | 2679 | audio_coding_->DisableNack(); |
pwestin@webrtc.org | db24995 | 2013-06-05 15:33:20 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
pwestin@webrtc.org | d30859e | 2013-06-06 21:09:01 +0000 | [diff] [blame] | 2682 | // Called when we are missing one or more packets. |
| 2683 | int Channel::ResendPackets(const uint16_t* sequence_numbers, int length) { |
pwestin@webrtc.org | db24995 | 2013-06-05 15:33:20 +0000 | [diff] [blame] | 2684 | return _rtpRtcpModule->SendNACK(sequence_numbers, length); |
| 2685 | } |
| 2686 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2687 | uint32_t Channel::Demultiplex(const AudioFrame& audioFrame) { |
| 2688 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2689 | "Channel::Demultiplex()"); |
| 2690 | _audioFrame.CopyFrom(audioFrame); |
| 2691 | _audioFrame.id_ = _channelId; |
| 2692 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2693 | } |
| 2694 | |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 2695 | void Channel::Demultiplex(const int16_t* audio_data, |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 2696 | int sample_rate, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 2697 | size_t number_of_frames, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 2698 | size_t number_of_channels) { |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 2699 | CodecInst codec; |
| 2700 | GetSendCodec(codec); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 2701 | |
Alejandro Luebs | cdfe20b | 2015-09-23 12:49:12 -0700 | [diff] [blame] | 2702 | // Never upsample or upmix the capture signal here. This should be done at the |
| 2703 | // end of the send chain. |
| 2704 | _audioFrame.sample_rate_hz_ = std::min(codec.plfreq, sample_rate); |
| 2705 | _audioFrame.num_channels_ = std::min(number_of_channels, codec.channels); |
| 2706 | RemixAndResample(audio_data, number_of_frames, number_of_channels, |
| 2707 | sample_rate, &input_resampler_, &_audioFrame); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2710 | uint32_t Channel::PrepareEncodeAndSend(int mixingFrequency) { |
| 2711 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2712 | "Channel::PrepareEncodeAndSend()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2713 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2714 | if (_audioFrame.samples_per_channel_ == 0) { |
| 2715 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2716 | "Channel::PrepareEncodeAndSend() invalid audio frame"); |
| 2717 | return 0xFFFFFFFF; |
| 2718 | } |
| 2719 | |
| 2720 | if (channel_state_.Get().input_file_playing) { |
| 2721 | MixOrReplaceAudioWithFile(mixingFrequency); |
| 2722 | } |
| 2723 | |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2724 | bool is_muted = InputMute(); // Cache locally as InputMute() takes a lock. |
| 2725 | AudioFrameOperations::Mute(&_audioFrame, previous_frame_muted_, is_muted); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2726 | |
| 2727 | if (channel_state_.Get().input_external_media) { |
| 2728 | rtc::CritScope cs(&_callbackCritSect); |
| 2729 | const bool isStereo = (_audioFrame.num_channels_ == 2); |
| 2730 | if (_inputExternalMediaCallbackPtr) { |
| 2731 | _inputExternalMediaCallbackPtr->Process( |
| 2732 | _channelId, kRecordingPerChannel, (int16_t*)_audioFrame.data_, |
| 2733 | _audioFrame.samples_per_channel_, _audioFrame.sample_rate_hz_, |
| 2734 | isStereo); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2735 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2736 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2737 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2738 | if (_includeAudioLevelIndication) { |
| 2739 | size_t length = |
| 2740 | _audioFrame.samples_per_channel_ * _audioFrame.num_channels_; |
Tommi | 60c4e0a | 2016-05-26 21:35:27 +0200 | [diff] [blame] | 2741 | RTC_CHECK_LE(length, sizeof(_audioFrame.data_)); |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2742 | if (is_muted && previous_frame_muted_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2743 | rms_level_.ProcessMuted(length); |
| 2744 | } else { |
| 2745 | rms_level_.Process(_audioFrame.data_, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2746 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2747 | } |
solenberg | 1c2af8e | 2016-03-24 10:36:00 -0700 | [diff] [blame] | 2748 | previous_frame_muted_ = is_muted; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2749 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2750 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2753 | uint32_t Channel::EncodeAndSend() { |
| 2754 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2755 | "Channel::EncodeAndSend()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2756 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2757 | assert(_audioFrame.num_channels_ <= 2); |
| 2758 | if (_audioFrame.samples_per_channel_ == 0) { |
| 2759 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2760 | "Channel::EncodeAndSend() invalid audio frame"); |
| 2761 | return 0xFFFFFFFF; |
| 2762 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2763 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2764 | _audioFrame.id_ = _channelId; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2765 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2766 | // --- Add 10ms of raw (PCM) audio data to the encoder @ 32kHz. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2767 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2768 | // The ACM resamples internally. |
| 2769 | _audioFrame.timestamp_ = _timeStamp; |
| 2770 | // This call will trigger AudioPacketizationCallback::SendData if encoding |
| 2771 | // is done and payload is ready for packetization and transmission. |
| 2772 | // Otherwise, it will return without invoking the callback. |
| 2773 | if (audio_coding_->Add10MsData((AudioFrame&)_audioFrame) < 0) { |
| 2774 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2775 | "Channel::EncodeAndSend() ACM encoding failed"); |
| 2776 | return 0xFFFFFFFF; |
| 2777 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2778 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2779 | _timeStamp += static_cast<uint32_t>(_audioFrame.samples_per_channel_); |
| 2780 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 2783 | void Channel::DisassociateSendChannel(int channel_id) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 2784 | rtc::CritScope lock(&assoc_send_channel_lock_); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 2785 | Channel* channel = associate_send_channel_.channel(); |
| 2786 | if (channel && channel->ChannelId() == channel_id) { |
| 2787 | // If this channel is associated with a send channel of the specified |
| 2788 | // Channel ID, disassociate with it. |
| 2789 | ChannelOwner ref(NULL); |
| 2790 | associate_send_channel_ = ref; |
| 2791 | } |
| 2792 | } |
| 2793 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 2794 | void Channel::SetRtcEventLog(RtcEventLog* event_log) { |
| 2795 | event_log_proxy_->SetEventLog(event_log); |
| 2796 | } |
| 2797 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2798 | int Channel::RegisterExternalMediaProcessing(ProcessingTypes type, |
| 2799 | VoEMediaProcess& processObject) { |
| 2800 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2801 | "Channel::RegisterExternalMediaProcessing()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2802 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2803 | rtc::CritScope cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2804 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2805 | if (kPlaybackPerChannel == type) { |
| 2806 | if (_outputExternalMediaCallbackPtr) { |
| 2807 | _engineStatisticsPtr->SetLastError( |
| 2808 | VE_INVALID_OPERATION, kTraceError, |
| 2809 | "Channel::RegisterExternalMediaProcessing() " |
| 2810 | "output external media already enabled"); |
| 2811 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2812 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2813 | _outputExternalMediaCallbackPtr = &processObject; |
| 2814 | _outputExternalMedia = true; |
| 2815 | } else if (kRecordingPerChannel == type) { |
| 2816 | if (_inputExternalMediaCallbackPtr) { |
| 2817 | _engineStatisticsPtr->SetLastError( |
| 2818 | VE_INVALID_OPERATION, kTraceError, |
| 2819 | "Channel::RegisterExternalMediaProcessing() " |
| 2820 | "output external media already enabled"); |
| 2821 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2822 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2823 | _inputExternalMediaCallbackPtr = &processObject; |
| 2824 | channel_state_.SetInputExternalMedia(true); |
| 2825 | } |
| 2826 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2829 | int Channel::DeRegisterExternalMediaProcessing(ProcessingTypes type) { |
| 2830 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2831 | "Channel::DeRegisterExternalMediaProcessing()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2832 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2833 | rtc::CritScope cs(&_callbackCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2834 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2835 | if (kPlaybackPerChannel == type) { |
| 2836 | if (!_outputExternalMediaCallbackPtr) { |
| 2837 | _engineStatisticsPtr->SetLastError( |
| 2838 | VE_INVALID_OPERATION, kTraceWarning, |
| 2839 | "Channel::DeRegisterExternalMediaProcessing() " |
| 2840 | "output external media already disabled"); |
| 2841 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2842 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2843 | _outputExternalMedia = false; |
| 2844 | _outputExternalMediaCallbackPtr = NULL; |
| 2845 | } else if (kRecordingPerChannel == type) { |
| 2846 | if (!_inputExternalMediaCallbackPtr) { |
| 2847 | _engineStatisticsPtr->SetLastError( |
| 2848 | VE_INVALID_OPERATION, kTraceWarning, |
| 2849 | "Channel::DeRegisterExternalMediaProcessing() " |
| 2850 | "input external media already disabled"); |
| 2851 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2852 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2853 | channel_state_.SetInputExternalMedia(false); |
| 2854 | _inputExternalMediaCallbackPtr = NULL; |
| 2855 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2856 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2857 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 2860 | int Channel::SetExternalMixing(bool enabled) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2861 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2862 | "Channel::SetExternalMixing(enabled=%d)", enabled); |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 2863 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2864 | if (channel_state_.Get().playing) { |
| 2865 | _engineStatisticsPtr->SetLastError( |
| 2866 | VE_INVALID_OPERATION, kTraceError, |
| 2867 | "Channel::SetExternalMixing() " |
| 2868 | "external mixing cannot be changed while playing."); |
| 2869 | return -1; |
| 2870 | } |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 2871 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2872 | _externalMixing = enabled; |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 2873 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2874 | return 0; |
roosa@google.com | 1b60ceb | 2012-12-12 23:00:29 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2877 | int Channel::GetNetworkStatistics(NetworkStatistics& stats) { |
| 2878 | return audio_coding_->GetNetworkStatistics(&stats); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 +0000 | [diff] [blame] | 2881 | void Channel::GetDecodingCallStatistics(AudioDecodingCallStats* stats) const { |
| 2882 | audio_coding_->GetDecodingCallStatistics(stats); |
| 2883 | } |
| 2884 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2885 | bool Channel::GetDelayEstimate(int* jitter_buffer_delay_ms, |
| 2886 | int* playout_buffer_delay_ms) const { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 2887 | rtc::CritScope lock(&video_sync_lock_); |
henrik.lundin | b3f1c5d | 2016-08-22 15:39:53 -0700 | [diff] [blame] | 2888 | *jitter_buffer_delay_ms = audio_coding_->FilteredCurrentDelayMs(); |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2889 | *playout_buffer_delay_ms = playout_delay_ms_; |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2890 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
solenberg | 358057b | 2015-11-27 10:46:42 -0800 | [diff] [blame] | 2893 | uint32_t Channel::GetDelayEstimate() const { |
| 2894 | int jitter_buffer_delay_ms = 0; |
| 2895 | int playout_buffer_delay_ms = 0; |
| 2896 | GetDelayEstimate(&jitter_buffer_delay_ms, &playout_buffer_delay_ms); |
| 2897 | return jitter_buffer_delay_ms + playout_buffer_delay_ms; |
| 2898 | } |
| 2899 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 2900 | int Channel::LeastRequiredDelayMs() const { |
| 2901 | return audio_coding_->LeastRequiredDelayMs(); |
| 2902 | } |
| 2903 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2904 | int Channel::SetMinimumPlayoutDelay(int delayMs) { |
| 2905 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2906 | "Channel::SetMinimumPlayoutDelay()"); |
| 2907 | if ((delayMs < kVoiceEngineMinMinPlayoutDelayMs) || |
| 2908 | (delayMs > kVoiceEngineMaxMinPlayoutDelayMs)) { |
| 2909 | _engineStatisticsPtr->SetLastError( |
| 2910 | VE_INVALID_ARGUMENT, kTraceError, |
| 2911 | "SetMinimumPlayoutDelay() invalid min delay"); |
| 2912 | return -1; |
| 2913 | } |
| 2914 | if (audio_coding_->SetMinimumPlayoutDelay(delayMs) != 0) { |
| 2915 | _engineStatisticsPtr->SetLastError( |
| 2916 | VE_AUDIO_CODING_MODULE_ERROR, kTraceError, |
| 2917 | "SetMinimumPlayoutDelay() failed to set min playout delay"); |
| 2918 | return -1; |
| 2919 | } |
| 2920 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2921 | } |
| 2922 | |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2923 | int Channel::GetPlayoutTimestamp(unsigned int& timestamp) { |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 2924 | uint32_t playout_timestamp_rtp = 0; |
| 2925 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 2926 | rtc::CritScope lock(&video_sync_lock_); |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 2927 | playout_timestamp_rtp = playout_timestamp_rtp_; |
| 2928 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2929 | if (playout_timestamp_rtp == 0) { |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2930 | _engineStatisticsPtr->SetLastError( |
skvlad | 4c0536b | 2016-07-07 13:06:26 -0700 | [diff] [blame] | 2931 | VE_CANNOT_RETRIEVE_VALUE, kTraceStateInfo, |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2932 | "GetPlayoutTimestamp() failed to retrieve timestamp"); |
| 2933 | return -1; |
| 2934 | } |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 2935 | timestamp = playout_timestamp_rtp; |
pwestin@webrtc.org | 1de0135 | 2013-04-11 20:23:35 +0000 | [diff] [blame] | 2936 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 2939 | int Channel::SetInitTimestamp(unsigned int timestamp) { |
| 2940 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2941 | "Channel::SetInitTimestamp()"); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 2942 | if (channel_state_.Get().sending) { |
| 2943 | _engineStatisticsPtr->SetLastError(VE_SENDING, kTraceError, |
| 2944 | "SetInitTimestamp() already sending"); |
| 2945 | return -1; |
| 2946 | } |
| 2947 | _rtpRtcpModule->SetStartTimestamp(timestamp); |
| 2948 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2949 | } |
| 2950 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 2951 | int Channel::SetInitSequenceNumber(short sequenceNumber) { |
| 2952 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2953 | "Channel::SetInitSequenceNumber()"); |
| 2954 | if (channel_state_.Get().sending) { |
| 2955 | _engineStatisticsPtr->SetLastError( |
| 2956 | VE_SENDING, kTraceError, "SetInitSequenceNumber() already sending"); |
| 2957 | return -1; |
| 2958 | } |
| 2959 | _rtpRtcpModule->SetSequenceNumber(sequenceNumber); |
| 2960 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2963 | int Channel::GetRtpRtcp(RtpRtcp** rtpRtcpModule, |
| 2964 | RtpReceiver** rtp_receiver) const { |
| 2965 | *rtpRtcpModule = _rtpRtcpModule.get(); |
| 2966 | *rtp_receiver = rtp_receiver_.get(); |
| 2967 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
andrew@webrtc.org | e59a0ac | 2012-05-08 17:12:40 +0000 | [diff] [blame] | 2970 | // TODO(andrew): refactor Mix functions here and in transmit_mixer.cc to use |
| 2971 | // a shared helper. |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2972 | int32_t Channel::MixOrReplaceAudioWithFile(int mixingFrequency) { |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 2973 | std::unique_ptr<int16_t[]> fileBuffer(new int16_t[640]); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2974 | size_t fileSamples(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2975 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2976 | { |
| 2977 | rtc::CritScope cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2978 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2979 | if (!input_file_player_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2980 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2981 | "Channel::MixOrReplaceAudioWithFile() fileplayer" |
| 2982 | " doesnt exist"); |
| 2983 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 2986 | if (input_file_player_->Get10msAudioFromFile(fileBuffer.get(), &fileSamples, |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 2987 | mixingFrequency) == -1) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2988 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2989 | "Channel::MixOrReplaceAudioWithFile() file mixing " |
| 2990 | "failed"); |
| 2991 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2992 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2993 | if (fileSamples == 0) { |
| 2994 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 2995 | "Channel::MixOrReplaceAudioWithFile() file is ended"); |
| 2996 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 2997 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | assert(_audioFrame.samples_per_channel_ == fileSamples); |
| 3001 | |
| 3002 | if (_mixFileWithMicrophone) { |
| 3003 | // Currently file stream is always mono. |
| 3004 | // TODO(xians): Change the code when FilePlayer supports real stereo. |
| 3005 | MixWithSat(_audioFrame.data_, _audioFrame.num_channels_, fileBuffer.get(), |
| 3006 | 1, fileSamples); |
| 3007 | } else { |
| 3008 | // Replace ACM audio with file. |
| 3009 | // Currently file stream is always mono. |
| 3010 | // TODO(xians): Change the code when FilePlayer supports real stereo. |
| 3011 | _audioFrame.UpdateFrame( |
| 3012 | _channelId, 0xFFFFFFFF, fileBuffer.get(), fileSamples, mixingFrequency, |
| 3013 | AudioFrame::kNormalSpeech, AudioFrame::kVadUnknown, 1); |
| 3014 | } |
| 3015 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3018 | int32_t Channel::MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency) { |
| 3019 | assert(mixingFrequency <= 48000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3020 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 3021 | std::unique_ptr<int16_t[]> fileBuffer(new int16_t[960]); |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3022 | size_t fileSamples(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3023 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3024 | { |
| 3025 | rtc::CritScope cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3026 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 3027 | if (!output_file_player_) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3028 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3029 | "Channel::MixAudioWithFile() file mixing failed"); |
| 3030 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3033 | // We should get the frequency we ask for. |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 3034 | if (output_file_player_->Get10msAudioFromFile( |
| 3035 | fileBuffer.get(), &fileSamples, mixingFrequency) == -1) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3036 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3037 | "Channel::MixAudioWithFile() file mixing failed"); |
| 3038 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3039 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3040 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3041 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3042 | if (audioFrame.samples_per_channel_ == fileSamples) { |
| 3043 | // Currently file stream is always mono. |
| 3044 | // TODO(xians): Change the code when FilePlayer supports real stereo. |
| 3045 | MixWithSat(audioFrame.data_, audioFrame.num_channels_, fileBuffer.get(), 1, |
| 3046 | fileSamples); |
| 3047 | } else { |
| 3048 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3049 | "Channel::MixAudioWithFile() samples_per_channel_(%" PRIuS |
| 3050 | ") != " |
| 3051 | "fileSamples(%" PRIuS ")", |
| 3052 | audioFrame.samples_per_channel_, fileSamples); |
| 3053 | return -1; |
| 3054 | } |
| 3055 | |
| 3056 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3059 | void Channel::UpdatePlayoutTimestamp(bool rtcp) { |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3060 | jitter_buffer_playout_timestamp_ = audio_coding_->PlayoutTimestamp(); |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3061 | |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3062 | if (!jitter_buffer_playout_timestamp_) { |
| 3063 | // This can happen if this channel has not received any RTP packets. In |
| 3064 | // this case, NetEq is not capable of computing a playout timestamp. |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3065 | return; |
| 3066 | } |
| 3067 | |
| 3068 | uint16_t delay_ms = 0; |
| 3069 | if (_audioDeviceModulePtr->PlayoutDelay(&delay_ms) == -1) { |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3070 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3071 | "Channel::UpdatePlayoutTimestamp() failed to read playout" |
| 3072 | " delay from the ADM"); |
| 3073 | _engineStatisticsPtr->SetLastError( |
| 3074 | VE_CANNOT_RETRIEVE_VALUE, kTraceError, |
| 3075 | "UpdatePlayoutTimestamp() failed to retrieve playout delay"); |
| 3076 | return; |
| 3077 | } |
| 3078 | |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3079 | RTC_DCHECK(jitter_buffer_playout_timestamp_); |
| 3080 | uint32_t playout_timestamp = *jitter_buffer_playout_timestamp_; |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3081 | |
| 3082 | // Remove the playout delay. |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3083 | playout_timestamp -= (delay_ms * (GetPlayoutFrequency() / 1000)); |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3084 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3085 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3086 | "Channel::UpdatePlayoutTimestamp() => playoutTimestamp = %lu", |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3087 | playout_timestamp); |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3088 | |
| 3089 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 3090 | rtc::CritScope lock(&video_sync_lock_); |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3091 | if (rtcp) { |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3092 | playout_timestamp_rtcp_ = playout_timestamp; |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3093 | } else { |
henrik.lundin | 96bd502 | 2016-04-06 04:13:56 -0700 | [diff] [blame] | 3094 | playout_timestamp_rtp_ = playout_timestamp; |
deadbeef | 7437588 | 2015-08-13 12:09:10 -0700 | [diff] [blame] | 3095 | } |
| 3096 | playout_delay_ms_ = delay_ms; |
| 3097 | } |
| 3098 | } |
| 3099 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3100 | void Channel::RegisterReceiveCodecsToRTPModule() { |
| 3101 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3102 | "Channel::RegisterReceiveCodecsToRTPModule()"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3103 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3104 | CodecInst codec; |
| 3105 | const uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3106 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3107 | for (int idx = 0; idx < nSupportedCodecs; idx++) { |
| 3108 | // Open up the RTP/RTCP receiver for all supported codecs |
| 3109 | if ((audio_coding_->Codec(idx, &codec) == -1) || |
| 3110 | (rtp_receiver_->RegisterReceivePayload( |
| 3111 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 3112 | (codec.rate < 0) ? 0 : codec.rate) == -1)) { |
| 3113 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3114 | "Channel::RegisterReceiveCodecsToRTPModule() unable" |
| 3115 | " to register %s (%d/%d/%" PRIuS |
| 3116 | "/%d) to RTP/RTCP " |
| 3117 | "receiver", |
| 3118 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 3119 | codec.rate); |
| 3120 | } else { |
| 3121 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
| 3122 | "Channel::RegisterReceiveCodecsToRTPModule() %s " |
| 3123 | "(%d/%d/%" PRIuS |
| 3124 | "/%d) has been added to the RTP/RTCP " |
| 3125 | "receiver", |
| 3126 | codec.plname, codec.pltype, codec.plfreq, codec.channels, |
| 3127 | codec.rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3128 | } |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3129 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3132 | int Channel::SetSendRtpHeaderExtension(bool enable, |
| 3133 | RTPExtensionType type, |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 3134 | unsigned char id) { |
| 3135 | int error = 0; |
| 3136 | _rtpRtcpModule->DeregisterSendRtpHeaderExtension(type); |
| 3137 | if (enable) { |
| 3138 | error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id); |
| 3139 | } |
| 3140 | return error; |
| 3141 | } |
minyue@webrtc.org | c1a40a7 | 2014-05-28 09:52:06 +0000 | [diff] [blame] | 3142 | |
henrik.lundin | b3e3001 | 2016-08-31 14:09:51 -0700 | [diff] [blame] | 3143 | int32_t Channel::GetPlayoutFrequency() const { |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 3144 | int32_t playout_frequency = audio_coding_->PlayoutFrequency(); |
| 3145 | CodecInst current_recive_codec; |
| 3146 | if (audio_coding_->ReceiveCodec(¤t_recive_codec) == 0) { |
| 3147 | if (STR_CASE_CMP("G722", current_recive_codec.plname) == 0) { |
| 3148 | // Even though the actual sampling rate for G.722 audio is |
| 3149 | // 16,000 Hz, the RTP clock rate for the G722 payload format is |
| 3150 | // 8,000 Hz because that value was erroneously assigned in |
| 3151 | // RFC 1890 and must remain unchanged for backward compatibility. |
| 3152 | playout_frequency = 8000; |
| 3153 | } else if (STR_CASE_CMP("opus", current_recive_codec.plname) == 0) { |
| 3154 | // We are resampling Opus internally to 32,000 Hz until all our |
| 3155 | // DSP routines can operate at 48,000 Hz, but the RTP clock |
| 3156 | // rate for the Opus payload format is standardized to 48,000 Hz, |
| 3157 | // because that is the maximum supported decoding sampling rate. |
| 3158 | playout_frequency = 48000; |
| 3159 | } |
| 3160 | } |
| 3161 | return playout_frequency; |
| 3162 | } |
| 3163 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3164 | int64_t Channel::GetRTT(bool allow_associate_channel) const { |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 3165 | RtcpMode method = _rtpRtcpModule->RTCP(); |
| 3166 | if (method == RtcpMode::kOff) { |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 3167 | return 0; |
| 3168 | } |
| 3169 | std::vector<RTCPReportBlock> report_blocks; |
| 3170 | _rtpRtcpModule->RemoteRTCPStat(&report_blocks); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3171 | |
| 3172 | int64_t rtt = 0; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 3173 | if (report_blocks.empty()) { |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3174 | if (allow_associate_channel) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 3175 | rtc::CritScope lock(&assoc_send_channel_lock_); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3176 | Channel* channel = associate_send_channel_.channel(); |
| 3177 | // Tries to get RTT from an associated channel. This is important for |
| 3178 | // receive-only channels. |
| 3179 | if (channel) { |
| 3180 | // To prevent infinite recursion and deadlock, calling GetRTT of |
| 3181 | // associate channel should always use "false" for argument: |
| 3182 | // |allow_associate_channel|. |
| 3183 | rtt = channel->GetRTT(false); |
| 3184 | } |
| 3185 | } |
| 3186 | return rtt; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | uint32_t remoteSSRC = rtp_receiver_->SSRC(); |
| 3190 | std::vector<RTCPReportBlock>::const_iterator it = report_blocks.begin(); |
| 3191 | for (; it != report_blocks.end(); ++it) { |
| 3192 | if (it->remoteSSRC == remoteSSRC) |
| 3193 | break; |
| 3194 | } |
| 3195 | if (it == report_blocks.end()) { |
| 3196 | // We have not received packets with SSRC matching the report blocks. |
| 3197 | // To calculate RTT we try with the SSRC of the first report block. |
| 3198 | // This is very important for send-only channels where we don't know |
| 3199 | // the SSRC of the other end. |
| 3200 | remoteSSRC = report_blocks[0].remoteSSRC; |
| 3201 | } |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 3202 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 3203 | int64_t avg_rtt = 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3204 | int64_t max_rtt = 0; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 3205 | int64_t min_rtt = 0; |
kwiberg | 55b97fe | 2016-01-28 05:22:45 -0800 | [diff] [blame] | 3206 | if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
| 3207 | 0) { |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 3208 | return 0; |
| 3209 | } |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 3210 | return rtt; |
minyue@webrtc.org | 2b58a44 | 2014-09-11 07:51:53 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 3213 | } // namespace voe |
| 3214 | } // namespace webrtc |