diff options
author | Gilbok Lee <gilbok.lee@samsung.com> | 2017-04-10 13:17:41 +0900 |
---|---|---|
committer | Gilbok Lee <gilbok.lee@samsung.com> | 2017-04-10 16:41:05 +0900 |
commit | 42e03880d935d628608776e138915c23cbe6f780 (patch) | |
tree | 56b06b55da1d627e79a7c7611fb29986870c59ab /src/mm_radio_priv_hal.c | |
parent | 3bc8e303ae07b3d3c9933495b86f6d7ebc0c875c (diff) | |
download | libmm-radio-42e03880d935d628608776e138915c23cbe6f780.tar.gz libmm-radio-42e03880d935d628608776e138915c23cbe6f780.tar.bz2 libmm-radio-42e03880d935d628608776e138915c23cbe6f780.zip |
Added implementation of interruption by resource managersubmit/tizen/20170420.053325accepted/tizen/unified/20170420.154835
1. Add cmd rock during _mm_radio_stop()
[Version] 0.2.25
[Profile] Mobile, Wearable
[Issue Type] Add featuresBrief
Change-Id: I720bbed4681ac7f8c870164d08413d35db3b54ea
Diffstat (limited to 'src/mm_radio_priv_hal.c')
-rw-r--r-- | src/mm_radio_priv_hal.c | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/src/mm_radio_priv_hal.c b/src/mm_radio_priv_hal.c index f13b632..f4a92e9 100644 --- a/src/mm_radio_priv_hal.c +++ b/src/mm_radio_priv_hal.c @@ -209,6 +209,13 @@ int _mmradio_create_radio(mm_radio_t *radio) MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL); + /* initialize resource manager */ + ret = mmradio_resource_manager_init(&radio->resource_manager, radio); + if (ret) { + MMRADIO_LOG_ERROR("failed to initialize resource manager\n"); + return MM_ERROR_RADIO_INTERNAL; + } + #ifdef TIZEN_FEATURE_SOUND_FOCUS ret = mmradio_sound_focus_register(&radio->sound_focus, (mm_sound_focus_changed_cb)__mmradio_sound_focus_cb, @@ -263,6 +270,12 @@ int _mmradio_realize(mm_radio_t *radio) ret = _mmradio_apply_region(radio, region, update); + ret = mmradio_resource_manager_prepare(&radio->resource_manager, MM_RADIO_RESOURCE_TYPE_RADIO); + if (ret != MM_ERROR_NONE) { + MMRADIO_LOG_ERROR("resource manager prepare fail"); + return MM_ERROR_RADIO_INTERNAL; + } + #ifdef TIZEN_FEATURE_SOUND_VSTREAM ret = sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_RADIO, NULL, radio, &radio->stream_info); if (ret != MM_ERROR_NONE) { @@ -332,6 +345,10 @@ int _mmradio_unrealize(mm_radio_t *radio) sound_manager_destroy_virtual_stream(radio->vstream); sound_manager_destroy_stream_information(radio->stream_info); #endif + mmradio_resource_manager_unprepare(&radio->resource_manager); + if (ret != MM_ERROR_NONE) + MMRADIO_LOG_ERROR("resource manager unprepare fail"); + pthread_mutex_destroy(&radio->seek_cancel_mutex); MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL); @@ -375,6 +392,13 @@ int _mmradio_destroy(mm_radio_t *radio) return MM_ERROR_RADIO_INTERNAL; } #endif + + ret = mmradio_resource_manager_deinit(&radio->resource_manager); + if (ret) { + MMRADIO_LOG_ERROR("failed to initialize resource manager\n"); + return MM_ERROR_RADIO_INTERNAL; + } + MMRADIO_LOG_FLEAVE(); return MM_ERROR_NONE; @@ -541,6 +565,11 @@ int _mmradio_start(mm_radio_t *radio) #endif if (!radio->is_ready) { + ret = mmradio_resource_manager_acquire(&radio->resource_manager); + if (ret != MM_ERROR_NONE) { + MMRADIO_LOG_ERROR("failed to acquire resource manager"); + return ret; + } ret = radio_hal_prepare(radio->hal_inf); if (ret == MM_ERROR_NOT_SUPPORT_API) { MMRADIO_LOG_WARNING("radio_hal_prepare is not supported"); @@ -659,6 +688,12 @@ int _mmradio_stop(mm_radio_t *radio) radio->is_ready = FALSE; + ret = mmradio_resource_manager_release(&radio->resource_manager); + if (ret != MM_ERROR_NONE) { + MMRADIO_LOG_ERROR("failed to release resource"); + return ret; + } + #ifdef TIZEN_FEATURE_SOUND_FOCUS if (radio->sound_focus.handle > 0) { ret = mmradio_release_sound_focus(&radio->sound_focus); @@ -776,6 +811,12 @@ int _mmradio_start_scan(mm_radio_t *radio) radio->stop_scan = false; if (!radio->is_ready) { + ret = mmradio_resource_manager_acquire(&radio->resource_manager); + if (ret != MM_ERROR_NONE) { + MMRADIO_LOG_ERROR("failed to acquire resource manager"); + return ret; + } + ret = radio_hal_prepare(radio->hal_inf); if (ret == MM_ERROR_NOT_SUPPORT_API) { MMRADIO_LOG_WARNING("radio_hal_prepare is not supported"); @@ -847,7 +888,7 @@ int _mmradio_stop_scan(mm_radio_t *radio) int _mm_radio_get_signal_strength(mm_radio_t *radio, int *value) { int ret = MM_ERROR_NONE; - uint32_t strength = 0; + int32_t strength = 0; MMRADIO_LOG_FENTER(); MMRADIO_CHECK_INSTANCE(radio); @@ -988,6 +1029,10 @@ FINISHED_ERR: radio->is_ready = FALSE; + ret = mmradio_resource_manager_release(&radio->resource_manager); + if (ret != MM_ERROR_NONE) + MMRADIO_LOG_ERROR("failed to release resource"); + MMRADIO_SET_STATE(radio, MM_RADIO_STATE_READY); } @@ -1073,6 +1118,8 @@ void __mmradio_seek_thread(mm_radio_t *radio) MMRADIO_LOG_ERROR("failed to tune to new frequency"); goto SEEK_FAILED; } + radio->freq = (int)freq; + MMRADIO_LOG_WARNING("setting frequency : [%d]", radio->freq); } if (radio->seek_unmute) { @@ -1117,6 +1164,7 @@ SEEK_FAILED: param.radio_scan.frequency = -1; MMRADIO_POST_MSG(radio, MM_MESSAGE_RADIO_SEEK_FINISH, ¶m); radio->is_seeking = FALSE; + radio->seek_thread = 0; pthread_exit(NULL); return; } @@ -1306,13 +1354,26 @@ static bool __mmradio_set_state(mm_radio_t *radio, int new_state) msg.union_type = MM_MSG_UNION_CODE; msg.code = radio->sound_focus.event_src; MMRADIO_POST_MSG(radio, msg_type, &msg); + } else if (radio->resource_manager.by_rm_cb) { + msg_type = MM_MESSAGE_STATE_INTERRUPTED; + msg.union_type = MM_MSG_UNION_CODE; + msg.code = MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT; + MMRADIO_POST_MSG(radio, msg_type, &msg); } else { msg_type = MM_MESSAGE_STATE_CHANGED; MMRADIO_POST_MSG(radio, msg_type, &msg); } #else - msg_type = MM_MESSAGE_STATE_CHANGED; - MMRADIO_POST_MSG(radio, msg_type, &msg); + if (radio->resource_manager.by_rm_cb) { + msg_type = MM_MESSAGE_STATE_INTERRUPTED; + msg.union_type = MM_MSG_UNION_CODE; + msg.code = MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT; + MMRADIO_POST_MSG(radio, msg_type, &msg); + } else { + msg_type = MM_MESSAGE_STATE_CHANGED; + MMRADIO_POST_MSG(radio, msg_type, &msg); + } + #endif MMRADIO_LOG_FLEAVE(); @@ -1352,9 +1413,11 @@ static void __mmradio_sound_focus_cb(int id, mm_sound_focus_type_e focus_type, radio->sound_focus.cur_focus_type &= ~focus_type; radio->sound_focus.by_focus_cb = true; + MMRADIO_CMD_LOCK(radio); result = _mmradio_stop(radio); if (result) MMRADIO_LOG_ERROR("failed to stop radio"); + MMRADIO_CMD_UNLOCK(radio); radio->sound_focus.by_focus_cb = false; @@ -1405,9 +1468,11 @@ static void __mmradio_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_t radio->sound_focus.cur_focus_type &= ~focus_type; radio->sound_focus.by_focus_cb = true; + MMRADIO_CMD_LOCK(radio); result = _mmradio_stop(radio); if (result) MMRADIO_LOG_ERROR("failed to stop radio"); + MMRADIO_CMD_UNLOCK(radio); radio->sound_focus.by_focus_cb = false; |