From 4bf9f23b11ddcabe24f4f780dac3572facf4214b Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Tue, 30 Aug 2016 13:57:45 +0900 Subject: [PATCH] Split section for pool / stream APIs Change-Id: Id17f6f9286bc3f9472c3592078b15c43d9399bd7 --- include/sound_pool.h | 160 +++++++++++++++++++++--------------------- src/sound_pool.c | 191 ++++++++++++++++++++++++++------------------------- 2 files changed, 178 insertions(+), 173 deletions(-) diff --git a/include/sound_pool.h b/include/sound_pool.h index 9642bdc..72cbcfd 100644 --- a/include/sound_pool.h +++ b/include/sound_pool.h @@ -178,24 +178,6 @@ sound_pool_error_e sound_pool_load_source_from_file(sound_pool_h pool, sound_pool_error_e sound_pool_unload_source(sound_pool_h pool, const char *tag); /** - * @brief Gets current @a state of @a pool. - * - * @since_tizen 3.0 - * @param [in] pool The handle to the sound pool - * @param [out] state Current state of @a pool - * @return @c 0 on success, otherwise a negative error value - * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER - * Invalid parameter (@a pool is NULL or corrupted, @a tag is NULL) - * - * @pre Create sound @a pool handler by calling @ref sound_pool_create() - * - * @see sound_pool_create() - * @see sound_pool_state_e - */ -sound_pool_error_e sound_pool_get_state(sound_pool_h pool, - sound_pool_state_e *state); - -/** * @brief Changes current @a state of @a pool to SOUND_POOL_STATE_ACTIVE. * @remarks When activation is performed, all suspended streams with highest * priority in the pool will resume their playback. Paused streams will @@ -243,6 +225,61 @@ sound_pool_error_e sound_pool_activate(sound_pool_h pool); sound_pool_error_e sound_pool_deactivate(sound_pool_h pool); /** + * @brief Sets pool global volume parameter. + * @details Volume of all streams related to @a pool will be scaled + * in accordance to global pool volume parameter + * (i.e. [stream real volume] = [global volume] * [stream volume], + * where [stream volume] is the volume parameter of arbitrary stream). + * + * @since_tizen 3.0 + * @param [in] pool The handle to the sound pool + * @param [in] volume Pool global volume in 0.0~1.0 range + * @return @c 0 on success, otherwise a negative error value + * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER Invalid parameter + * (@a pool is NULL or corrupted, or @a volume isn't in 0.0~1.0 range) + * @retval #SOUND_POOL_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create sound @a pool handler by calling @ref sound_pool_create() + * + * @see sound_pool_create() + */ +sound_pool_error_e sound_pool_set_volume(sound_pool_h pool, float volume); + +/** + * @brief Gets pool global volume parameter. + * + * @since_tizen 3.0 + * @param [in] pool The handle to the sound pool + * @param [out] volume Pool global volume in 0.0~1.0 range + * @return @c 0 on success, otherwise a negative error value + * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER Invalid parameter + * (@a pool is NULL or corrupted, or @a volume is NULL) + * + * @pre Create sound @a pool handler by calling @ref sound_pool_create() + * + * @see sound_pool_create() + */ +sound_pool_error_e sound_pool_get_volume(sound_pool_h pool, float *volume); + +/** + * @brief Gets current @a state of @a pool. + * + * @since_tizen 3.0 + * @param [in] pool The handle to the sound pool + * @param [out] state Current state of @a pool + * @return @c 0 on success, otherwise a negative error value + * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER + * Invalid parameter (@a pool is NULL or corrupted, @a tag is NULL) + * + * @pre Create sound @a pool handler by calling @ref sound_pool_create() + * + * @see sound_pool_create() + * @see sound_pool_state_e + */ +sound_pool_error_e sound_pool_get_state(sound_pool_h pool, + sound_pool_state_e *state); + +/** * @brief Sets callback for handling sound @a pool state change. * * @since_tizen 3.0 @@ -417,68 +454,6 @@ sound_pool_error_e sound_pool_stream_resume(sound_pool_h pool, unsigned id); sound_pool_error_e sound_pool_stream_stop(sound_pool_h pool, unsigned id); /** - * @brief Sets pool global volume parameter. - * @details Volume of all streams related to @a pool will be scaled - * in accordance to global pool volume parameter - * (i.e. [stream real volume] = [global volume] * [stream volume], - * where [stream volume] is the volume parameter of arbitrary stream). - * - * @since_tizen 3.0 - * @param [in] pool The handle to the sound pool - * @param [in] volume Pool global volume in 0.0~1.0 range - * @return @c 0 on success, otherwise a negative error value - * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER Invalid parameter - * (@a pool is NULL or corrupted, or @a volume isn't in 0.0~1.0 range) - * @retval #SOUND_POOL_ERROR_INVALID_OPERATION Invalid operation - * - * @pre Create sound @a pool handler by calling @ref sound_pool_create() - * - * @see sound_pool_create() - */ -sound_pool_error_e sound_pool_set_volume(sound_pool_h pool, float volume); - -/** - * @brief Gets pool global volume parameter. - * - * @since_tizen 3.0 - * @param [in] pool The handle to the sound pool - * @param [out] volume Pool global volume in 0.0~1.0 range - * @return @c 0 on success, otherwise a negative error value - * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER Invalid parameter - * (@a pool is NULL or corrupted, or @a volume is NULL) - * - * @pre Create sound @a pool handler by calling @ref sound_pool_create() - * - * @see sound_pool_create() - */ -sound_pool_error_e sound_pool_get_volume(sound_pool_h pool, float *volume); - -/** - * @brief Gets current @a state of stream by @a id. - * - * @since_tizen 3.0 - * @param [in] pool The handle to the sound pool - * @param [in] id Unique stream identifier - * @param [out] state Current state of stream - * @return @c 0 on success, otherwise a negative error value - * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER Invalid parameter - * (@a pool is NULL or corrupted, or @a state is NULL) - * @retval #SOUND_POOL_ERROR_KEY_NOT_AVAILABLE No streams identified by @a id - * exist in pool - * - * @pre Create sound pool handler by calling @ref sound_pool_create() - * @pre Load source to @a pool by calling @ref sound_pool_load_source_from_file() - * @pre Start stream playback by calling @ref sound_pool_stream_play() - * - * @see sound_pool_create() - * @see sound_pool_load_source_from_file() - * @see sound_pool_stream_play() - * @see sound_pool_stream_state_e - */ -sound_pool_error_e sound_pool_stream_get_state(sound_pool_h pool, unsigned id, - sound_pool_stream_state_e *state); - -/** * @brief Sets stream @a loop parameter by stream @a id. * * @since_tizen 3.0 @@ -654,6 +629,31 @@ sound_pool_error_e sound_pool_stream_get_priority(sound_pool_h pool, unsigned id unsigned *priority); /** + * @brief Gets current @a state of stream by @a id. + * + * @since_tizen 3.0 + * @param [in] pool The handle to the sound pool + * @param [in] id Unique stream identifier + * @param [out] state Current state of stream + * @return @c 0 on success, otherwise a negative error value + * @retval #SOUND_POOL_ERROR_INVALID_PARAMETER Invalid parameter + * (@a pool is NULL or corrupted, or @a state is NULL) + * @retval #SOUND_POOL_ERROR_KEY_NOT_AVAILABLE No streams identified by @a id + * exist in pool + * + * @pre Create sound pool handler by calling @ref sound_pool_create() + * @pre Load source to @a pool by calling @ref sound_pool_load_source_from_file() + * @pre Start stream playback by calling @ref sound_pool_stream_play() + * + * @see sound_pool_create() + * @see sound_pool_load_source_from_file() + * @see sound_pool_stream_play() + * @see sound_pool_stream_state_e + */ +sound_pool_error_e sound_pool_stream_get_state(sound_pool_h pool, unsigned id, + sound_pool_stream_state_e *state); + +/** * @brief Sets callback for handling stream state change events. * * @since_tizen 3.0 diff --git a/src/sound_pool.c b/src/sound_pool.c index 597c979..ea23673 100644 --- a/src/sound_pool.c +++ b/src/sound_pool.c @@ -25,6 +25,7 @@ #include "internal/soundpool.h" #include "internal/source.h" #include "internal/stream.h" +#include "internal/priority.h" /* * Public Implementation @@ -32,6 +33,8 @@ static unsigned int sound_pool_amount = 0; +/*------------------- Pool related APIs -------------------------*/ + sound_pool_error_e sound_pool_create(sound_pool_h *pool) { SP_DEBUG_FENTER(); @@ -109,6 +112,93 @@ sound_pool_error_e sound_pool_unload_source(sound_pool_h pool, const char *tag) return ret; } +sound_pool_error_e sound_pool_activate(sound_pool_h pool) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_activate((sound_pool_t *)pool); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "activating sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +sound_pool_error_e sound_pool_deactivate(sound_pool_h pool) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_deactivate((sound_pool_t *)pool); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "deactivating sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +sound_pool_error_e sound_pool_set_volume(sound_pool_h pool, float volume) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_set_volume((sound_pool_t *)pool, volume); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "setting volume for sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +sound_pool_error_e sound_pool_get_volume(sound_pool_h pool, float *volume) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_get_volume((sound_pool_t *)pool, volume); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "getting volume for sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +sound_pool_error_e sound_pool_get_state(sound_pool_h pool, sound_pool_state_e *state) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_get_state(pool, state); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "getting state of the sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +sound_pool_error_e sound_pool_set_state_change_callback(sound_pool_h pool, + sound_pool_state_change_cb callback, void *data) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_set_callback((sound_pool_t *)pool, callback, data); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "setting state changing callback for sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +sound_pool_error_e sound_pool_unset_state_change_callback(sound_pool_h pool) +{ + SP_DEBUG_FENTER(); + + sound_pool_error_e ret = _sound_pool_unset_callback((sound_pool_t *)pool); + SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " + "unsetting state changing callback for sound pool"); + + SP_DEBUG_FLEAVE(); + return ret; +} + +/*------------------ Stream related APIs -------------------------*/ + sound_pool_error_e sound_pool_stream_play(sound_pool_h pool, const char *tag, unsigned loop, float volume, unsigned priority, sound_pool_stream_state_change_cb callback, void *data, unsigned *id) @@ -218,85 +308,6 @@ sound_pool_error_e sound_pool_stream_stop(sound_pool_h pool, unsigned id) return ret; } -sound_pool_error_e sound_pool_get_state(sound_pool_h pool, sound_pool_state_e *state) -{ - SP_DEBUG_FENTER(); - - sound_pool_error_e ret = _sound_pool_get_state(pool, state); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "getting state of the sound pool"); - - SP_DEBUG_FLEAVE(); - return ret; -} - -sound_pool_error_e sound_pool_activate(sound_pool_h pool) -{ - SP_DEBUG_FENTER(); - - sound_pool_error_e ret = _sound_pool_activate((sound_pool_t *)pool); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "activating sound pool"); - - SP_DEBUG_FLEAVE(); - return ret; -} - -sound_pool_error_e sound_pool_deactivate(sound_pool_h pool) -{ - SP_DEBUG_FENTER(); - - sound_pool_error_e ret = _sound_pool_deactivate((sound_pool_t *)pool); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "deactivating sound pool"); - - SP_DEBUG_FLEAVE(); - return ret; -} - -sound_pool_error_e sound_pool_set_volume(sound_pool_h pool, float volume) -{ - SP_DEBUG_FENTER(); - - sound_pool_error_e ret = _sound_pool_set_volume((sound_pool_t *)pool, volume); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "setting volume for sound pool"); - - SP_DEBUG_FLEAVE(); - return ret; -} - -sound_pool_error_e sound_pool_get_volume(sound_pool_h pool, float *volume) -{ - SP_DEBUG_FENTER(); - - sound_pool_error_e ret = _sound_pool_get_volume((sound_pool_t *)pool, volume); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "getting volume for sound pool"); - - SP_DEBUG_FLEAVE(); - return ret; -} - -sound_pool_error_e sound_pool_stream_get_state(sound_pool_h pool, unsigned id, - sound_pool_stream_state_e *state) -{ - SP_DEBUG_FENTER(); - - sound_pool_t *_pool = (sound_pool_t *)pool; - sound_stream_t *_stream = NULL; - sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "getting sound stream [%u] from the sound pool", id); - - ret = _sound_stream_get_state(_stream, state); - SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "getting sound stream [%u] state", id); - - SP_DEBUG_FLEAVE(); - return ret; -} - sound_pool_error_e sound_pool_stream_set_loop(sound_pool_h pool, unsigned id, unsigned loop) { @@ -411,26 +422,20 @@ sound_pool_error_e sound_pool_stream_get_priority(sound_pool_h pool, return ret; } -sound_pool_error_e sound_pool_set_state_change_callback(sound_pool_h pool, - sound_pool_state_change_cb callback, void *data) +sound_pool_error_e sound_pool_stream_get_state(sound_pool_h pool, unsigned id, + sound_pool_stream_state_e *state) { SP_DEBUG_FENTER(); - sound_pool_error_e ret = _sound_pool_set_callback((sound_pool_t *)pool, callback, data); + sound_pool_t *_pool = (sound_pool_t *)pool; + sound_stream_t *_stream = NULL; + sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream); SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "setting state changing callback for sound pool"); - - SP_DEBUG_FLEAVE(); - return ret; -} - -sound_pool_error_e sound_pool_unset_state_change_callback(sound_pool_h pool) -{ - SP_DEBUG_FENTER(); + "getting sound stream [%u] from the sound pool", id); - sound_pool_error_e ret = _sound_pool_unset_callback((sound_pool_t *)pool); + ret = _sound_stream_get_state(_stream, state); SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when " - "unsetting state changing callback for sound pool"); + "getting sound stream [%u] state", id); SP_DEBUG_FLEAVE(); return ret; -- 2.7.4