OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 | 523 |
524 // Push the incoming payload (parsed and ready for decoding) into the ACM | 524 // Push the incoming payload (parsed and ready for decoding) into the ACM |
525 if (audio_coding_->IncomingPacket(payloadData, payloadSize, *rtpHeader) != | 525 if (audio_coding_->IncomingPacket(payloadData, payloadSize, *rtpHeader) != |
526 0) { | 526 0) { |
527 _engineStatisticsPtr->SetLastError( | 527 _engineStatisticsPtr->SetLastError( |
528 VE_AUDIO_CODING_MODULE_ERROR, kTraceWarning, | 528 VE_AUDIO_CODING_MODULE_ERROR, kTraceWarning, |
529 "Channel::OnReceivedPayloadData() unable to push data to the ACM"); | 529 "Channel::OnReceivedPayloadData() unable to push data to the ACM"); |
530 return -1; | 530 return -1; |
531 } | 531 } |
532 | 532 |
533 // Update the packet delay. | |
534 UpdatePacketDelay(rtpHeader->header.timestamp, | |
535 rtpHeader->header.sequenceNumber); | |
536 | |
537 int64_t round_trip_time = 0; | 533 int64_t round_trip_time = 0; |
538 _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL, | 534 _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL, |
539 NULL); | 535 NULL); |
540 | 536 |
541 std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time); | 537 std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time); |
542 if (!nack_list.empty()) { | 538 if (!nack_list.empty()) { |
543 // Can't use nack_list.data() since it's not supported by all | 539 // Can't use nack_list.data() since it's not supported by all |
544 // compilers. | 540 // compilers. |
545 ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size())); | 541 ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size())); |
546 } | 542 } |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 _mixFileWithMicrophone(false), | 869 _mixFileWithMicrophone(false), |
874 input_mute_(false), | 870 input_mute_(false), |
875 previous_frame_muted_(false), | 871 previous_frame_muted_(false), |
876 _panLeft(1.0f), | 872 _panLeft(1.0f), |
877 _panRight(1.0f), | 873 _panRight(1.0f), |
878 _outputGain(1.0f), | 874 _outputGain(1.0f), |
879 _lastLocalTimeStamp(0), | 875 _lastLocalTimeStamp(0), |
880 _lastPayloadType(0), | 876 _lastPayloadType(0), |
881 _includeAudioLevelIndication(false), | 877 _includeAudioLevelIndication(false), |
882 _outputSpeechType(AudioFrame::kNormalSpeech), | 878 _outputSpeechType(AudioFrame::kNormalSpeech), |
883 _average_jitter_buffer_delay_us(0), | |
884 _previousTimestamp(0), | |
885 _recPacketDelayMs(20), | |
886 _RxVadDetection(false), | 879 _RxVadDetection(false), |
887 _rxAgcIsEnabled(false), | 880 _rxAgcIsEnabled(false), |
888 _rxNsIsEnabled(false), | 881 _rxNsIsEnabled(false), |
889 restored_packet_in_use_(false), | 882 restored_packet_in_use_(false), |
890 rtcp_observer_(new VoERtcpObserver(this)), | 883 rtcp_observer_(new VoERtcpObserver(this)), |
891 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), | 884 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), |
892 associate_send_channel_(ChannelOwner(nullptr)), | 885 associate_send_channel_(ChannelOwner(nullptr)), |
893 pacing_enabled_(config.Get<VoicePacing>().enabled), | 886 pacing_enabled_(config.Get<VoicePacing>().enabled), |
894 feedback_observer_proxy_(new TransportFeedbackProxy()), | 887 feedback_observer_proxy_(new TransportFeedbackProxy()), |
895 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), | 888 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), |
(...skipping 2482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 rtc::CritScope lock(&video_sync_lock_); | 3371 rtc::CritScope lock(&video_sync_lock_); |
3379 if (rtcp) { | 3372 if (rtcp) { |
3380 playout_timestamp_rtcp_ = playout_timestamp; | 3373 playout_timestamp_rtcp_ = playout_timestamp; |
3381 } else { | 3374 } else { |
3382 playout_timestamp_rtp_ = playout_timestamp; | 3375 playout_timestamp_rtp_ = playout_timestamp; |
3383 } | 3376 } |
3384 playout_delay_ms_ = delay_ms; | 3377 playout_delay_ms_ = delay_ms; |
3385 } | 3378 } |
3386 } | 3379 } |
3387 | 3380 |
3388 // Called for incoming RTP packets after successful RTP header parsing. | |
3389 // TODO(henrik.lundin): Clean out this method. With the introduction of | |
3390 // AudioCoding::FilteredCurrentDelayMs() most (if not all) of this method can | |
3391 // be deleted, along with a few member variables. (WebRTC issue 6237.) | |
3392 void Channel::UpdatePacketDelay(uint32_t rtp_timestamp, | |
3393 uint16_t sequence_number) { | |
3394 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, _channelId), | |
3395 "Channel::UpdatePacketDelay(timestamp=%lu, sequenceNumber=%u)", | |
3396 rtp_timestamp, sequence_number); | |
3397 | |
3398 // Get frequency of last received payload | |
3399 int rtp_receive_frequency = GetPlayoutFrequency(); | |
3400 | |
3401 // |jitter_buffer_playout_timestamp_| updated in UpdatePlayoutTimestamp for | |
3402 // every incoming packet. May be empty if no valid playout timestamp is | |
3403 // available. | |
3404 // If |rtp_timestamp| is newer than |jitter_buffer_playout_timestamp_|, the | |
3405 // resulting difference is positive and will be used. When the inverse is | |
3406 // true (can happen when a network glitch causes a packet to arrive late, | |
3407 // and during long comfort noise periods with clock drift), or when | |
3408 // |jitter_buffer_playout_timestamp_| has no value, the difference is not | |
3409 // changed from the initial 0. | |
3410 uint32_t timestamp_diff_ms = 0; | |
3411 if (jitter_buffer_playout_timestamp_ && | |
3412 IsNewerTimestamp(rtp_timestamp, *jitter_buffer_playout_timestamp_)) { | |
3413 timestamp_diff_ms = (rtp_timestamp - *jitter_buffer_playout_timestamp_) / | |
3414 (rtp_receive_frequency / 1000); | |
3415 if (timestamp_diff_ms > (2 * kVoiceEngineMaxMinPlayoutDelayMs)) { | |
3416 // Diff is too large; set it to zero instead. | |
3417 timestamp_diff_ms = 0; | |
3418 } | |
3419 } | |
3420 | |
3421 uint16_t packet_delay_ms = | |
3422 (rtp_timestamp - _previousTimestamp) / (rtp_receive_frequency / 1000); | |
3423 | |
3424 _previousTimestamp = rtp_timestamp; | |
3425 | |
3426 if (timestamp_diff_ms == 0) | |
3427 return; | |
3428 | |
3429 { | |
3430 rtc::CritScope lock(&video_sync_lock_); | |
3431 | |
3432 if (packet_delay_ms >= 10 && packet_delay_ms <= 60) { | |
3433 _recPacketDelayMs = packet_delay_ms; | |
3434 } | |
3435 | |
3436 if (_average_jitter_buffer_delay_us == 0) { | |
3437 _average_jitter_buffer_delay_us = timestamp_diff_ms * 1000; | |
3438 return; | |
3439 } | |
3440 | |
3441 // Filter average delay value using exponential filter (alpha is | |
3442 // 7/8). We derive 1000 *_average_jitter_buffer_delay_us here (reduces | |
3443 // risk of rounding error) and compensate for it in GetDelayEstimate() | |
3444 // later. | |
3445 _average_jitter_buffer_delay_us = | |
3446 (_average_jitter_buffer_delay_us * 7 + 1000 * timestamp_diff_ms + 500) / | |
3447 8; | |
3448 } | |
3449 } | |
3450 | |
3451 void Channel::RegisterReceiveCodecsToRTPModule() { | 3381 void Channel::RegisterReceiveCodecsToRTPModule() { |
3452 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 3382 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
3453 "Channel::RegisterReceiveCodecsToRTPModule()"); | 3383 "Channel::RegisterReceiveCodecsToRTPModule()"); |
3454 | 3384 |
3455 CodecInst codec; | 3385 CodecInst codec; |
3456 const uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); | 3386 const uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
3457 | 3387 |
3458 for (int idx = 0; idx < nSupportedCodecs; idx++) { | 3388 for (int idx = 0; idx < nSupportedCodecs; idx++) { |
3459 // Open up the RTP/RTCP receiver for all supported codecs | 3389 // Open up the RTP/RTCP receiver for all supported codecs |
3460 if ((audio_coding_->Codec(idx, &codec) == -1) || | 3390 if ((audio_coding_->Codec(idx, &codec) == -1) || |
(...skipping 23 matching lines...) Expand all Loading... |
3484 RTPExtensionType type, | 3414 RTPExtensionType type, |
3485 unsigned char id) { | 3415 unsigned char id) { |
3486 int error = 0; | 3416 int error = 0; |
3487 _rtpRtcpModule->DeregisterSendRtpHeaderExtension(type); | 3417 _rtpRtcpModule->DeregisterSendRtpHeaderExtension(type); |
3488 if (enable) { | 3418 if (enable) { |
3489 error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id); | 3419 error = _rtpRtcpModule->RegisterSendRtpHeaderExtension(type, id); |
3490 } | 3420 } |
3491 return error; | 3421 return error; |
3492 } | 3422 } |
3493 | 3423 |
3494 int32_t Channel::GetPlayoutFrequency() { | 3424 int32_t Channel::GetPlayoutFrequency() const { |
3495 int32_t playout_frequency = audio_coding_->PlayoutFrequency(); | 3425 int32_t playout_frequency = audio_coding_->PlayoutFrequency(); |
3496 CodecInst current_recive_codec; | 3426 CodecInst current_recive_codec; |
3497 if (audio_coding_->ReceiveCodec(¤t_recive_codec) == 0) { | 3427 if (audio_coding_->ReceiveCodec(¤t_recive_codec) == 0) { |
3498 if (STR_CASE_CMP("G722", current_recive_codec.plname) == 0) { | 3428 if (STR_CASE_CMP("G722", current_recive_codec.plname) == 0) { |
3499 // Even though the actual sampling rate for G.722 audio is | 3429 // Even though the actual sampling rate for G.722 audio is |
3500 // 16,000 Hz, the RTP clock rate for the G722 payload format is | 3430 // 16,000 Hz, the RTP clock rate for the G722 payload format is |
3501 // 8,000 Hz because that value was erroneously assigned in | 3431 // 8,000 Hz because that value was erroneously assigned in |
3502 // RFC 1890 and must remain unchanged for backward compatibility. | 3432 // RFC 1890 and must remain unchanged for backward compatibility. |
3503 playout_frequency = 8000; | 3433 playout_frequency = 8000; |
3504 } else if (STR_CASE_CMP("opus", current_recive_codec.plname) == 0) { | 3434 } else if (STR_CASE_CMP("opus", current_recive_codec.plname) == 0) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 int64_t min_rtt = 0; | 3486 int64_t min_rtt = 0; |
3557 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3487 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
3558 0) { | 3488 0) { |
3559 return 0; | 3489 return 0; |
3560 } | 3490 } |
3561 return rtt; | 3491 return rtt; |
3562 } | 3492 } |
3563 | 3493 |
3564 } // namespace voe | 3494 } // namespace voe |
3565 } // namespace webrtc | 3495 } // namespace webrtc |
OLD | NEW |