summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunjin Park <hyunjin45.park@samsung.com>2015-09-22 19:43:25 +0900
committerHyunjin Park <hyunjin45.park@samsung.com>2015-09-24 21:01:52 +0900
commit0b27ea9bf4d71eb00eb7b6dce64b9d5c924216a2 (patch)
tree5d7a2b18cdb0c3407d34d91f79ad601db11da46e
parent3cbc3986bc483432ff4f023d796654ea8dd642da (diff)
downloadlibmm-radio-0b27ea9bf4d71eb00eb7b6dce64b9d5c924216a2.tar.gz
libmm-radio-0b27ea9bf4d71eb00eb7b6dce64b9d5c924216a2.tar.bz2
libmm-radio-0b27ea9bf4d71eb00eb7b6dce64b9d5c924216a2.zip
Signed-off-by: Hyunjin Park <hyunjin45.park@samsung.com> Change-Id: Ica7ac7942b356062a623664e6c0c3702e54bc39d
-rwxr-xr-x[-rw-r--r--]packaging/libmm-radio.spec2
-rwxr-xr-x[-rw-r--r--]src/Makefile.am2
-rwxr-xr-x[-rw-r--r--]src/include/mm_radio_audio_focus.h (renamed from src/include/mm_radio_asm.h)23
-rwxr-xr-x[-rw-r--r--]src/include/mm_radio_priv.h19
-rw-r--r--src/mm_radio_asm.c154
-rwxr-xr-xsrc/mm_radio_audio_focus.c232
-rwxr-xr-xsrc/mm_radio_priv.c163
7 files changed, 351 insertions, 244 deletions
diff --git a/packaging/libmm-radio.spec b/packaging/libmm-radio.spec
index bc2fbba..2c08afc 100644..100755
--- a/packaging/libmm-radio.spec
+++ b/packaging/libmm-radio.spec
@@ -1,6 +1,6 @@
Name: libmm-radio
Summary: Multimedia Framework Radio Library
-Version: 0.2.1
+Version: 0.2.2
Release: 1
Group: System/Libraries
License: Apache-2.0
diff --git a/src/Makefile.am b/src/Makefile.am
index 4f7a481..30e4998 100644..100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,7 @@ includelibmmfradio_HEADERS = include/mm_radio.h
libmmfradio_la_SOURCES = mm_radio.c \
mm_radio_priv.c \
- mm_radio_asm.c
+ mm_radio_audio_focus.c
libmmfradio_la_CFLAGS = -I. -I./include \
$(GTHREAD_CFLAGS) \
diff --git a/src/include/mm_radio_asm.h b/src/include/mm_radio_audio_focus.h
index c8d1c93..46b7d04 100644..100755
--- a/src/include/mm_radio_asm.h
+++ b/src/include/mm_radio_audio_focus.h
@@ -18,9 +18,9 @@
* limitations under the License.
*
*/
-
-#ifndef MM_RADIO_ASM_H_
-#define MM_RADIO_ASM_H_
+
+#ifndef MM_RADIO_AUDIO_FOCUS_H_
+#define MM_RADIO_AUDIO_FOCUS_H_
#include <mm_types.h>
#include <mm_error.h>
@@ -28,6 +28,7 @@
#include <mm_session.h>
#include <mm_session_private.h>
#include <audio-session-manager.h>
+#include <mm_sound_focus.h>
enum {
MMRADIO_ASM_CB_NONE,
@@ -39,12 +40,14 @@ typedef struct {
int pid;
int by_asm_cb;
int event_src;
- ASM_sound_states_t state;
-} MMRadioASM;
+ int sound_focus_register;
+ int asm_session_flags;
+} MMRadioAudioFocus;
-/* returns allocated handle */
-int mmradio_asm_register(MMRadioASM* sm, ASM_sound_cb_t callback, void* param);
-int mmradio_asm_deregister(MMRadioASM* sm);
-int mmradio_asm_set_state(MMRadioASM* sm, ASM_sound_states_t state, ASM_resource_t resource);
+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);
+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_ASM_H_ */
+#endif /* MM_RADIO_AUDIO_FOCUS_H_ */
diff --git a/src/include/mm_radio_priv.h b/src/include/mm_radio_priv.h
index bd070ae..e4609b9 100644..100755
--- a/src/include/mm_radio_priv.h
+++ b/src/include/mm_radio_priv.h
@@ -35,14 +35,17 @@
#include <mm_types.h>
#include <mm_message.h>
-#include "mm_radio_asm.h"
+#include "mm_radio_audio_focus.h"
#include "mm_radio.h"
#include "mm_radio_utils.h"
#include <linux/videodev2.h>
#include <gst/gst.h>
#include <gst/gstbuffer.h>
-
+
+#include <mm_sound.h>
+#include <mm_sound_focus.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -184,8 +187,7 @@ typedef struct {
int prev_seek_freq;
MMRadioSeekDirectionType seek_direction;
- /* ASM */
- MMRadioASM sm;
+ MMRadioAudioFocus sm;
int freq;
#ifdef USE_GST_PIPELINE
@@ -224,6 +226,15 @@ int _mmradio_destroy_pipeline(mm_radio_t* radio);
int _mmradio_apply_region(mm_radio_t*radio, MMRadioRegionType region, bool update);
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);
MMHandleType mmradio_get_attrs(mm_radio_t* radio, MMRadioAttrsType type);
diff --git a/src/mm_radio_asm.c b/src/mm_radio_asm.c
deleted file mode 100644
index d049610..0000000
--- a/src/mm_radio_asm.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * libmm-radio
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <assert.h>
-#include <mm_debug.h>
-#include "mm_radio_asm.h"
-#include "mm_radio_utils.h"
-
-int mmradio_asm_register(MMRadioASM* sm, ASM_sound_cb_t callback, void* param)
-{
- /* read mm-session information */
- int session_type = MM_SESSION_TYPE_MEDIA;
- int session_options = 0;
- int errorcode = MM_ERROR_NONE;
- int asm_handle = -1;
- int event_type = ASM_EVENT_MEDIA_FMRADIO;
- int pid = -1;
-
- MMRADIO_LOG_FENTER();
-
- if ( ! sm )
- {
- MMRADIO_LOG_ERROR("invalid session handle\n");
- return MM_ERROR_RADIO_NOT_INITIALIZED;
- }
-
- /* read session information */
- errorcode = _mm_session_util_read_information(pid, &session_type, &session_options);
- if ( errorcode )
- {
- debug_warning("Read Session Information failed. use default \"media\" type\n");
- session_type = MM_SESSION_TYPE_MEDIA;
- }
-
- /* check if it's MEDIA type */
- if ( session_type != MM_SESSION_TYPE_MEDIA)
- {
- MMRADIO_LOG_DEBUG("session type is not MEDIA (%d)\n", session_type);
- return MM_ERROR_RADIO_INTERNAL;
- }
-
- /* check if it's running on the media_server */
- if ( sm->pid > 0 )
- {
- pid = sm->pid;
- MMRADIO_LOG_DEBUG("mm-radio is running on different process. Just faking pid to [%d]. :-p\n", pid);
- }
- else
- {
- MMRADIO_LOG_DEBUG("no pid has assigned. using default(current) context\n");
- }
-
- /* register audio-session-manager callback */
- if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, callback, (void*)param, ASM_RESOURCE_NONE, &errorcode))
- {
- MMRADIO_LOG_CRITICAL("ASM_register_sound() failed\n");
- return errorcode;
- }
- /* set session options */
- if (session_options)
- {
- if( ! ASM_set_session_option(asm_handle, session_options, &errorcode))
- {
- debug_error("ASM_set_session_options() failed, error(%x)\n", errorcode);
- return errorcode;
- }
- }
-
- /* now succeded to register our callback. take result */
- sm->handle = asm_handle;
- sm->state = ASM_STATE_NONE;
-
- MMRADIO_LOG_FLEAVE();
-
- return MM_ERROR_NONE;
-}
-
-int mmradio_asm_deregister(MMRadioASM* sm)
-{
- int event_type = ASM_EVENT_MEDIA_FMRADIO;
- int errorcode = 0;
-
- MMRADIO_LOG_FENTER();
-
- if ( ! sm )
- {
- MMRADIO_LOG_ERROR("invalid session handle\n");
- return MM_ERROR_RADIO_NOT_INITIALIZED;
- }
-
- if( ! ASM_unregister_sound( sm->handle, event_type, &errorcode) )
- {
- MMRADIO_LOG_ERROR("Unregister sound failed 0x%X\n", errorcode);
- return MM_ERROR_POLICY_INTERNAL;
- }
-
- MMRADIO_LOG_FLEAVE();
-
- return MM_ERROR_NONE;
-}
-
-int mmradio_asm_set_state(MMRadioASM* sm, ASM_sound_states_t state, ASM_resource_t resource)
-{
- int event_type = ASM_EVENT_MEDIA_FMRADIO;
-
- MMRADIO_LOG_FENTER();
-
- if ( ! sm )
- {
- MMRADIO_LOG_ERROR("invalid session handle\n");
- return MM_ERROR_RADIO_NOT_INITIALIZED;
- }
-
- if ( sm->by_asm_cb == MMRADIO_ASM_CB_NONE ) //|| sm->state == ASM_STATE_PLAYING )
- {
- int ret = 0;
-
- if( ! ASM_set_sound_state( sm->handle, event_type, state, resource, &ret) )
- {
- MMRADIO_LOG_ERROR("set ASM state to [%d] failed 0x%X\n", state, ret);
- return MM_ERROR_POLICY_BLOCKED;
- }
-
- sm->state = state;
- }
- else // by asm callback
- {
- sm->by_asm_cb = MMRADIO_ASM_CB_NONE;
- sm->state = state;
- }
-
- MMRADIO_LOG_FLEAVE();
-
- return MM_ERROR_NONE;
-}
-
diff --git a/src/mm_radio_audio_focus.c b/src/mm_radio_audio_focus.c
new file mode 100755
index 0000000..73868ec
--- /dev/null
+++ b/src/mm_radio_audio_focus.c
@@ -0,0 +1,232 @@
+/*
+ * libmm-radio
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <assert.h>
+#include <mm_debug.h>
+#include "mm_radio_audio_focus.h"
+#include "mm_radio_utils.h"
+#include "mm_sound_focus.h"
+#include "unistd.h"
+
+int mmradio_audio_focus_register(MMRadioAudioFocus* sm, mm_sound_focus_changed_cb callback, void* param)
+{
+ /* read mm-session information */
+ int session_type = MM_SESSION_TYPE_MEDIA;
+ int session_flags = 0;
+ int errorcode = MM_ERROR_NONE;
+ int pid = getpid();
+ int handle;
+
+ MMRADIO_LOG_FENTER();
+
+ if ( ! sm )
+ {
+ MMRADIO_LOG_ERROR("invalid session handle\n");
+ return MM_ERROR_RADIO_NOT_INITIALIZED;
+ }
+
+ /* 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;
+ }
+
+ /* check if it's MEDIA type */
+ if ( session_type != MM_SESSION_TYPE_MEDIA)
+ {
+ MMRADIO_LOG_DEBUG("session type is not MEDIA (%d)\n", session_type);
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ /* check if it's running on the media_server */
+ if ( pid > 0 )
+ sm->pid = pid;
+ else
+ return MM_ERROR_INVALID_ARGUMENT;
+
+ 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)
+ {
+ 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_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+
+int mmradio_audio_focus_deregister(MMRadioAudioFocus* sm)
+{
+ MMRADIO_LOG_FENTER();
+
+ 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");
+ }
+
+ MMRADIO_LOG_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+int mmradio_set_audio_focus(MMRadioAudioFocus* sm, mm_sound_focus_changed_watch_cb callback, void* param)
+{
+ 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_acquire_focus(sm->handle, FOCUS_FOR_BOTH, NULL);
+ if(ret != MM_ERROR_NONE)
+ {
+ MMRADIO_LOG_ERROR("mm_sound_set_audio_focus failed\n");
+ return MM_ERROR_POLICY_BLOCKED;
+ }
+ }
+ 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 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
+ {
+ ret = mm_sound_unset_focus_watch_callback(sm->handle);
+ if(ret != MM_ERROR_NONE)
+ {
+ MMRADIO_LOG_ERROR("mmradio_unset_audio_focus failed\n");
+ return MM_ERROR_POLICY_BLOCKED;
+ }
+
+ MMRADIO_LOG_ERROR("mmradio_unset_audio_focus ret: %d\n", ret);
+ }
+
+ MMRADIO_LOG_FLEAVE();
+ return ret ;
+}
+
+#define AUDIO_FOCUS_REASON_MAX 128
+
+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)
+{
+ MMRADIO_LOG_FENTER();
+ MMRADIO_LOG_ERROR("mmradio_get_audio_focus_reason focus_state : %d reason_for_change :%s\n", focus_state, reason_for_change);
+
+ if(0 == strncmp(reason_for_change, "call-voice", AUDIO_FOCUS_REASON_MAX)
+ || (0 == strncmp(reason_for_change, "voip", AUDIO_FOCUS_REASON_MAX))
+ || (0 == strncmp(reason_for_change, "ringtone-voip", AUDIO_FOCUS_REASON_MAX))
+ || (0 == strncmp(reason_for_change, "ringtone-call", AUDIO_FOCUS_REASON_MAX))
+ )
+ {
+ if(focus_state == FOCUS_IS_RELEASED)
+ *event_source = ASM_EVENT_SOURCE_CALL_START;
+ else if(focus_state == FOCUS_IS_ACQUIRED)
+ *event_source = ASM_EVENT_SOURCE_CALL_END;
+ *postMsg = true;
+ }
+ else if(0 == strncmp(reason_for_change, "alarm", AUDIO_FOCUS_REASON_MAX))
+ {
+ if(focus_state == FOCUS_IS_RELEASED)
+ *event_source = ASM_EVENT_SOURCE_ALARM_START;
+ else if(focus_state == FOCUS_IS_ACQUIRED)
+ *event_source = ASM_EVENT_SOURCE_ALARM_END;
+ *postMsg = true;
+ }
+ else if(0 == strncmp(reason_for_change, "notification", AUDIO_FOCUS_REASON_MAX))
+ {
+ if(focus_state == FOCUS_IS_RELEASED)
+ *event_source = ASM_EVENT_SOURCE_NOTIFY_START;
+ else if(focus_state == FOCUS_IS_ACQUIRED)
+ *event_source = ASM_EVENT_SOURCE_NOTIFY_END;
+ *postMsg = true;
+ }
+ else if(0 == strncmp(reason_for_change, "emergency", AUDIO_FOCUS_REASON_MAX))
+ {
+ if(focus_state == FOCUS_IS_RELEASED)
+ *event_source = ASM_EVENT_SOURCE_EMERGENCY_START;
+ else if(focus_state == FOCUS_IS_ACQUIRED)
+ *event_source = ASM_EVENT_SOURCE_EMERGENCY_END;
+ *postMsg = false;
+ }
+ else if(0 == strncmp(reason_for_change, "media", AUDIO_FOCUS_REASON_MAX))
+ {
+ *event_source = ASM_EVENT_SOURCE_MEDIA;
+ *postMsg = false;
+ }
+ else
+ {
+ *event_source = ASM_EVENT_SOURCE_MEDIA;
+ *postMsg = false;
+ }
+ MMRADIO_LOG_FLEAVE();
+}
diff --git a/src/mm_radio_priv.c b/src/mm_radio_priv.c
index 7a58de3..0d0dc4b 100755
--- a/src/mm_radio_priv.c
+++ b/src/mm_radio_priv.c
@@ -33,12 +33,12 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
-#include <mm_sound.h>
#include <mm_error.h>
#include <mm_debug.h>
#include <mm_message.h>
+
#include "mm_radio_priv.h"
/*===========================================================================================
@@ -121,7 +121,6 @@ static int __mmradio_get_state(mm_radio_t* radio);
static bool __mmradio_set_state(mm_radio_t* radio, int new_state);
static void __mmradio_seek_thread(mm_radio_t* radio);
static void __mmradio_scan_thread(mm_radio_t* radio);
-ASM_cb_result_t __mmradio_asm_callback(int handle, ASM_event_sources_t sound_event, ASM_sound_commands_t command, unsigned int sound_status, void* cb_data);
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);
@@ -224,12 +223,12 @@ _mmradio_create_radio(mm_radio_t* radio)
MMRADIO_SET_STATE( radio, MM_RADIO_STATE_NULL );
- /* register to ASM */
- ret = mmradio_asm_register(&radio->sm, __mmradio_asm_callback, (void*)radio);
+ /* register to audio focus */
+ 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 asm server\n");
+ MMRADIO_LOG_ERROR("failed to register audio focus\n");
return MM_ERROR_RADIO_INTERNAL;
}
@@ -371,6 +370,12 @@ _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");
+ return ret;
+ }
#ifdef USE_GST_PIPELINE
ret= _mmradio_destroy_pipeline(radio);
if ( ret ) {
@@ -393,10 +398,10 @@ _mmradio_destroy(mm_radio_t* radio)
MMRADIO_CHECK_INSTANCE( radio );
MMRADIO_CHECK_STATE_RETURN_IF_FAIL( radio, MMRADIO_COMMAND_DESTROY );
- ret = mmradio_asm_deregister(&radio->sm);
+ ret = mmradio_audio_focus_deregister(&radio->sm);
if ( ret )
{
- MMRADIO_LOG_ERROR("failed to deregister asm server\n");
+ MMRADIO_LOG_ERROR("failed to deregister audio focus\n");
return MM_ERROR_RADIO_INTERNAL;
}
@@ -660,10 +665,10 @@ _mmradio_start(mm_radio_t* radio)
MMRADIO_LOG_DEBUG("now tune to frequency : %d\n", radio->freq);
- ret = mmradio_asm_set_state(&radio->sm, ASM_STATE_PLAYING, ASM_RESOURCE_RADIO_TUNNER);
+ ret = mmradio_set_audio_focus(&radio->sm, _mmradio_sound_focus_watch_cb, (void *)radio);
if ( ret )
{
- MMRADIO_LOG_ERROR("failed to set asm state to PLAYING\n");
+ MMRADIO_LOG_ERROR("failed to set audio focus\n");
return ret;
}
@@ -703,12 +708,6 @@ _mmradio_stop(mm_radio_t* radio)
MMRADIO_SET_STATE( radio, MM_RADIO_STATE_READY );
- ret = mmradio_asm_set_state(&radio->sm, ASM_STATE_STOP, ASM_RESOURCE_NONE);
- if ( ret )
- {
- MMRADIO_LOG_ERROR("failed to set asm state to PLAYING\n");
- return ret;
- }
#ifdef USE_GST_PIPELINE
ret= _mmradio_stop_pipeline( radio );
if ( ret ) {
@@ -964,7 +963,7 @@ __mmradio_scan_thread(mm_radio_t* radio)
vs.seek_upward = 1; /* up : 1 ------- down : 0 */
MMRADIO_LOG_FENTER();
- MMRADIO_CHECK_INSTANCE( radio );
+ MMRADIO_CHECK_INSTANCE_RETURN_VOID( radio );
if( _mmradio_mute(radio) != MM_ERROR_NONE)
goto FINISHED;
@@ -1083,7 +1082,7 @@ __mmradio_seek_thread(mm_radio_t* radio)
vs.wrap_around = DEFAULT_WRAP_AROUND;
MMRADIO_LOG_FENTER();
- MMRADIO_CHECK_INSTANCE( radio );
+ MMRADIO_CHECK_INSTANCE_RETURN_VOID( radio );
/* check direction */
switch( radio->seek_direction )
@@ -1411,79 +1410,95 @@ __mmradio_get_state(mm_radio_t* radio)
return radio->current_state;
}
-ASM_cb_result_t
-__mmradio_asm_callback(int handle, ASM_event_sources_t event_source, ASM_sound_commands_t command, unsigned int sound_status, void* cb_data)
+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)
{
- mm_radio_t* radio = (mm_radio_t*) cb_data;
+ mm_radio_t *radio = (mm_radio_t *) user_data;
+ ASM_event_sources_t event_source;
int result = MM_ERROR_NONE;
- ASM_cb_result_t cb_res = ASM_CB_RES_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(command)
- {
- case ASM_COMMAND_STOP:
- case ASM_COMMAND_PAUSE:
- {
- MMRADIO_LOG_DEBUG("ASM asked me to stop. cmd : %d\n", command);
- switch(event_source)
- {
- case ASM_EVENT_SOURCE_CALL_START:
- case ASM_EVENT_SOURCE_ALARM_START:
- case ASM_EVENT_SOURCE_EARJACK_UNPLUG:
- case ASM_EVENT_SOURCE_MEDIA:
- {
- 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("skip unrealize in asm callback");
- }
- break;
-
- case ASM_EVENT_SOURCE_RESOURCE_CONFLICT:
- default:
- {
- radio->sm.by_asm_cb = MMRADIO_ASM_CB_POSTMSG;
- result = _mmradio_stop(radio);
- if( result )
- {
- MMRADIO_LOG_ERROR("failed to stop radio\n");
- }
- }
- break;
+ 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");
}
- cb_res = ASM_CB_RES_STOP;
- }
- break;
+ MMRADIO_LOG_DEBUG("FOCUS_IS_RELEASED\n");
+ break;
- case ASM_COMMAND_PLAY:
- case ASM_COMMAND_RESUME:
- {
- MMMessageParamType msg = {0,};
- msg.union_type = MM_MSG_UNION_CODE;
- msg.code = event_source;
+ 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);
- MMRADIO_LOG_DEBUG("Got ASM resume message by %d\n", msg.code);
- MMRADIO_POST_MSG(radio, MM_MESSAGE_READY_TO_RESUME, &msg);
+ radio->sm.by_asm_cb = MMRADIO_ASM_CB_NONE;
- cb_res = ASM_CB_RES_IGNORE;
- radio->sm.by_asm_cb = MMRADIO_ASM_CB_NONE;
- }
- break;
+ MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED\n");
+ }
+ break;
default:
- break;
+ 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)
+ MMRADIO_POST_MSG(radio, MM_MESSAGE_READY_TO_RESUME, &msg);
- return cb_res;
+ 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;
+ }
+ break;
+
+ default:
+ MMRADIO_LOG_DEBUG("Unknown focus_state postMsg : %d\n", postMsg);
+ break;
+ }
+ MMRADIO_LOG_FLEAVE();
}
int _mmradio_get_region_type(mm_radio_t*radio, MMRadioRegionType *type)