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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 int NetEqImpl::LeastRequiredDelayMs() const { | 357 int NetEqImpl::LeastRequiredDelayMs() const { |
358 rtc::CritScope lock(&crit_sect_); | 358 rtc::CritScope lock(&crit_sect_); |
359 assert(delay_manager_.get()); | 359 assert(delay_manager_.get()); |
360 return delay_manager_->least_required_delay_ms(); | 360 return delay_manager_->least_required_delay_ms(); |
361 } | 361 } |
362 | 362 |
363 int NetEqImpl::SetTargetDelay() { | 363 int NetEqImpl::SetTargetDelay() { |
364 return kNotImplemented; | 364 return kNotImplemented; |
365 } | 365 } |
366 | 366 |
367 int NetEqImpl::TargetDelay() { | 367 int NetEqImpl::TargetDelayMs() { |
368 return kNotImplemented; | 368 rtc::CritScope lock(&crit_sect_); |
369 RTC_DCHECK(delay_manager_.get()); | |
370 // The value from TargetLevel() is in number of packets, represented in Q8. | |
371 const size_t target_delay_samples = | |
372 (delay_manager_->TargetLevel() * decoder_frame_length_) >> 8; | |
373 return static_cast<int>(target_delay_samples) / | |
374 rtc::CheckedDivExact(fs_hz_, 1000); | |
369 } | 375 } |
370 | 376 |
371 int NetEqImpl::CurrentDelayMs() const { | 377 int NetEqImpl::CurrentDelayMs() const { |
372 rtc::CritScope lock(&crit_sect_); | 378 rtc::CritScope lock(&crit_sect_); |
373 if (fs_hz_ == 0) | 379 if (fs_hz_ == 0) |
374 return 0; | 380 return 0; |
375 // Sum up the samples in the packet buffer with the future length of the sync | 381 // Sum up the samples in the packet buffer with the future length of the sync |
376 // buffer, and divide the sum by the sample rate. | 382 // buffer, and divide the sum by the sample rate. |
377 const size_t delay_samples = | 383 const size_t delay_samples = |
378 packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) + | 384 packet_buffer_->NumSamplesInBuffer(decoder_frame_length_) + |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 | 568 |
563 std::vector<uint16_t> NetEqImpl::GetNackList(int64_t round_trip_time_ms) const { | 569 std::vector<uint16_t> NetEqImpl::GetNackList(int64_t round_trip_time_ms) const { |
564 rtc::CritScope lock(&crit_sect_); | 570 rtc::CritScope lock(&crit_sect_); |
565 if (!nack_enabled_) { | 571 if (!nack_enabled_) { |
566 return std::vector<uint16_t>(); | 572 return std::vector<uint16_t>(); |
567 } | 573 } |
568 RTC_DCHECK(nack_.get()); | 574 RTC_DCHECK(nack_.get()); |
569 return nack_->GetNackList(round_trip_time_ms); | 575 return nack_->GetNackList(round_trip_time_ms); |
570 } | 576 } |
571 | 577 |
578 std::vector<uint32_t> NetEqImpl::LastDecodedTimestamps() const { | |
579 rtc::CritScope lock(&crit_sect_); | |
580 return last_decoded_timestamps_; | |
581 } | |
582 | |
583 size_t NetEqImpl::SyncBufferSizeMs() const { | |
584 rtc::CritScope lock(&crit_sect_); | |
585 return sync_buffer_->FutureLength() / rtc::CheckedDivExact(fs_hz_, 1000); | |
586 } | |
587 | |
572 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const { | 588 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const { |
573 rtc::CritScope lock(&crit_sect_); | 589 rtc::CritScope lock(&crit_sect_); |
574 return sync_buffer_.get(); | 590 return sync_buffer_.get(); |
575 } | 591 } |
576 | 592 |
577 Operations NetEqImpl::last_operation_for_test() const { | 593 Operations NetEqImpl::last_operation_for_test() const { |
578 rtc::CritScope lock(&crit_sect_); | 594 rtc::CritScope lock(&crit_sect_); |
579 return last_operation_; | 595 return last_operation_; |
580 } | 596 } |
581 | 597 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 } | 882 } |
867 return 0; | 883 return 0; |
868 } | 884 } |
869 | 885 |
870 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame, bool* muted) { | 886 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame, bool* muted) { |
871 PacketList packet_list; | 887 PacketList packet_list; |
872 DtmfEvent dtmf_event; | 888 DtmfEvent dtmf_event; |
873 Operations operation; | 889 Operations operation; |
874 bool play_dtmf; | 890 bool play_dtmf; |
875 *muted = false; | 891 *muted = false; |
892 last_decoded_timestamps_.clear(); | |
876 tick_timer_->Increment(); | 893 tick_timer_->Increment(); |
877 stats_.IncreaseCounter(output_size_samples_, fs_hz_); | 894 stats_.IncreaseCounter(output_size_samples_, fs_hz_); |
878 | 895 |
879 // Check for muted state. | 896 // Check for muted state. |
880 if (enable_muted_state_ && expand_->Muted() && packet_buffer_->Empty()) { | 897 if (enable_muted_state_ && expand_->Muted() && packet_buffer_->Empty()) { |
881 RTC_DCHECK_EQ(last_mode_, kModeExpand); | 898 RTC_DCHECK_EQ(last_mode_, kModeExpand); |
882 playout_timestamp_ += static_cast<uint32_t>(output_size_samples_); | 899 playout_timestamp_ += static_cast<uint32_t>(output_size_samples_); |
883 audio_frame->sample_rate_hz_ = fs_hz_; | 900 audio_frame->sample_rate_hz_ = fs_hz_; |
884 audio_frame->samples_per_channel_ = output_size_samples_; | 901 audio_frame->samples_per_channel_ = output_size_samples_; |
885 audio_frame->timestamp_ = | 902 audio_frame->timestamp_ = |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1491 LOG(LS_WARNING) << "Decoded too much CNG."; | 1508 LOG(LS_WARNING) << "Decoded too much CNG."; |
1492 return kDecodedTooMuch; | 1509 return kDecodedTooMuch; |
1493 } | 1510 } |
1494 } | 1511 } |
1495 return 0; | 1512 return 0; |
1496 } | 1513 } |
1497 | 1514 |
1498 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation, | 1515 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation, |
1499 AudioDecoder* decoder, int* decoded_length, | 1516 AudioDecoder* decoder, int* decoded_length, |
1500 AudioDecoder::SpeechType* speech_type) { | 1517 AudioDecoder::SpeechType* speech_type) { |
1518 RTC_DCHECK(last_decoded_timestamps_.empty()); | |
ivoc
2017/04/26 12:23:43
Couldn't this function be called back-to-back with
hlundin-webrtc
2017/04/26 14:11:38
I hope not.
NetEqImpl::GetAudioInternal calls Net
| |
1519 | |
1501 // Do decoding. | 1520 // Do decoding. |
1502 while ( | 1521 while ( |
1503 !packet_list->empty() && | 1522 !packet_list->empty() && |
1504 !decoder_database_->IsComfortNoise(packet_list->front().payload_type)) { | 1523 !decoder_database_->IsComfortNoise(packet_list->front().payload_type)) { |
1505 assert(decoder); // At this point, we must have a decoder object. | 1524 assert(decoder); // At this point, we must have a decoder object. |
1506 // The number of channels in the |sync_buffer_| should be the same as the | 1525 // The number of channels in the |sync_buffer_| should be the same as the |
1507 // number decoder channels. | 1526 // number decoder channels. |
1508 assert(sync_buffer_->Channels() == decoder->Channels()); | 1527 assert(sync_buffer_->Channels() == decoder->Channels()); |
1509 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); | 1528 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); |
1510 assert(operation == kNormal || operation == kAccelerate || | 1529 assert(operation == kNormal || operation == kAccelerate || |
1511 operation == kFastAccelerate || operation == kMerge || | 1530 operation == kFastAccelerate || operation == kMerge || |
1512 operation == kPreemptiveExpand); | 1531 operation == kPreemptiveExpand); |
1513 | 1532 |
1514 auto opt_result = packet_list->front().frame->Decode( | 1533 auto opt_result = packet_list->front().frame->Decode( |
1515 rtc::ArrayView<int16_t>(&decoded_buffer_[*decoded_length], | 1534 rtc::ArrayView<int16_t>(&decoded_buffer_[*decoded_length], |
1516 decoded_buffer_length_ - *decoded_length)); | 1535 decoded_buffer_length_ - *decoded_length)); |
1536 last_decoded_timestamps_.push_back(packet_list->front().timestamp); | |
1517 packet_list->pop_front(); | 1537 packet_list->pop_front(); |
1518 if (opt_result) { | 1538 if (opt_result) { |
1519 const auto& result = *opt_result; | 1539 const auto& result = *opt_result; |
1520 *speech_type = result.speech_type; | 1540 *speech_type = result.speech_type; |
1521 if (result.num_decoded_samples > 0) { | 1541 if (result.num_decoded_samples > 0) { |
1522 *decoded_length += rtc::dchecked_cast<int>(result.num_decoded_samples); | 1542 *decoded_length += rtc::dchecked_cast<int>(result.num_decoded_samples); |
1523 // Update |decoder_frame_length_| with number of samples per channel. | 1543 // Update |decoder_frame_length_| with number of samples per channel. |
1524 decoder_frame_length_ = | 1544 decoder_frame_length_ = |
1525 result.num_decoded_samples / decoder->Channels(); | 1545 result.num_decoded_samples / decoder->Channels(); |
1526 } | 1546 } |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2149 } | 2169 } |
2150 } | 2170 } |
2151 | 2171 |
2152 void NetEqImpl::CreateDecisionLogic() { | 2172 void NetEqImpl::CreateDecisionLogic() { |
2153 decision_logic_.reset(DecisionLogic::Create( | 2173 decision_logic_.reset(DecisionLogic::Create( |
2154 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), | 2174 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
2155 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), | 2175 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
2156 tick_timer_.get())); | 2176 tick_timer_.get())); |
2157 } | 2177 } |
2158 } // namespace webrtc | 2178 } // namespace webrtc |
OLD | NEW |