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 public API for the SoundPool.
22 #include "sound_pool.h"
23 #include "sound_pool_private.h"
25 #include "internal/soundpool.h"
26 #include "internal/source.h"
27 #include "internal/stream.h"
30 * Public Implementation
33 static unsigned int sound_pool_amount = 0;
35 sound_pool_error_e sound_pool_create(sound_pool_h *pool)
38 SP_RETVM_IF(SOUND_POOL_MAX_POOLS_AMOUNT < (sound_pool_amount + 1),
39 SOUND_POOL_ERROR_INVALID_OPERATION,
40 "Max pools count should be no more than %d.",
41 SOUND_POOL_MAX_POOLS_AMOUNT);
42 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER);
44 sound_pool_t *_pool = NULL;
45 sound_pool_error_e ret = _sound_pool_create(&_pool);
46 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
47 "Error while creating sound pool instance.");
48 SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_OPERATION);
52 SP_INFO("Number of created pools is [%u]", sound_pool_amount);
58 sound_pool_error_e sound_pool_destroy(sound_pool_h pool)
62 sound_pool_error_e ret = _sound_pool_destroy((sound_pool_t *)pool);
63 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
64 "Error occurred when destroying the sound pool");
66 SP_INFO("Number of pools is [%u]", sound_pool_amount);
72 sound_pool_error_e sound_pool_load_source_from_file(sound_pool_h pool,
73 const char *file_name, const char *tag)
77 sound_pool_t *_pool = (sound_pool_t *)pool;
78 sound_source_t *_src = NULL;
79 sound_pool_error_e ret = _sound_source_create(_pool, tag, &_src);
80 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
81 "Error while creating sound source instance.");
83 ret = _sound_source_load_from_file(_src, file_name);
84 if (ret != SOUND_POOL_ERROR_NONE) {
85 SP_ERROR("Error occurred when loading sound source from file");
86 if (_sound_source_destroy(_src) != SOUND_POOL_ERROR_NONE)
87 SP_ERROR("Error occurred during removal of sound source[%s].", tag);
94 sound_pool_error_e sound_pool_unload_source(sound_pool_h pool, const char *tag)
98 sound_pool_t *_pool = (sound_pool_t *)pool;
99 sound_source_t *_source = NULL;
100 sound_pool_error_e ret = _sound_pool_get_source_by_tag(_pool, tag, &_source);
101 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
102 "getting sound source [%s] from the sound pool", tag);
103 SP_INST_CHECK(_source, SOUND_POOL_ERROR_INVALID_OPERATION);
105 ret = _sound_source_destroy(_source);
106 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
107 "destroying sound source [%s]", tag);
113 sound_pool_error_e sound_pool_stream_play(sound_pool_h pool, const char *tag,
114 unsigned loop, float volume, unsigned priority,
115 sound_pool_stream_state_change_cb callback, void *data, unsigned *id)
118 SP_INST_CHECK(id, SOUND_POOL_ERROR_INVALID_PARAMETER);
120 sound_pool_t *_pool = (sound_pool_t *)pool;
121 sound_source_t *_source = NULL;
122 sound_pool_error_e ret = _sound_pool_get_source_by_tag(_pool, tag, &_source);
123 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
124 "getting sound source [%s] from the sound pool", tag);
125 SP_INST_CHECK(_source, SOUND_POOL_ERROR_INVALID_OPERATION);
127 sound_stream_t *_stream = NULL;
128 ret = _sound_stream_create(_source, &_stream);
129 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret,
130 "Error while creating sound source instance.");
132 ret = _sound_stream_set_loop(_stream, loop);
133 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
134 "setting sound stream loop parameter", tag);
136 ret = _sound_stream_set_volume(_stream, volume);
137 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
138 "setting sound stream volume parameter", tag);
141 ret = _sound_stream_set_callback(_stream, callback, data);
142 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
143 "setting sound stream callback", tag);
146 ret = _sound_stream_set_priority(_stream, priority);
147 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
148 "setting sound stream priority parameter", tag);
156 sound_pool_error_e sound_pool_stream_pause(sound_pool_h pool, unsigned id)
160 sound_pool_t *_pool = (sound_pool_t *)pool;
161 sound_stream_t *_stream = NULL;
162 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
163 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
164 "getting sound stream [%u] from the sound pool", id);
165 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
167 ret = _sound_stream_pause(_stream);
168 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
169 "pausing sound stream [%u]", id);
175 sound_pool_error_e sound_pool_stream_resume(sound_pool_h pool, unsigned id)
178 sound_pool_t *_pool = (sound_pool_t *)pool;
179 sound_stream_t *_stream = NULL;
180 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
181 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
182 "getting sound stream [%u] from the sound pool", id);
183 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
185 ret = _sound_stream_resume(_stream);
186 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
187 "resuming sound stream [%u]", id);
193 sound_pool_error_e sound_pool_stream_stop(sound_pool_h pool, unsigned id)
197 sound_pool_t *_pool = (sound_pool_t *)pool;
198 sound_stream_t *_stream = NULL;
199 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
200 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
201 "getting sound stream [%u] from the sound pool", id);
202 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
204 ret = _sound_stream_stop(_stream);
205 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
206 "stopping sound stream [%u]", id);
212 sound_pool_error_e sound_pool_get_state(sound_pool_h pool, sound_pool_state_e *state)
216 sound_pool_error_e ret = _sound_pool_get_state(pool, state);
217 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
218 "getting state of the sound pool");
224 sound_pool_error_e sound_pool_activate(sound_pool_h pool)
228 sound_pool_error_e ret = _sound_pool_activate((sound_pool_t *)pool);
229 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
230 "activating sound pool");
236 sound_pool_error_e sound_pool_deactivate(sound_pool_h pool)
240 sound_pool_error_e ret = _sound_pool_deactivate((sound_pool_t *)pool);
241 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
242 "deactivating sound pool");
248 sound_pool_error_e sound_pool_set_volume(sound_pool_h pool, float volume)
252 sound_pool_error_e ret = _sound_pool_set_volume((sound_pool_t *)pool, volume);
253 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
254 "setting volume for sound pool");
260 sound_pool_error_e sound_pool_get_volume(sound_pool_h pool, float *volume)
264 sound_pool_error_e ret = _sound_pool_get_volume((sound_pool_t *)pool, volume);
265 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
266 "getting volume for sound pool");
272 sound_pool_error_e sound_pool_stream_get_state(sound_pool_h pool, unsigned id,
273 sound_pool_stream_state_e *state)
277 sound_pool_t *_pool = (sound_pool_t *)pool;
278 sound_stream_t *_stream = NULL;
279 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
280 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
281 "getting sound stream [%u] from the sound pool", id);
282 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
284 ret = _sound_stream_get_state(_stream, state);
285 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
286 "getting sound stream [%u] state", id);
292 sound_pool_error_e sound_pool_stream_set_loop(sound_pool_h pool, unsigned id,
297 sound_pool_t *_pool = (sound_pool_t *)pool;
298 sound_stream_t *_stream = NULL;
299 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
300 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
301 "getting sound stream [%u] from the sound pool", id);
302 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
304 ret = _sound_stream_set_loop(_stream, loop);
305 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
306 "setting sound stream [%u] loop parameter", id);
312 sound_pool_error_e sound_pool_stream_get_loop(sound_pool_h pool, unsigned id,
317 sound_pool_t *_pool = (sound_pool_t *)pool;
318 sound_stream_t *_stream = NULL;
319 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
320 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
321 "getting sound stream [%u] from the sound pool", id);
322 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
324 ret = _sound_stream_get_loop(_stream, loop);
325 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
326 "getting sound stream [%u] loop parameter", id);
332 sound_pool_error_e sound_pool_stream_set_volume(sound_pool_h pool, unsigned id,
337 sound_pool_t *_pool = (sound_pool_t *)pool;
338 sound_stream_t *_stream = NULL;
339 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
340 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
341 "getting sound stream [%u] from the sound pool", id);
342 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
344 ret = _sound_stream_set_volume(_stream, volume);
345 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
346 "setting sound stream [%u] volume parameter", id);
352 sound_pool_error_e sound_pool_stream_get_volume(sound_pool_h pool, unsigned id,
357 sound_pool_t *_pool = (sound_pool_t *)pool;
358 sound_stream_t *_stream = NULL;
359 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
360 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
361 "getting sound stream [%u] from the sound pool", id);
362 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
364 ret = _sound_stream_get_volume(_stream, volume);
365 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
366 "getting sound stream [%u] volume parameter", id);
372 sound_pool_error_e sound_pool_stream_set_priority(sound_pool_h pool,
373 unsigned id, unsigned priority)
377 sound_pool_t *_pool = (sound_pool_t *)pool;
378 sound_stream_t *_stream = NULL;
379 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
380 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
381 "getting sound stream [%u] from the sound pool", id);
382 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
384 ret = _sound_stream_set_priority(_stream, priority);
385 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
386 "setting sound stream [%u] priority parameter", id);
392 sound_pool_error_e sound_pool_stream_get_priority(sound_pool_h pool,
393 unsigned id, unsigned *priority)
397 sound_pool_t *_pool = (sound_pool_t *)pool;
398 sound_stream_t *_stream = NULL;
399 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
400 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
401 "getting sound stream [%u] from the sound pool", id);
402 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
404 ret = _sound_stream_get_priority(_stream, priority);
405 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
406 "getting sound stream [%u] priority parameter", id);
412 sound_pool_error_e sound_pool_set_state_change_callback(sound_pool_h pool,
413 sound_pool_state_change_cb callback, void *data)
417 sound_pool_error_e ret = _sound_pool_set_callback((sound_pool_t *)pool, callback, data);
418 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
419 "setting state changing callback for sound pool");
425 sound_pool_error_e sound_pool_unset_state_change_callback(sound_pool_h pool)
429 sound_pool_error_e ret = _sound_pool_unset_callback((sound_pool_t *)pool);
430 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
431 "unsetting state changing callback for sound pool");
437 sound_pool_error_e sound_pool_stream_set_state_change_callback(
438 sound_pool_h pool, unsigned id,
439 sound_pool_stream_state_change_cb callback, void *data)
443 sound_pool_t *_pool = (sound_pool_t *)pool;
444 sound_stream_t *_stream = NULL;
445 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
446 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
447 "getting sound stream [%u] from the sound pool", id);
448 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
450 ret = _sound_stream_set_callback(_stream, callback, data);
451 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
452 "setting sound stream [%u] state changing callback", id);
458 sound_pool_error_e sound_pool_stream_unset_state_change_callback(
459 sound_pool_h pool, unsigned id)
463 sound_pool_t *_pool = (sound_pool_t *)pool;
464 sound_stream_t *_stream = NULL;
465 sound_pool_error_e ret = _sound_pool_get_stream_by_id(_pool, id, &_stream);
466 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
467 "getting sound stream [%u] from the sound pool", id);
468 SP_INST_CHECK(_stream, SOUND_POOL_ERROR_INVALID_OPERATION);
470 ret = _sound_stream_unset_callback(_stream);
471 SP_RETVM_IF(ret != SOUND_POOL_ERROR_NONE, ret, "Error occurred when "
472 "unsetting sound stream [%u] state changing callback", id);