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

Side by Side Diff: media/audio/android/opensles_input.cc

Issue 314713002: Modifies AudioInputCallback::OnData and use media::AudioBus instead of plain byte vector (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed SpeechRecognitionBrowserTest Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/audio/android/audio_manager_android.h" 9 #include "media/audio/android/audio_manager_android.h"
10 #include "media/base/audio_bus.h"
10 11
11 #define LOG_ON_FAILURE_AND_RETURN(op, ...) \ 12 #define LOG_ON_FAILURE_AND_RETURN(op, ...) \
12 do { \ 13 do { \
13 SLresult err = (op); \ 14 SLresult err = (op); \
14 if (err != SL_RESULT_SUCCESS) { \ 15 if (err != SL_RESULT_SUCCESS) { \
15 DLOG(ERROR) << #op << " failed: " << err; \ 16 DLOG(ERROR) << #op << " failed: " << err; \
16 return __VA_ARGS__; \ 17 return __VA_ARGS__; \
17 } \ 18 } \
18 } while (0) 19 } while (0)
19 20
20 namespace media { 21 namespace media {
21 22
22 OpenSLESInputStream::OpenSLESInputStream(AudioManagerAndroid* audio_manager, 23 OpenSLESInputStream::OpenSLESInputStream(AudioManagerAndroid* audio_manager,
23 const AudioParameters& params) 24 const AudioParameters& params)
24 : audio_manager_(audio_manager), 25 : audio_manager_(audio_manager),
25 callback_(NULL), 26 callback_(NULL),
26 recorder_(NULL), 27 recorder_(NULL),
27 simple_buffer_queue_(NULL), 28 simple_buffer_queue_(NULL),
28 active_buffer_index_(0), 29 active_buffer_index_(0),
29 buffer_size_bytes_(0), 30 buffer_size_bytes_(0),
30 started_(false) { 31 started_(false),
32 audio_bus_(media::AudioBus::Create(params)) {
31 DVLOG(2) << __PRETTY_FUNCTION__; 33 DVLOG(2) << __PRETTY_FUNCTION__;
32 format_.formatType = SL_DATAFORMAT_PCM; 34 format_.formatType = SL_DATAFORMAT_PCM;
33 format_.numChannels = static_cast<SLuint32>(params.channels()); 35 format_.numChannels = static_cast<SLuint32>(params.channels());
34 // Provides sampling rate in milliHertz to OpenSLES. 36 // Provides sampling rate in milliHertz to OpenSLES.
35 format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000); 37 format_.samplesPerSec = static_cast<SLuint32>(params.sample_rate() * 1000);
36 format_.bitsPerSample = params.bits_per_sample(); 38 format_.bitsPerSample = params.bits_per_sample();
37 format_.containerSize = params.bits_per_sample(); 39 format_.containerSize = params.bits_per_sample();
38 format_.endianness = SL_BYTEORDER_LITTLEENDIAN; 40 format_.endianness = SL_BYTEORDER_LITTLEENDIAN;
39 if (format_.numChannels == 1) 41 if (format_.numChannels == 1)
40 format_.channelMask = SL_SPEAKER_FRONT_CENTER; 42 format_.channelMask = SL_SPEAKER_FRONT_CENTER;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 stream->ReadBufferQueue(); 290 stream->ReadBufferQueue();
289 } 291 }
290 292
291 void OpenSLESInputStream::ReadBufferQueue() { 293 void OpenSLESInputStream::ReadBufferQueue() {
292 base::AutoLock lock(lock_); 294 base::AutoLock lock(lock_);
293 if (!started_) 295 if (!started_)
294 return; 296 return;
295 297
296 TRACE_EVENT0("audio", "OpenSLESOutputStream::ReadBufferQueue"); 298 TRACE_EVENT0("audio", "OpenSLESOutputStream::ReadBufferQueue");
297 299
300 // Convert from interleaved format to deinterleaved audio bus format.
301 audio_bus_->FromInterleaved(audio_data_[active_buffer_index_],
302 audio_bus_->frames(),
303 format_.bitsPerSample / 8);
304
298 // TODO(henrika): Investigate if it is possible to get an accurate 305 // TODO(henrika): Investigate if it is possible to get an accurate
299 // delay estimation. 306 // delay estimation.
300 callback_->OnData(this, 307 callback_->OnData(this, audio_bus_.get(), buffer_size_bytes_, 0.0);
301 audio_data_[active_buffer_index_],
302 buffer_size_bytes_,
303 buffer_size_bytes_,
304 0.0);
305 308
306 // Done with this buffer. Send it to device for recording. 309 // Done with this buffer. Send it to device for recording.
307 SLresult err = 310 SLresult err =
308 (*simple_buffer_queue_)->Enqueue(simple_buffer_queue_, 311 (*simple_buffer_queue_)->Enqueue(simple_buffer_queue_,
309 audio_data_[active_buffer_index_], 312 audio_data_[active_buffer_index_],
310 buffer_size_bytes_); 313 buffer_size_bytes_);
311 if (SL_RESULT_SUCCESS != err) 314 if (SL_RESULT_SUCCESS != err)
312 HandleError(err); 315 HandleError(err);
313 316
314 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue; 317 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue;
(...skipping 17 matching lines...) Expand all
332 } 335 }
333 } 336 }
334 337
335 void OpenSLESInputStream::HandleError(SLresult error) { 338 void OpenSLESInputStream::HandleError(SLresult error) {
336 DLOG(ERROR) << "OpenSLES Input error " << error; 339 DLOG(ERROR) << "OpenSLES Input error " << error;
337 if (callback_) 340 if (callback_)
338 callback_->OnError(this); 341 callback_->OnError(this);
339 } 342 }
340 343
341 } // namespace media 344 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698