Chromium Code Reviews| Index: components/audio_modem/audio_recorder_impl.cc |
| diff --git a/components/audio_modem/audio_recorder_impl.cc b/components/audio_modem/audio_recorder_impl.cc |
| index 9be772e0a8776c93332c4af0ce0cf0b6c428686f..b694c3974cc3ce749339328e34e93716c8d33a1a 100644 |
| --- a/components/audio_modem/audio_recorder_impl.cc |
| +++ b/components/audio_modem/audio_recorder_impl.cc |
| @@ -54,7 +54,6 @@ void ProcessSamples( |
| AudioRecorderImpl::AudioRecorderImpl() |
| : is_recording_(false), |
| stream_(nullptr), |
| - temp_conversion_buffer_(nullptr), |
| total_buffer_frames_(0), |
| buffer_frame_index_(0) { |
| } |
| @@ -103,20 +102,8 @@ void AudioRecorderImpl::InitializeOnAudioThread() { |
| : media::AudioManager::Get()->GetInputStreamParameters( |
| media::AudioManagerBase::kDefaultDeviceId); |
| - const media::AudioParameters dest_params(params.format(), |
| - kDefaultChannelLayout, |
| - kDefaultSampleRate, |
| - kDefaultBitsPerSample, |
| - params.frames_per_buffer(), |
| - media::AudioParameters::NO_EFFECTS); |
| - |
| - converter_.reset(new media::AudioConverter( |
| - params, dest_params, params.sample_rate() == dest_params.sample_rate())); |
| - converter_->AddInput(this); |
| - |
| - total_buffer_frames_ = kProcessIntervalMs * dest_params.sample_rate() / 1000; |
| - buffer_ = |
| - media::AudioBus::Create(dest_params.channels(), total_buffer_frames_); |
| + total_buffer_frames_ = kProcessIntervalMs * params.sample_rate() / 1000; |
| + buffer_ = media::AudioBus::Create(params.channels(), total_buffer_frames_); |
| buffer_frame_index_ = 0; |
| stream_ = input_stream_for_testing_ |
| @@ -141,7 +128,6 @@ void AudioRecorderImpl::RecordOnAudioThread() { |
| return; |
| VLOG(3) << "Starting recording."; |
| - converter_->Reset(); |
| stream_->Start(this); |
| is_recording_ = true; |
| } |
| @@ -176,46 +162,27 @@ void AudioRecorderImpl::OnData(media::AudioInputStream* stream, |
| const media::AudioBus* source, |
| uint32 /* hardware_delay_bytes */, |
| double /* volume */) { |
| - temp_conversion_buffer_ = source; |
| - while (temp_conversion_buffer_) { |
| - // source->frames() == source_params.frames_per_buffer(), so we only have |
| - // one chunk of data in the source; correspondingly set the destination |
| - // size to one chunk. |
| - // TODO(rkc): Optimize this to directly write into buffer_ so we can avoid |
| - // the copy into this buffer and then the copy back into buffer_. |
| - scoped_ptr<media::AudioBus> converted_source = |
| - media::AudioBus::Create(kDefaultChannels, converter_->ChunkSize()); |
| - |
| - // Convert accumulated samples into converted_source. Note: One call may not |
| - // be enough to consume the samples from |source|. The converter may have |
| - // accumulated samples over time due to a fractional input:output sample |
| - // rate ratio. Since |source| is ephemeral, Convert() must be called until |
| - // |source| is at least buffered into the converter. Once |source| is |
| - // consumed during ProvideInput(), |temp_conversion_buffer_| will be set to |
| - // NULL, which will break the conversion loop. |
| - converter_->Convert(converted_source.get()); |
| - |
| - int remaining_buffer_frames = buffer_->frames() - buffer_frame_index_; |
| - int frames_to_copy = |
| - std::min(remaining_buffer_frames, converted_source->frames()); |
| - converted_source->CopyPartialFramesTo( |
| - 0, frames_to_copy, buffer_frame_index_, buffer_.get()); |
| - buffer_frame_index_ += frames_to_copy; |
| - |
| - // Buffer full, send it for processing. |
| - if (buffer_->frames() == buffer_frame_index_) { |
| - ProcessSamples(buffer_.Pass(), decode_callback_); |
| - buffer_ = media::AudioBus::Create(kDefaultChannels, total_buffer_frames_); |
| - buffer_frame_index_ = 0; |
| - |
| - // Copy any remaining frames in the source to our buffer. |
| - int remaining_source_frames = converted_source->frames() - frames_to_copy; |
| - converted_source->CopyPartialFramesTo(frames_to_copy, |
| - remaining_source_frames, |
| - buffer_frame_index_, |
| - buffer_.get()); |
| - buffer_frame_index_ += remaining_source_frames; |
| - } |
| + // source->frames() == source_params.frames_per_buffer(), so we only have |
| + // one chunk of data in the source; correspondingly set the destination |
| + // size to one chunk. |
| + |
| + int remaining_buffer_frames = buffer_->frames() - buffer_frame_index_; |
| + int frames_to_copy = std::min(remaining_buffer_frames, source->frames()); |
| + source->CopyPartialFramesTo(0, frames_to_copy, buffer_frame_index_, |
| + buffer_.get()); |
| + buffer_frame_index_ += frames_to_copy; |
| + |
| + // Buffer full, send it for processing. |
| + if (buffer_->frames() == buffer_frame_index_) { |
|
DaleCurtis
2015/02/20 18:31:42
Is this always going to be an exact match? It seem
rkc
2015/02/20 18:53:07
It'll still be an exact match since if buffer_fram
|
| + ProcessSamples(buffer_.Pass(), decode_callback_); |
| + buffer_ = media::AudioBus::Create(kDefaultChannels, total_buffer_frames_); |
| + buffer_frame_index_ = 0; |
| + |
| + // Copy any remaining frames in the source to our buffer. |
| + int remaining_source_frames = source->frames() - frames_to_copy; |
| + source->CopyPartialFramesTo(frames_to_copy, remaining_source_frames, |
| + buffer_frame_index_, buffer_.get()); |
| + buffer_frame_index_ += remaining_source_frames; |
| } |
| } |
| @@ -227,15 +194,6 @@ void AudioRecorderImpl::OnError(media::AudioInputStream* /* stream */) { |
| base::Unretained(this))); |
| } |
| -double AudioRecorderImpl::ProvideInput(media::AudioBus* dest, |
| - base::TimeDelta /* buffer_delay */) { |
| - DCHECK(temp_conversion_buffer_); |
| - DCHECK_LE(temp_conversion_buffer_->frames(), dest->frames()); |
| - temp_conversion_buffer_->CopyTo(dest); |
| - temp_conversion_buffer_ = nullptr; |
| - return 1.0; |
| -} |
| - |
| void AudioRecorderImpl::FlushAudioLoopForTesting() { |
| if (media::AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()) |
| return; |