From 4aeac85e78ef15509efeef6cabbab5317fd9f217 Mon Sep 17 00:00:00 2001 From: KimJeongYeon Date: Tue, 2 Jun 2015 14:58:33 +0900 Subject: [PATCH] audio-io add drain/flush APIs [Version] 0.2.2 [Profile] Common [Issue Type] Add features [Dependency module] libmm-sound [Dependency commit] e8195430f9822760bbb469b48bd5cab807202dec [Comment] + audio_in_flush() + audio_out_drain() + audio_out_flush() Signed-off-by: KimJeongYeon Change-Id: Ib9898c3a0420af9ba6480cea3d0299bacdc46160 --- include/audio_io.h | 57 ++++++++++++++++++++++++++++-- packaging/capi-media-audio-io.spec | 2 +- src/audio_io.c | 45 +++++++++++++++++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) mode change 100755 => 100644 src/audio_io.c diff --git a/include/audio_io.h b/include/audio_io.h index 0b237cf..b797d2d 100644 --- a/include/audio_io.h +++ b/include/audio_io.h @@ -263,6 +263,23 @@ int audio_in_prepare(audio_in_h input); */ int audio_in_unprepare(audio_in_h input); +/** + * @brief Flushes and discards buffered audio data from the input stream. + * + * @since_tizen 2.4 + * + * @param[in] input The handle to the audio input + * @return @c 0 on success, + * otherwise a negative error value + * @retval #AUDIO_IO_ERROR_NONE Successful + * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported + * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state + * + * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED. + */ +int audio_in_flush(audio_in_h input); + /** * @brief Reads audio data from the audio input buffer. * @@ -271,7 +288,7 @@ int audio_in_unprepare(audio_in_h input); * @param[in] input The handle to the audio input * @param[out] buffer The PCM buffer address * @param[in] length The length of the PCM data buffer (in bytes) - * @return The number of read bytes on success, + * @return The number of read bytes on success, * otherwise a negative error value * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer @@ -589,6 +606,42 @@ int audio_out_prepare(audio_out_h output); */ int audio_out_unprepare(audio_out_h output); +/** + * @brief Drains buffered audio data from the output stream. + * + * @details This function waits until drains stream buffer completely. (e.g end of playback) + * + * @since_tizen 2.4 + * + * @param[in] output The handle to the audio output + * @return @c 0 on success, + * otherwise a negative error value + * @retval #AUDIO_IO_ERROR_NONE Successful + * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state + * + * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED. + * @see audio_out_flush() + */ +int audio_out_drain(audio_out_h output); + +/** + * @brief Flushes and discards buffered audio data from the output stream. + * + * @since_tizen 2.4 + * + * @param[in] output The handle to the audio output + * @return @c 0 on success, + * otherwise a negative error value + * @retval #AUDIO_IO_ERROR_NONE Successful + * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state + * + * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED. + * @see audio_out_drain() + */ +int audio_out_flush(audio_out_h output); + /** * @brief Starts writing the audio data to the device. * @@ -597,7 +650,7 @@ int audio_out_unprepare(audio_out_h output); * @param[in] output The handle to the audio output * @param[in,out] buffer The PCM buffer address * @param[in] length The length of the PCM buffer (in bytes) - * @return The written data size on success, + * @return The written data size on success, * otherwise a negative error value * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer diff --git a/packaging/capi-media-audio-io.spec b/packaging/capi-media-audio-io.spec index 92118a3..fe26901 100644 --- a/packaging/capi-media-audio-io.spec +++ b/packaging/capi-media-audio-io.spec @@ -1,6 +1,6 @@ Name: capi-media-audio-io Summary: An Audio Input & Audio Output library in Tizen Native API -Version: 0.2.1 +Version: 0.2.2 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/audio_io.c b/src/audio_io.c old mode 100755 new mode 100644 index 8ed0cee..6b29ada --- a/src/audio_io.c +++ b/src/audio_io.c @@ -94,6 +94,21 @@ int audio_in_unprepare(audio_in_h input) return AUDIO_IO_ERROR_NONE; } +int audio_in_flush(audio_in_h input) +{ + AUDIO_IO_NULL_ARG_CHECK(input); + audio_in_s *handle = (audio_in_s *) input; + int ret = MM_ERROR_NONE; + + ret = mm_sound_pcm_capture_flush(handle->mm_handle); + if (ret != MM_ERROR_NONE) { + return __convert_audio_io_error_code(ret, (char*)__FUNCTION__); + } + + LOGI("[%s] mm_sound_pcm_capture_flush() success",__FUNCTION__); + return AUDIO_IO_ERROR_NONE; +} + int audio_in_read(audio_in_h input, void *buffer, unsigned int length ) { AUDIO_IO_NULL_ARG_CHECK(input); @@ -286,6 +301,36 @@ int audio_out_unprepare(audio_out_h output) return AUDIO_IO_ERROR_NONE; } +int audio_out_drain(audio_out_h output) +{ + AUDIO_IO_NULL_ARG_CHECK(output); + audio_out_s *handle = (audio_out_s *) output; + int ret = MM_ERROR_NONE; + + ret = mm_sound_pcm_play_drain(handle->mm_handle); + if (ret != MM_ERROR_NONE) { + return __convert_audio_io_error_code(ret, (char*)__FUNCTION__); + } + + LOGI("[%s] mm_sound_pcm_play_drain() success",__FUNCTION__); + return AUDIO_IO_ERROR_NONE; +} + +int audio_out_flush(audio_out_h output) +{ + AUDIO_IO_NULL_ARG_CHECK(output); + audio_out_s *handle = (audio_out_s *) output; + int ret = MM_ERROR_NONE; + + ret = mm_sound_pcm_play_flush(handle->mm_handle); + if (ret != MM_ERROR_NONE) { + return __convert_audio_io_error_code(ret, (char*)__FUNCTION__); + } + + LOGI("[%s] mm_sound_pcm_play_flush() success",__FUNCTION__); + return AUDIO_IO_ERROR_NONE; +} + int audio_out_write(audio_out_h output, void* buffer, unsigned int length) { AUDIO_IO_NULL_ARG_CHECK(output); -- 2.34.1