From: Ievgen Vagin Date: Wed, 31 Aug 2016 17:08:24 +0000 (+0300) Subject: Isolated ALURE/ALUT source loading logic, avoided usage of deprecated alutLoadWAVFile() X-Git-Tag: submit/tizen/20160921.041639~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f967781d3315e6cc44272ee10286c0e50b49de54;p=platform%2Fcore%2Fapi%2Fsound-pool.git Isolated ALURE/ALUT source loading logic, avoided usage of deprecated alutLoadWAVFile() Change-Id: I8c74ac0a7eb0bec149596838dcd3c05ec8397746 Signed-off-by: Ievgen Vagin --- diff --git a/src/source.c b/src/source.c index 09f6906..21de78d 100644 --- a/src/source.c +++ b/src/source.c @@ -23,15 +23,17 @@ #include "internal/source.h" #include "internal/stream.h" +#include #include #ifdef ENABLE_ALURE # include #endif -static int __sound_pool_add_source(sound_pool_t *pool, sound_source_t *src); -static int __sound_pool_remove_source(sound_pool_t *pool, sound_source_t *src); +static sound_pool_error_e __sound_pool_add_source(sound_pool_t *pool, sound_source_t *src); +static sound_pool_error_e __sound_pool_remove_source(sound_pool_t *pool, sound_source_t *src); +static sound_pool_error_e __probe_file_access(const char *file, int amode); -static int __sound_pool_add_source(sound_pool_t *pool, sound_source_t *src) +static sound_pool_error_e __sound_pool_add_source(sound_pool_t *pool, sound_source_t *src) { SP_DEBUG_FENTER(); SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER); @@ -55,7 +57,7 @@ static int __sound_pool_add_source(sound_pool_t *pool, sound_source_t *src) return SOUND_POOL_ERROR_NONE; } -static int __sound_pool_remove_source(sound_pool_t *pool, sound_source_t *src) +static sound_pool_error_e __sound_pool_remove_source(sound_pool_t *pool, sound_source_t *src) { SP_DEBUG_FENTER(); SP_INST_CHECK(pool, SOUND_POOL_ERROR_INVALID_PARAMETER); @@ -90,6 +92,30 @@ static int __sound_pool_remove_source(sound_pool_t *pool, sound_source_t *src) return SOUND_POOL_ERROR_NONE; } +/* file parameter should be not-NULL and not empty c-string */ +static sound_pool_error_e __probe_file_access(const char *file, int amode) +{ + SP_DEBUG_FENTER(); + sound_pool_error_e ret = SOUND_POOL_ERROR_NONE; + + if (-1 == access(file, amode)) { + char errmsg[256]; + strerror_r(errno, errmsg, sizeof(errmsg)); + SP_ERROR("Couldn`t open file in [%i] mode, reason [%s].", amode, errmsg); + if (EACCES == errno) + ret = SOUND_POOL_ERROR_PERMISSION_DENIED; + else if (ENOENT == errno) + ret = SOUND_POOL_ERROR_NO_SUCH_FILE; + else + ret = SOUND_POOL_ERROR_INVALID_OPERATION; + SP_DEBUG_FLEAVE(); + return ret; + } + + SP_DEBUG_FLEAVE(); + return ret; +} + sound_pool_error_e _sound_source_create(sound_pool_t *pool, const char *tag, sound_source_t **src) { @@ -177,39 +203,29 @@ sound_pool_error_e _sound_source_load_from_file(sound_source_t *src, SP_RETVM_IF(!alcMakeContextCurrent(src->parent_pool->al_context), SOUND_POOL_ERROR_INVALID_OPERATION, "Can't set current AL context."); - sound_pool_error_e ret = SOUND_POOL_ERROR_NONE; - ALenum format; - ALsizei size; - ALvoid* data = NULL; - ALsizei freq; - ALboolean loop; + sound_pool_error_e ret = __probe_file_access(fname, R_OK); + SP_RETVM_IF(SOUND_POOL_ERROR_NONE != ret, ret, + "Can't load source from [%s] file.", fname); - alutLoadWAVFile((ALbyte*)fname, &format, &data, &size, &freq, &loop); + ALuint buffer_handle = AL_NONE; + src->al_buffer = AL_NONE; #ifdef ENABLE_ALURE - if (alGetError() != AL_NO_ERROR || !data) { - if (alureBufferDataFromFile(fname, src->al_buffer) == AL_FALSE) { - src->al_buffer = AL_NONE; - SP_ERROR("Can't load audio file. No such file [%s]", fname); - ret = SOUND_POOL_ERROR_NO_SUCH_FILE; - } - SP_DEBUG_FLEAVE(); - return ret; - } + buffer_handle = alureCreateBufferFromFile((const ALchar *)fname); + SP_RETVM_IF(buffer_handle == AL_NONE, SOUND_POOL_ERROR_INVALID_OPERATION, + "Can't load audio file [%s]. Error message [%s]", fname, + alureGetErrorString()); #else - SP_RETVM_IF(alGetError() != AL_NO_ERROR || !data, - SOUND_POOL_ERROR_NO_SUCH_FILE, "Can't load audio file. No such " - "file [%s]", fname); + alutInitWithoutContext(NULL, NULL); + buffer_handle = alutCreateBufferFromFile(fname); + ALenum error = alutGetError(); + alutExit(); + SP_RETVM_IF(error != ALUT_ERROR_NO_ERROR || buffer_handle == AL_NONE, + SOUND_POOL_ERROR_INVALID_OPERATION, "Can't load audio file [%s]. " + "Error message [%s]", fname, alutGetErrorString(error)); #endif - alBufferData(src->al_buffer, format, data, size, freq); - if (alGetError() != AL_NO_ERROR) { - SP_ERROR("Can't create audio buffer from file [%s]", fname); - ret = SOUND_POOL_ERROR_INVALID_OPERATION; - } - - alutUnloadWAV(format, data, size, freq); - + src->al_buffer = buffer_handle; SP_DEBUG_FLEAVE(); return ret; } diff --git a/src/stream.c b/src/stream.c index eefe07f..453e847 100644 --- a/src/stream.c +++ b/src/stream.c @@ -473,7 +473,7 @@ sound_pool_error_e _sound_stream_set_priority(sound_stream_t *stream, 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, + 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");