Android: create and destroy OpenSL ES engine

This commit is contained in:
Michael Maltese 2016-10-30 16:00:36 -07:00
parent e75329f585
commit 852403f405
2 changed files with 22 additions and 0 deletions

View file

@ -14,6 +14,8 @@ static void destroy_android(struct SoundIoPrivate *si) {
if (sia->cond)
soundio_os_cond_destroy(sia->cond);
if (sia->engineObject)
(*sia->engineObject)->Destroy(sia->engineObject);
}
static void flush_events_android(struct SoundIoPrivate *si) {
@ -44,6 +46,21 @@ enum SoundIoError soundio_android_init(struct SoundIoPrivate *si) {
struct SoundIo *soundio = &si->pub;
struct SoundIoAndroid *sia = &si->backend_data.android;
if (slCreateEngine(&sia->engineObject, 0, NULL, 0, NULL, NULL) != SL_RESULT_SUCCESS)
return SoundIoErrorInitAudioBackend;
if ((*sia->engineObject)->Realize(sia->engineObject, SL_BOOLEAN_FALSE) != SL_RESULT_SUCCESS)
{
destroy_android(si);
return SoundIoErrorInitAudioBackend;
}
if ((*sia->engineObject)->GetInterface(sia->engineObject, SL_IID_ENGINE, &sia->engineEngine) != SL_RESULT_SUCCESS)
{
destroy_android(si);
return SoundIoErrorInitAudioBackend;
}
sia->cond = soundio_os_cond_create();
if (!sia->cond) {
destroy_android(si);

View file

@ -8,6 +8,8 @@
#ifndef SOUNDIO_ANDROID_H
#define SOUNDIO_ANDROID_H
#include <SLES/OpenSLES.h>
#include "os.h"
#include "soundio_internal.h"
@ -17,6 +19,9 @@ enum SoundIoError soundio_android_init(struct SoundIoPrivate *si);
struct SoundIoAndroid {
struct SoundIoOsCond *cond;
bool devices_emitted;
SLObjectItf engineObject;
SLEngineItf engineEngine;
};
#endif