Fix for SVACE defects
[platform/core/api/sound-pool.git] / src / soundpool.c
index 631a3aa..bbcd013 100644 (file)
@@ -29,7 +29,6 @@
 
 #define DEFAULT_VOLUME_VALUE 1.0f
 
-static ALCdevice *device = NULL;
 static void __stream_activate_iter(gpointer key, gpointer value,
                gpointer user_data);
 static void __stream_deactivate_iter(gpointer key, gpointer value,
@@ -38,7 +37,7 @@ static void __stream_deactivate_iter(gpointer key, gpointer value,
 static void __stream_activate_iter(gpointer key, gpointer value,
                gpointer user_data)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_RETM_IF(!user_data, "Empty user data.");
        SP_RETM_IF(!value, "Empty sound stream data.");
        guint *len = (guint*)user_data;
@@ -59,7 +58,7 @@ static void __stream_activate_iter(gpointer key, gpointer value,
 static void __stream_deactivate_iter(gpointer key, gpointer value,
                gpointer user_data)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_RETM_IF(!user_data, "Empty user data.");
        SP_RETM_IF(!value, "Empty sound stream data.");
        guint *len = (guint*)user_data;
@@ -73,11 +72,10 @@ static void __stream_deactivate_iter(gpointer key, gpointer value,
        SP_DEBUG_FLEAVE();
 }
 
-sound_pool_error_e _sound_pool_create(size_t max_streams, sound_pool_t **pool)
+sound_pool_error_e _sound_pool_create(sound_pool_t **pool)
 {
-       SP_DEBUF_FENTER();
-       SP_RETVM_IF(max_streams == 0, SOUND_POOL_ERROR_INVALID_PARAMETER,
-                       "Max streams count should be greater than 0.");
+       SP_DEBUG_FENTER();
+       SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
 
        sound_pool_t *_pool = NULL;
        SP_RETVM_IF(!(_pool = g_try_malloc0(sizeof(*_pool))),
@@ -86,7 +84,7 @@ sound_pool_error_e _sound_pool_create(size_t max_streams, sound_pool_t **pool)
        SP_RETVM_IF(!pool, SOUND_POOL_ERROR_INVALID_PARAMETER, "Can't create "
                        "sound pool. Pool pointer is NULL");
 
-       int ret = SOUND_POOL_ERROR_NONE;
+       sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
        _pool->al_context = NULL;
        _pool->al_context = alcCreateContext(alcOpenDevice(NULL), NULL);
        if (!_pool->al_context) {
@@ -111,7 +109,6 @@ sound_pool_error_e _sound_pool_create(size_t max_streams, sound_pool_t **pool)
                                "table in sound pool", cfail);
        }
 
-       _pool->max_streams = max_streams;
        _pool->volume = DEFAULT_VOLUME_VALUE;
        _pool->max_stream_index = 0;
        _pool->state = SOUND_POOL_STATE_INACTIVE;
@@ -141,12 +138,12 @@ cfail:
 
 sound_pool_error_e _sound_pool_destroy(sound_pool_t *pool)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        _sound_pool_deactivate(pool);
 
        if (pool->cbmgr) {
-               const int ret = _stream_cb_manager_destroy(pool->cbmgr);
+               sound_pool_error_e ret = _stream_cb_manager_destroy(pool->cbmgr);
                SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
                                "Error occurred when " "trying to destroy sound pool callback manager.");
                pool->cbmgr = NULL;
@@ -173,7 +170,7 @@ sound_pool_error_e _sound_pool_destroy(sound_pool_t *pool)
        }
 
        if (pool->mgr_priority) {
-               const int ret = _sound_stream_priority_destroy(pool->mgr_priority);
+               sound_pool_error_e ret = _sound_stream_priority_destroy(pool->mgr_priority);
                SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
                                "Error occurred when trying to destroy priority manager.");
                pool->mgr_priority = NULL;
@@ -194,7 +191,7 @@ sound_pool_error_e _sound_pool_destroy(sound_pool_t *pool)
 
 sound_pool_error_e _sound_pool_activate(sound_pool_t *pool)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
 
        SP_RETVM_IF(pool->state == SOUND_POOL_STATE_ACTIVE,
@@ -204,8 +201,8 @@ sound_pool_error_e _sound_pool_activate(sound_pool_t *pool)
        sound_pool_state_e old_state = pool->state;
        pool->state = SOUND_POOL_STATE_ACTIVE;
 
-       /* Generate array of all AlSources in pool */
-       GPtrArray *streams = NULL;
+       _sound_stream_priority_update_playback(pool->mgr_priority);
+
        if (g_hash_table_size(pool->streams) > 0) {
                SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
                                SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
@@ -214,9 +211,6 @@ sound_pool_error_e _sound_pool_activate(sound_pool_t *pool)
                SP_INFO("Resuming [%d] number of streams.", len);
        }
 
-       if (streams)
-               g_ptr_array_free(streams, TRUE);
-
        SP_INFO("Sound pool has been activated");
 
        if (pool->state_cb_info.callback)
@@ -229,7 +223,7 @@ sound_pool_error_e _sound_pool_activate(sound_pool_t *pool)
 
 sound_pool_error_e _sound_pool_deactivate(sound_pool_t *pool)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_RETVM_IF(pool->state == SOUND_POOL_STATE_INACTIVE,
                        SOUND_POOL_ERROR_INVALID_OPERATION,
@@ -238,8 +232,6 @@ sound_pool_error_e _sound_pool_deactivate(sound_pool_t *pool)
        sound_pool_state_e old_state = pool->state;
        pool->state = SOUND_POOL_STATE_INACTIVE;
 
-       /* Generate array of all AlSources in pool */
-       GPtrArray *streams = NULL;
        if (g_hash_table_size(pool->streams) > 0) {
                SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
                                SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
@@ -248,9 +240,6 @@ sound_pool_error_e _sound_pool_deactivate(sound_pool_t *pool)
                SP_INFO("Suspending [%d] number of streams.", len);
        }
 
-       if (streams)
-               g_ptr_array_free(streams, TRUE);
-
        SP_INFO("Sound pool has been deactivated");
 
        if (pool->state_cb_info.callback)
@@ -264,7 +253,7 @@ sound_pool_error_e _sound_pool_deactivate(sound_pool_t *pool)
 sound_pool_error_e _sound_pool_get_state(sound_pool_t *pool,
                sound_pool_state_e *state)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(state, SOUND_POOL_ERROR_INVALID_PARAMETER);
        *state = pool->state;
@@ -274,7 +263,7 @@ sound_pool_error_e _sound_pool_get_state(sound_pool_t *pool,
 
 sound_pool_error_e _sound_pool_set_volume(sound_pool_t *pool, float volume)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_RETVM_IF((volume < 0.0f || volume > 1.0f),
                        SOUND_POOL_ERROR_INVALID_PARAMETER,
@@ -291,7 +280,7 @@ sound_pool_error_e _sound_pool_set_volume(sound_pool_t *pool, float volume)
 
 sound_pool_error_e _sound_pool_get_volume(sound_pool_t *pool, float *volume)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(volume, SOUND_POOL_ERROR_INVALID_PARAMETER);
        *volume = pool->volume;
@@ -302,7 +291,7 @@ sound_pool_error_e _sound_pool_get_volume(sound_pool_t *pool, float *volume)
 sound_pool_error_e _sound_pool_set_callback(sound_pool_t *pool,
                sound_pool_state_change_cb callback, void *data)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
        SP_INST_CHECK(callback, SOUND_POOL_ERROR_INVALID_PARAMETER);
 
@@ -315,7 +304,7 @@ sound_pool_error_e _sound_pool_set_callback(sound_pool_t *pool,
 
 sound_pool_error_e _sound_pool_unset_callback(sound_pool_t *pool)
 {
-       SP_DEBUF_FENTER();
+       SP_DEBUG_FENTER();
        SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
 
        pool->state_cb_info.callback = NULL;