Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl.cc

Issue 1750353002: Change NetEq::GetAudio to use AudioFrame (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 int error = 141 int error =
142 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true); 142 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true);
143 143
144 if (error != 0) { 144 if (error != 0) {
145 error_code_ = error; 145 error_code_ = error;
146 return kFail; 146 return kFail;
147 } 147 }
148 return kOK; 148 return kOK;
149 } 149 }
150 150
151 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio, 151 int NetEqImpl::GetAudio(AudioFrame* audio_frame, NetEqOutputType* type) {
152 size_t* samples_per_channel, size_t* num_channels,
153 NetEqOutputType* type) {
154 TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio"); 152 TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio");
155 rtc::CritScope lock(&crit_sect_); 153 rtc::CritScope lock(&crit_sect_);
156 int error = GetAudioInternal(max_length, output_audio, samples_per_channel, 154 int error = GetAudioInternal(audio_frame);
157 num_channels); 155 RTC_DCHECK_EQ(
156 audio_frame->sample_rate_hz_,
157 rtc::checked_cast<int>(audio_frame->samples_per_channel_ * 100));
158 if (error != 0) { 158 if (error != 0) {
159 error_code_ = error; 159 error_code_ = error;
160 return kFail; 160 return kFail;
161 } 161 }
162 if (type) { 162 if (type) {
163 *type = LastOutputType(); 163 *type = LastOutputType();
164 } 164 }
165 last_output_sample_rate_hz_ = 165 last_output_sample_rate_hz_ = audio_frame->sample_rate_hz_;
166 rtc::checked_cast<int>(*samples_per_channel * 100);
167 RTC_DCHECK(last_output_sample_rate_hz_ == 8000 || 166 RTC_DCHECK(last_output_sample_rate_hz_ == 8000 ||
168 last_output_sample_rate_hz_ == 16000 || 167 last_output_sample_rate_hz_ == 16000 ||
169 last_output_sample_rate_hz_ == 32000 || 168 last_output_sample_rate_hz_ == 32000 ||
170 last_output_sample_rate_hz_ == 48000) 169 last_output_sample_rate_hz_ == 48000)
171 << "Unexpected sample rate " << last_output_sample_rate_hz_; 170 << "Unexpected sample rate " << last_output_sample_rate_hz_;
172 return kOK; 171 return kOK;
173 } 172 }
174 173
175 int NetEqImpl::RegisterPayloadType(NetEqDecoder codec, 174 int NetEqImpl::RegisterPayloadType(NetEqDecoder codec,
176 const std::string& name, 175 const std::string& name,
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } else if (delay_manager_->last_pack_cng_or_dtmf() == -1) { 731 } else if (delay_manager_->last_pack_cng_or_dtmf() == -1) {
733 // This is first "normal" packet after CNG or DTMF. 732 // This is first "normal" packet after CNG or DTMF.
734 // Reset packet time counter and measure time until next packet, 733 // Reset packet time counter and measure time until next packet,
735 // but don't update statistics. 734 // but don't update statistics.
736 delay_manager_->set_last_pack_cng_or_dtmf(0); 735 delay_manager_->set_last_pack_cng_or_dtmf(0);
737 delay_manager_->ResetPacketIatCount(); 736 delay_manager_->ResetPacketIatCount();
738 } 737 }
739 return 0; 738 return 0;
740 } 739 }
741 740
742 int NetEqImpl::GetAudioInternal(size_t max_length, 741 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame) {
743 int16_t* output,
744 size_t* samples_per_channel,
745 size_t* num_channels) {
746 PacketList packet_list; 742 PacketList packet_list;
747 DtmfEvent dtmf_event; 743 DtmfEvent dtmf_event;
748 Operations operation; 744 Operations operation;
749 bool play_dtmf; 745 bool play_dtmf;
750 int return_value = GetDecision(&operation, &packet_list, &dtmf_event, 746 int return_value = GetDecision(&operation, &packet_list, &dtmf_event,
751 &play_dtmf); 747 &play_dtmf);
752 if (return_value != 0) { 748 if (return_value != 0) {
753 last_mode_ = kModeError; 749 last_mode_ = kModeError;
754 return return_value; 750 return return_value;
755 } 751 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 if (last_mode_ != kModeRfc3389Cng) { 846 if (last_mode_ != kModeRfc3389Cng) {
851 comfort_noise_->Reset(); 847 comfort_noise_->Reset();
852 } 848 }
853 849
854 // Copy from |algorithm_buffer| to |sync_buffer_|. 850 // Copy from |algorithm_buffer| to |sync_buffer_|.
855 sync_buffer_->PushBack(*algorithm_buffer_); 851 sync_buffer_->PushBack(*algorithm_buffer_);
856 852
857 // Extract data from |sync_buffer_| to |output|. 853 // Extract data from |sync_buffer_| to |output|.
858 size_t num_output_samples_per_channel = output_size_samples_; 854 size_t num_output_samples_per_channel = output_size_samples_;
859 size_t num_output_samples = output_size_samples_ * sync_buffer_->Channels(); 855 size_t num_output_samples = output_size_samples_ * sync_buffer_->Channels();
860 if (num_output_samples > max_length) { 856 if (num_output_samples > AudioFrame::kMaxDataSizeSamples) {
861 LOG(LS_WARNING) << "Output array is too short. " << max_length << " < " << 857 LOG(LS_WARNING) << "Output array is too short. "
862 output_size_samples_ << " * " << sync_buffer_->Channels(); 858 << AudioFrame::kMaxDataSizeSamples << " < "
863 num_output_samples = max_length; 859 << output_size_samples_ << " * "
864 num_output_samples_per_channel = max_length / sync_buffer_->Channels(); 860 << sync_buffer_->Channels();
861 num_output_samples = AudioFrame::kMaxDataSizeSamples;
862 num_output_samples_per_channel =
863 AudioFrame::kMaxDataSizeSamples / sync_buffer_->Channels();
865 } 864 }
866 const size_t samples_from_sync = 865 sync_buffer_->GetNextAudioInterleaved(num_output_samples_per_channel,
867 sync_buffer_->GetNextAudioInterleaved(num_output_samples_per_channel, 866 audio_frame);
868 output); 867 audio_frame->sample_rate_hz_ = fs_hz_;
869 *num_channels = sync_buffer_->Channels();
870 if (sync_buffer_->FutureLength() < expand_->overlap_length()) { 868 if (sync_buffer_->FutureLength() < expand_->overlap_length()) {
871 // The sync buffer should always contain |overlap_length| samples, but now 869 // The sync buffer should always contain |overlap_length| samples, but now
872 // too many samples have been extracted. Reinstall the |overlap_length| 870 // too many samples have been extracted. Reinstall the |overlap_length|
873 // lookahead by moving the index. 871 // lookahead by moving the index.
874 const size_t missing_lookahead_samples = 872 const size_t missing_lookahead_samples =
875 expand_->overlap_length() - sync_buffer_->FutureLength(); 873 expand_->overlap_length() - sync_buffer_->FutureLength();
876 RTC_DCHECK_GE(sync_buffer_->next_index(), missing_lookahead_samples); 874 RTC_DCHECK_GE(sync_buffer_->next_index(), missing_lookahead_samples);
877 sync_buffer_->set_next_index(sync_buffer_->next_index() - 875 sync_buffer_->set_next_index(sync_buffer_->next_index() -
878 missing_lookahead_samples); 876 missing_lookahead_samples);
879 } 877 }
880 if (samples_from_sync != output_size_samples_) { 878 if (audio_frame->samples_per_channel_ != output_size_samples_) {
881 LOG(LS_ERROR) << "samples_from_sync (" << samples_from_sync 879 LOG(LS_ERROR) << "audio_frame->samples_per_channel_ ("
880 << audio_frame->samples_per_channel_
882 << ") != output_size_samples_ (" << output_size_samples_ 881 << ") != output_size_samples_ (" << output_size_samples_
883 << ")"; 882 << ")";
884 // TODO(minyue): treatment of under-run, filling zeros 883 // TODO(minyue): treatment of under-run, filling zeros
885 memset(output, 0, num_output_samples * sizeof(int16_t)); 884 memset(audio_frame->data_, 0, num_output_samples * sizeof(int16_t));
886 *samples_per_channel = output_size_samples_;
887 return kSampleUnderrun; 885 return kSampleUnderrun;
888 } 886 }
889 *samples_per_channel = output_size_samples_;
890 887
891 // Should always have overlap samples left in the |sync_buffer_|. 888 // Should always have overlap samples left in the |sync_buffer_|.
892 RTC_DCHECK_GE(sync_buffer_->FutureLength(), expand_->overlap_length()); 889 RTC_DCHECK_GE(sync_buffer_->FutureLength(), expand_->overlap_length());
893 890
894 if (play_dtmf) { 891 if (play_dtmf) {
895 return_value = DtmfOverdub(dtmf_event, sync_buffer_->Channels(), output); 892 return_value =
893 DtmfOverdub(dtmf_event, sync_buffer_->Channels(), audio_frame->data_);
896 } 894 }
897 895
898 // Update the background noise parameters if last operation wrote data 896 // Update the background noise parameters if last operation wrote data
899 // straight from the decoder to the |sync_buffer_|. That is, none of the 897 // straight from the decoder to the |sync_buffer_|. That is, none of the
900 // operations that modify the signal can be followed by a parameter update. 898 // operations that modify the signal can be followed by a parameter update.
901 if ((last_mode_ == kModeNormal) || 899 if ((last_mode_ == kModeNormal) ||
902 (last_mode_ == kModeAccelerateFail) || 900 (last_mode_ == kModeAccelerateFail) ||
903 (last_mode_ == kModePreemptiveExpandFail) || 901 (last_mode_ == kModePreemptiveExpandFail) ||
904 (last_mode_ == kModeRfc3389Cng) || 902 (last_mode_ == kModeRfc3389Cng) ||
905 (last_mode_ == kModeCodecInternalCng)) { 903 (last_mode_ == kModeCodecInternalCng)) {
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 2041
2044 void NetEqImpl::CreateDecisionLogic() { 2042 void NetEqImpl::CreateDecisionLogic() {
2045 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, 2043 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_,
2046 playout_mode_, 2044 playout_mode_,
2047 decoder_database_.get(), 2045 decoder_database_.get(),
2048 *packet_buffer_.get(), 2046 *packet_buffer_.get(),
2049 delay_manager_.get(), 2047 delay_manager_.get(),
2050 buffer_level_filter_.get())); 2048 buffer_level_filter_.get()));
2051 } 2049 }
2052 } // namespace webrtc 2050 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.h ('k') | webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698