OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_device/android/opensles_player.h" | 11 #include "webrtc/modules/audio_device/android/opensles_player.h" |
12 | 12 |
13 #include <android/log.h> | 13 #include <android/log.h> |
14 | 14 |
15 #include "webrtc/base/arraysize.h" | 15 #include "webrtc/base/arraysize.h" |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/format_macros.h" | 17 #include "webrtc/base/format_macros.h" |
18 #include "webrtc/modules/audio_device/android/audio_manager.h" | 18 #include "webrtc/modules/audio_device/android/audio_manager.h" |
19 #include "webrtc/modules/audio_device/android/fine_audio_buffer.h" | 19 #include "webrtc/modules/audio_device/fine_audio_buffer.h" |
20 | 20 |
21 #define TAG "OpenSLESPlayer" | 21 #define TAG "OpenSLESPlayer" |
22 #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) | 22 #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__) |
23 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) | 23 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) |
24 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) | 24 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) |
25 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) | 25 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) |
26 #define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) | 26 #define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) |
27 | 27 |
28 #define RETURN_ON_ERROR(op, ...) \ | 28 #define RETURN_ON_ERROR(op, ...) \ |
29 do { \ | 29 do { \ |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 bytes_per_buffer_ = audio_parameters_.GetBytesPerBuffer(); | 235 bytes_per_buffer_ = audio_parameters_.GetBytesPerBuffer(); |
236 ALOGD("native buffer size: %" PRIuS, bytes_per_buffer_); | 236 ALOGD("native buffer size: %" PRIuS, bytes_per_buffer_); |
237 // Create a modified audio buffer class which allows us to ask for any number | 237 // Create a modified audio buffer class which allows us to ask for any number |
238 // of samples (and not only multiple of 10ms) to match the native OpenSL ES | 238 // of samples (and not only multiple of 10ms) to match the native OpenSL ES |
239 // buffer size. | 239 // buffer size. |
240 fine_buffer_.reset(new FineAudioBuffer(audio_device_buffer_, | 240 fine_buffer_.reset(new FineAudioBuffer(audio_device_buffer_, |
241 bytes_per_buffer_, | 241 bytes_per_buffer_, |
242 audio_parameters_.sample_rate())); | 242 audio_parameters_.sample_rate())); |
243 // Each buffer must be of this size to avoid unnecessary memcpy while caching | 243 // Each buffer must be of this size to avoid unnecessary memcpy while caching |
244 // data between successive callbacks. | 244 // data between successive callbacks. |
245 const size_t required_buffer_size = fine_buffer_->RequiredBufferSizeBytes(); | 245 const size_t required_buffer_size = |
| 246 fine_buffer_->RequiredPlayoutBufferSizeBytes(); |
246 ALOGD("required buffer size: %" PRIuS, required_buffer_size); | 247 ALOGD("required buffer size: %" PRIuS, required_buffer_size); |
247 for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) { | 248 for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) { |
248 audio_buffers_[i].reset(new SLint8[required_buffer_size]); | 249 audio_buffers_[i].reset(new SLint8[required_buffer_size]); |
249 } | 250 } |
250 } | 251 } |
251 | 252 |
252 bool OpenSLESPlayer::CreateEngine() { | 253 bool OpenSLESPlayer::CreateEngine() { |
253 ALOGD("CreateEngine"); | 254 ALOGD("CreateEngine"); |
254 DCHECK(thread_checker_.CalledOnValidThread()); | 255 DCHECK(thread_checker_.CalledOnValidThread()); |
255 if (engine_object_.Get()) | 256 if (engine_object_.Get()) |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 return; | 414 return; |
414 } | 415 } |
415 EnqueuePlayoutData(); | 416 EnqueuePlayoutData(); |
416 } | 417 } |
417 | 418 |
418 void OpenSLESPlayer::EnqueuePlayoutData() { | 419 void OpenSLESPlayer::EnqueuePlayoutData() { |
419 // Read audio data from the WebRTC source using the FineAudioBuffer object | 420 // Read audio data from the WebRTC source using the FineAudioBuffer object |
420 // to adjust for differences in buffer size between WebRTC (10ms) and native | 421 // to adjust for differences in buffer size between WebRTC (10ms) and native |
421 // OpenSL ES. | 422 // OpenSL ES. |
422 SLint8* audio_ptr = audio_buffers_[buffer_index_].get(); | 423 SLint8* audio_ptr = audio_buffers_[buffer_index_].get(); |
423 fine_buffer_->GetBufferData(audio_ptr); | 424 fine_buffer_->GetPlayoutData(audio_ptr); |
424 // Enqueue the decoded audio buffer for playback. | 425 // Enqueue the decoded audio buffer for playback. |
425 SLresult err = | 426 SLresult err = |
426 (*simple_buffer_queue_) | 427 (*simple_buffer_queue_) |
427 ->Enqueue(simple_buffer_queue_, audio_ptr, bytes_per_buffer_); | 428 ->Enqueue(simple_buffer_queue_, audio_ptr, bytes_per_buffer_); |
428 if (SL_RESULT_SUCCESS != err) { | 429 if (SL_RESULT_SUCCESS != err) { |
429 ALOGE("Enqueue failed: %d", err); | 430 ALOGE("Enqueue failed: %d", err); |
430 } | 431 } |
431 buffer_index_ = (buffer_index_ + 1) % kNumOfOpenSLESBuffers; | 432 buffer_index_ = (buffer_index_ + 1) % kNumOfOpenSLESBuffers; |
432 } | 433 } |
433 | 434 |
434 SLuint32 OpenSLESPlayer::GetPlayState() const { | 435 SLuint32 OpenSLESPlayer::GetPlayState() const { |
435 DCHECK(player_); | 436 DCHECK(player_); |
436 SLuint32 state; | 437 SLuint32 state; |
437 SLresult err = (*player_)->GetPlayState(player_, &state); | 438 SLresult err = (*player_)->GetPlayState(player_, &state); |
438 if (SL_RESULT_SUCCESS != err) { | 439 if (SL_RESULT_SUCCESS != err) { |
439 ALOGE("GetPlayState failed: %d", err); | 440 ALOGE("GetPlayState failed: %d", err); |
440 } | 441 } |
441 return state; | 442 return state; |
442 } | 443 } |
443 | 444 |
444 } // namespace webrtc | 445 } // namespace webrtc |
OLD | NEW |