blob: 3a40bf477992698795e58cbd3957b87b3fa5a41c [file] [log] [blame]
henrikab2619892015-05-18 16:49:16 +02001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/audio_device/android/opensles_player.h"
12
13#include <android/log.h>
14
kwiberg529662a2017-09-04 05:43:17 -070015#include "webrtc/api/array_view.h"
henrika521f7a82016-05-31 07:03:17 -070016#include "webrtc/modules/audio_device/android/audio_common.h"
henrikab2619892015-05-18 16:49:16 +020017#include "webrtc/modules/audio_device/android/audio_manager.h"
henrika86d907c2015-09-07 16:09:50 +020018#include "webrtc/modules/audio_device/fine_audio_buffer.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020019#include "webrtc/rtc_base/arraysize.h"
20#include "webrtc/rtc_base/checks.h"
21#include "webrtc/rtc_base/format_macros.h"
22#include "webrtc/rtc_base/timeutils.h"
henrikab2619892015-05-18 16:49:16 +020023
24#define TAG "OpenSLESPlayer"
25#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
26#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
27#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
28#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
29#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
30
henrika521f7a82016-05-31 07:03:17 -070031#define RETURN_ON_ERROR(op, ...) \
32 do { \
33 SLresult err = (op); \
34 if (err != SL_RESULT_SUCCESS) { \
35 ALOGE("%s failed: %s", #op, GetSLErrorString(err)); \
36 return __VA_ARGS__; \
37 } \
henrikab2619892015-05-18 16:49:16 +020038 } while (0)
39
40namespace webrtc {
41
42OpenSLESPlayer::OpenSLESPlayer(AudioManager* audio_manager)
henrika521f7a82016-05-31 07:03:17 -070043 : audio_manager_(audio_manager),
44 audio_parameters_(audio_manager->GetPlayoutAudioParameters()),
45 audio_device_buffer_(nullptr),
henrikab2619892015-05-18 16:49:16 +020046 initialized_(false),
47 playing_(false),
henrikab2619892015-05-18 16:49:16 +020048 buffer_index_(0),
49 engine_(nullptr),
50 player_(nullptr),
51 simple_buffer_queue_(nullptr),
henrikae71b24e2015-11-12 01:48:32 -080052 volume_(nullptr),
53 last_play_time_(0) {
henrikab2619892015-05-18 16:49:16 +020054 ALOGD("ctor%s", GetThreadInfo().c_str());
55 // Use native audio output parameters provided by the audio manager and
56 // define the PCM format structure.
57 pcm_format_ = CreatePCMConfiguration(audio_parameters_.channels(),
58 audio_parameters_.sample_rate(),
59 audio_parameters_.bits_per_sample());
60 // Detach from this thread since we want to use the checker to verify calls
61 // from the internal audio thread.
62 thread_checker_opensles_.DetachFromThread();
63}
64
65OpenSLESPlayer::~OpenSLESPlayer() {
66 ALOGD("dtor%s", GetThreadInfo().c_str());
henrikg91d6ede2015-09-17 00:24:34 -070067 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +020068 Terminate();
69 DestroyAudioPlayer();
70 DestroyMix();
henrika521f7a82016-05-31 07:03:17 -070071 engine_ = nullptr;
henrikg91d6ede2015-09-17 00:24:34 -070072 RTC_DCHECK(!engine_);
73 RTC_DCHECK(!output_mix_.Get());
74 RTC_DCHECK(!player_);
75 RTC_DCHECK(!simple_buffer_queue_);
76 RTC_DCHECK(!volume_);
henrikab2619892015-05-18 16:49:16 +020077}
78
79int OpenSLESPlayer::Init() {
80 ALOGD("Init%s", GetThreadInfo().c_str());
henrikg91d6ede2015-09-17 00:24:34 -070081 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrika76535de2017-09-11 01:25:55 -070082 if (audio_parameters_.channels() == 2) {
83 // TODO(henrika): FineAudioBuffer needs more work to support stereo.
84 ALOGE("OpenSLESPlayer does not support stereo");
85 return -1;
86 }
henrikab2619892015-05-18 16:49:16 +020087 return 0;
88}
89
90int OpenSLESPlayer::Terminate() {
91 ALOGD("Terminate%s", GetThreadInfo().c_str());
henrikg91d6ede2015-09-17 00:24:34 -070092 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +020093 StopPlayout();
94 return 0;
95}
96
97int OpenSLESPlayer::InitPlayout() {
98 ALOGD("InitPlayout%s", GetThreadInfo().c_str());
henrikg91d6ede2015-09-17 00:24:34 -070099 RTC_DCHECK(thread_checker_.CalledOnValidThread());
100 RTC_DCHECK(!initialized_);
101 RTC_DCHECK(!playing_);
henrika918b5542016-09-19 15:44:09 +0200102 if (!ObtainEngineInterface()) {
103 ALOGE("Failed to obtain SL Engine interface");
104 return -1;
105 }
henrikab2619892015-05-18 16:49:16 +0200106 CreateMix();
107 initialized_ = true;
108 buffer_index_ = 0;
109 return 0;
110}
111
112int OpenSLESPlayer::StartPlayout() {
113 ALOGD("StartPlayout%s", GetThreadInfo().c_str());
henrikg91d6ede2015-09-17 00:24:34 -0700114 RTC_DCHECK(thread_checker_.CalledOnValidThread());
115 RTC_DCHECK(initialized_);
116 RTC_DCHECK(!playing_);
henrika918b5542016-09-19 15:44:09 +0200117 if (fine_audio_buffer_) {
118 fine_audio_buffer_->ResetPlayout();
119 }
henrikab2619892015-05-18 16:49:16 +0200120 // The number of lower latency audio players is limited, hence we create the
121 // audio player in Start() and destroy it in Stop().
122 CreateAudioPlayer();
123 // Fill up audio buffers to avoid initial glitch and to ensure that playback
124 // starts when mode is later changed to SL_PLAYSTATE_PLAYING.
125 // TODO(henrika): we can save some delay by only making one call to
126 // EnqueuePlayoutData. Most likely not worth the risk of adding a glitch.
henrika918b5542016-09-19 15:44:09 +0200127 last_play_time_ = rtc::Time();
henrikab2619892015-05-18 16:49:16 +0200128 for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) {
henrika14acf652016-10-11 06:15:41 -0700129 EnqueuePlayoutData(true);
henrikab2619892015-05-18 16:49:16 +0200130 }
131 // Start streaming data by setting the play state to SL_PLAYSTATE_PLAYING.
132 // For a player object, when the object is in the SL_PLAYSTATE_PLAYING
133 // state, adding buffers will implicitly start playback.
134 RETURN_ON_ERROR((*player_)->SetPlayState(player_, SL_PLAYSTATE_PLAYING), -1);
135 playing_ = (GetPlayState() == SL_PLAYSTATE_PLAYING);
henrikg91d6ede2015-09-17 00:24:34 -0700136 RTC_DCHECK(playing_);
henrikab2619892015-05-18 16:49:16 +0200137 return 0;
138}
139
140int OpenSLESPlayer::StopPlayout() {
141 ALOGD("StopPlayout%s", GetThreadInfo().c_str());
henrikg91d6ede2015-09-17 00:24:34 -0700142 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +0200143 if (!initialized_ || !playing_) {
144 return 0;
145 }
146 // Stop playing by setting the play state to SL_PLAYSTATE_STOPPED.
147 RETURN_ON_ERROR((*player_)->SetPlayState(player_, SL_PLAYSTATE_STOPPED), -1);
148 // Clear the buffer queue to flush out any remaining data.
149 RETURN_ON_ERROR((*simple_buffer_queue_)->Clear(simple_buffer_queue_), -1);
kwiberg5377bc72016-10-04 13:46:56 -0700150#if RTC_DCHECK_IS_ON
henrikab2619892015-05-18 16:49:16 +0200151 // Verify that the buffer queue is in fact cleared as it should.
152 SLAndroidSimpleBufferQueueState buffer_queue_state;
153 (*simple_buffer_queue_)->GetState(simple_buffer_queue_, &buffer_queue_state);
kwibergaf476c72016-11-28 15:21:39 -0800154 RTC_DCHECK_EQ(0, buffer_queue_state.count);
155 RTC_DCHECK_EQ(0, buffer_queue_state.index);
henrikab2619892015-05-18 16:49:16 +0200156#endif
157 // The number of lower latency audio players is limited, hence we create the
158 // audio player in Start() and destroy it in Stop().
159 DestroyAudioPlayer();
160 thread_checker_opensles_.DetachFromThread();
161 initialized_ = false;
162 playing_ = false;
163 return 0;
164}
165
166int OpenSLESPlayer::SpeakerVolumeIsAvailable(bool& available) {
167 available = false;
168 return 0;
169}
170
171int OpenSLESPlayer::MaxSpeakerVolume(uint32_t& maxVolume) const {
172 return -1;
173}
174
175int OpenSLESPlayer::MinSpeakerVolume(uint32_t& minVolume) const {
176 return -1;
177}
178
179int OpenSLESPlayer::SetSpeakerVolume(uint32_t volume) {
180 return -1;
181}
182
183int OpenSLESPlayer::SpeakerVolume(uint32_t& volume) const {
184 return -1;
185}
186
187void OpenSLESPlayer::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
188 ALOGD("AttachAudioBuffer");
henrikg91d6ede2015-09-17 00:24:34 -0700189 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +0200190 audio_device_buffer_ = audioBuffer;
191 const int sample_rate_hz = audio_parameters_.sample_rate();
192 ALOGD("SetPlayoutSampleRate(%d)", sample_rate_hz);
193 audio_device_buffer_->SetPlayoutSampleRate(sample_rate_hz);
Peter Kasting69558702016-01-12 16:26:35 -0800194 const size_t channels = audio_parameters_.channels();
195 ALOGD("SetPlayoutChannels(%" PRIuS ")", channels);
henrikab2619892015-05-18 16:49:16 +0200196 audio_device_buffer_->SetPlayoutChannels(channels);
henrikg91d6ede2015-09-17 00:24:34 -0700197 RTC_CHECK(audio_device_buffer_);
henrikab2619892015-05-18 16:49:16 +0200198 AllocateDataBuffers();
199}
200
henrikab2619892015-05-18 16:49:16 +0200201void OpenSLESPlayer::AllocateDataBuffers() {
202 ALOGD("AllocateDataBuffers");
henrikg91d6ede2015-09-17 00:24:34 -0700203 RTC_DCHECK(thread_checker_.CalledOnValidThread());
204 RTC_DCHECK(!simple_buffer_queue_);
205 RTC_CHECK(audio_device_buffer_);
henrikab2619892015-05-18 16:49:16 +0200206 // Create a modified audio buffer class which allows us to ask for any number
207 // of samples (and not only multiple of 10ms) to match the native OpenSL ES
henrika918b5542016-09-19 15:44:09 +0200208 // buffer size. The native buffer size corresponds to the
209 // PROPERTY_OUTPUT_FRAMES_PER_BUFFER property which is the number of audio
210 // frames that the HAL (Hardware Abstraction Layer) buffer can hold. It is
211 // recommended to construct audio buffers so that they contain an exact
212 // multiple of this number. If so, callbacks will occur at regular intervals,
213 // which reduces jitter.
henrikab3ebc1a2017-02-27 05:14:17 -0800214 const size_t buffer_size_in_bytes = audio_parameters_.GetBytesPerBuffer();
215 ALOGD("native buffer size: %" PRIuS, buffer_size_in_bytes);
henrika918b5542016-09-19 15:44:09 +0200216 ALOGD("native buffer size in ms: %.2f",
217 audio_parameters_.GetBufferSizeInMilliseconds());
henrikabb6f7522017-05-30 02:01:30 -0700218 fine_audio_buffer_.reset(new FineAudioBuffer(audio_device_buffer_,
219 audio_parameters_.sample_rate(),
220 2 * buffer_size_in_bytes));
henrikab3ebc1a2017-02-27 05:14:17 -0800221 // Allocated memory for audio buffers.
henrikab2619892015-05-18 16:49:16 +0200222 for (int i = 0; i < kNumOfOpenSLESBuffers; ++i) {
henrikab3ebc1a2017-02-27 05:14:17 -0800223 audio_buffers_[i].reset(new SLint8[buffer_size_in_bytes]);
henrikab2619892015-05-18 16:49:16 +0200224 }
225}
226
henrika521f7a82016-05-31 07:03:17 -0700227bool OpenSLESPlayer::ObtainEngineInterface() {
228 ALOGD("ObtainEngineInterface");
henrikg91d6ede2015-09-17 00:24:34 -0700229 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrika918b5542016-09-19 15:44:09 +0200230 if (engine_)
231 return true;
henrika521f7a82016-05-31 07:03:17 -0700232 // Get access to (or create if not already existing) the global OpenSL Engine
233 // object.
234 SLObjectItf engine_object = audio_manager_->GetOpenSLEngine();
235 if (engine_object == nullptr) {
236 ALOGE("Failed to access the global OpenSL engine");
237 return false;
238 }
239 // Get the SL Engine Interface which is implicit.
henrikab2619892015-05-18 16:49:16 +0200240 RETURN_ON_ERROR(
henrika521f7a82016-05-31 07:03:17 -0700241 (*engine_object)->GetInterface(engine_object, SL_IID_ENGINE, &engine_),
henrikab2619892015-05-18 16:49:16 +0200242 false);
henrikab2619892015-05-18 16:49:16 +0200243 return true;
244}
245
henrikab2619892015-05-18 16:49:16 +0200246bool OpenSLESPlayer::CreateMix() {
247 ALOGD("CreateMix");
henrikg91d6ede2015-09-17 00:24:34 -0700248 RTC_DCHECK(thread_checker_.CalledOnValidThread());
249 RTC_DCHECK(engine_);
henrikab2619892015-05-18 16:49:16 +0200250 if (output_mix_.Get())
251 return true;
252
253 // Create the ouput mix on the engine object. No interfaces will be used.
254 RETURN_ON_ERROR((*engine_)->CreateOutputMix(engine_, output_mix_.Receive(), 0,
henrika521f7a82016-05-31 07:03:17 -0700255 nullptr, nullptr),
henrikab2619892015-05-18 16:49:16 +0200256 false);
257 RETURN_ON_ERROR(output_mix_->Realize(output_mix_.Get(), SL_BOOLEAN_FALSE),
258 false);
259 return true;
260}
261
262void OpenSLESPlayer::DestroyMix() {
263 ALOGD("DestroyMix");
henrikg91d6ede2015-09-17 00:24:34 -0700264 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +0200265 if (!output_mix_.Get())
266 return;
267 output_mix_.Reset();
268}
269
270bool OpenSLESPlayer::CreateAudioPlayer() {
271 ALOGD("CreateAudioPlayer");
henrikg91d6ede2015-09-17 00:24:34 -0700272 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikg91d6ede2015-09-17 00:24:34 -0700273 RTC_DCHECK(output_mix_.Get());
henrikab2619892015-05-18 16:49:16 +0200274 if (player_object_.Get())
275 return true;
henrikg91d6ede2015-09-17 00:24:34 -0700276 RTC_DCHECK(!player_);
277 RTC_DCHECK(!simple_buffer_queue_);
278 RTC_DCHECK(!volume_);
henrikab2619892015-05-18 16:49:16 +0200279
280 // source: Android Simple Buffer Queue Data Locator is source.
281 SLDataLocator_AndroidSimpleBufferQueue simple_buffer_queue = {
282 SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
283 static_cast<SLuint32>(kNumOfOpenSLESBuffers)};
284 SLDataSource audio_source = {&simple_buffer_queue, &pcm_format_};
285
286 // sink: OutputMix-based data is sink.
287 SLDataLocator_OutputMix locator_output_mix = {SL_DATALOCATOR_OUTPUTMIX,
288 output_mix_.Get()};
henrika521f7a82016-05-31 07:03:17 -0700289 SLDataSink audio_sink = {&locator_output_mix, nullptr};
henrikab2619892015-05-18 16:49:16 +0200290
291 // Define interfaces that we indend to use and realize.
292 const SLInterfaceID interface_ids[] = {
293 SL_IID_ANDROIDCONFIGURATION, SL_IID_BUFFERQUEUE, SL_IID_VOLUME};
294 const SLboolean interface_required[] = {
295 SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
296
297 // Create the audio player on the engine interface.
298 RETURN_ON_ERROR(
299 (*engine_)->CreateAudioPlayer(
300 engine_, player_object_.Receive(), &audio_source, &audio_sink,
301 arraysize(interface_ids), interface_ids, interface_required),
302 false);
303
304 // Use the Android configuration interface to set platform-specific
305 // parameters. Should be done before player is realized.
306 SLAndroidConfigurationItf player_config;
307 RETURN_ON_ERROR(
308 player_object_->GetInterface(player_object_.Get(),
309 SL_IID_ANDROIDCONFIGURATION, &player_config),
310 false);
311 // Set audio player configuration to SL_ANDROID_STREAM_VOICE which
312 // corresponds to android.media.AudioManager.STREAM_VOICE_CALL.
henrika1ba936a2015-11-03 04:27:58 -0800313 SLint32 stream_type = SL_ANDROID_STREAM_VOICE;
henrikab2619892015-05-18 16:49:16 +0200314 RETURN_ON_ERROR(
315 (*player_config)
316 ->SetConfiguration(player_config, SL_ANDROID_KEY_STREAM_TYPE,
317 &stream_type, sizeof(SLint32)),
318 false);
319
320 // Realize the audio player object after configuration has been set.
321 RETURN_ON_ERROR(
322 player_object_->Realize(player_object_.Get(), SL_BOOLEAN_FALSE), false);
323
324 // Get the SLPlayItf interface on the audio player.
325 RETURN_ON_ERROR(
326 player_object_->GetInterface(player_object_.Get(), SL_IID_PLAY, &player_),
327 false);
328
329 // Get the SLAndroidSimpleBufferQueueItf interface on the audio player.
330 RETURN_ON_ERROR(
331 player_object_->GetInterface(player_object_.Get(), SL_IID_BUFFERQUEUE,
332 &simple_buffer_queue_),
333 false);
334
335 // Register callback method for the Android Simple Buffer Queue interface.
336 // This method will be called when the native audio layer needs audio data.
337 RETURN_ON_ERROR((*simple_buffer_queue_)
338 ->RegisterCallback(simple_buffer_queue_,
339 SimpleBufferQueueCallback, this),
340 false);
341
342 // Get the SLVolumeItf interface on the audio player.
343 RETURN_ON_ERROR(player_object_->GetInterface(player_object_.Get(),
344 SL_IID_VOLUME, &volume_),
345 false);
346
347 // TODO(henrika): might not be required to set volume to max here since it
348 // seems to be default on most devices. Might be required for unit tests.
349 // RETURN_ON_ERROR((*volume_)->SetVolumeLevel(volume_, 0), false);
350
351 return true;
352}
353
354void OpenSLESPlayer::DestroyAudioPlayer() {
355 ALOGD("DestroyAudioPlayer");
henrikg91d6ede2015-09-17 00:24:34 -0700356 RTC_DCHECK(thread_checker_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +0200357 if (!player_object_.Get())
358 return;
henrika918b5542016-09-19 15:44:09 +0200359 (*simple_buffer_queue_)
360 ->RegisterCallback(simple_buffer_queue_, nullptr, nullptr);
henrikab2619892015-05-18 16:49:16 +0200361 player_object_.Reset();
362 player_ = nullptr;
363 simple_buffer_queue_ = nullptr;
364 volume_ = nullptr;
365}
366
367// static
368void OpenSLESPlayer::SimpleBufferQueueCallback(
369 SLAndroidSimpleBufferQueueItf caller,
370 void* context) {
371 OpenSLESPlayer* stream = reinterpret_cast<OpenSLESPlayer*>(context);
372 stream->FillBufferQueue();
373}
374
375void OpenSLESPlayer::FillBufferQueue() {
henrikg91d6ede2015-09-17 00:24:34 -0700376 RTC_DCHECK(thread_checker_opensles_.CalledOnValidThread());
henrikab2619892015-05-18 16:49:16 +0200377 SLuint32 state = GetPlayState();
378 if (state != SL_PLAYSTATE_PLAYING) {
379 ALOGW("Buffer callback in non-playing state!");
380 return;
381 }
henrika14acf652016-10-11 06:15:41 -0700382 EnqueuePlayoutData(false);
henrikab2619892015-05-18 16:49:16 +0200383}
384
henrika14acf652016-10-11 06:15:41 -0700385void OpenSLESPlayer::EnqueuePlayoutData(bool silence) {
henrikae71b24e2015-11-12 01:48:32 -0800386 // Check delta time between two successive callbacks and provide a warning
387 // if it becomes very large.
henrika918b5542016-09-19 15:44:09 +0200388 // TODO(henrika): using 150ms as upper limit but this value is rather random.
henrikae71b24e2015-11-12 01:48:32 -0800389 const uint32_t current_time = rtc::Time();
390 const uint32_t diff = current_time - last_play_time_;
henrika918b5542016-09-19 15:44:09 +0200391 if (diff > 150) {
henrikae71b24e2015-11-12 01:48:32 -0800392 ALOGW("Bad OpenSL ES playout timing, dT=%u [ms]", diff);
393 }
394 last_play_time_ = current_time;
henrikab2619892015-05-18 16:49:16 +0200395 SLint8* audio_ptr = audio_buffers_[buffer_index_].get();
henrika14acf652016-10-11 06:15:41 -0700396 if (silence) {
397 RTC_DCHECK(thread_checker_.CalledOnValidThread());
398 // Avoid aquiring real audio data from WebRTC and fill the buffer with
399 // zeros instead. Used to prime the buffer with silence and to avoid asking
400 // for audio data from two different threads.
401 memset(audio_ptr, 0, audio_parameters_.GetBytesPerBuffer());
402 } else {
403 RTC_DCHECK(thread_checker_opensles_.CalledOnValidThread());
404 // Read audio data from the WebRTC source using the FineAudioBuffer object
405 // to adjust for differences in buffer size between WebRTC (10ms) and native
406 // OpenSL ES.
henrikabb6f7522017-05-30 02:01:30 -0700407 fine_audio_buffer_->GetPlayoutData(rtc::ArrayView<SLint8>(
408 audio_ptr, audio_parameters_.GetBytesPerBuffer()));
henrika14acf652016-10-11 06:15:41 -0700409 }
henrikab2619892015-05-18 16:49:16 +0200410 // Enqueue the decoded audio buffer for playback.
henrika918b5542016-09-19 15:44:09 +0200411 SLresult err = (*simple_buffer_queue_)
412 ->Enqueue(simple_buffer_queue_, audio_ptr,
413 audio_parameters_.GetBytesPerBuffer());
henrikab2619892015-05-18 16:49:16 +0200414 if (SL_RESULT_SUCCESS != err) {
415 ALOGE("Enqueue failed: %d", err);
416 }
417 buffer_index_ = (buffer_index_ + 1) % kNumOfOpenSLESBuffers;
418}
419
420SLuint32 OpenSLESPlayer::GetPlayState() const {
henrikg91d6ede2015-09-17 00:24:34 -0700421 RTC_DCHECK(player_);
henrikab2619892015-05-18 16:49:16 +0200422 SLuint32 state;
423 SLresult err = (*player_)->GetPlayState(player_, &state);
424 if (SL_RESULT_SUCCESS != err) {
425 ALOGE("GetPlayState failed: %d", err);
426 }
427 return state;
428}
429
430} // namespace webrtc