summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunjin Park <hyunjin45.park@samsung.com>2015-10-12 18:14:26 +0900
committerHyunjin Park <hyunjin45.park@samsung.com>2015-10-22 17:28:38 +0900
commit8f0367bb9c78c5c207d0e83824829fe638d8fc9a (patch)
treee0040570d7bc45ac23514535808cb940dab05b89
parent16046cf8091a3baa6f7fe768e6650e15b413884c (diff)
downloadlibmm-radio-8f0367bb9c78c5c207d0e83824829fe638d8fc9a.tar.gz
libmm-radio-8f0367bb9c78c5c207d0e83824829fe638d8fc9a.tar.bz2
libmm-radio-8f0367bb9c78c5c207d0e83824829fe638d8fc9a.zip
[libmm-radio] fix sound focus fuction
Signed-off-by: Hyunjin Park <hyunjin45.park@samsung.com> Change-Id: I7d9404de7f2b2b47246679c024ee03d9cb567174
-rwxr-xr-xsrc/include/mm_radio_audio_focus.h6
-rwxr-xr-xsrc/include/mm_radio_priv.h10
-rwxr-xr-xsrc/mm_radio_audio_focus.c84
-rwxr-xr-xsrc/mm_radio_priv.c89
4 files changed, 61 insertions, 128 deletions
diff --git a/src/include/mm_radio_audio_focus.h b/src/include/mm_radio_audio_focus.h
index 46b7d04..b8fec93 100755
--- a/src/include/mm_radio_audio_focus.h
+++ b/src/include/mm_radio_audio_focus.h
@@ -40,14 +40,14 @@ typedef struct {
int pid;
int by_asm_cb;
int event_src;
- int sound_focus_register;
int asm_session_flags;
+ mm_sound_focus_type_e cur_focus_type;
} MMRadioAudioFocus;
int mmradio_audio_focus_register(MMRadioAudioFocus* sm, mm_sound_focus_changed_cb callback, void* param);
int mmradio_audio_focus_deregister(MMRadioAudioFocus* sm);
-int mmradio_set_audio_focus(MMRadioAudioFocus* sm, mm_sound_focus_changed_watch_cb callback, void* param);
-int mmradio_unset_audio_focus(MMRadioAudioFocus* sm, void* param);
+int mmradio_acquire_audio_focus(MMRadioAudioFocus* sm);
+int mmradio_release_audio_focus(MMRadioAudioFocus* sm);
void mmradio_get_audio_focus_reason(mm_sound_focus_state_e focus_state, const char *reason_for_change, ASM_event_sources_t *event_source, int *postMsg);
#endif /* MM_RADIO_AUDIO_FOCUS_H_ */
diff --git a/src/include/mm_radio_priv.h b/src/include/mm_radio_priv.h
index 2418eba..b6569bb 100755
--- a/src/include/mm_radio_priv.h
+++ b/src/include/mm_radio_priv.h
@@ -43,9 +43,6 @@
#include <gst/gst.h>
#include <gst/gstbuffer.h>
-#include <mm_sound.h>
-#include <mm_sound_focus.h>
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -228,13 +225,6 @@ int _mmradio_apply_region(mm_radio_t*radio, MMRadioRegionType region, bool updat
int _mmradio_get_region_type(mm_radio_t*radio, MMRadioRegionType *type);
int _mmradio_get_region_frequency_range(mm_radio_t* radio, unsigned int *min_freq, unsigned int *max_freq);
int _mmradio_get_channel_spacing(mm_radio_t* radio, unsigned int *ch_spacing);
-void _mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
- mm_sound_focus_state_e focus_state, const char *reason_for_change,
- const char *additional_info, void *user_data);
-
-void _mmradio_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type,
- mm_sound_focus_state_e focus_state, const char *reason_for_change,
- const char *additional_info, void *user_data);
#if 0
int mmradio_set_attrs(mm_radio_t* radio, MMRadioAttrsType type, MMHandleType attrs);
diff --git a/src/mm_radio_audio_focus.c b/src/mm_radio_audio_focus.c
index 73868ec..aa16385 100755
--- a/src/mm_radio_audio_focus.c
+++ b/src/mm_radio_audio_focus.c
@@ -37,25 +37,24 @@ int mmradio_audio_focus_register(MMRadioAudioFocus* sm, mm_sound_focus_changed_c
MMRADIO_LOG_FENTER();
- if ( ! sm )
+ if ( !sm )
{
MMRADIO_LOG_ERROR("invalid session handle\n");
return MM_ERROR_RADIO_NOT_INITIALIZED;
}
+ sm->cur_focus_type = FOCUS_NONE;
/* read session information */
errorcode = _mm_session_util_read_information(pid, &session_type, &session_flags);
if ( errorcode == MM_ERROR_NONE )
{
debug_warning("Read Session Information success. session_type : %d flags: %d \n", session_type, session_flags);
- sm->sound_focus_register = true;
sm->asm_session_flags = session_flags;
session_type = MM_SESSION_TYPE_MEDIA;
}
else
{
- debug_warning("Read Session Information failed. skip sound focus function. errorcode %x \n" ,errorcode);
- sm->sound_focus_register = false;
+ debug_warning("Read Session Information failed. skip sound focus register function. errorcode %x \n" ,errorcode);
}
/* check if it's MEDIA type */
@@ -66,24 +65,17 @@ int mmradio_audio_focus_register(MMRadioAudioFocus* sm, mm_sound_focus_changed_c
}
/* check if it's running on the media_server */
- if ( pid > 0 )
- sm->pid = pid;
- else
- return MM_ERROR_INVALID_ARGUMENT;
+ sm->pid = pid;
- MMRADIO_LOG_DEBUG("sound register focus pid[%d]", pid);
+ MMRADIO_LOG_DEBUG("sound register focus pid[%d]", pid);
mm_sound_focus_get_id(&handle);
sm->handle = handle;
- if(sm->sound_focus_register)
+
+ if(mm_sound_register_focus_for_session(handle, pid, "radio", callback, param) != MM_ERROR_NONE)
{
- if(mm_sound_register_focus_for_session(handle, pid, "radio", callback, param) != MM_ERROR_NONE)
- {
- MMRADIO_LOG_DEBUG("mm_sound_register_focus_for_session is failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- else
- MMRADIO_LOG_DEBUG("mm_sound_register_focus_for_session is success. handle : %d session_type : %d, flags : %x\n", handle, session_type, sm->asm_session_flags);
+ MMRADIO_LOG_DEBUG("mm_sound_register_focus_for_session is failed\n");
+ return MM_ERROR_POLICY_BLOCKED;
}
MMRADIO_LOG_FLEAVE();
@@ -96,79 +88,61 @@ int mmradio_audio_focus_deregister(MMRadioAudioFocus* sm)
{
MMRADIO_LOG_FENTER();
- if ( ! sm )
+ if ( !sm )
{
MMRADIO_LOG_ERROR("invalid session handle\n");
return MM_ERROR_RADIO_NOT_INITIALIZED;
}
- if(sm->sound_focus_register)
- {
- if (MM_ERROR_NONE != mm_sound_unregister_focus(sm->handle))
- MMRADIO_LOG_ERROR("mm_sound_unregister_focus failed\n");
- }
+ if (MM_ERROR_NONE != mm_sound_unregister_focus(sm->handle))
+ MMRADIO_LOG_ERROR("mm_sound_unregister_focus failed\n");
+
MMRADIO_LOG_FLEAVE();
return MM_ERROR_NONE;
}
-int mmradio_set_audio_focus(MMRadioAudioFocus* sm, mm_sound_focus_changed_watch_cb callback, void* param)
+int mmradio_acquire_audio_focus(MMRadioAudioFocus* sm)
{
int ret = MM_ERROR_NONE;
+ mm_sound_focus_type_e focus_type = FOCUS_NONE;
MMRADIO_LOG_FENTER();
- MMRADIO_LOG_ERROR("mmradio_set_audio_focus asm_session_flags : %d\n", sm->asm_session_flags);
- if(sm->asm_session_flags & MM_SESSION_OPTION_PAUSE_OTHERS)
+ MMRADIO_LOG_ERROR("mmradio_acquire_audio_focus sm->cur_focus_type : %d\n", sm->cur_focus_type);
+
+ focus_type = FOCUS_FOR_BOTH & ~(sm->cur_focus_type);
+ if (focus_type != FOCUS_NONE)
{
- ret = mm_sound_acquire_focus(sm->handle, FOCUS_FOR_BOTH, NULL);
- if(ret != MM_ERROR_NONE)
+ ret = mm_sound_acquire_focus(sm->handle, focus_type, NULL);
+ if (ret != MM_ERROR_NONE)
{
- MMRADIO_LOG_ERROR("mm_sound_set_audio_focus failed\n");
+ MMRADIO_LOG_ERROR("mm_sound_acquire_focus is failed\n");
return MM_ERROR_POLICY_BLOCKED;
}
+ sm->cur_focus_type = FOCUS_FOR_BOTH;
}
- else
- {
- ret = mm_sound_set_focus_watch_callback_for_session(sm->pid, FOCUS_FOR_BOTH, callback, param, &sm->handle);
- if(ret != MM_ERROR_NONE)
- {
- MMRADIO_LOG_ERROR("mm_sound_set_audio_focus failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- MMRADIO_LOG_ERROR("mmradio_set_audio_focus ret: %d\n", ret);
- }
MMRADIO_LOG_FLEAVE();
return ret ;
}
-int mmradio_unset_audio_focus(MMRadioAudioFocus* sm, void* param)
+int mmradio_release_audio_focus(MMRadioAudioFocus* sm)
{
int ret = MM_ERROR_NONE;
MMRADIO_LOG_FENTER();
- MMRADIO_LOG_ERROR("mmradio_set_audio_focus asm_session_flags : %d\n", sm->asm_session_flags);
- if(sm->asm_session_flags & MM_SESSION_OPTION_PAUSE_OTHERS)
- {
- ret = mm_sound_release_focus(sm->handle, FOCUS_FOR_BOTH, NULL);
- if(ret != MM_ERROR_NONE)
- {
- MMRADIO_LOG_ERROR("mmradio_unset_audio_focus failed\n");
- return MM_ERROR_POLICY_BLOCKED;
- }
- }
- else
+ MMRADIO_LOG_ERROR("mmradio_release_audio_focus sm->cur_focus_type : %d\n", sm->cur_focus_type);
+ if (sm->cur_focus_type != FOCUS_NONE)
{
- ret = mm_sound_unset_focus_watch_callback(sm->handle);
+ ret = mm_sound_release_focus(sm->handle, sm->cur_focus_type, NULL);
if(ret != MM_ERROR_NONE)
{
- MMRADIO_LOG_ERROR("mmradio_unset_audio_focus failed\n");
+ MMRADIO_LOG_ERROR("mm_sound_release_focus is failed\n");
return MM_ERROR_POLICY_BLOCKED;
}
-
- MMRADIO_LOG_ERROR("mmradio_unset_audio_focus ret: %d\n", ret);
+ sm->cur_focus_type = FOCUS_NONE;
}
MMRADIO_LOG_FLEAVE();
diff --git a/src/mm_radio_priv.c b/src/mm_radio_priv.c
index 48ec079..f5ed857 100755
--- a/src/mm_radio_priv.c
+++ b/src/mm_radio_priv.c
@@ -38,6 +38,8 @@
#include <mm_debug.h>
#include <mm_message.h>
+#include <mm_sound.h>
+#include <mm_sound_focus.h>
#include <mm_sound_device.h>
#include "mm_radio_priv.h"
@@ -125,6 +127,9 @@ static void __mmradio_scan_thread(mm_radio_t* radio);
static bool __is_tunable_frequency(mm_radio_t* radio, int freq);
static int __mmradio_set_deemphasis(mm_radio_t* radio);
static int __mmradio_set_band_range(mm_radio_t* radio);
+static void __mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
+ mm_sound_focus_state_e focus_state, const char *reason_for_change,
+ const char *additional_info, void *user_data);
static void __mmradio_device_connected_cb(MMSoundDevice_t device, bool is_connected, void *user_data);
/*===========================================================================
@@ -237,11 +242,11 @@ _mmradio_create_radio(mm_radio_t* radio)
}
/* register to audio focus */
- ret = mmradio_audio_focus_register(&radio->sm, _mmradio_sound_focus_cb, (void *)radio);
+ ret = mmradio_audio_focus_register(&radio->sm, __mmradio_sound_focus_cb, (void *)radio);
if ( ret )
{
/* NOTE : we are dealing it as an error since we cannot expect it's behavior */
- MMRADIO_LOG_ERROR("failed to register audio focus\n");
+ MMRADIO_LOG_ERROR("mmradio_audio_focus_register is failed\n");
return MM_ERROR_RADIO_INTERNAL;
}
@@ -384,9 +389,10 @@ _mmradio_unrealize(mm_radio_t* radio)
MMRADIO_SET_STATE( radio, MM_RADIO_STATE_NULL );
- ret = mmradio_unset_audio_focus(&radio->sm, (void *)radio);
- if (ret) {
- MMRADIO_LOG_ERROR("failed to unset audio focus\n");
+ ret = mmradio_release_audio_focus(&radio->sm);
+ if (ret)
+ {
+ MMRADIO_LOG_ERROR("mmradio_release_audio_focus is failed\n");
return ret;
}
#ifdef USE_GST_PIPELINE
@@ -684,7 +690,7 @@ _mmradio_start(mm_radio_t* radio)
MMRADIO_LOG_DEBUG("now tune to frequency : %d\n", radio->freq);
- ret = mmradio_set_audio_focus(&radio->sm, _mmradio_sound_focus_watch_cb, (void *)radio);
+ ret = mmradio_acquire_audio_focus(&radio->sm);
if ( ret )
{
MMRADIO_LOG_ERROR("failed to set audio focus\n");
@@ -1429,7 +1435,8 @@ __mmradio_get_state(mm_radio_t* radio)
return radio->current_state;
}
-void _mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
+static void
+__mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
mm_sound_focus_state_e focus_state, const char *reason_for_change,
const char *additional_info, void *user_data)
{
@@ -1445,80 +1452,42 @@ void _mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
radio->sm.event_src = event_source;
switch (focus_state) {
- case FOCUS_IS_RELEASED:
- radio->sm.by_asm_cb = MMRADIO_ASM_CB_POSTMSG;
- result = _mmradio_stop(radio);
- if (result) {
- MMRADIO_LOG_ERROR("failed to stop radio\n");
+ case FOCUS_IS_RELEASED: {
+ radio->sm.cur_focus_type &= ~focus_type;
+ radio->sm.by_asm_cb = MMRADIO_ASM_CB_POSTMSG;
+
+ result = _mmradio_stop(radio);
+ if (result) {
+ MMRADIO_LOG_ERROR("failed to stop radio\n");
+ }
+ MMRADIO_LOG_DEBUG("FOCUS_IS_RELEASED cur_focus_type : %d\n", radio->sm.cur_focus_type);
}
- MMRADIO_LOG_DEBUG("FOCUS_IS_RELEASED\n");
break;
case FOCUS_IS_ACQUIRED: {
MMMessageParamType msg = {0,};
msg.union_type = MM_MSG_UNION_CODE;
msg.code = event_source;
- if (postMsg)
- MMRADIO_POST_MSG(radio, MM_MESSAGE_READY_TO_RESUME, &msg);
-
- radio->sm.by_asm_cb = MMRADIO_ASM_CB_NONE;
- MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED\n");
- }
- break;
+ radio->sm.cur_focus_type |= focus_type;
- default:
- MMRADIO_LOG_DEBUG("Unknown focus_state\n");
- break;
- }
- MMRADIO_LOG_FLEAVE();
-}
-
-void _mmradio_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
- const char *reason_for_change, const char *additional_info, void *user_data)
-{
- mm_radio_t *radio = (mm_radio_t *) user_data;
- ASM_event_sources_t event_source;
- int result = MM_ERROR_NONE;
- int postMsg = false;
-
- MMRADIO_LOG_FENTER();
- MMRADIO_CHECK_INSTANCE_RETURN_VOID(radio);
-
- mmradio_get_audio_focus_reason(!focus_state, reason_for_change, &event_source, &postMsg);
- radio->sm.event_src = event_source;
-
- switch (focus_state) {
- case FOCUS_IS_RELEASED: {
- MMMessageParamType msg = {0,};
- msg.union_type = MM_MSG_UNION_CODE;
- msg.code = event_source;
- if (postMsg)
+ if ((postMsg) && (FOCUS_FOR_BOTH == radio->sm.cur_focus_type))
MMRADIO_POST_MSG(radio, MM_MESSAGE_READY_TO_RESUME, &msg);
radio->sm.by_asm_cb = MMRADIO_ASM_CB_NONE;
- MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED postMsg: %d\n", postMsg);
- }
- break;
-
- case FOCUS_IS_ACQUIRED: {
- radio->sm.by_asm_cb = MMRADIO_ASM_CB_POSTMSG;
- result = _mmradio_stop(radio);
- if (result) {
- MMRADIO_LOG_ERROR("failed to stop radio\n");
- }
- MMRADIO_LOG_DEBUG("FOCUS_IS_RELEASED\n");
- break;
+ MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED cur_focus_type : %d\n", radio->sm.cur_focus_type);
}
break;
default:
- MMRADIO_LOG_DEBUG("Unknown focus_state postMsg : %d\n", postMsg);
+ MMRADIO_LOG_DEBUG("Unknown focus_state\n");
break;
}
+
MMRADIO_LOG_FLEAVE();
}
+
static void
__mmradio_device_connected_cb(MMSoundDevice_t device, bool is_connected, void *user_data)
{