| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/android/opensles_input.h" | 5 #include "media/audio/android/opensles_input.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "media/audio/android/audio_manager_android.h" | 10 #include "media/audio/android/audio_manager_android.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 format_.formatType = SL_DATAFORMAT_PCM; | 35 format_.formatType = SL_DATAFORMAT_PCM; |
| 36 format_.numChannels = static_cast<SLuint32>(params.channels()); | 36 format_.numChannels = static_cast<SLuint32>(params.channels()); |
| 37 // Provides sampling rate in milliHertz to OpenSLES. | 37 // Provides sampling rate in milliHertz to OpenSLES. |
| 38 format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000); | 38 format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000); |
| 39 format_.bitsPerSample = params.bits_per_sample(); | 39 format_.bitsPerSample = params.bits_per_sample(); |
| 40 format_.containerSize = params.bits_per_sample(); | 40 format_.containerSize = params.bits_per_sample(); |
| 41 format_.endianness = SL_BYTEORDER_LITTLEENDIAN; | 41 format_.endianness = SL_BYTEORDER_LITTLEENDIAN; |
| 42 format_.channelMask = ChannelCountToSLESChannelMask(params.channels()); | 42 format_.channelMask = ChannelCountToSLESChannelMask(params.channels()); |
| 43 | 43 |
| 44 buffer_size_bytes_ = params.GetBytesPerBuffer(); | 44 buffer_size_bytes_ = params.GetBytesPerBuffer(); |
| 45 hardware_delay_ = base::TimeDelta::FromSecondsD( |
| 46 params.frames_per_buffer() / static_cast<double>(params.sample_rate())); |
| 45 | 47 |
| 46 memset(&audio_data_, 0, sizeof(audio_data_)); | 48 memset(&audio_data_, 0, sizeof(audio_data_)); |
| 47 } | 49 } |
| 48 | 50 |
| 49 OpenSLESInputStream::~OpenSLESInputStream() { | 51 OpenSLESInputStream::~OpenSLESInputStream() { |
| 50 DVLOG(2) << __PRETTY_FUNCTION__; | 52 DVLOG(2) << __PRETTY_FUNCTION__; |
| 51 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 52 DCHECK(!recorder_object_.Get()); | 54 DCHECK(!recorder_object_.Get()); |
| 53 DCHECK(!engine_object_.Get()); | 55 DCHECK(!engine_object_.Get()); |
| 54 DCHECK(!recorder_); | 56 DCHECK(!recorder_); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 301 |
| 300 TRACE_EVENT0("audio", "OpenSLESOutputStream::ReadBufferQueue"); | 302 TRACE_EVENT0("audio", "OpenSLESOutputStream::ReadBufferQueue"); |
| 301 | 303 |
| 302 // Convert from interleaved format to deinterleaved audio bus format. | 304 // Convert from interleaved format to deinterleaved audio bus format. |
| 303 audio_bus_->FromInterleaved(audio_data_[active_buffer_index_], | 305 audio_bus_->FromInterleaved(audio_data_[active_buffer_index_], |
| 304 audio_bus_->frames(), | 306 audio_bus_->frames(), |
| 305 format_.bitsPerSample / 8); | 307 format_.bitsPerSample / 8); |
| 306 | 308 |
| 307 // TODO(henrika): Investigate if it is possible to get an accurate | 309 // TODO(henrika): Investigate if it is possible to get an accurate |
| 308 // delay estimation. | 310 // delay estimation. |
| 309 callback_->OnData(this, audio_bus_.get(), buffer_size_bytes_, 0.0); | 311 callback_->OnData(this, audio_bus_.get(), hardware_delay_, |
| 312 base::TimeTicks::Now(), 0.0); |
| 310 | 313 |
| 311 // Done with this buffer. Send it to device for recording. | 314 // Done with this buffer. Send it to device for recording. |
| 312 SLresult err = | 315 SLresult err = |
| 313 (*simple_buffer_queue_)->Enqueue(simple_buffer_queue_, | 316 (*simple_buffer_queue_)->Enqueue(simple_buffer_queue_, |
| 314 audio_data_[active_buffer_index_], | 317 audio_data_[active_buffer_index_], |
| 315 buffer_size_bytes_); | 318 buffer_size_bytes_); |
| 316 if (SL_RESULT_SUCCESS != err) | 319 if (SL_RESULT_SUCCESS != err) |
| 317 HandleError(err); | 320 HandleError(err); |
| 318 | 321 |
| 319 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue; | 322 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 337 } | 340 } |
| 338 } | 341 } |
| 339 | 342 |
| 340 void OpenSLESInputStream::HandleError(SLresult error) { | 343 void OpenSLESInputStream::HandleError(SLresult error) { |
| 341 DLOG(ERROR) << "OpenSLES Input error " << error; | 344 DLOG(ERROR) << "OpenSLES Input error " << error; |
| 342 if (callback_) | 345 if (callback_) |
| 343 callback_->OnError(this); | 346 callback_->OnError(this); |
| 344 } | 347 } |
| 345 | 348 |
| 346 } // namespace media | 349 } // namespace media |
| OLD | NEW |