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

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

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

Powered by Google App Engine
This is Rietveld 408576698