summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaekyu Park <jk7744.park@samsung.com>2016-05-27 16:52:07 +0900
committerJaekyu Park <jk7744.park@samsung.com>2016-05-27 16:52:07 +0900
commit4e22da6c4c00c4ee49746c724e4904a242d7a86c (patch)
treef5a565f115a1ce7fa4c3faa1af38a10e9a79f05a
parentb35c90ecb124f099e5e1f2239d90383671b15f5b (diff)
downloadlibmm-sound-4e22da6c4c00c4ee49746c724e4904a242d7a86c.tar.gz
libmm-sound-4e22da6c4c00c4ee49746c724e4904a242d7a86c.tar.bz2
libmm-sound-4e22da6c4c00c4ee49746c724e4904a242d7a86c.zip
-rw-r--r--mm_sound_pcm.c25
-rw-r--r--mm_sound_pcm_async.c186
-rw-r--r--packaging/libmm-sound.spec2
3 files changed, 143 insertions, 70 deletions
diff --git a/mm_sound_pcm.c b/mm_sound_pcm.c
index cc41e4f..5af3f40 100644
--- a/mm_sound_pcm.c
+++ b/mm_sound_pcm.c
@@ -356,6 +356,9 @@ int mm_sound_pcm_capture_open(MMSoundPcmHandle_t *handle, const unsigned int rat
int errorcode = 0;
int ret_mutex = 0;
int ret = MM_ERROR_NONE;
+ int capture_h_count = 0;
+ int cur_session = MM_SESSION_TYPE_MEDIA;
+ int session_options = 0;
int volume_config = 0;
pa_sample_spec ss;
@@ -454,9 +457,19 @@ int mm_sound_pcm_capture_open(MMSoundPcmHandle_t *handle, const unsigned int rat
if(pcmHandle->handle<0) {
result = pcmHandle->handle;
debug_error("Device Open Error 0x%x\n", result);
+ if (pcmHandle->asm_handle)
+ ASM_unregister_sound(pcmHandle->asm_handle, pcmHandle->asm_event, &errorcode);
PCM_LOCK_DESTROY_INTERNAL(&pcmHandle->pcm_mutex_internal);
free(pcmHandle);
PCM_CAPTURE_H_COUNT_DEC();
+ PCM_CAPTURE_H_COUNT_GET(capture_h_count);
+ if (capture_h_count == 0) {
+ /* read session information */
+ if(_mm_session_util_read_information(-1, &cur_session, &session_options) == 0)
+ if (cur_session == MM_SESSION_TYPE_MEDIA_RECORD)
+ _mm_session_util_write_information(-1, MM_SESSION_TYPE_MEDIA, session_options);
+
+ }
return result;
}
@@ -482,6 +495,9 @@ int mm_sound_pcm_capture_open_ex(MMSoundPcmHandle_t *handle, const unsigned int
int result = MM_ERROR_NONE;
int errorcode = 0;
int ret_mutex = 0;
+ int capture_h_count = 0;
+ int cur_session = MM_SESSION_TYPE_MEDIA;
+ int session_options = 0;
int volume_config = 0;
pa_sample_spec ss;
@@ -598,9 +614,18 @@ int mm_sound_pcm_capture_open_ex(MMSoundPcmHandle_t *handle, const unsigned int
if(pcmHandle->handle<0) {
result = pcmHandle->handle;
debug_error("Device Open Error 0x%x\n", result);
+ if (pcmHandle->asm_handle)
+ ASM_unregister_sound(pcmHandle->asm_handle, pcmHandle->asm_event, &errorcode);
PCM_LOCK_DESTROY_INTERNAL(&pcmHandle->pcm_mutex_internal);
free(pcmHandle);
PCM_CAPTURE_H_COUNT_DEC();
+ PCM_CAPTURE_H_COUNT_GET(capture_h_count);
+ if (capture_h_count == 0) {
+ /* read session information */
+ if(_mm_session_util_read_information(-1, &cur_session, &session_options) == 0)
+ if (cur_session == MM_SESSION_TYPE_MEDIA_RECORD)
+ _mm_session_util_write_information(-1, MM_SESSION_TYPE_MEDIA, session_options);
+ }
return result;
}
diff --git a/mm_sound_pcm_async.c b/mm_sound_pcm_async.c
index 91cf700..cde2aa9 100644
--- a/mm_sound_pcm_async.c
+++ b/mm_sound_pcm_async.c
@@ -62,8 +62,8 @@
#define PCM_UNLOCK_INTERNAL(LOCK) do { pthread_mutex_unlock(LOCK); } while (0)
#define PCM_LOCK_DESTROY_INTERNAL(LOCK) do { pthread_mutex_destroy(LOCK); } while (0)
-#define MAINLOOP_LOCK(LOCK) do { pa_threaded_mainloop_lock(LOCK); debug_msg("MAINLOOP locked"); } while (0)
-#define MAINLOOP_UNLOCK(LOCK) do { pa_threaded_mainloop_unlock(LOCK); debug_msg("MAINLOOP unlocked"); } while (0)
+#define MAINLOOP_LOCK(LOCK) do { pa_threaded_mainloop_lock(LOCK); /*debug_msg("MAINLOOP locked");*/ } while (0)
+#define MAINLOOP_UNLOCK(LOCK) do { pa_threaded_mainloop_unlock(LOCK); /*debug_msg("MAINLOOP unlocked");*/ } while (0)
typedef struct {
int asm_handle;
@@ -613,7 +613,13 @@ int mm_sound_pcm_capture_peek(MMSoundPcmHandle_t handle, const void **buffer, co
goto EXIT;
}
#endif
+ if (!pa_threaded_mainloop_in_thread(pcmHandle->mainloop)) {
+ MAINLOOP_LOCK(pcmHandle->mainloop);
+ }
ret = pa_stream_peek (pcmHandle->s, buffer, (unsigned int *)length);
+ if (!pa_threaded_mainloop_in_thread(pcmHandle->mainloop)) {
+ MAINLOOP_UNLOCK(pcmHandle->mainloop);
+ }
EXIT:
// PCM_UNLOCK_INTERNAL(&pcmHandle->pcm_mutex_internal);
@@ -643,8 +649,14 @@ int mm_sound_pcm_capture_drop(MMSoundPcmHandle_t handle)
goto EXIT;
}
+ if (!pa_threaded_mainloop_in_thread(pcmHandle->mainloop)) {
+ MAINLOOP_LOCK(pcmHandle->mainloop);
+ }
if (pa_stream_drop(pcmHandle->s) != 0)
ret = MM_ERROR_SOUND_INTERNAL;
+ if (!pa_threaded_mainloop_in_thread(pcmHandle->mainloop)) {
+ MAINLOOP_UNLOCK(pcmHandle->mainloop);
+ }
EXIT:
// PCM_UNLOCK_INTERNAL(&pcmHandle->pcm_mutex_internal);
NULL_HANDLE:
@@ -959,11 +971,17 @@ int mm_sound_pcm_play_write_async(MMSoundPcmHandle_t handle, void* ptr, unsigned
}
#endif
/* Write */
-
+ if (!pa_threaded_mainloop_in_thread(pcmHandle->mainloop)) {
+ MAINLOOP_LOCK(pcmHandle->mainloop);
+ }
ret = pa_stream_write(pcmHandle->s, ptr, length_byte, NULL, 0LL, PA_SEEK_RELATIVE);
if (ret == 0) {
ret = length_byte;
}
+ if (!pa_threaded_mainloop_in_thread(pcmHandle->mainloop)) {
+ MAINLOOP_UNLOCK(pcmHandle->mainloop);
+ }
+
EXIT:
// PCM_UNLOCK_INTERNAL(&pcmHandle->pcm_mutex_internal);
NULL_HANDLE:
@@ -1113,6 +1131,17 @@ static void __mm_sound_pa_success_cb(pa_context *c, int success, void *userdata)
pa_threaded_mainloop_signal(handle->mainloop, 0);
}
+static void __mm_sound_pa_success_nosignal_cb(pa_context *c, int success, void *userdata)
+{
+ mm_sound_pcm_async_t* handle = (mm_sound_pcm_async_t*) userdata;
+
+ if (!success) {
+ debug_error("pa control failed: %s\n", pa_strerror(pa_context_errno(c)));
+ } else {
+ debug_msg("pa control success\n");
+ }
+}
+
static void _context_state_cb(pa_context *c, void *userdata)
{
pa_context_state_t state;
@@ -1396,104 +1425,123 @@ 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)
{
- pa_operation *o = NULL;
+ pa_operation *o = NULL;
- MAINLOOP_LOCK(handle->mainloop);
+ if (pa_threaded_mainloop_in_thread(handle->mainloop)) {
+ o = pa_stream_cork(handle->s, cork, (pa_stream_success_cb_t)__mm_sound_pa_success_nosignal_cb, handle);
+ if (o)
+ pa_operation_unref(o);
+ } else {
+ MAINLOOP_LOCK(handle->mainloop);
- o = pa_stream_cork(handle->s, cork, (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);
+ o = pa_stream_cork(handle->s, cork, (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);
+ MAINLOOP_UNLOCK(handle->mainloop);
+ }
- return 0;
+ return 0;
unlock_and_fail:
debug_error ("error!!!!");
- if (o) {
- pa_operation_cancel(o);
- pa_operation_unref(o);
- }
+ if (o) {
+ pa_operation_cancel(o);
+ pa_operation_unref(o);
+ }
- MAINLOOP_UNLOCK(handle->mainloop);
- return -1;
+ MAINLOOP_UNLOCK(handle->mainloop);
+ return -1;
}
static int _mm_sound_pa_drain(mm_sound_pcm_async_t* handle)
{
- pa_operation *o = NULL;
+ pa_operation *o = NULL;
- MAINLOOP_LOCK(handle->mainloop);
+ if (pa_threaded_mainloop_in_thread(handle->mainloop)) {
+ o = pa_stream_drain(handle->s, (pa_stream_success_cb_t)__mm_sound_pa_success_nosignal_cb, handle);
+ if (o)
+ pa_operation_unref(o);
+ } else {
+ MAINLOOP_LOCK(handle->mainloop);
- o = pa_stream_drain(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);
+ o = pa_stream_drain(handle->s, (pa_stream_success_cb_t)__mm_sound_pa_success_cb, handle);
+ if (!(o)) {
+ goto unlock_and_fail;
+ }
+ handle->operation_success = 0;
- MAINLOOP_UNLOCK(handle->mainloop);
+ 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);
- return 0;
+ MAINLOOP_UNLOCK(handle->mainloop);
+ }
+
+ return 0;
unlock_and_fail:
debug_error ("error!!!!");
- if (o) {
- pa_operation_cancel(o);
- pa_operation_unref(o);
- }
+ if (o) {
+ pa_operation_cancel(o);
+ pa_operation_unref(o);
+ }
- MAINLOOP_UNLOCK(handle->mainloop);
- return -1;
+ MAINLOOP_UNLOCK(handle->mainloop);
+ return -1;
}
static int _mm_sound_pa_flush(mm_sound_pcm_async_t* handle)
{
- pa_operation *o = NULL;
+ pa_operation *o = NULL;
- MAINLOOP_LOCK(handle->mainloop);
+ if (pa_threaded_mainloop_in_thread(handle->mainloop)) {
+ o = pa_stream_flush(handle->s, (pa_stream_success_cb_t)__mm_sound_pa_success_nosignal_cb, handle);
+ if (o)
+ pa_operation_unref(o);
+ } else {
+ 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);
+ 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);
+ MAINLOOP_UNLOCK(handle->mainloop);
+ }
- return 0;
+ return 0;
unlock_and_fail:
debug_error ("error!!!!");
- if (o) {
- pa_operation_cancel(o);
- pa_operation_unref(o);
- }
+ if (o) {
+ pa_operation_cancel(o);
+ pa_operation_unref(o);
+ }
- MAINLOOP_UNLOCK(handle->mainloop);
- return -1;
+ 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
index 5badadb..3391164 100644
--- 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.255
+Version: 0.9.258
Release: 0
Group: System/Libraries
License: Apache-2.0