GHashTable *sources;
GHashTable *streams;
- guint max_streams;
guint max_stream_index;
sound_pool_state_e state;
/* Max amount of sound pools which could be created. */
#define SOUND_POOL_MAX_POOLS_AMOUNT 32U
-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);
sound_pool_error_e _sound_pool_destroy(sound_pool_t *pool);
* @param [in] prev_state Previous stream state
* @param [in] cur_state Current stream state
* @param [in] data The user data passed from the code where
- * @ref sound_pool_stream_set_state_change_callback() was
- * called.
+ * @ref sound_pool_stream_set_state_change_callback()
+ * was called.
*
* @pre Create sound pool handler by calling @ref sound_pool_create()
* @pre Load source to pool by calling @ref sound_pool_load_source_from_file()
* @ref sound_pool_activate() function.
*
* @since_tizen 3.0
- * @param [in] max_streams Maximum number of active streams
- * @param [out] pool The handle to the pool that will be created
+ * @param [out] pool The handle to the pool that will be created
* @return @c 0 on success, otherwise a negative error value
* @retval #SOUND_POOL_ERROR_INVALID_PARAMETER
- * Invalid parameter (@a pool is NULL or @a max_streams is 0)
+ * Invalid parameter (@a pool is NULL)
* @retval #SOUND_POOL_ERROR_OUT_OF_MEMORY
* Not enough memory to create sound pool
* @retval #SOUND_POOL_ERROR_INVALID_OPERATION
*
* @see sound_pool_destroy()
*/
-sound_pool_error_e sound_pool_create(unsigned max_streams, sound_pool_h *pool);
+sound_pool_error_e sound_pool_create(sound_pool_h *pool);
/**
* @brief Destroys sound pool and cleans allocated memory.
* @see sound_pool_destroy()
* @see sound_pool_unload_source()
*/
-sound_pool_error_e sound_pool_load_source_from_file(sound_pool_h pool, const char *file_name,
- const char *tag);
+sound_pool_error_e sound_pool_load_source_from_file(sound_pool_h pool,
+ const char *file_name, const char *tag);
/**
* @brief Unloads source from @a pool.
/**
* @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
+ * remain their state.
*
* @since_tizen 3.0
* @param [in] pool The handle to the sound pool
/**
* @brief Changes current @a state of @a pool to SOUND_POOL_STATE_INACTIVE.
+ * @remarks When deactivation is performed, all playing streams in the pool will
+ * be suspended (change state to SOUND_POOL_STREAM_STATE_SUSPENDED).
+ * Paused streams will remain their state.
*
* @since_tizen 3.0
* @param [in] pool The handle to the sound pool
* (@a pool is NULL or corrupted)
*
* @pre Create sound @a pool handler by calling @ref sound_pool_create()
- * @pre Set state change callback by calling @ref sound_pool_set_state_change_callback()
+ * @pre Set state change callback by calling
+ * @ref sound_pool_set_state_change_callback()
*
* @see sound_pool_create()
* @see sound_pool_set_state_change_callback()
* @details Creates stream with @a id that can be used to change parameters and
* get additional information.
* Sets stream state to SOUND_POOL_STREAM_STATE_PLAYING
- * @remarks In case maximum active streams number after calling
- * @ref sound_pool_stream_play() was exceeded the stream
- * with lowest @a priority will be stopped.
- * Resultant stream volume will depend on global pool volume.
+ * @remarks Resultant stream volume will depend on global pool volume.
*
* @since_tizen 3.0
* @param [in] pool The handle to the sound pool
* @param [in] loop Number of times stream will be repeated
* (pass 0 if stream should be repeated continuously)
* @param [in] volume Stream volume in 0.0~1.0 range
- * @param [in] priority Stream priority (0 = lowest priority)
+ * @param [in] priority Stream priority (0 = lowest priority). Check
+ * @ref sound_pool_stream_set_priority() documentation
+ * for details on prioritization rules.
* @param [in] callback The callback that will be called after stream state
* will be changed, or NULL if this callback call
* isn't needed. If @a callback is set, then it will
* @see sound_pool_set_volume
* @see sound_pool_get_volume
*/
-sound_pool_error_e sound_pool_stream_play(sound_pool_h pool, const char *tag, unsigned loop,
- float volume, unsigned priority,
+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 *user_data,
unsigned *id);
* @see sound_pool_load_source_from_file()
* @see sound_pool_stream_play()
*/
-sound_pool_error_e sound_pool_stream_set_loop(sound_pool_h pool, unsigned id, unsigned loop);
+sound_pool_error_e sound_pool_stream_set_loop(sound_pool_h pool, unsigned id,
+ unsigned loop);
/**
* @brief Gets stream @a loop parameter by stream @a id.
* @see sound_pool_load_source_from_file()
* @see sound_pool_stream_play()
*/
-sound_pool_error_e sound_pool_stream_get_loop(sound_pool_h pool, unsigned id, unsigned *loop);
+sound_pool_error_e sound_pool_stream_get_loop(sound_pool_h pool, unsigned id,
+ unsigned *loop);
/**
* @brief Sets stream volume parameters by stream @a id.
/**
* @brief Sets stream priority parameter by stream @a id.
+ * @remarks Only streams with highest priority in the active Sound Pool can be
+ * played. If at least one stream with highest priority gets
+ * #SOUND_POOL_STREAM_STATE_PLAYING state, then all has been playing
+ * streams with lower priorities will be transfered to the
+ * #SOUND_POOL_STREAM_STATE_SUSPENDED state. If there is no more
+ * playing streams in some priority group (group of streams with the
+ * same priority), then all suspended previously streams in the group
+ * with one level lower priority will be resumed. For example, if we
+ * have N suspended streams in 'LOW' group, M suspended streams in
+ * 'MEDIUM' group and K playing streams in 'HIGH' group then the
+ * following rules are valid: When all K streams in HIGH priority group
+ * will be finished, paused, or stopped and Sound Pool is in active
+ * state, only then M streams from MEDIUM priority group will be
+ * resumed. When all M+K streams from HIGH and MEDIUM priority groups
+ * will be finished, paused or stopped and Sound Pool is in active
+ * state, only then N streams from LOW priority group will be resumed.
+ * Transfering at least one stream from higher priority group will lead
+ * to suspending of all the streams from lower priorities group(s).
+ * Priorities don't make any effect in inactive Sound Pools. But after
+ * pool activation, all mentioned rules will be applied.
*
* @since_tizen 3.0
* @param [in] pool The handle to the sound pool
* @brief Gets stream priority parameter by stream @a id.
*
* @since_tizen 3.0
- * @param [in] pool The handle to the sound pool
- * @param [in] id Unique stream identifier
- * @param [in] priority Stream priority (0 = lowest priority)
+ * @param [in] pool The handle to the sound pool
+ * @param [in] id Unique stream identifier
+ * @param [out] priority Stream priority (0 = lowest priority). Check
+ * @ref sound_pool_stream_set_priority() documentation
+ * for details on prioritization rules.
* @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 priority is NULL)
* @see sound_pool_stream_play()
* @see sound_pool_stream_state_change_cb
*/
-sound_pool_error_e sound_pool_stream_set_state_change_callback(sound_pool_h pool, unsigned id,
- sound_pool_stream_state_change_cb callback, void *user_data);
+sound_pool_error_e sound_pool_stream_set_state_change_callback(sound_pool_h pool,
+ unsigned id, sound_pool_stream_state_change_cb callback, void *user_data);
/**
* @brief Unsets callback for handling stream state change events.
*
* @since_tizen 3.0
*/
-typedef enum
-{
+typedef enum {
SOUND_POOL_ERROR_NONE
= TIZEN_ERROR_NONE, /**< Successful */
SOUND_POOL_ERROR_NOT_SUPPORTED
*/
#include "internal/priority.h"
+#include "internal/stream_cb_manager.h"
-static gint __stream_stream_proirity_cmp(gconstpointer a, gconstpointer b);
+static gint __sound_stream_priority_cmp(gconstpointer a, gconstpointer b);
-static gint __stream_stream_proirity_cmp(gconstpointer a, gconstpointer b)
+static gint __sound_stream_priority_cmp(gconstpointer a, gconstpointer b)
{
SP_DEBUG_FENTER();
SP_RETVM_IF(!a, 0, "Firs pointer is NULL.");
SP_RETVM_IF(-1 == position, SOUND_POOL_ERROR_INVALID_PARAMETER,
"Can't find stream in priority queue[%s]", stream->parent_source->tag_name);
- if (position < mgr->pool->max_streams)
- *out = TRUE;
+ *out = TRUE;
SP_DEBUG_FLEAVE();
return SOUND_POOL_ERROR_NONE;
}
mgr->priority_queue = g_list_sort(mgr->priority_queue,
- __stream_stream_proirity_cmp);
+ __sound_stream_priority_cmp);
GList *iter = mgr->priority_queue;
for (; iter != NULL; iter = iter->next) {
sound_stream_t *stream = (sound_stream_t *)iter->data;
-
if (SOUND_POOL_ERROR_NONE != _sound_stream_priority_check(mgr, stream,
&can_run))
continue;
static unsigned int sound_pool_amount = 0;
-sound_pool_error_e sound_pool_create(unsigned max_streams, sound_pool_h *pool)
+sound_pool_error_e sound_pool_create(sound_pool_h *pool)
{
SP_DEBUG_FENTER();
- SP_RETVM_IF(max_streams == 0, SOUND_POOL_ERROR_INVALID_PARAMETER,
- "Max streams count should be greater then 0.");
SP_RETVM_IF(SOUND_POOL_MAX_POOLS_AMOUNT < (sound_pool_amount + 1),
SOUND_POOL_ERROR_INVALID_OPERATION,
"Max pools count should be no more than %d.",
SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
sound_pool_t *_pool = NULL;
- sound_pool_error_e ret = _sound_pool_create(max_streams, &_pool);
+ sound_pool_error_e ret = _sound_pool_create(&_pool);
SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
"Error while creating sound pool instance.");
SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_OPERATION);
#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,
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_DEBUG_FENTER();
- SP_RETVM_IF(max_streams == 0, SOUND_POOL_ERROR_INVALID_PARAMETER,
- "Max streams count should be greater than 0.");
+ SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
sound_pool_t *_pool = NULL;
SP_RETVM_IF(!(_pool = g_try_malloc0(sizeof(*_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;
g_hash_table_iter_init(&iter, pool->streams);
while (g_hash_table_iter_next(&iter, &key, &value)) {
guint size_before = g_hash_table_size(pool->streams);
- gchar *tag = (gchar*)key;
sound_stream_t *stream = (sound_stream_t*)value;
if (src == stream->parent_source)
_sound_stream_destroy((sound_stream_t*)value);
SP_DEBUG_FLEAVE();
}
-static sound_pool_error_e __sound_pool_add_stream(sound_pool_t *pool, sound_stream_t *stream)
+static sound_pool_error_e __sound_pool_add_stream(sound_pool_t *pool,
+ sound_stream_t *stream)
{
SP_DEBUG_FENTER();
SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
SOUND_POOL_ERROR_INVALID_OPERATION, "Error occurred when adding "
"the stream [%u] to the sound pool", stream->id);
- sound_pool_error_e ret = _sound_stream_priority_add_stream(pool->mgr_priority, stream);
+ sound_pool_error_e ret =
+ _sound_stream_priority_add_stream(pool->mgr_priority, stream);
SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "Error occurred when adding "
"the stream [%u] to the priority queue.", stream->id);
return SOUND_POOL_ERROR_NONE;
}
-sound_pool_error_e _sound_stream_set_priority(sound_stream_t *stream, unsigned rank)
+sound_pool_error_e _sound_stream_set_priority(sound_stream_t *stream,
+ unsigned rank)
{
SP_DEBUG_FENTER();
SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
return SOUND_POOL_ERROR_NONE;
}
-sound_pool_error_e _sound_stream_get_priority(sound_stream_t *stream, unsigned *rank)
+sound_pool_error_e _sound_stream_get_priority(sound_stream_t *stream,
+ unsigned *rank)
{
SP_DEBUG_FENTER();
SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
#include <stdlib.h>
#include <unistd.h>
-#define DEFAULT_MAX_STREAMS_PER_POOL_CNT 25
+#define DEFAULT_MAX_STREAMS_PER_POOL_CNT 25U
+#define DEFAULT_STREAM_PRIORITY_RANK 255U
#define MICROSECS_PER_MILLISEC 1000
#define MAX_POOL_CNT 100
#define MAX_STREAM_CNT 1000
/* Messages to be used for callbacks output (for pool state changing) */
-static char *stream_messages[MAX_POOL_CNT][MAX_STREAM_CNT] = { NULL };
+static char *stream_messages[MAX_POOL_CNT][MAX_STREAM_CNT] = {{ NULL }};
/* Messages to be used for callbacks output (for stream state changing) */
-static char *stream_scripts[MAX_POOL_CNT][MAX_STREAM_CNT] = { NULL };
+static char *stream_scripts[MAX_POOL_CNT][MAX_STREAM_CNT] = {{ NULL }};
+static const char *__stringify_sound_pool_error(sound_pool_error_e error);
static int __proxy_sound_pool_execute_script(const char *pars);
-const char *__stringify_sound_pool_error(sound_pool_error_e error)
+static const char *__stringify_sound_pool_error(sound_pool_error_e error)
{
switch (error) {
case SOUND_POOL_ERROR_NONE:
case SOUND_POOL_ERROR_PERMISSION_DENIED:
return "SOUND_POOL_ERROR_PERMISSION_DENIED";
break;
+ case SOUND_POOL_ERROR_NO_SUCH_FILE:
+ return "SOUND_POOL_ERROR_NO_SUCH_FILE";
+ break;
default:
return "";
break;
"identifiers.\n");
printf(CMD_SET_STREAM_PRIORITY "\n");
- printf("\t- use this command to set priority parameter of the stream.\n");
+ printf("\t- use this command to set priority parameter of the stream. "
+ "0 is the lowest priority.\n");
printf(CMD_GET_STREAM_PRIORITY "\n");
printf("\t- shows priority rank of the stream in the pool with specified "
- "identifiers.\n");
+ "identifiers. 0 is the lowest priority.\n");
printf(CMD_GET_STREAM_STATE "\n");
printf("\t- shows state of the stream in the pool with specified "
}
/* CMD_CREATE_POOL */
-static int __proxy_sound_pool_create(const char *pars)
+static int __proxy_sound_pool_create()
{
_logger_log_info(CMD_CREATE_POOL " command was called");
-
- unsigned int max_streams = DEFAULT_MAX_STREAMS_PER_POOL_CNT;
- if (pars != NULL)
- sscanf(pars, " %u", &max_streams);
-
_logger_log_info("Creating the pool...");
sound_pool_h pool = NULL;
- int ret = sound_pool_create(max_streams, &pool);
+ int ret = sound_pool_create(&pool);
if (ret == SOUND_POOL_ERROR_NONE) {
- _logger_log_info("sound_pool_create(%u, pool) returned %s value",
- max_streams, __stringify_sound_pool_error(ret));
+ _logger_log_info("sound_pool_create(pool) returned %s value",
+ __stringify_sound_pool_error(ret));
size_t idx = 0;
while (idx < MAX_POOL_CNT) {
else
_logger_log_info("Identifier of the pool has been created is %zu", idx);
} else {
- _logger_log_err("sound_pool_create(%u, pool) returned %s value",
- max_streams, __stringify_sound_pool_error(ret));
+ _logger_log_err("sound_pool_create(pool) returned %s value",
+ __stringify_sound_pool_error(ret));
}
return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
size_t idx = 0;
int loop = 0;
float volume = 1.0f;
- int rank = 0;
+ unsigned rank = DEFAULT_STREAM_PRIORITY_RANK;
char tag[MAX_PATH_LEN] = {'\0'};
- if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ] %i %f %i",
+ if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ] %i %f %u",
&idx, tag, &loop, &volume, &rank) < 2) {
_printf(CMD_COLOR_RED, "You have to specify at least pool identifier and "
"source tag to be played in stream! Format: " CMD_PLAY_STREAM
- " <pool id> <source tag> <loop> <volume> <priority rank>... \n");
+ " <pool id> <source tag> <loop> <volume> <priority rank>... "
+ "0 'priority rank' value corresponds to the lowest priority.\n");
return FAIL;
}
_logger_log_info("Playing stream based on source with '%s' tag from the pool "
"with %zu identifier...", tag, idx);
- int stream_idx = 0;
+ unsigned stream_idx = 0;
int ret = sound_pool_stream_play(pools[idx], tag, loop, volume, rank, NULL,
NULL, &stream_idx);
if (ret == SOUND_POOL_ERROR_NONE) {
- _logger_log_info("sound_pool_play_stream(pool, \"%s\", %i, %f, %i,"
+ _logger_log_info("sound_pool_play_stream(pool, \"%s\", %i, %f, %u,"
" NULL, NULL, &stream_idx) returned %s value. "
"Generated identifier is %i", tag, loop, volume, rank,
__stringify_sound_pool_error(ret), stream_idx);
_printf(CMD_COLOR_GREEN, "Generated stream identifier is %i\n", stream_idx);
} else {
- _logger_log_err("sound_pool_play_stream(pool, \"%s\", %i, %f, %i,"
+ _logger_log_err("sound_pool_play_stream(pool, \"%s\", %i, %f, %u,"
" NULL, NULL, &stream_idx) returned %s value",
tag, loop, volume, rank, __stringify_sound_pool_error(ret));
}
{
size_t idx = 0;
size_t stream_idx = 0;
- int rank_val = 0;
+ unsigned rank = 0;
if ((pars == NULL)
- || (sscanf(pars, " %zu %zu %i", &idx, &stream_idx, &rank_val) < 3)) {
+ || (sscanf(pars, " %zu %zu %u", &idx, &stream_idx, &rank) < 3)) {
_printf(CMD_COLOR_RED, "You have to specify all following parameters: "
"pool identifier, stream identifier, and priority rank! Format: "
CMD_SET_STREAM_PRIORITY " <pool id> <stream id> <rank>\n");
if (pools[idx] == NULL)
_logger_log_warn("Pool with specified identifier is NULL");
- if (rank_val < 0)
+ if (rank < 0)
_logger_log_warn("Priority rank should to be greater or equal 0, but "
- "it's value is %i", rank_val);
+ "it's value is %i", rank);
_logger_log_info(CMD_SET_STREAM_PRIORITY " command was called");
- int ret = sound_pool_stream_set_priority(pools[idx], stream_idx, rank_val);
+ int ret = sound_pool_stream_set_priority(pools[idx], stream_idx, rank);
if (ret == SOUND_POOL_ERROR_NONE)
- _logger_log_info("sound_pool_stream_set_priority(pool, %zu, %i) "
- "returned %s value", stream_idx, rank_val,
+ _logger_log_info("sound_pool_stream_set_priority(pool, %zu, %u) "
+ "returned %s value", stream_idx, rank,
__stringify_sound_pool_error(ret));
else
- _logger_log_err("sound_pool_stream_set_priority(pool, %zu, %i) "
- "returned %s value", stream_idx, rank_val,
+ _logger_log_err("sound_pool_stream_set_priority(pool, %zu, %u) "
+ "returned %s value", stream_idx, rank,
__stringify_sound_pool_error(ret));
return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
int ret = sound_pool_stream_get_priority(pools[idx], stream_idx, &rank);
if (ret == SOUND_POOL_ERROR_NONE)
- _logger_log_info("sound_pool_stream_get_priority(pool, %zu, rank) "
- "returned %s value, rank value is %i", stream_idx,
+ _logger_log_info("sound_pool_stream_get_priority(pool, %u, rank) "
+ "returned %s value, rank value is %u", stream_idx,
__stringify_sound_pool_error(ret), rank);
else
- _logger_log_err("sound_pool_stream_get_priority(pool, %zu, rank) "
- "returned %s value, rank value is %i", stream_idx,
+ _logger_log_err("sound_pool_stream_get_priority(pool, %u, rank) "
+ "returned %s value, rank value is %u", stream_idx,
__stringify_sound_pool_error(ret), rank);
return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);
/* Number of parameters supported by each command */
static int cmd_pars[MAX_COMMAND_LINE_LEN] = { /* CMD_EXIT */ 0,
- /* CMD_HELP */ 0, /* CMD_CREATE_POOL */ 1, /* CMD_DESTROY_POOL */ 1,
+ /* CMD_HELP */ 0, /* CMD_CREATE_POOL */ 0, /* CMD_DESTROY_POOL */ 1,
/* CMD_ACTIVATE_POOL */ 1, /* CMD_DEACTIVATE_POOL */ 1,
/* CMD_GET_POOL_STATE */ 1, /* CMD_SET_POOL_VOLUME */ 2,
/* CMD_GET_POOL_VOLUME */ 2, /* CMD_SET_POOL_CB_MSG */ 2,
while((cmd_line + trim_len)[0] == ' ')
trim_len++;
- char *cmd = cmd_line + trim_len;
+ const char *cmd = cmd_line + trim_len;
/* Macro for checking command correctness */
# define CHECK_CMD(ccmd, line) \