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

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

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 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
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | media/audio/audio_device_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_output.h" 5 #include "media/audio/android/opensles_output.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/audio/audio_util.h" 8 #include "media/audio/audio_util.h"
9 #include "media/audio/android/audio_manager_android.h" 9 #include "media/audio/android/audio_manager_android.h"
10 10
(...skipping 17 matching lines...) Expand all
28 format_.containerSize = params.bits_per_sample(); 28 format_.containerSize = params.bits_per_sample();
29 format_.endianness = SL_BYTEORDER_LITTLEENDIAN; 29 format_.endianness = SL_BYTEORDER_LITTLEENDIAN;
30 if (format_.numChannels == 1) 30 if (format_.numChannels == 1)
31 format_.channelMask = SL_SPEAKER_FRONT_CENTER; 31 format_.channelMask = SL_SPEAKER_FRONT_CENTER;
32 else if (format_.numChannels == 2) 32 else if (format_.numChannels == 2)
33 format_.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; 33 format_.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
34 else 34 else
35 NOTREACHED() << "Unsupported number of channels: " << format_.numChannels; 35 NOTREACHED() << "Unsupported number of channels: " << format_.numChannels;
36 36
37 buffer_size_bytes_ = params.GetBytesPerBuffer(); 37 buffer_size_bytes_ = params.GetBytesPerBuffer();
38 audio_bus_ = AudioBus::Create(params);
38 39
39 memset(&audio_data_, 0, sizeof(audio_data_)); 40 memset(&audio_data_, 0, sizeof(audio_data_));
40 } 41 }
41 42
42 OpenSLESOutputStream::~OpenSLESOutputStream() { 43 OpenSLESOutputStream::~OpenSLESOutputStream() {
43 DCHECK(!engine_object_.Get()); 44 DCHECK(!engine_object_.Get());
44 DCHECK(!player_object_.Get()); 45 DCHECK(!player_object_.Get());
45 DCHECK(!output_mixer_.Get()); 46 DCHECK(!output_mixer_.Get());
46 DCHECK(!player_); 47 DCHECK(!player_);
47 DCHECK(!simple_buffer_queue_); 48 DCHECK(!simple_buffer_queue_);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 stream->FillBufferQueue(); 251 stream->FillBufferQueue();
251 } 252 }
252 253
253 void OpenSLESOutputStream::FillBufferQueue() { 254 void OpenSLESOutputStream::FillBufferQueue() {
254 if (!started_) 255 if (!started_)
255 return; 256 return;
256 257
257 // Read data from the registered client source. 258 // Read data from the registered client source.
258 // TODO(xians): Get an accurate delay estimation. 259 // TODO(xians): Get an accurate delay estimation.
259 uint32 hardware_delay = buffer_size_bytes_; 260 uint32 hardware_delay = buffer_size_bytes_;
260 size_t num_filled_bytes = callback_->OnMoreData( 261 int frames_filled = callback_->OnMoreData(
261 audio_data_[active_queue_], 262 audio_bus_.get(), AudioBuffersState(0, hardware_delay));
262 buffer_size_bytes_, 263 int num_filled_bytes =
263 AudioBuffersState(0, hardware_delay)); 264 frames_filled * audio_bus_->channels() * format_.bitsPerSample / 8;
264 DCHECK(num_filled_bytes <= buffer_size_bytes_); 265 DCHECK_LE(static_cast<size_t>(num_filled_bytes), buffer_size_bytes_);
266 // Note: If this ever changes to output raw float the data must be clipped and
267 // sanitized since it may come from an untrusted source such as NaCl.
268 audio_bus_->ToInterleaved(
269 frames_filled, format_.bitsPerSample / 8, audio_data_[active_queue_]);
265 270
266 // Perform in-place, software-volume adjustments. 271 // Perform in-place, software-volume adjustments.
267 media::AdjustVolume(audio_data_[active_queue_], 272 media::AdjustVolume(audio_data_[active_queue_],
268 num_filled_bytes, 273 num_filled_bytes,
269 format_.numChannels, 274 format_.numChannels,
270 format_.containerSize >> 3, 275 format_.bitsPerSample / 8,
271 volume_); 276 volume_);
272 277
273 // Enqueue the buffer for playback. 278 // Enqueue the buffer for playback.
274 SLresult err = (*simple_buffer_queue_)->Enqueue( 279 SLresult err = (*simple_buffer_queue_)->Enqueue(
275 simple_buffer_queue_, 280 simple_buffer_queue_,
276 audio_data_[active_queue_], 281 audio_data_[active_queue_],
277 num_filled_bytes); 282 num_filled_bytes);
278 if (SL_RESULT_SUCCESS != err) 283 if (SL_RESULT_SUCCESS != err)
279 HandleError(err); 284 HandleError(err);
280 285
(...skipping 16 matching lines...) Expand all
297 } 302 }
298 } 303 }
299 304
300 void OpenSLESOutputStream::HandleError(SLresult error) { 305 void OpenSLESOutputStream::HandleError(SLresult error) {
301 DLOG(FATAL) << "OpenSLES error " << error; 306 DLOG(FATAL) << "OpenSLES error " << error;
302 if (callback_) 307 if (callback_)
303 callback_->OnError(this, error); 308 callback_->OnError(this, error);
304 } 309 }
305 310
306 } // namespace media 311 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | media/audio/audio_device_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698