From 3fda82e71fa95cc011c080dc4af0fed328fce263 Mon Sep 17 00:00:00 2001 From: KimJeongYeon Date: Tue, 2 Jun 2015 14:49:22 +0900 Subject: [PATCH] libmm-sound add drain/flush APIs [Version] 0.9.184 [Profile] Common [Issue Type] Add features [Dependency module] NA [Dependency commit] NA [Comment] + mm_sound_pcm_capture_flush_async() + mm_sound_pcm_capture_flush() + mm_sound_pcm_play_drain_async() + mm_sound_pcm_play_drain() + mm_sound_pcm_play_flush_async() + mm_sound_pcm_play_flush() Signed-off-by: KimJeongYeon Change-Id: I2a85893ffe800d3ec1c7d63ce702523e9b6ff6ab --- include/mm_sound.h | 42 ++++++++++++++++++++ include/mm_sound_pa_client.h | 1 + include/mm_sound_pcm_async.h | 3 ++ mm_sound_pa_client.c | 19 +++++++++ mm_sound_pcm.c | 51 ++++++++++++++++++++++++ mm_sound_pcm_async.c | 94 ++++++++++++++++++++++++++++++++++++++++++++ packaging/libmm-sound.spec | 2 +- 7 files changed, 211 insertions(+), 1 deletion(-) mode change 100755 => 100644 packaging/libmm-sound.spec diff --git a/include/mm_sound.h b/include/mm_sound.h index 2cdec83..fdd7969 100644 --- a/include/mm_sound.h +++ b/include/mm_sound.h @@ -1018,6 +1018,34 @@ int mm_sound_pcm_play_start(MMSoundPcmHandle_t handle); int mm_sound_pcm_play_stop(MMSoundPcmHandle_t handle); /** + * This function flush pcm playback + * + * @param handle [in] handle to flush playback + * + * @return This function returns MM_ERROR_NONE on success, or negative value + * with error code. + * @remark + * @see + * @pre PCM playback handle should be allocated. + * @post PCM playback data will not be buffered. + */ +int mm_sound_pcm_play_drain(MMSoundPcmHandle_t handle); + +/** + * This function flush pcm playback + * + * @param handle [in] handle to flush playback + * + * @return This function returns MM_ERROR_NONE on success, or negative value + * with error code. + * @remark + * @see + * @pre PCM playback handle should be allocated. + * @post PCM playback data will not be buffered. + */ +int mm_sound_pcm_play_flush(MMSoundPcmHandle_t handle); + +/** * This function is to play PCM memory buffer. * * @param handle [in] handle to play pcm data @@ -1351,6 +1379,20 @@ int mm_sound_pcm_capture_start(MMSoundPcmHandle_t handle); int mm_sound_pcm_capture_stop(MMSoundPcmHandle_t handle); /** + * This function flush pcm capture + * + * @param handle [in] handle to flush capture + * + * @return This function returns MM_ERROR_NONE on success, or negative value + * with error code. + * @remark + * @see + * @pre PCM capture handle should be allocated. + * @post PCM capture data will not be buffered. + */ +int mm_sound_pcm_capture_flush(MMSoundPcmHandle_t handle); + +/** * This function captures PCM to memory buffer. (Samsung extension) * * @param handle [in] handle to play pcm data diff --git a/include/mm_sound_pa_client.h b/include/mm_sound_pa_client.h index 9728c7f..13c7d64 100644 --- a/include/mm_sound_pa_client.h +++ b/include/mm_sound_pa_client.h @@ -78,6 +78,7 @@ int mm_sound_pa_write(const int handle, void* buf, const int size); int mm_sound_pa_close(const int handle); int mm_sound_pa_cork(const int handle, const int cork); int mm_sound_pa_drain(const int handle); +int mm_sound_pa_flush(const int handle); int mm_sound_pa_set_volume_by_type(const int type, const int value); int mm_sound_pa_get_latency(const int handle, int* latency); int mm_sound_pa_set_call_mute(const int type, const int mute, int direction); diff --git a/include/mm_sound_pcm_async.h b/include/mm_sound_pcm_async.h index 4f3eff6..74322d8 100644 --- a/include/mm_sound_pcm_async.h +++ b/include/mm_sound_pcm_async.h @@ -34,6 +34,7 @@ int mm_sound_pcm_capture_open_async(MMSoundPcmHandle_t *handle, const unsigned i mm_sound_pcm_stream_cb_t callback, void* userdata); int mm_sound_pcm_capture_start_async(MMSoundPcmHandle_t handle); int mm_sound_pcm_capture_stop_async(MMSoundPcmHandle_t handle); +int mm_sound_pcm_capture_flush_async(MMSoundPcmHandle_t handle); int mm_sound_pcm_capture_peek(MMSoundPcmHandle_t handle, const void **buffer, const unsigned int *length); int mm_sound_pcm_capture_drop(MMSoundPcmHandle_t handle); int mm_sound_pcm_capture_close_async(MMSoundPcmHandle_t handle); @@ -44,6 +45,8 @@ int mm_sound_pcm_play_open_async (MMSoundPcmHandle_t *handle, const unsigned int mm_sound_pcm_stream_cb_t callback, void* userdata); int mm_sound_pcm_play_start_async(MMSoundPcmHandle_t handle); int mm_sound_pcm_play_stop_async(MMSoundPcmHandle_t handle); +int mm_sound_pcm_play_drain_async(MMSoundPcmHandle_t handle); +int mm_sound_pcm_play_flush_async(MMSoundPcmHandle_t handle); int mm_sound_pcm_play_write_async(MMSoundPcmHandle_t handle, void* ptr, unsigned int length_byte); int mm_sound_pcm_play_close_async(MMSoundPcmHandle_t handle); diff --git a/mm_sound_pa_client.c b/mm_sound_pa_client.c index 736afe8..3a4cefb 100644 --- a/mm_sound_pa_client.c +++ b/mm_sound_pa_client.c @@ -687,6 +687,25 @@ int mm_sound_pa_drain(const int handle) } EXPORT_API +int mm_sound_pa_flush(const int handle) +{ + mm_sound_handle_t* phandle = NULL; + int err = MM_ERROR_NONE; + + CHECK_HANDLE_RANGE(handle); + GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc); + if(phandle == NULL) + return MM_ERROR_SOUND_INTERNAL; + + if (0 > pa_simple_flush(phandle->s, &err)) { + debug_error("pa_simple_flush() failed with %s\n", pa_strerror(err)); + err = MM_ERROR_SOUND_INTERNAL; + } + + return err; +} + +EXPORT_API int mm_sound_pa_get_latency(const int handle, int* latency) { mm_sound_handle_t* phandle = NULL; diff --git a/mm_sound_pcm.c b/mm_sound_pcm.c index 4fcc086..c1f13bc 100644 --- a/mm_sound_pcm.c +++ b/mm_sound_pcm.c @@ -761,6 +761,23 @@ int mm_sound_pcm_capture_stop(MMSoundPcmHandle_t handle) } EXPORT_API +int mm_sound_pcm_capture_flush(MMSoundPcmHandle_t handle) +{ + int ret = 0; + mm_sound_pcm_t *pcmHandle = (mm_sound_pcm_t*)handle; + + /* Check input param */ + if(pcmHandle == NULL) + return MM_ERROR_INVALID_ARGUMENT; + + debug_warning ("enter : handle=[%p]\n", handle); + ret = mm_sound_pa_flush(pcmHandle->handle); + debug_warning ("leave : handle=[%p], ret=[0x%X]\n", handle, ret); + + return ret; +} + +EXPORT_API int mm_sound_pcm_capture_read(MMSoundPcmHandle_t handle, void *buffer, const unsigned int length ) { int ret = 0; @@ -1083,6 +1100,40 @@ int mm_sound_pcm_play_stop(MMSoundPcmHandle_t handle) } EXPORT_API +int mm_sound_pcm_play_drain(MMSoundPcmHandle_t handle) +{ + int ret = 0; + mm_sound_pcm_t *pcmHandle = (mm_sound_pcm_t*)handle; + + /* Check input param */ + if(pcmHandle == NULL) + return MM_ERROR_INVALID_ARGUMENT; + + debug_warning ("enter : handle=[%p]\n", handle); + ret = mm_sound_pa_drain(pcmHandle->handle); + debug_warning ("leave : handle=[%p], ret=[0x%X]\n", handle, ret); + + return ret; +} + +EXPORT_API +int mm_sound_pcm_play_flush(MMSoundPcmHandle_t handle) +{ + int ret = 0; + mm_sound_pcm_t *pcmHandle = (mm_sound_pcm_t*)handle; + + /* Check input param */ + if(pcmHandle == NULL) + return MM_ERROR_INVALID_ARGUMENT; + + debug_warning ("enter : handle=[%p]\n", handle); + ret = mm_sound_pa_flush(pcmHandle->handle); + debug_warning ("leave : handle=[%p], ret=[0x%X]\n", handle, ret); + + return ret; +} + +EXPORT_API int mm_sound_pcm_play_write(MMSoundPcmHandle_t handle, void* ptr, unsigned int length_byte) { int ret = 0; diff --git a/mm_sound_pcm_async.c b/mm_sound_pcm_async.c index add7b17..6db311a 100644 --- a/mm_sound_pcm_async.c +++ b/mm_sound_pcm_async.c @@ -101,6 +101,7 @@ static int mm_sound_pa_open(mm_sound_pcm_async_t* handle, int mode, int policy, static int _mm_sound_pa_close(mm_sound_pcm_async_t* handle); static int _mm_sound_pa_cork(mm_sound_pcm_async_t* handle, int cork); static int _mm_sound_pa_drain(mm_sound_pcm_async_t* handle); +static int _mm_sound_pa_flush(mm_sound_pcm_async_t* handle); static int _mm_sound_pa_get_latency(mm_sound_pcm_async_t* handle, int* latency);; static void __mm_sound_pa_success_cb(pa_context *c, int success, void *userdata); @@ -561,6 +562,26 @@ int mm_sound_pcm_capture_stop_async(MMSoundPcmHandle_t handle) } EXPORT_API +int mm_sound_pcm_capture_flush_async(MMSoundPcmHandle_t handle) +{ + int ret = 0; + mm_sound_pcm_async_t *pcmHandle = (mm_sound_pcm_async_t*)handle; + + /* Check input param */ + if(pcmHandle == NULL) { + debug_error ("Handle is null, return Invalid Argument\n"); + ret = MM_ERROR_INVALID_ARGUMENT; + return ret; + } + + debug_warning ("enter : handle=[%p]\n", handle); + ret = _mm_sound_pa_flush(handle); + debug_warning ("leave : handle=[%p], ret=[0x%X]\n", handle, ret); + + return ret; +} + +EXPORT_API int mm_sound_pcm_capture_peek(MMSoundPcmHandle_t handle, const void **buffer, const unsigned int *length) { int ret = 0; @@ -865,6 +886,46 @@ int mm_sound_pcm_play_stop_async(MMSoundPcmHandle_t handle) } EXPORT_API +int mm_sound_pcm_play_drain_async(MMSoundPcmHandle_t handle) +{ + int ret = 0; + mm_sound_pcm_async_t *pcmHandle = (mm_sound_pcm_async_t*)handle; + + /* Check input param */ + if(pcmHandle == NULL) { + debug_error ("Handle is null, return Invalid Argument\n"); + ret = MM_ERROR_INVALID_ARGUMENT; + return ret; + } + + debug_warning ("enter : handle=[%p]\n", handle); + ret = _mm_sound_pa_drain(handle); + debug_warning ("leave : handle=[%p], ret=[0x%X]\n", handle, ret); + + return ret; +} + +EXPORT_API +int mm_sound_pcm_play_flush_async(MMSoundPcmHandle_t handle) +{ + int ret = 0; + mm_sound_pcm_async_t *pcmHandle = (mm_sound_pcm_async_t*)handle; + + /* Check input param */ + if(pcmHandle == NULL) { + debug_error ("Handle is null, return Invalid Argument\n"); + ret = MM_ERROR_INVALID_ARGUMENT; + return ret; + } + + debug_warning ("enter : handle=[%p]\n", handle); + ret = _mm_sound_pa_flush(handle); + debug_warning ("leave : handle=[%p], ret=[0x%X]\n", handle, ret); + + return ret; +} + +EXPORT_API int mm_sound_pcm_play_write_async(MMSoundPcmHandle_t handle, void* ptr, unsigned int length_byte) { int ret = 0; @@ -1413,6 +1474,39 @@ unlock_and_fail: return -1; } +static int _mm_sound_pa_flush(mm_sound_pcm_async_t* handle) +{ + pa_operation *o = NULL; + + MAINLOOP_LOCK(handle->mainloop); + + o = pa_stream_flush(handle->s, (pa_stream_success_cb_t)__mm_sound_pa_success_cb, handle); + if (!(o)) { + goto unlock_and_fail; + } + handle->operation_success = 0; + while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) { + pa_threaded_mainloop_wait(handle->mainloop); + } + if (!(handle->operation_success)) { + goto unlock_and_fail; + } + pa_operation_unref(o); + + MAINLOOP_UNLOCK(handle->mainloop); + + return 0; + +unlock_and_fail: + debug_error ("error!!!!"); + if (o) { + pa_operation_cancel(o); + pa_operation_unref(o); + } + + MAINLOOP_UNLOCK(handle->mainloop); + return -1; +} static int _mm_sound_pa_get_latency(mm_sound_pcm_async_t* handle, int* latency) { diff --git a/packaging/libmm-sound.spec b/packaging/libmm-sound.spec old mode 100755 new mode 100644 index 539d86c..7831b9e --- a/packaging/libmm-sound.spec +++ b/packaging/libmm-sound.spec @@ -1,6 +1,6 @@ Name: libmm-sound Summary: MMSound Package contains client lib and sound_server binary -Version: 0.9.183 +Version: 0.9.184 Release: 0 Group: System/Libraries License: Apache-2.0 -- 2.7.4