sound_pool_t *_pool = (sound_pool_t *)pool;
sound_source_t *_source = NULL;
- sound_pool_error_e ret_destroy = SOUND_POOL_ERROR_NONE;
sound_pool_error_e ret = _sound_pool_get_source_by_tag(_pool, tag, &_source);
SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
"getting sound source [%s] from the sound pool", tag);
sound_stream_t *_stream = NULL;
- ret = _sound_stream_create(_source, &_stream);
+ ret = _sound_stream_create(_source, loop, volume, priority, callback, data,
+ &_stream);
SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
"Error while creating sound source instance.");
- ret = _sound_stream_set_loop(_stream, loop);
- if (ret != SOUND_POOL_ERROR_NONE)
- GOTO_FAIL("Error occurred when setting sound stream loop parameter", cfail);
-
- ret = _sound_stream_set_volume(_stream, volume);
- if (ret != SOUND_POOL_ERROR_NONE)
- GOTO_FAIL("Error occurred when setting sound stream volume " "parameter",
- cfail);
-
- if (callback) {
- ret = _sound_stream_set_callback(_stream, callback, data);
- if (ret != SOUND_POOL_ERROR_NONE)
- GOTO_FAIL("Error occurred when setting sound stream callback", cfail);
- }
-
- ret = _sound_stream_set_priority(_stream, priority);
- if (ret != SOUND_POOL_ERROR_NONE)
- GOTO_FAIL("Error occurred when setting sound stream priority "
- "parameter", cfail);
-
*id = _stream->id;
SP_DEBUG_FLEAVE();
return ret;
-
-cfail:
- ret_destroy = _sound_stream_destroy(_stream);
- SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret_destroy, ret_destroy,
- "Error occurred during removal of uncompleted sound stream.");
- SP_DEBUG_FLEAVE();
- return ret;
}
sound_pool_error_e sound_pool_stream_pause(sound_pool_h pool, unsigned id)
#include "internal/stream_cb_manager.h"
-#define DEFAULT_STREAM_PRIORITY 255U
-#define DEFAULT_STREAM_LOOP 1U
-#define DEFAULT_STREAM_VOLUME 1.0f
-
static const char *__stringify_stream_state(sound_pool_stream_state_e state);
static void __al_source_state_cb(ALuint source, ALenum state, ALvoid *data);
static sound_pool_error_e __sound_pool_add_stream(sound_pool_t *pool, sound_stream_t *stream);
stream->state = SOUND_POOL_STREAM_STATE_PLAYING;
break;
case AL_PAUSED:
- if (pool->state == SOUND_POOL_STATE_INACTIVE)
+ if (pool->state == SOUND_POOL_STATE_INACTIVE) {
stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
- else if (pool->state == SOUND_POOL_STATE_ACTIVE)
- stream->state = SOUND_POOL_STREAM_STATE_PAUSED;
+ } else if (pool->state == SOUND_POOL_STATE_ACTIVE) {
+ if (stream->stopped) { /* Stream stopped due to priority issue */
+ stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
+ stream->stopped = FALSE;
+ } else {
+ stream->state = SOUND_POOL_STREAM_STATE_PAUSED;
+ }
+ }
break;
case AL_STOPPED:
if (stream->stopped)
return SOUND_POOL_ERROR_NONE;
}
-sound_pool_error_e _sound_stream_create(sound_source_t *src,
- sound_stream_t **stream)
+static sound_pool_error_e __sound_stream_init(sound_stream_t *stream,
+ unsigned loop, float volume, unsigned priority,
+ sound_pool_stream_state_change_cb cb, void *data)
+{
+ SP_DEBUG_FENTER();
+ sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
+
+ if (cb) {
+ ret = _sound_stream_set_callback(stream, cb, data);
+ SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
+ "Error occurred when setting sound stream callback");
+ }
+
+ ret = _sound_stream_set_loop(stream, loop);
+ SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
+ "Error occurred when setting sound stream loop parameter");
+
+ ret = _sound_stream_set_volume(stream, volume);
+ SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
+ "Error occurred when setting sound stream volume parameter");
+
+ ret = _sound_stream_set_priority(stream, priority);
+ SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
+ "Error occurred when setting sound stream priority parameter");
+
+ SP_DEBUG_FLEAVE();
+ return ret;
+}
+
+sound_pool_error_e _sound_stream_create(sound_source_t *src, unsigned loop,
+ float volume, unsigned priority, sound_pool_stream_state_change_cb cb,
+ void *data, sound_stream_t **stream)
{
SP_DEBUG_FENTER();
SP_RETVM_IF(!src, SOUND_POOL_ERROR_INVALID_PARAMETER,
SP_RETVM_IF(!alcMakeContextCurrent(src->parent_pool->al_context),
SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
+ sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
sound_stream_t *_stream = NULL;
SP_RETVM_IF(!(_stream = g_try_malloc0(sizeof(*_stream))),
SOUND_POOL_ERROR_OUT_OF_MEMORY,
"Memory alloc failure. Can't create sound stream");
_stream->parent_source = src;
- _stream->priority = DEFAULT_STREAM_PRIORITY;
- _stream->loop = DEFAULT_STREAM_LOOP;
- _stream->volume = DEFAULT_STREAM_VOLUME;
_stream->state_previous = SOUND_POOL_STREAM_STATE_NONE;
_stream->state = SOUND_POOL_STREAM_STATE_NONE;
_stream->stopped = FALSE;
- _stream->state_cb_info.callback = NULL;
- _stream->state_cb_info.user_data = NULL;
- sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
alGenSources((ALsizei)1, &_stream->al_source);
if (alGetError() != AL_NO_ERROR) {
ret = SOUND_POOL_ERROR_OUT_OF_MEMORY;
"Data to OpenAL Source", cfail);
}
+ ret = __sound_stream_init(_stream, loop, volume, priority, cb, data);
+ if (ret != SOUND_POOL_ERROR_NONE)
+ GOTO_FAIL("Sound stream initialization error occurred", cfail);
+
ret = __sound_pool_add_stream(src->parent_pool, _stream);
if (ret != SOUND_POOL_ERROR_NONE)
GOTO_FAIL("Error occurred when trying to add source to pool", cfail);
return ret;
cfail:
- _sound_stream_destroy(_stream);
+ if (SOUND_POOL_ERROR_NONE == _sound_stream_destroy(_stream))
+ _stream = NULL;
+
+ SP_SAFE_GFREE(_stream);
+
SP_DEBUG_FLEAVE();
return ret;
}
SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
- if (pool->state == SOUND_POOL_STATE_INACTIVE &&
- stream->state == SOUND_POOL_STREAM_STATE_NONE) {
- stream->state_previous = stream->state;
- stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
- ret = _stream_cb_manager_register_event(pool->cbmgr, stream);
- SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "State changing event "
- "wasn't registered. Callbacks will be not called");
- SP_INFO("Don't play due to SoundPool is in inactive state.");
- } else {
- alSourcePlay(stream->al_source);
- }
+ alSourcePlay(stream->al_source);
+ SP_RETVM_IF(alGetError() != AL_NO_ERROR, SOUND_POOL_ERROR_INVALID_OPERATION,
+ "OpenAL error occurred when trying to play OpenAL Source");
SP_DEBUG_FLEAVE();
return ret;