2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @brief This file include implementation of protected API
20 * for the sound streams(OpenAL sources) as part of SoundPool.
23 #include "internal/stream.h"
24 #include "internal/priority.h"
26 #include "internal/stream_cb_manager.h"
28 static const char *__stringify_stream_state(sound_pool_stream_state_e state);
29 static void __al_source_state_cb(ALuint source, ALenum state, ALvoid *data);
30 static sound_pool_error_e __sound_pool_add_stream(sound_pool_t *pool, sound_stream_t *stream);
31 static sound_pool_error_e __sound_pool_remove_stream(sound_pool_t *pool, sound_stream_t *stream);
33 static const char *__stringify_stream_state(sound_pool_stream_state_e state)
36 case SOUND_POOL_STREAM_STATE_NONE:
37 return "SOUND_POOL_STREAM_STATE_NONE";
38 case SOUND_POOL_STREAM_STATE_PLAYING:
39 return "SOUND_POOL_STREAM_STATE_PLAYING";
40 case SOUND_POOL_STREAM_STATE_PAUSED:
41 return "SOUND_POOL_STREAM_STATE_PAUSED";
42 case SOUND_POOL_STREAM_STATE_SUSPENDED:
43 return "SOUND_POOL_STREAM_STATE_SUSPENDED";
44 case SOUND_POOL_STREAM_STATE_STOPPED:
45 return "SOUND_POOL_STREAM_STATE_STOPPED";
46 case SOUND_POOL_STREAM_STATE_FINISHED:
47 return "SOUND_POOL_STREAM_STATE_FINISHED";
53 static void __al_source_state_cb(ALuint source, ALenum state, ALvoid *data)
57 sound_stream_t *stream = (sound_stream_t *)data;
58 SP_RETM_IF(!stream, "Can't handle stream in OpenAL callback, it is NULL");
59 sound_pool_t *pool = stream->parent_source->parent_pool;
60 SP_RETM_IF(!pool, "Can't handle stream in OpenAL callback, stream's sound "
63 stream->state_previous = stream->state;
67 stream->state = SOUND_POOL_STREAM_STATE_NONE;
70 stream->state = SOUND_POOL_STREAM_STATE_PLAYING;
73 if (pool->state == SOUND_POOL_STATE_INACTIVE) {
74 stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
75 } else if (pool->state == SOUND_POOL_STATE_ACTIVE) {
76 if (stream->suspended) { /* Stream stopped due to priority issue */
77 stream->state = SOUND_POOL_STREAM_STATE_SUSPENDED;
79 stream->state = SOUND_POOL_STREAM_STATE_PAUSED;
85 stream->state = SOUND_POOL_STREAM_STATE_STOPPED;
87 stream->state = SOUND_POOL_STREAM_STATE_FINISHED;
90 SP_ERROR("Invalid OpenAl state value [%#04x]", state);
94 SP_INFO("Stream [%s:%d] state changed from [%s] to [%s]",
95 stream->parent_source->tag_name, stream->id,
96 __stringify_stream_state(stream->state_previous),
97 __stringify_stream_state(stream->state));
99 SP_RETM_IF(_stream_cb_manager_register_event(pool->cbmgr, stream) !=
100 SOUND_POOL_ERROR_NONE, "State changing event wasn't registered."
101 "Callbacks will be not called");
106 static sound_pool_error_e __sound_pool_add_stream(sound_pool_t *pool,
107 sound_stream_t *stream)
110 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
111 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
112 SP_RETVM_IF(!pool->streams, SOUND_POOL_ERROR_INVALID_OPERATION, "Sound "
113 "pool to add the stream is corrupted: NULL streams hash table");
114 stream->id = ++(pool->max_stream_index);
115 SP_DEBUG("Id assigned to the stream is [%u]", stream->id);
116 SP_RETVM_IF(g_hash_table_contains(pool->streams, (gpointer)&stream->id),
117 SOUND_POOL_ERROR_INVALID_PARAMETER,
118 "Stream ID already exists in streams hash table.");
119 SP_RETVM_IF(stream->parent_source->parent_pool != pool,
120 SOUND_POOL_ERROR_INVALID_OPERATION, "Sound stream can't be added "
121 "to the pool different to the pool for which sound stream was created");
123 SP_RETVM_IF(!g_hash_table_insert(pool->streams, (gpointer)&stream->id, stream),
124 SOUND_POOL_ERROR_INVALID_OPERATION, "Error occurred when adding "
125 "the stream [%u] to the sound pool", stream->id);
127 sound_pool_error_e ret =
128 _sound_stream_priority_add_stream(pool->mgr_priority, stream);
129 SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "Error occurred when adding "
130 "the stream [%u] to the priority queue.", stream->id);
133 return SOUND_POOL_ERROR_NONE;
136 static sound_pool_error_e __sound_pool_remove_stream(sound_pool_t *pool, sound_stream_t *stream)
139 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
140 SP_INST_CHECK(pool->mgr_priority, SOUND_POOL_ERROR_INVALID_PARAMETER);
141 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
142 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
144 if (stream->parent_source->parent_pool == pool) {
145 if (!g_hash_table_remove(pool->streams, &stream->id)
146 || SOUND_POOL_ERROR_NONE
147 != _sound_stream_priority_remove_stream(pool->mgr_priority,
149 SP_DEBUG("Id [%u] doesn't exist in streams hash table", stream->id);
151 SP_INFO("[%u] sound stream was removed from pool", stream->id);
153 SP_DEBUG("Stream wasn't removed from sound pool as it isn't known by "
154 "the pool for which operation is performed");
158 return SOUND_POOL_ERROR_NONE;
161 static sound_pool_error_e __sound_stream_init(sound_stream_t *stream,
162 unsigned loop, float volume, unsigned priority, sound_pool_stream_priority_policy_e priority_policy,
163 sound_pool_stream_state_changed_cb cb, void *data)
166 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
169 ret = _sound_stream_set_callback(stream, cb, data);
170 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
171 "Error occurred when setting sound stream callback");
174 ret = _sound_stream_set_loop(stream, loop);
175 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
176 "Error occurred when setting sound stream loop parameter");
178 ret = _sound_stream_set_volume(stream, volume);
179 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
180 "Error occurred when setting sound stream volume parameter");
182 ret = _sound_stream_set_priority(stream, priority);
183 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
184 "Error occurred when setting sound stream priority parameter");
186 ret = _sound_stream_set_priority_policy(stream, priority_policy);
187 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
188 "Error occurred when setting sound stream priority_policy parameter");
194 sound_pool_error_e _sound_stream_create(sound_source_t *src, unsigned loop,
195 float volume, unsigned priority, sound_pool_stream_priority_policy_e priority_policy,
196 sound_pool_stream_state_changed_cb cb,
197 void *data, sound_stream_t **stream)
200 SP_RETVM_IF(!src, SOUND_POOL_ERROR_INVALID_PARAMETER,
201 "Can't create sound stream in NULL sound source");
202 SP_RETVM_IF(!stream, SOUND_POOL_ERROR_INVALID_PARAMETER,
203 "Can't create sound stream. Stream pointer is NULL");
204 SP_RETVM_IF(!src->parent_pool, SOUND_POOL_ERROR_INVALID_PARAMETER,
205 "Can't create sound stream. Source's pool is NULL");
207 SP_RETVM_IF(!alcMakeContextCurrent(src->parent_pool->al_context),
208 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
210 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
211 sound_stream_t *_stream = NULL;
212 SP_RETVM_IF(!(_stream = g_try_malloc0(sizeof(*_stream))),
213 SOUND_POOL_ERROR_OUT_OF_MEMORY,
214 "Memory alloc failure. Can't create sound stream");
216 _stream->parent_source = src;
217 _stream->state_previous = SOUND_POOL_STREAM_STATE_NONE;
218 _stream->state = SOUND_POOL_STREAM_STATE_NONE;
219 _stream->stopped = FALSE;
221 alGenSources((ALsizei)1, &_stream->al_source);
222 if (alGetError() != AL_NO_ERROR) {
223 ret = SOUND_POOL_ERROR_OUT_OF_MEMORY;
224 GOTO_FAIL("OpenAL error occurred when trying to generate OpenAL Source",
228 alSourcei(_stream->al_source, AL_BUFFER, src->al_buffer);
229 if (alGetError() != AL_NO_ERROR) {
230 ret = SOUND_POOL_ERROR_INVALID_OPERATION;
231 GOTO_FAIL("OpenAL error occurred when trying to assign OpenAL Buffer "
232 "to OpenAL Source", cfail);
235 alSourcep(_stream->al_source, AL_SOURCE_STATE_CALLBACK,
236 (ALvoid *)__al_source_state_cb);
237 if (alGetError() != AL_NO_ERROR) {
238 ret = SOUND_POOL_ERROR_INVALID_OPERATION;
239 GOTO_FAIL("OpenAL error occurred when trying to assign OpenAL Callback "
240 "to OpenAL Source", cfail);
243 alSourcep(_stream->al_source, AL_SOURCE_STATE_CALLBACK_DATA, (ALvoid *)_stream);
244 if (alGetError() != AL_NO_ERROR) {
245 ret = SOUND_POOL_ERROR_INVALID_OPERATION;
246 GOTO_FAIL("OpenAL error occurred when trying to assign OpenAL Callback "
247 "Data to OpenAL Source", cfail);
250 ret = __sound_stream_init(_stream, loop, volume, priority, priority_policy, cb, data);
251 if (ret != SOUND_POOL_ERROR_NONE)
252 GOTO_FAIL("Sound stream initialization error occurred", cfail);
254 ret = __sound_pool_add_stream(src->parent_pool, _stream);
255 if (ret != SOUND_POOL_ERROR_NONE)
256 GOTO_FAIL("Error occurred when trying to add source to pool", cfail);
263 if (SOUND_POOL_ERROR_NONE == _sound_stream_destroy(_stream))
266 SP_SAFE_GFREE(_stream);
272 sound_pool_error_e _sound_stream_destroy(sound_stream_t *stream)
275 SP_RETVM_IF(!stream, SOUND_POOL_ERROR_INVALID_PARAMETER,
276 "Can't destroy NULL sound stream");
277 SP_RETVM_IF(!stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER,
278 "Invalid parent source.");
279 SP_RETVM_IF(!stream->parent_source->parent_pool, SOUND_POOL_ERROR_INVALID_PARAMETER,
280 "Empty parent pool pointer.");
282 if (stream->parent_source) {
283 if (__sound_pool_remove_stream(stream->parent_source->parent_pool,
284 stream) != SOUND_POOL_ERROR_NONE)
285 SP_DEBUG("Stream[%s] wasn't removed from sound pool. Continue destroying",
286 stream->parent_source->tag_name);
287 if (alcMakeContextCurrent(stream->parent_source->parent_pool->al_context)) {
288 alSourcei(stream->al_source, AL_BUFFER, 0);
289 alDeleteSources(1, &stream->al_source);
290 SP_DEBUG("Deleting OpenAL source with id [%u]", stream->al_source);
291 if (alGetError() != AL_NO_ERROR)
292 SP_ERROR("OpenAL error while stream[%d] destroying.", stream->id);
294 SP_DEBUG("Can't set current context for deleting OpenAL source with id [%u]",
299 SP_SAFE_GFREE(stream);
302 return SOUND_POOL_ERROR_NONE;
305 sound_pool_error_e _sound_stream_play(sound_stream_t *stream)
308 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
309 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
310 sound_pool_t *pool = stream->parent_source->parent_pool;
311 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
312 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
313 SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_SUSPENDED &&
314 stream->state != SOUND_POOL_STREAM_STATE_PAUSED &&
315 stream->state != SOUND_POOL_STREAM_STATE_NONE,
316 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't play stream[%s] in [%s] "
317 "state", stream->parent_source->tag_name, __stringify_stream_state(stream->state));
318 SP_RETVM_IF(stream->state == SOUND_POOL_STREAM_STATE_SUSPENDED &&
319 pool->state == SOUND_POOL_STATE_INACTIVE,
320 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't play suspended stream "
321 "in inactive sound pool");
323 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
324 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
326 alSourcePlay(stream->al_source);
327 SP_RETVM_IF(alGetError() != AL_NO_ERROR, SOUND_POOL_ERROR_INVALID_OPERATION,
328 "OpenAL error occured when trying to play OpenAL Source");
334 sound_pool_error_e _sound_stream_suspend(sound_stream_t *stream)
337 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
338 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
339 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
340 stream->suspended = TRUE; /* Shows it was stopped due to priority */
341 alSourcePause(stream->al_source);
342 stream->suspended = FALSE;
348 sound_pool_error_e _sound_stream_send_event(sound_stream_t *stream, sound_pool_stream_state_e state)
351 sound_pool_t *pool = stream->parent_source->parent_pool;
352 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
353 stream->state_previous = stream->state;
354 stream->state = state;
355 ret = _stream_cb_manager_register_event(pool->cbmgr, stream);
356 SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "State changing event "
357 "wasn't registered. Callbacks will be not called");
363 sound_pool_error_e _sound_stream_pause(sound_stream_t *stream)
366 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
367 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
368 sound_pool_t *pool = stream->parent_source->parent_pool;
369 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
370 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
371 SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_SUSPENDED &&
372 stream->state != SOUND_POOL_STREAM_STATE_PLAYING,
373 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't pause stream in [%s] "
374 "state", __stringify_stream_state(stream->state));
376 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
377 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
379 if (pool->state == SOUND_POOL_STATE_INACTIVE &&
380 stream->state == SOUND_POOL_STREAM_STATE_SUSPENDED) {
381 ret = _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_PAUSED);
382 SP_INFO("Don't paused due to SoundPool is in inactive state.");
384 alSourcePause(stream->al_source);
391 sound_pool_error_e _sound_stream_resume(sound_stream_t *stream)
394 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
395 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
396 sound_pool_t *pool = stream->parent_source->parent_pool;
397 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
398 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
399 SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_PAUSED,
400 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't resume stream in [%s] "
401 "state", __stringify_stream_state(stream->state));
403 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
404 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
406 if (pool->state == SOUND_POOL_STATE_INACTIVE &&
407 stream->state == SOUND_POOL_STREAM_STATE_PAUSED) {
408 ret = _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_SUSPENDED);
409 SP_INFO("Don't resumed due to SoundPool is in inactive state.");
411 alSourcePlay(stream->al_source);
418 sound_pool_error_e _sound_stream_stop(sound_stream_t *stream)
421 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
422 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
423 sound_pool_t *pool = stream->parent_source->parent_pool;
424 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
425 SP_RETVM_IF(stream->state != SOUND_POOL_STREAM_STATE_PLAYING &&
426 stream->state != SOUND_POOL_STREAM_STATE_SUSPENDED &&
427 stream->state != SOUND_POOL_STREAM_STATE_PAUSED,
428 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't stop stream in [%s] "
429 "state", __stringify_stream_state(stream->state));
431 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
432 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
434 stream->stopped = TRUE;
435 alSourceStop(stream->al_source);
438 return SOUND_POOL_ERROR_NONE;
441 sound_pool_error_e _sound_stream_set_loop(sound_stream_t *stream, unsigned loop)
444 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
445 sound_pool_t *pool = stream->parent_source->parent_pool;
446 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
447 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
448 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
450 alSourcei(stream->al_source, AL_LOOP_COUNT, (ALint)loop);
454 return SOUND_POOL_ERROR_NONE;
457 sound_pool_error_e _sound_stream_set_volume(sound_stream_t *stream, float volume)
460 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
461 SP_RETVM_IF((volume < 0.0f || volume > 1.0f),
462 SOUND_POOL_ERROR_INVALID_PARAMETER,
463 "Volume for sound stream should be in range 0.0..1.0.");
464 sound_pool_t *pool = stream->parent_source->parent_pool;
465 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
466 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
467 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
469 alSourcef(stream->al_source, AL_GAIN, volume);
471 stream->volume = volume;
474 return SOUND_POOL_ERROR_NONE;
477 sound_pool_error_e _sound_stream_set_mute(sound_stream_t *stream, gboolean mute)
481 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
483 sound_pool_t *pool = stream->parent_source->parent_pool;
484 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
485 SP_RETVM_IF(!alcMakeContextCurrent(pool->al_context),
486 SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current context.");
488 alSourcef(stream->al_source, AL_GAIN, ((int)!mute * stream->volume));
492 return SOUND_POOL_ERROR_NONE;
495 sound_pool_error_e _sound_stream_get_volume(sound_stream_t *stream, float *volume)
498 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
499 SP_INST_CHECK(volume, SOUND_POOL_ERROR_INVALID_PARAMETER);
501 *volume = stream->volume;
504 return SOUND_POOL_ERROR_NONE;
507 sound_pool_error_e _sound_stream_get_state(sound_stream_t *stream,
508 sound_pool_stream_state_e *state)
511 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
512 SP_INST_CHECK(state, SOUND_POOL_ERROR_INVALID_PARAMETER);
514 *state = stream->state;
517 SP_DEBUG(" Stream is in Mute.");
520 return SOUND_POOL_ERROR_NONE;
523 sound_pool_error_e _sound_stream_set_priority(sound_stream_t *stream,
527 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
528 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
529 SP_INST_CHECK(stream->parent_source->parent_pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
530 SP_INST_CHECK(stream->parent_source->parent_pool->mgr_priority,
531 SOUND_POOL_ERROR_INVALID_PARAMETER);
532 sound_pool_error_e ret = SOUND_POOL_ERROR_NONE;
534 stream->priority = rank;
535 if (stream->parent_source->parent_pool->state == SOUND_POOL_STATE_INACTIVE) {
536 if (stream->state == SOUND_POOL_STREAM_STATE_NONE) {
537 ret = _sound_stream_send_event(stream, SOUND_POOL_STREAM_STATE_SUSPENDED);
538 SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, "Error occured during"
541 SP_DEBUG("No need to update priority, Sound pool is INACTIVE.");
542 return SOUND_POOL_ERROR_NONE;
545 _sound_stream_priority_update_playback(stream->parent_source->parent_pool->mgr_priority);
548 return SOUND_POOL_ERROR_NONE;
551 sound_pool_error_e _sound_stream_set_priority_policy(sound_stream_t *stream,
552 sound_pool_stream_priority_policy_e priority_policy)
555 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
556 SP_INST_CHECK(stream->parent_source, SOUND_POOL_ERROR_INVALID_PARAMETER);
557 SP_INST_CHECK(stream->parent_source->parent_pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
558 SP_INST_CHECK(stream->parent_source->parent_pool->mgr_priority,
559 SOUND_POOL_ERROR_INVALID_PARAMETER);
561 SP_RETVM_IF((priority_policy > SOUND_POOL_STREAM_PRIORITY_POLICY_SUSPENDED),
562 SOUND_POOL_ERROR_INVALID_PARAMETER,
563 "Priority policy can be 0 or 1.");
566 stream->priority_policy = priority_policy;
568 SP_INFO("Priority policy is %d.", stream->priority_policy);
570 return SOUND_POOL_ERROR_NONE;
573 sound_pool_error_e _sound_stream_get_priority(sound_stream_t *stream,
577 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
578 SP_INST_CHECK(rank, SOUND_POOL_ERROR_INVALID_PARAMETER);
580 *rank = stream->priority;
583 return SOUND_POOL_ERROR_NONE;
586 sound_pool_error_e _sound_stream_set_callback(sound_stream_t *stream,
587 sound_pool_stream_state_changed_cb callback, void *data)
590 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
591 SP_INST_CHECK(callback, SOUND_POOL_ERROR_INVALID_PARAMETER);
593 stream->state_cb_info.callback = callback;
594 stream->state_cb_info.user_data = data;
597 return SOUND_POOL_ERROR_NONE;
600 sound_pool_error_e _sound_pool_get_stream_by_id(sound_pool_t *pool, unsigned id,
601 sound_stream_t **stream)
604 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
605 SP_INST_CHECK(stream, SOUND_POOL_ERROR_INVALID_PARAMETER);
607 SP_RETVM_IF(!pool->streams, SOUND_POOL_ERROR_INVALID_OPERATION, "Corrupted "
608 "sound pool. Sources hash table is NULL");
610 *stream = (sound_stream_t *)g_hash_table_lookup(pool->streams, &id);
611 SP_RETVM_IF(!(*stream), SOUND_POOL_ERROR_KEY_NOT_AVAILABLE, "Tag doesn't "
612 "exist in sources hash table");
615 return SOUND_POOL_ERROR_NONE;