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) {
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);
#endif
if (!radio->is_ready) {
+ 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;
+ }
ret = mmradio_resource_manager_acquire(&radio->resource_manager);
if (ret != MM_ERROR_NONE) {
MMRADIO_LOG_ERROR("failed to acquire resource manager");
+ mmradio_resource_manager_unprepare(&radio->resource_manager);
return ret;
}
ret = radio_hal_prepare(radio->hal_inf);
int _mmradio_stop(mm_radio_t *radio)
{
int ret = MM_ERROR_NONE;
+ mm_radio_resource_state_e resource_state = MM_RADIO_RESOURCE_STATE_NONE;
MMRADIO_LOG_FENTER();
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;
+ if (!radio->resource_manager.by_rm_cb && /* is being released */
+ mmradio_resource_manager_get_state(&radio->resource_manager, &resource_state) == MM_ERROR_NONE) {
+ if (resource_state == MM_RADIO_RESOURCE_STATE_ACQUIRED) {
+ ret = mmradio_resource_manager_release(&radio->resource_manager);
+ if (ret != MM_ERROR_NONE) {
+ MMRADIO_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
+ return ret;
+ }
+ }
+ }
+
+ if (mmradio_resource_manager_get_state(&radio->resource_manager, &resource_state) == MM_ERROR_NONE) {
+ if (resource_state == MM_RADIO_RESOURCE_STATE_PREPARED) {
+ ret = mmradio_resource_manager_unprepare(&radio->resource_manager);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager unprepare fail");
+ }
}
#ifdef TIZEN_FEATURE_SOUND_FOCUS
radio->stop_scan = false;
if (!radio->is_ready) {
+ 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;
+ }
ret = mmradio_resource_manager_acquire(&radio->resource_manager);
if (ret != MM_ERROR_NONE) {
MMRADIO_LOG_ERROR("failed to acquire resource manager");
+ mmradio_resource_manager_unprepare(&radio->resource_manager);
return ret;
}
{
int ret = MM_ERROR_NONE;
int prev_freq = 0;
+ mm_radio_resource_state_e resource_state = MM_RADIO_RESOURCE_STATE_NONE;
MMRADIO_LOG_FENTER();
MMRADIO_CHECK_INSTANCE_RETURN_VOID(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");
+ if (!radio->resource_manager.by_rm_cb && /* is being released */
+ mmradio_resource_manager_get_state(&radio->resource_manager, &resource_state) == MM_ERROR_NONE) {
+ if (resource_state == MM_RADIO_RESOURCE_STATE_ACQUIRED) {
+ ret = mmradio_resource_manager_release(&radio->resource_manager);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
+ }
+ }
+
+ if (mmradio_resource_manager_get_state(&radio->resource_manager, &resource_state) == MM_ERROR_NONE) {
+ if (resource_state == MM_RADIO_RESOURCE_STATE_PREPARED) {
+ ret = mmradio_resource_manager_unprepare(&radio->resource_manager);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager unprepare fail");
+ }
+ }
MMRADIO_SET_STATE(radio, MM_RADIO_STATE_READY);
}
radio->current_state = new_state;
/* fill message param */
+ msg.union_type = MM_MSG_UNION_STATE;
msg.state.previous = radio->old_state;
msg.state.current = radio->current_state;
/* post message to application */
if (radio->sound_focus.by_focus_cb) {
msg_type = MM_MESSAGE_STATE_INTERRUPTED;
- msg.union_type = MM_MSG_UNION_CODE;
- msg.code = radio->sound_focus.event_src;
+ msg.state.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;
+ msg.state.code = MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT;
MMRADIO_POST_MSG(radio, msg_type, &msg);
} else {
msg_type = MM_MESSAGE_STATE_CHANGED;
#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;
+ msg.state.code = MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT;
MMRADIO_POST_MSG(radio, msg_type, &msg);
} else {
msg_type = MM_MESSAGE_STATE_CHANGED;
}
radio = (mm_radio_t *)user_data;
if (err != MRP_RES_ERROR_NONE) {
- MMRADIO_LOG_ERROR(" - error message received from Murphy, for the radio(%p), err(0x%x)\n", radio, err);
+ MMRADIO_LOG_ERROR(" - error message received from Murphy, for the radio(%p), err(0x%x)", radio, err);
return;
}
switch (context->state) {
case MRP_RES_CONNECTED:
- MMRADIO_LOG_DEBUG(" - connected to Murphy\n");
+ MMRADIO_LOG_DEBUG(" - connected to Murphy");
if ((rset = mrp_res_list_resources(context)) != NULL) {
mrp_res_string_array_t *resource_names;
resource_names = mrp_res_list_resource_names(rset);
if (!resource_names) {
- MMRADIO_LOG_ERROR(" - no resources available\n");
+ MMRADIO_LOG_ERROR(" - no resources available");
return;
}
for (i = 0; i < resource_names->num_strings; i++) {
radio->resource_manager.is_connected = true;
break;
case MRP_RES_DISCONNECTED:
- MMRADIO_LOG_DEBUG(" - disconnected from Murphy\n");
+ MMRADIO_LOG_DEBUG(" - disconnected from Murphy");
if (radio->resource_manager.rset) {
mrp_res_delete_resource_set(radio->resource_manager.rset);
radio->resource_manager.rset = NULL;
return;
}
- MMRADIO_LOG_DEBUG(" - resource set state of radio(%p) is changed to [%s]\n",
+ MMRADIO_LOG_DEBUG(" - resource set state of radio(%p) is changed to [%s]",
radio, _mmrdio_resource_state_to_str(rs->state));
for (i = 0; i < MM_RADIO_RESOURCE_MAX; i++) {
res = mrp_res_get_resource_by_name(rs, mm_radio_resource_str[i]);
if (res == NULL)
- MMRADIO_LOG_WARNING(" -- %s not present in resource set\n", mm_radio_resource_str[i]);
+ MMRADIO_LOG_WARNING(" -- %s not present in resource set", mm_radio_resource_str[i]);
else
- MMRADIO_LOG_DEBUG(" -- resource name [%s] -> [%s]'\n", res->name,
+ MMRADIO_LOG_DEBUG(" -- resource name [%s] -> [%s]", res->name,
_mmrdio_resource_state_to_str(res->state));
}
MMRADIO_LOG_FENTER();
if (user_data == NULL) {
- MMRADIO_LOG_ERROR("- user_data is null\n");
+ MMRADIO_LOG_ERROR("- user_data is null");
return;
}
return;
}
- MMRADIO_LOG_DEBUG(" - resource set state of radio(%p) is changed to [%s]\n", radio,
+ MMRADIO_LOG_DEBUG(" - resource set state of radio(%p) is changed to [%s]", radio,
_mmrdio_resource_state_to_str(rs->state));
for (i = 0; i < MM_RADIO_RESOURCE_MAX; i++) {
res = mrp_res_get_resource_by_name(rs, mm_radio_resource_str[i]);
if (res == NULL) {
- MMRADIO_LOG_WARNING(" -- %s not present in resource set\n", mm_radio_resource_str[i]);
+ MMRADIO_LOG_WARNING(" -- %s not present in resource set", mm_radio_resource_str[i]);
} else {
- MMRADIO_LOG_DEBUG(" -- resource name [%s] -> [%s]'\n", res->name,
+ MMRADIO_LOG_DEBUG(" -- resource name [%s] -> [%s]", res->name,
_mmrdio_resource_state_to_str(res->state));
if (res->state == MRP_RES_RESOURCE_ABOUT_TO_LOOSE)
resource_released = TRUE;
MMRADIO_LOG_ERROR("failed to stop radio");
MMRADIO_CMD_UNLOCK(radio);
- radio->resource_manager.by_rm_cb = false;
-
} else {
MMRADIO_LOG_WARNING("could not find videobin");
}
static int _mmradio_create_rset(mm_radio_resource_manager *resource_manager)
{
if (resource_manager->rset) {
- MMRADIO_LOG_ERROR(" - resource set was already created\n");
+ MMRADIO_LOG_ERROR(" - resource set was already created");
return MM_ERROR_RESOURCE_INVALID_STATE;
}
MRP_APP_CLASS_FOR_RADIO, __mmradio_rset_state_callback,
(void*)resource_manager->user_data);
if (resource_manager->rset == NULL) {
- MMRADIO_LOG_ERROR(" - could not create resource set\n");
+ MMRADIO_LOG_ERROR(" - could not create resource set");
return MM_ERROR_RESOURCE_INTERNAL;
}
if (!mrp_res_set_autorelease(TRUE, resource_manager->rset))
- MMRADIO_LOG_WARNING(" - could not set autorelease flag!\n");
+ MMRADIO_LOG_WARNING(" - could not set autorelease flag!");
return MM_ERROR_NONE;
}
MRP_RESOURCE_TYPE_MANDATORY,
MRP_RESOURCE_TYPE_EXCLUSIVE);
if (resource == NULL) {
- MMRADIO_LOG_ERROR(" - could not include resource[%s]\n", resource_name);
+ MMRADIO_LOG_ERROR(" - could not include resource[%s]", resource_name);
return MM_ERROR_RESOURCE_INTERNAL;
}
- MMRADIO_LOG_DEBUG(" - include resource[%s]\n", resource_name);
+ MMRADIO_LOG_DEBUG(" - include resource[%s]", resource_name);
return MM_ERROR_NONE;
}
if (resource_manager->rset) {
mrp_ret = mrp_res_set_release_callback(resource_manager->rset, __mmradio_mrp_resource_release_cb, resource_manager->user_data);
if (!mrp_ret) {
- MMRADIO_LOG_ERROR(" - could not set release callback\n");
+ MMRADIO_LOG_ERROR(" - could not set release callback");
ret = MM_ERROR_RESOURCE_INTERNAL;
}
} else {
- MMRADIO_LOG_ERROR(" - resource set is null\n");
+ MMRADIO_LOG_ERROR(" - resource set is null");
ret = MM_ERROR_RESOURCE_INVALID_STATE;
}
MMRADIO_LOG_FLEAVE();
if (resource_manager->mloop) {
resource_manager->context = mrp_res_create(resource_manager->mloop, __mmradio_resource_state_callback, user_data);
if (resource_manager->context == NULL) {
- MMRADIO_LOG_ERROR(" - could not get context for resource manager\n");
+ MMRADIO_LOG_ERROR(" - could not get context for resource manager");
mrp_mainloop_destroy(resource_manager->mloop);
resource_manager->mloop = NULL;
return MM_ERROR_RESOURCE_INTERNAL;
}
resource_manager->user_data = user_data;
} else {
- MMRADIO_LOG_ERROR("- could not get mainloop for resource manager\n");
+ MMRADIO_LOG_ERROR("- could not get mainloop for resource manager");
return MM_ERROR_RESOURCE_INTERNAL;
}
MMRADIO_CHECK_CONNECTION_RESOURCE_MANAGER(resource_manager);
if (resource_manager->rset == NULL) {
- MMRADIO_LOG_ERROR("- could not unprepare for resource_manager, mmradio_resource_manager_unprepare() first\n");
+ MMRADIO_LOG_ERROR("- could not unprepare for resource_manager, mmradio_resource_manager_prepare() first");
ret = MM_ERROR_RESOURCE_INVALID_STATE;
} else {
MMRADIO_RESOURCE_LOCK(resource_manager);
} else {
ret = _mmradio_set_resource_release_cb(resource_manager);
if (ret) {
- MMRADIO_LOG_ERROR("- could not set resource release cb, ret(0x%x)\n", ret);
+ MMRADIO_LOG_ERROR("- could not set resource release cb, ret(0x%x)", ret);
ret = MM_ERROR_RESOURCE_INTERNAL;
} else {
MMRADIO_RESOURCE_LOCK(resource_manager);
ret = mrp_res_acquire_resource_set(resource_manager->rset);
if (ret) {
- MMRADIO_LOG_ERROR("- could not acquire resource, ret(%d)\n", ret);
+ MMRADIO_LOG_ERROR("- could not acquire resource, ret(%d)", ret);
ret = MM_ERROR_RESOURCE_INTERNAL;
} else {
gint64 end_time = g_get_monotonic_time() + MMRADIO_RESOURCE_TIMEOUT * G_TIME_SPAN_SECOND;
- MMRADIO_LOG_DEBUG("- acquire resource waiting..%p till %lld\n", resource_manager, end_time);
+ MMRADIO_LOG_DEBUG("- acquire resource waiting..%p till %lld", resource_manager, end_time);
if (!MMRADIO_RESOURCE_WAIT_UNTIL(resource_manager, end_time)) {
- MMRADIO_LOG_ERROR("- could not acquire resource\n");
+ MMRADIO_LOG_ERROR("- could not acquire resource");
ret = MM_ERROR_RESOURCE_INTERNAL;
} else {
- MMRADIO_LOG_DEBUG("- resources are acquired\n");
+ MMRADIO_LOG_DEBUG("- resources are acquired");
}
}
MMRADIO_CHECK_CONNECTION_RESOURCE_MANAGER(resource_manager);
if (resource_manager->rset == NULL) {
- MMRADIO_LOG_ERROR("- could not release resource, resource set is null\n");
+ MMRADIO_LOG_ERROR("- could not release resource, resource set is null");
ret = MM_ERROR_RESOURCE_INVALID_STATE;
} else {
if (resource_manager->rset->state != MRP_RES_RESOURCE_ACQUIRED) {
- MMRADIO_LOG_ERROR("- could not release resource, resource set state is [%s]\n",
+ MMRADIO_LOG_ERROR("- could not release resource, resource set state is [%s]",
_mmrdio_resource_state_to_str(resource_manager->rset->state));
ret = MM_ERROR_RESOURCE_INVALID_STATE;
} else {
MMRADIO_RESOURCE_LOCK(resource_manager);
ret = mrp_res_release_resource_set(resource_manager->rset);
if (ret) {
- MMRADIO_LOG_ERROR("- could not release resource, ret(%d)\n", ret);
+ MMRADIO_LOG_ERROR("- could not release resource, ret(%d)", ret);
ret = MM_ERROR_RESOURCE_INTERNAL;
} else {
gint64 end_time = g_get_monotonic_time() + MMRADIO_RESOURCE_TIMEOUT * G_TIME_SPAN_SECOND;
- MMRADIO_LOG_DEBUG("- release resource waiting..%p till %lld\n", resource_manager, end_time);
+ MMRADIO_LOG_DEBUG("- release resource waiting..%p till %lld", resource_manager, end_time);
if (!MMRADIO_RESOURCE_WAIT_UNTIL(resource_manager, end_time))
- MMRADIO_LOG_WARNING("- could not release resource in time\n");
+ MMRADIO_LOG_WARNING("- could not release resource in time");
else
MMRADIO_LOG_DEBUG("- resources are released\n");
}
if (resource_manager->rset) {
if (resource_manager->rset->state == MRP_RES_RESOURCE_ACQUIRED) {
if (mrp_res_release_resource_set(resource_manager->rset))
- MMRADIO_LOG_ERROR("- could not release resource\n");
+ MMRADIO_LOG_ERROR("- could not release resource");
}
mrp_res_delete_resource_set(resource_manager->rset);
resource_manager->rset = NULL;
return MM_ERROR_NONE;
}
+
+
+int mmradio_resource_manager_get_state(mm_radio_resource_manager *resource_manager, mm_radio_resource_state_e *state)
+{
+
+ MMRADIO_LOG_FENTER();
+ MMRADIO_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager);
+ MMRADIO_CHECK_ARG(state);
+
+ MMRADIO_LOG_DEBUG("resource_state is %d", resource_manager->state);
+
+ *state = resource_manager->state;
+
+ MMRADIO_LOG_FLEAVE();
+
+ return MM_ERROR_NONE;
+}