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_output.h" | 5 #include "media/audio/android/opensles_output.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "media/audio/android/audio_manager_android.h" | 9 #include "media/audio/android/audio_manager_android.h" |
10 | 10 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 323 } |
324 | 324 |
325 void OpenSLESOutputStream::FillBufferQueueNoLock() { | 325 void OpenSLESOutputStream::FillBufferQueueNoLock() { |
326 // Ensure that the calling thread has acquired the lock since it is not | 326 // Ensure that the calling thread has acquired the lock since it is not |
327 // done in this method. | 327 // done in this method. |
328 lock_.AssertAcquired(); | 328 lock_.AssertAcquired(); |
329 | 329 |
330 // Read data from the registered client source. | 330 // Read data from the registered client source. |
331 // TODO(henrika): Investigate if it is possible to get a more accurate | 331 // TODO(henrika): Investigate if it is possible to get a more accurate |
332 // delay estimation. | 332 // delay estimation. |
333 const uint32 hardware_delay = buffer_size_bytes_; | 333 const uint32_t hardware_delay = buffer_size_bytes_; |
334 int frames_filled = | 334 int frames_filled = |
335 callback_->OnMoreData(audio_bus_.get(), hardware_delay, 0); | 335 callback_->OnMoreData(audio_bus_.get(), hardware_delay, 0); |
336 if (frames_filled <= 0) { | 336 if (frames_filled <= 0) { |
337 // Audio source is shutting down, or halted on error. | 337 // Audio source is shutting down, or halted on error. |
338 return; | 338 return; |
339 } | 339 } |
340 | 340 |
341 // Note: If the internal representation ever changes from 16-bit PCM to | 341 // Note: If the internal representation ever changes from 16-bit PCM to |
342 // raw float, the data must be clipped and sanitized since it may come | 342 // raw float, the data must be clipped and sanitized since it may come |
343 // from an untrusted source such as NaCl. | 343 // from an untrusted source such as NaCl. |
(...skipping 14 matching lines...) Expand all Loading... |
358 if (SL_RESULT_SUCCESS != err) | 358 if (SL_RESULT_SUCCESS != err) |
359 HandleError(err); | 359 HandleError(err); |
360 | 360 |
361 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue; | 361 active_buffer_index_ = (active_buffer_index_ + 1) % kMaxNumOfBuffersInQueue; |
362 } | 362 } |
363 | 363 |
364 void OpenSLESOutputStream::SetupAudioBuffer() { | 364 void OpenSLESOutputStream::SetupAudioBuffer() { |
365 DCHECK(thread_checker_.CalledOnValidThread()); | 365 DCHECK(thread_checker_.CalledOnValidThread()); |
366 DCHECK(!audio_data_[0]); | 366 DCHECK(!audio_data_[0]); |
367 for (int i = 0; i < kMaxNumOfBuffersInQueue; ++i) { | 367 for (int i = 0; i < kMaxNumOfBuffersInQueue; ++i) { |
368 audio_data_[i] = new uint8[buffer_size_bytes_]; | 368 audio_data_[i] = new uint8_t[buffer_size_bytes_]; |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 void OpenSLESOutputStream::ReleaseAudioBuffer() { | 372 void OpenSLESOutputStream::ReleaseAudioBuffer() { |
373 DCHECK(thread_checker_.CalledOnValidThread()); | 373 DCHECK(thread_checker_.CalledOnValidThread()); |
374 if (audio_data_[0]) { | 374 if (audio_data_[0]) { |
375 for (int i = 0; i < kMaxNumOfBuffersInQueue; ++i) { | 375 for (int i = 0; i < kMaxNumOfBuffersInQueue; ++i) { |
376 delete[] audio_data_[i]; | 376 delete[] audio_data_[i]; |
377 audio_data_[i] = NULL; | 377 audio_data_[i] = NULL; |
378 } | 378 } |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 void OpenSLESOutputStream::HandleError(SLresult error) { | 382 void OpenSLESOutputStream::HandleError(SLresult error) { |
383 DLOG(ERROR) << "OpenSLES Output error " << error; | 383 DLOG(ERROR) << "OpenSLES Output error " << error; |
384 if (callback_) | 384 if (callback_) |
385 callback_->OnError(this); | 385 callback_->OnError(this); |
386 } | 386 } |
387 | 387 |
388 } // namespace media | 388 } // namespace media |
OLD | NEW |