diff options
Diffstat (limited to 'src/mm_radio_priv_emulator.c')
-rw-r--r-- | src/mm_radio_priv_emulator.c | 187 |
1 files changed, 107 insertions, 80 deletions
diff --git a/src/mm_radio_priv_emulator.c b/src/mm_radio_priv_emulator.c index d468ef3..e601266 100644 --- a/src/mm_radio_priv_emulator.c +++ b/src/mm_radio_priv_emulator.c @@ -1,9 +1,7 @@ /* - * libmm-radio + * mm_radio_priv_emulator.c * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YoungHwan An <younghwan_.an@samsung.com> + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,9 +37,11 @@ #include <mm_message.h> #include <time.h> +#ifdef TIZEN_FEATURE_SOUND_FOCUS #include <mm_sound.h> #include <mm_sound_focus.h> #include <mm_sound_device.h> +#endif #include "mm_radio_priv.h" @@ -136,11 +136,14 @@ 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 int __mmradio_get_wave_num(mm_radio_t * radio); +#ifdef TIZEN_FEATURE_SOUND_FOCUS 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,int option, + mm_sound_focus_state_e focus_state, const char *reason_for_change, int option, const char *additional_info, void *user_data); -static void __mmradio_device_connected_cb(MMSoundDevice_t device, bool is_connected, void *user_data); - +static 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); +#endif /*=========================================================================== FUNCTION DEFINITIONS ========================================================================== */ @@ -234,22 +237,19 @@ int _mmradio_create_radio(mm_radio_t * radio) MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL); - /* add device conneted callback */ - ret = mm_sound_add_device_connected_callback(MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG, - (mm_sound_device_connected_cb)__mmradio_device_connected_cb, - (void *)radio, &radio->subs_id); - if (ret) { - MMRADIO_LOG_ERROR("mm_sound_add_device_connected_callback is failed\n"); - return MM_ERROR_RADIO_INTERNAL; - } - +#ifdef TIZEN_FEATURE_SOUND_FOCUS /* register to audio focus */ - ret = mmradio_audio_focus_register(&radio->sm, __mmradio_sound_focus_cb, (void *)radio); + ret = mmradio_sound_focus_register(&radio->sound_focus, + (mm_sound_focus_changed_cb)__mmradio_sound_focus_cb, + (mm_sound_focus_changed_watch_cb)__mmradio_sound_focus_watch_cb, + (void *)radio); + if (ret) { /* NOTE : we are dealing it as an error since we cannot expect it's behavior */ MMRADIO_LOG_ERROR("mmradio_audio_focus_register is failed\n"); return MM_ERROR_RADIO_INTERNAL; } +#endif MMRADIO_LOG_FLEAVE(); @@ -305,17 +305,6 @@ int _mmradio_realize(mm_radio_t * radio) MMRADIO_LOG_FLEAVE(); return MM_ERROR_NONE; - -/* error: - if (radio->radio_fd >= 0) { - close(radio->radio_fd); - radio->radio_fd = -1; - } - - MMRADIO_LOG_FLEAVE(); - - return MM_ERROR_RADIO_INTERNAL; -*/ } int _mmradio_unrealize(mm_radio_t * radio) @@ -335,11 +324,15 @@ int _mmradio_unrealize(mm_radio_t * radio) radio->radio_fd = -1; MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL); - ret = mmradio_release_audio_focus(&radio->sm); + +#ifdef TIZEN_FEATURE_SOUND_FOCUS + ret = mmradio_release_sound_focus(&radio->sound_focus); if (ret) { - MMRADIO_LOG_ERROR("mmradio_release_audio_focus is failed\n"); + MMRADIO_LOG_ERROR("mmradio_release_sound_focus is failed\n"); return ret; } +#endif + #ifdef USE_GST_PIPELINE ret = _mmradio_destroy_pipeline(radio); if (ret) { @@ -355,24 +348,21 @@ int _mmradio_unrealize(mm_radio_t * radio) int _mmradio_destroy(mm_radio_t * radio) { - int ret = 0; MMRADIO_LOG_FENTER(); MMRADIO_CHECK_INSTANCE(radio); MMRADIO_CHECK_STATE_RETURN_IF_FAIL(radio, MMRADIO_COMMAND_DESTROY); - ret = mmradio_audio_focus_deregister(&radio->sm); - if (ret) { - MMRADIO_LOG_ERROR("failed to deregister audio focus\n"); - return MM_ERROR_RADIO_INTERNAL; - } + _mmradio_unrealize(radio); - ret = mm_sound_remove_device_connected_callback(radio->subs_id); +#ifdef TIZEN_FEATURE_SOUND_FOCUS + int ret = 0; + ret = mmradio_sound_focus_deregister(&radio->sound_focus); if (ret) { - MMRADIO_LOG_ERROR("mm_sound_remove_device_connected_callback error %d\n", ret); + MMRADIO_LOG_ERROR("failed to deregister sound focus\n"); return MM_ERROR_RADIO_INTERNAL; } - _mmradio_unrealize(radio); +#endif MMRADIO_LOG_FLEAVE(); @@ -585,11 +575,15 @@ int _mmradio_start(mm_radio_t * radio) MMRADIO_SLOG_DEBUG("now tune to frequency : %d\n", radio->freq); - ret = mmradio_acquire_audio_focus(&radio->sm); - if (ret) { - MMRADIO_LOG_ERROR("failed to set audio focus\n"); - return ret; +#ifdef TIZEN_FEATURE_SOUND_FOCUS + if (radio->sound_focus.handle > 0) { + ret = mmradio_acquire_sound_focus(&radio->sound_focus); + if (ret != MM_ERROR_NONE) { + MMRADIO_LOG_ERROR("failed to set sound focus"); + return ret; + } } +#endif /* set stored frequency */ _mmradio_set_frequency(radio, radio->freq); @@ -624,6 +618,16 @@ int _mmradio_stop(mm_radio_t * radio) /* if( _mmradio_mute(radio) != MM_ERROR_NONE) */ /* return MM_ERROR_RADIO_NOT_INITIALIZED; */ +#ifdef TIZEN_FEATURE_SOUND_FOCUS + if (radio->sound_focus.handle > 0) { + ret = mmradio_release_sound_focus(&radio->sound_focus); + if (ret) { + MMRADIO_LOG_ERROR("mmradio_release_audio_focus is failed\n"); + return ret; + } + } +#endif + MMRADIO_SET_STATE(radio, MM_RADIO_STATE_READY); #ifdef USE_GST_PIPELINE @@ -1238,8 +1242,9 @@ static bool __mmradio_set_state(mm_radio_t * radio, int new_state) msg.state.previous = radio->old_state; msg.state.current = radio->current_state; +#ifdef TIZEN_FEATURE_SOUND_FOCUS /* post message to application */ - switch (radio->sm.by_focus_cb) { + switch (radio->sound_focus.by_focus_cb) { case MMRADIO_FOCUS_CB_NONE: { msg_type = MM_MESSAGE_STATE_CHANGED; @@ -1251,7 +1256,7 @@ static bool __mmradio_set_state(mm_radio_t * radio, int new_state) { msg_type = MM_MESSAGE_STATE_INTERRUPTED; msg.union_type = MM_MSG_UNION_CODE; - msg.code = radio->sm.event_src; + msg.code = radio->sound_focus.event_src; MMRADIO_POST_MSG(radio, msg_type, &msg); } break; @@ -1260,7 +1265,10 @@ static bool __mmradio_set_state(mm_radio_t * radio, int new_state) default: break; } - +#else + msg_type = MM_MESSAGE_STATE_CHANGED; + MMRADIO_POST_MSG(radio, msg_type, &msg); +#endif MMRADIO_LOG_FLEAVE(); return true; @@ -1276,11 +1284,12 @@ static int __mmradio_get_state(mm_radio_t * radio) return radio->current_state; } +#ifdef TIZEN_FEATURE_SOUND_FOCUS 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, int option, const char *additional_info, void *user_data) { - mm_radio_t *radio = (mm_radio_t *) user_data; + mm_radio_t *radio = (mm_radio_t *)user_data; enum MMMessageInterruptedCode event_source; int result = MM_ERROR_NONE; int postMsg = false; @@ -1288,19 +1297,19 @@ static void __mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type, 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; + mmradio_get_sound_focus_reason(focus_state, reason_for_change, &event_source, &postMsg); + radio->sound_focus.event_src = event_source; switch (focus_state) { case FOCUS_IS_RELEASED:{ - radio->sm.cur_focus_type &= ~focus_type; - radio->sm.by_focus_cb = MMRADIO_FOCUS_CB_POSTMSG; + radio->sound_focus.cur_focus_type &= ~focus_type; + radio->sound_focus.by_focus_cb = MMRADIO_FOCUS_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 cur_focus_type : %d\n", radio->sound_focus.cur_focus_type); } break; @@ -1309,14 +1318,14 @@ static void __mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type, msg.union_type = MM_MSG_UNION_CODE; msg.code = event_source; - radio->sm.cur_focus_type |= focus_type; + radio->sound_focus.cur_focus_type |= focus_type; - if ((postMsg) && (FOCUS_FOR_BOTH == radio->sm.cur_focus_type)) + if ((postMsg) && (FOCUS_FOR_BOTH == radio->sound_focus.cur_focus_type)) MMRADIO_POST_MSG(radio, MM_MESSAGE_READY_TO_RESUME, &msg); - radio->sm.by_focus_cb = MMRADIO_FOCUS_CB_NONE; + radio->sound_focus.by_focus_cb = MMRADIO_FOCUS_CB_NONE; - MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED cur_focus_type : %d\n", radio->sm.cur_focus_type); + MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED cur_focus_type : %d\n", radio->sound_focus.cur_focus_type); } break; @@ -1328,40 +1337,58 @@ static void __mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type, MMRADIO_LOG_FLEAVE(); } -static void __mmradio_device_connected_cb(MMSoundDevice_t device, bool is_connected, void *user_data) +static 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; + mm_radio_t *radio = (mm_radio_t *)user_data; + enum MMMessageInterruptedCode event_source; int result = MM_ERROR_NONE; - mm_sound_device_type_e type; + int postMsg = false; MMRADIO_LOG_FENTER(); MMRADIO_CHECK_INSTANCE_RETURN_VOID(radio); - if (mm_sound_get_device_type(device, &type) != MM_ERROR_NONE) { - debug_error("getting device type failed"); - } else { - switch (type) { - case MM_SOUND_DEVICE_TYPE_AUDIOJACK: - case MM_SOUND_DEVICE_TYPE_BLUETOOTH: - case MM_SOUND_DEVICE_TYPE_HDMI: - case MM_SOUND_DEVICE_TYPE_MIRRORING: - case MM_SOUND_DEVICE_TYPE_USB_AUDIO: - if (!is_connected) { - MMRADIO_LOG_ERROR("sound device unplugged"); - radio->sm.by_focus_cb = MMRADIO_FOCUS_CB_POSTMSG; - radio->sm.event_src = MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG; - - result = _mmradio_stop(radio); - if (result != MM_ERROR_NONE) - MMRADIO_LOG_ERROR("failed to stop radio\n"); - } - break; - default: - break; + mmradio_get_sound_focus_reason(focus_state, reason_for_change, &event_source, &postMsg); + radio->sound_focus.event_src = event_source; + + switch (focus_state) { + case FOCUS_IS_ACQUIRED: { + radio->sound_focus.cur_focus_type &= ~focus_type; + radio->sound_focus.by_focus_cb = MMRADIO_FOCUS_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->sound_focus.cur_focus_type); } + break; + + case FOCUS_IS_RELEASED: { + MMMessageParamType msg = { 0, }; + msg.union_type = MM_MSG_UNION_CODE; + msg.code = event_source; + + radio->sound_focus.cur_focus_type |= focus_type; + + if ((postMsg) && (FOCUS_FOR_BOTH == radio->sound_focus.cur_focus_type)) + MMRADIO_POST_MSG(radio, MM_MESSAGE_READY_TO_RESUME, &msg); + + radio->sound_focus.by_focus_cb = MMRADIO_FOCUS_CB_NONE; + + MMRADIO_LOG_DEBUG("FOCUS_IS_ACQUIRED cur_focus_type : %d\n", radio->sound_focus.cur_focus_type); + } + break; + + default: + MMRADIO_LOG_DEBUG("Unknown focus_state\n"); + break; } + MMRADIO_LOG_FLEAVE(); } +#endif int _mmradio_get_region_type(mm_radio_t * radio, MMRadioRegionType * type) { |