unsigned loop;
float volume;
+ sound_pool_stream_priority_policy_e priority_policy;
sound_pool_stream_state_e state;
sound_pool_stream_state_e state_previous;
gboolean stopped;
+ gboolean mute;
+ gboolean suspended;
struct {
sound_pool_stream_state_change_cb callback;
} sound_stream_t;
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);
+ float volume, unsigned priority, sound_pool_stream_priority_policy_e priority_policy,
+ sound_pool_stream_state_change_cb cb, void *data, sound_stream_t **stream);
sound_pool_error_e _sound_stream_destroy(sound_stream_t *src);
sound_pool_error_e _sound_stream_resume(sound_stream_t *stream);
+sound_pool_error_e _sound_stream_suspend(sound_stream_t *stream);
+
sound_pool_error_e _sound_stream_stop(sound_stream_t *stream);
sound_pool_error_e _sound_stream_set_loop(sound_stream_t *stream, unsigned loop);
sound_pool_error_e _sound_stream_set_volume(sound_stream_t *stream, float volume);
sound_pool_error_e _sound_stream_get_volume(sound_stream_t *stream, float *volume);
+sound_pool_error_e _sound_stream_set_mute(sound_stream_t *stream, gboolean mute);
+sound_pool_error_e _sound_stream_get_mute(sound_stream_t *stream, gboolean *mute);
+
sound_pool_error_e _sound_stream_set_priority(sound_stream_t *stream, unsigned rank);
sound_pool_error_e _sound_stream_get_priority(sound_stream_t *stream, unsigned *rank);
+sound_pool_error_e _sound_stream_set_priority_policy(sound_stream_t *stream,
+ sound_pool_stream_priority_policy_e priority_policy);
+
sound_pool_error_e _sound_stream_get_state(sound_stream_t *stream,
sound_pool_stream_state_e *state);
sound_pool_error_e _sound_stream_unset_callback(sound_stream_t *stream);
+sound_pool_error_e _sound_stream_send_event(sound_stream_t *stream,
+ sound_pool_stream_state_e state);
+
sound_pool_error_e _sound_pool_get_stream_by_id(sound_pool_t *pool, unsigned id,
sound_stream_t **stream);
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
* @param [in] priority Stream priority (0 = lowest priority). Check
* @ref sound_pool_stream_set_priority() documentation
* for details on prioritization rules.
+ * @param [in] priority_policy Stream priority policy.
+ * (#SOUND_POOL_STREAM_PRIORITY_POLICY_SUSPENDED Suspended)
+ * (#SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE Mute)
* @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
*/
sound_pool_error_e sound_pool_stream_play(sound_pool_h pool, const char *tag,
unsigned loop, float volume, unsigned priority,
+ sound_pool_stream_priority_policy_e priority_policy,
sound_pool_stream_state_change_cb callback, void *user_data,
unsigned *id);
} sound_pool_stream_state_e;
/**
+ * @brief Enumeration of sound pool stream priority policy.
+ *
+ * @since_tizen 4.0
+ */
+typedef enum {
+ SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE, /**< Stream priority policy is mute */
+ SOUND_POOL_STREAM_PRIORITY_POLICY_SUSPENDED /**< Stream priority policy is suspended */
+} sound_pool_stream_priority_policy_e;
+
+/**
* @brief Enumeration of sound pool state.
*
* @since_tizen 4.0
if (SOUND_POOL_ERROR_NONE != _sound_stream_priority_check(mgr, stream,
&can_run))
continue;
- if (TRUE == can_run) {
- if (SOUND_POOL_STREAM_STATE_PLAYING != stream->state &&
- SOUND_POOL_STREAM_STATE_PAUSED != stream->state)
+
+ if (can_run) {
+ switch (stream->state) {
+ case SOUND_POOL_STREAM_STATE_PLAYING:
+ if (SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE == stream->priority_policy && stream->mute) {
+ SP_INFO("stream[%d] with priority[%d] was Playing with mute, now unmute",
+ stream->id, stream->priority);
+ _sound_stream_set_mute(stream, FALSE);
+ }
+ break;
+ case SOUND_POOL_STREAM_STATE_NONE:
+ case SOUND_POOL_STREAM_STATE_SUSPENDED:
+ SP_INFO("stream[%d] with priority[%d] was Suspended(pool deactivate) or initial created, now play",
+ stream->id, stream->priority);
_sound_stream_play(stream);
- } else if (SOUND_POOL_STREAM_STATE_PLAYING == stream->state) {
- stream->stopped = TRUE; /* Shows it was stopped due to priority */
- _sound_stream_pause(stream);
- } else if (SOUND_POOL_STREAM_STATE_NONE == stream->state) {
- /* This case handles newly created streams in active pool, but with
- too low priority for transition to playing state: */
- stream->state_previous = stream->state;
- stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
- if (_stream_cb_manager_register_event(mgr->pool->cbmgr, stream) !=
- SOUND_POOL_ERROR_NONE)
- SP_DEBUG("State changing event wasn't registered."
- "Callbacks will be not called");
+ break;
+ default:
+ break;
+ }
+ } else { /* Can't run */
+ if (SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE == stream->priority_policy) {
+ /* mute policy */
+ switch (stream->state) {
+ case SOUND_POOL_STREAM_STATE_PLAYING:
+ if (!stream->mute) {
+ SP_INFO("stream[%d] with priority[%d] was Playing, now mute",
+ stream->id, stream->priority);
+ _sound_stream_set_mute(stream, TRUE);
+ }
+ break;
+ case SOUND_POOL_STREAM_STATE_NONE:
+ case SOUND_POOL_STREAM_STATE_SUSPENDED:
+ SP_INFO("stream[%d] with priority[%d] was Suspended(pool deactivate) or initial created, now play with mute",
+ stream->id, stream->priority);
+ _sound_stream_set_mute(stream, TRUE);
+ _sound_stream_play(stream);
+ break;
+ default:
+ /* nothing to do */
+ break;
+ }
+ } else {
+ /* suspended policy */
+ switch (stream->state) {
+ case SOUND_POOL_STREAM_STATE_PLAYING:
+ SP_INFO("stream[%d] with priority[%d] was Playing, now Suspend",
+ stream->id, stream->priority);
+ _sound_stream_suspend(stream);
+ break;
+ case SOUND_POOL_STREAM_STATE_NONE:
+ /* This case handles newly created streams in active pool, but with
+ too low priority for transition to playing state: */
+ _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_SUSPENDED);
+ break;
+ default:
+ /* nothing to do */
+ break;
+ }
+ }
}
+
}
SP_DEBUG_FLEAVE();
}
+
sound_pool_error_e sound_pool_stream_play(sound_pool_h pool, const char *tag,
unsigned loop, float volume, unsigned priority,
+ sound_pool_stream_priority_policy_e priority_policy,
sound_pool_stream_state_change_cb callback, void *data, unsigned *id)
{
SP_DEBUG_FENTER();
"getting sound source [%s] from the sound pool", tag);
sound_stream_t *_stream = NULL;
- ret = _sound_stream_create(_source, loop, volume, priority, callback, data,
- &_stream);
+ ret = _sound_stream_create(_source, loop, volume, priority, priority_policy,
+ callback, data, &_stream);
SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
"Error while creating sound source instance.");
if (pool->state == SOUND_POOL_STATE_INACTIVE) {
stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
} else if (pool->state == SOUND_POOL_STATE_ACTIVE) {
- if (stream->stopped) { /* Stream stopped due to priority issue */
+ if (stream->suspended) { /* Stream stopped due to priority issue */
stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
- stream->stopped = FALSE;
} else {
stream->state = SOUND_POOL_STREAM_STATE_PAUSED;
}
}
static sound_pool_error_e __sound_stream_init(sound_stream_t *stream,
- unsigned loop, float volume, unsigned priority,
+ unsigned loop, float volume, unsigned priority, sound_pool_stream_priority_policy_e priority_policy,
sound_pool_stream_state_change_cb cb, void *data)
{
SP_DEBUG_FENTER();
SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
"Error occurred when setting sound stream priority parameter");
+ ret = _sound_stream_set_priority_policy(stream, priority_policy);
+ SP_RETVM_IF (ret != SOUND_POOL_ERROR_NONE, ret,
+ "Error occurred when setting sound stream priority_policy 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,
+ float volume, unsigned priority, sound_pool_stream_priority_policy_e priority_policy,
+ sound_pool_stream_state_change_cb cb,
void *data, sound_stream_t **stream)
{
SP_DEBUG_FENTER();
"Data to OpenAL Source", cfail);
}
- ret = __sound_stream_init(_stream, loop, volume, priority, cb, data);
+ ret = __sound_stream_init(_stream, loop, volume, priority, priority_policy, cb, data);
if (ret != SOUND_POOL_ERROR_NONE)
GOTO_FAIL("Sound stream initialization error occurred", cfail);
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");
+ "OpenAL error occured when trying to play OpenAL Source");
+
+ SP_DEBUG_FLEAVE();
+ return ret;
+}
+
+sound_pool_error_e _sound_stream_suspend(sound_stream_t *stream)
+{
+ SP_DEBUG_FENTER();
+ SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
+ SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
+ sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
+ stream->suspended = TRUE; /* Shows it was stopped due to priority */
+ alSourcePause(stream->al_source);
+ stream->suspended = FALSE;
+
+ SP_DEBUG_FLEAVE();
+ return ret;
+}
+
+sound_pool_error_e _sound_stream_send_event(sound_stream_t *stream, sound_pool_stream_state_e state)
+{
+ SP_DEBUG_FENTER();
+ sound_pool_t *pool = stream->parent_source->parent_pool;
+ sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
+ stream->state_previous = stream->state;
+ stream->state = 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_DEBUG_FLEAVE();
return ret;
if (pool->state == SOUND_POOL_STATE_INACTIVE &&
stream->state == SOUND_POOL_STREAM_STATE_SUSPENDED) {
- stream->state_previous = stream->state;
- stream->state = SOUND_POOL_STREAM_STATE_PAUSED;
- 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");
+ ret = _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_PAUSED);
SP_INFO("Don't paused due to SoundPool is in inactive state.");
} else {
alSourcePause(stream->al_source);
if (pool->state == SOUND_POOL_STATE_INACTIVE &&
stream->state == SOUND_POOL_STREAM_STATE_PAUSED) {
- 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");
+ ret = _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_SUSPENDED);
SP_INFO("Don't resumed due to SoundPool is in inactive state.");
} else {
alSourcePlay(stream->al_source);
return SOUND_POOL_ERROR_NONE;
}
+sound_pool_error_e _sound_stream_set_mute(sound_stream_t *stream, gboolean mute)
+{
+ SP_DEBUG_FENTER();
+
+ SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
+
+ sound_pool_t *pool = stream->parent_source->parent_pool;
+ SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
+ SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
+ SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
+
+ alSourcef(stream->al_source, AL_GAIN, ((int)!mute * stream->volume));
+ stream->mute = mute;
+
+ SP_DEBUG_FLEAVE();
+ return SOUND_POOL_ERROR_NONE;
+}
+
+sound_pool_error_e _sound_stream_get_mute(sound_stream_t *stream, gboolean *mute)
+{
+ SP_DEBUG_FENTER();
+ SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
+ SP_INST_CHECK(mute, SOUND_POOL_ERROR_INVALID_PARAMETER);
+
+ *mute = stream->mute;
+
+ SP_DEBUG_FLEAVE();
+ return SOUND_POOL_ERROR_NONE;
+}
+
sound_pool_error_e _sound_stream_get_volume(sound_stream_t *stream, float *volume)
{
SP_DEBUG_FENTER();
*state = stream->state;
+ if (stream->mute)
+ SP_DEBUG(" Stream is in Mute.");
+
SP_DEBUG_FLEAVE();
return SOUND_POOL_ERROR_NONE;
}
{
SP_DEBUG_FENTER();
SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
+ SP_INST_CHECK(stream->parent_source, 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);
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;
- 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");
+ ret = _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_SUSPENDED);
+ SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "Error occured during"
+ "send event");
}
SP_DEBUG("No need to update priority, Sound pool is INACTIVE.");
return SOUND_POOL_ERROR_NONE;
return SOUND_POOL_ERROR_NONE;
}
+sound_pool_error_e _sound_stream_set_priority_policy(sound_stream_t *stream,
+ sound_pool_stream_priority_policy_e priority_policy)
+{
+ SP_DEBUG_FENTER();
+ SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
+ SP_INST_CHECK(stream->parent_source, 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);
+
+
+ stream->priority_policy = priority_policy;
+
+ SP_INFO("Priority policy is %d.", stream->priority_policy);
+ SP_DEBUG_FLEAVE();
+ return SOUND_POOL_ERROR_NONE;
+}
+
sound_pool_error_e _sound_stream_get_priority(sound_stream_t *stream,
unsigned *rank)
{
int loop = 0;
float volume = 1.0f;
unsigned rank = DEFAULT_STREAM_PRIORITY_RANK;
+ sound_pool_stream_priority_policy_e priority_policy = SOUND_POOL_STREAM_PRIORITY_POLICY_MUTE;
char tag[MAX_PATH_LEN] = {'\0'};
- if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ] %i %f %u",
- &idx, tag, &loop, &volume, &rank) < 2) {
+ if ((pars == NULL) || sscanf(pars, " %zu %"MAX_PATH_LEN_STR"[^ ] %i %f %u %u",
+ &idx, tag, &loop, &volume, &rank, &priority_policy) < 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>... "
+ " <pool id> <source tag> <loop> <volume> <priority rank> <priority_policy>... "
"0 'priority rank' value corresponds to the lowest priority.\n");
return FAIL;
}
"with %zu identifier...", tag, idx);
unsigned stream_idx = 0;
- int ret = sound_pool_stream_play(pools[idx], tag, loop, volume, rank, NULL,
+ int ret = sound_pool_stream_play(pools[idx], tag, loop, volume, rank, priority_policy, __s_cb_msg,
NULL, &stream_idx);
if (ret == SOUND_POOL_ERROR_NONE) {
_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,
+ " %u, %p, NULL, &stream_idx) returned %s value. "
+ "Generated identifier is %i", tag, loop, volume, rank, priority_policy, __s_cb_msg,
__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, %u,"
- " NULL, NULL, &stream_idx) returned %s value",
- tag, loop, volume, rank, __stringify_sound_pool_error(ret));
+ " %u, %p, NULL, &stream_idx) returned %s value",
+ tag, loop, volume, rank, priority_policy, __s_cb_msg, __stringify_sound_pool_error(ret));
}
return (ret == SOUND_POOL_ERROR_NONE ? OK : FAIL);