Updated priority concept has been implemented.
[platform/core/api/sound-pool.git] / src / stream.c
index aace90f..eefe07f 100644 (file)
@@ -247,6 +247,8 @@ sound_pool_error_e _sound_stream_destroy(sound_stream_t *stream)
                        alSourcei(stream->al_source, AL_BUFFER, 0);
                        alDeleteSources(1, &stream->al_source);
                        SP_DEBUG("Deleting OpenAL source with id [%u]", stream->al_source);
+                       if (alGetError() != AL_NO_ERROR)
+                               SP_ERROR("OpenAL error while stream[%d] destroying.", stream->id);
                } else {
                        SP_DEBUG("Can't set current context for deleting OpenAL source with id [%u]",
                                        stream->al_source);
@@ -265,6 +267,7 @@ sound_pool_error_e _sound_stream_play(sound_stream_t *stream)
        SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
        sound_pool_t *pool = stream->parent_source->parent_pool;
+       sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_SUSPENDED &&
                        stream->state != SOUND_POOL_STREAM_STATE_PAUSED &&
@@ -283,17 +286,16 @@ sound_pool_error_e _sound_stream_play(sound_stream_t *stream)
                        stream->state == SOUND_POOL_STREAM_STATE_NONE) {
                stream->state_previous = stream->state;
                stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
-               if (_stream_cb_manager_register_event(pool->cbmgr, stream) !=
-                               SOUND_POOL_ERROR_NONE)
-                       SP_DEBUG("State changing event wasn't registered."
-                                       "Callbacks will be not called");
-               SP_DEBUG("Don't play due to SoundPool is in inactive state.");
+               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);
        }
 
        SP_DEBUG_FLEAVE();
-       return SOUND_POOL_ERROR_NONE;
+       return ret;
 }
 
 sound_pool_error_e _sound_stream_pause(sound_stream_t *stream)
@@ -302,6 +304,7 @@ sound_pool_error_e _sound_stream_pause(sound_stream_t *stream)
        SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
        sound_pool_t *pool = stream->parent_source->parent_pool;
+       sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_SUSPENDED &&
                        stream->state != SOUND_POOL_STREAM_STATE_PLAYING,
@@ -315,17 +318,16 @@ sound_pool_error_e _sound_stream_pause(sound_stream_t *stream)
                        stream->state == SOUND_POOL_STREAM_STATE_SUSPENDED) {
                stream->state_previous = stream->state;
                stream->state = SOUND_POOL_STREAM_STATE_PAUSED;
-               if (_stream_cb_manager_register_event(pool->cbmgr, stream) !=
-                               SOUND_POOL_ERROR_NONE)
-                       SP_DEBUG("State changing event wasn't registered."
-                                       "Callbacks will be not called");
-               SP_DEBUG("Don't paused due to SoundPool is in inactive state.");
+               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 paused due to SoundPool is in inactive state.");
        } else {
                alSourcePause(stream->al_source);
        }
 
        SP_DEBUG_FLEAVE();
-       return SOUND_POOL_ERROR_NONE;
+       return ret;
 }
 
 sound_pool_error_e _sound_stream_resume(sound_stream_t *stream)
@@ -334,6 +336,7 @@ sound_pool_error_e _sound_stream_resume(sound_stream_t *stream)
        SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
        sound_pool_t *pool = stream->parent_source->parent_pool;
+       sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_PAUSED,
                        SOUND_POOL_ERROR_INVALID_OPERATION, "Can't resume stream in [%s] "
@@ -347,17 +350,16 @@ sound_pool_error_e _sound_stream_resume(sound_stream_t *stream)
        {
                stream->state_previous = stream->state;
                stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
-               if (_stream_cb_manager_register_event(pool->cbmgr, stream) !=
-                               SOUND_POOL_ERROR_NONE)
-                       SP_DEBUG("State changing event wasn't registered."
-                                       "Callbacks will be not called");
-               SP_DEBUG("Don't resumed due to SoundPool is in inactive state.");
+               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 resumed due to SoundPool is in inactive state.");
        } else {
                alSourcePlay(stream->al_source);
        }
 
        SP_DEBUG_FLEAVE();
-       return SOUND_POOL_ERROR_NONE;
+       return ret;
 }
 
 sound_pool_error_e _sound_stream_stop(sound_stream_t *stream)
@@ -462,19 +464,19 @@ sound_pool_error_e _sound_stream_set_priority(sound_stream_t *stream,
        SP_DEBUG_FENTER();
        SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(stream->parent_source->parent_pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
-       SP_INST_CHECK(stream->parent_source->parent_pool->mgr_priority, SOUND_POOL_ERROR_INVALID_PARAMETER);
+       SP_INST_CHECK(stream->parent_source->parent_pool->mgr_priority,
+                       SOUND_POOL_ERROR_INVALID_PARAMETER);
+       sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
 
        stream->priority = rank;
        if (stream->parent_source->parent_pool->state == SOUND_POOL_STATE_INACTIVE) {
                if (stream->state == SOUND_POOL_STREAM_STATE_NONE) {
                        stream->state_previous = stream->state;
                        stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
-                       if (_stream_cb_manager_register_event(
-                                       stream->parent_source->parent_pool->cbmgr, stream)
-                                       != SOUND_POOL_ERROR_NONE)
-                               SP_DEBUG(
-                                               "State changing event wasn't registered." "Callbacks"
-                                               " will be not called");
+                       ret = _stream_cb_manager_register_event(        stream->parent_source->parent_pool->cbmgr,
+                                       stream);
+                       SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "State changing event "
+                                       "wasn't registered. Callbacks will be not called");
                }
                SP_DEBUG("No need to update priority, Sound pool is INACTIVE.");
                return SOUND_POOL_ERROR_NONE;