AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset strstr])
-PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
-AC_SUBST(GTHREAD_CFLAGS)
-AC_SUBST(GTHREAD_LIBS)
-
PKG_CHECK_MODULES(MMCOMMON, mm-common)
AC_SUBST(MMCOMMON_CFLAGS)
AC_SUBST(MMCOMMON_LIBS)
-PKG_CHECK_MODULES(MM_RESOURCE_MANAGER, mm-resource-manager)
-AC_SUBST(MM_RESOURCE_MANAGER_CFLAGS)
-AC_SUBST(MM_RESOURCE_MANAGER_LIBS)
+PKG_CHECK_MODULES(RM, resource-manager)
+AC_SUBST(RM_CFLAGS)
+AC_SUBST(RM_LIBS)
+
+PKG_CHECK_MODULES(RC, resource-center-api)
+AC_SUBST(RC_CFLAGS)
+AC_SUBST(RC_LIBS)
PKG_CHECK_MODULES(DLOG, dlog)
AC_SUBST(DLOG_CFLAGS)
Name: libmm-radio
Summary: Multimedia Framework Radio Library
-Version: 0.2.51
+Version: 0.3.1
Release: 0
Group: System/Libraries
License: Apache-2.0
BuildRequires: pkgconfig(gstreamer-1.0)
BuildRequires: pkgconfig(gstreamer-plugins-base-1.0)
%endif
-BuildRequires: pkgconfig(mm-resource-manager)
+BuildRequires: pkgconfig(resource-manager)
+BuildRequires: pkgconfig(resource-information)
+BuildRequires: pkgconfig(resource-center-api)
%if 0%{?gtests:1}
BuildRequires: pkgconfig(gmock)
%endif
libmmfradio_la_SOURCES = mm_radio.c
libmmfradio_la_CFLAGS = -I. -I./include \
- $(GTHREAD_CFLAGS) \
- $(MMCOMMON_CFLAGS) \
- $(MM_RESOURCE_MANAGER_CFLAGS) \
- $(SOUNDMGR_CFLAGS) \
- $(DLOG_CFLAGS)
-
-libmmfradio_la_LIBADD = $(GTHREAD_LIBS) \
- $(MMCOMMON_LIBS) \
- $(MM_RESOURCE_MANAGER_LIBS) \
- $(SOUNDMGR_LIBS) \
- $(DLOG_LIBS)
-
+ $(MMCOMMON_CFLAGS) \
+ $(SOUNDMGR_CFLAGS) \
+ $(DLOG_CFLAGS) \
+ $(GSTAPP_CFLAGS) \
+ $(RM_CFLAGS) \
+ $(RC_CFLAGS)
+
+libmmfradio_la_LIBADD = $(MMCOMMON_LIBS) \
+ $(SOUNDMGR_LIBS) \
+ $(DLOG_LIBS) \
+ $(RM_LIBS) \
+ $(RC_LIBS)
if ENABLE_EMULATOR
-libmmfradio_la_SOURCES += mm_radio_priv_emulator.c
+libmmfradio_la_SOURCES += mm_radio_priv_emulator.c mm_radio_rm.c
libmmfradio_la_CFLAGS += $(GST_CFLAGS) \
$(GSTAPP_CFLAGS)
-libmmfradio_la_LIBADD += $(GST_LIBS) \
- $(GSTAPP_LIBS)
+libmmfradio_la_LIBADD += $(GST_LIBS) \
+ $(GSTAPP_LIBS)
else
-libmmfradio_la_SOURCES += mm_radio_priv_hal.c
+libmmfradio_la_SOURCES += mm_radio_priv_hal.c mm_radio_rm.c
libmmfradio_la_CFLAGS += $(HAL_API_RADIO_CFLAGS)
#include <mm_types.h>
#include <mm_message.h>
-#include <media/mm_resource_manager.h>
#include "mm_radio.h"
#include "mm_radio_utils.h"
+#include "mm_radio_rm.h"
+
#include <linux/videodev2.h>
#include <gst/gst.h>
int freq;
mm_radio_gstreamer_s *pipeline;
- mm_resource_manager_h resource_manager;
- mm_resource_manager_res_h radio_resource;
+
+ radio_resource_s resource;
+
int interrupted_by_resource_conflict;
float local_volume;
#include <mm_types.h>
#include <mm_message.h>
-#include <media/mm_resource_manager.h>
#include <media/sound_manager.h>
#include <media/sound_manager_internal.h>
#include "mm_radio.h"
#include "mm_radio_utils.h"
+#include "mm_radio_rm.h"
#include <linux/videodev2.h>
#include <glib.h>
void *hal_radio;
- mm_resource_manager_h resource_manager;
- mm_resource_manager_res_h radio_resource;
+ radio_resource_s resource;
+
int interrupted_by_resource_conflict;
} mm_radio_t;
--- /dev/null
+/*
+ * mm_radio_rm.h
+ *
+ * Copyright (c) 2024 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.
+ * 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.
+ *
+ */
+
+#ifndef __MM_RADIO_RM_H__
+#define __MM_RADIO_RM_H__
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#include <glib.h>
+#include <mm_types.h>
+#include <rm_api.h>
+#include <rm_type.h>
+#include "mm_radio_utils.h"
+
+typedef enum {
+ MM_RADIO_RES_TYPE_RADIO, /**< ID of radio resource type */
+ MM_RADIO_RES_TYPE_MAX, /**< Used to iterate on resource types only */
+} MMRadioResourceTypes;
+
+typedef struct _radio_resource_s {
+ int rm_h;
+ rm_device_return_s returned_devices[MM_RADIO_RES_TYPE_MAX];
+ rm_consumer_info rci;
+ gboolean need_to_acquire[MM_RADIO_RES_TYPE_MAX];
+ GMutex rm_callback_lock;
+ GMutex rm_control_lock;
+} radio_resource_s;
+
+int mm_radio_rm_register(MMHandleType hradio);
+int mm_radio_rm_acquire(MMHandleType hradio, MMRadioResourceTypes type);
+int mm_radio_rm_release(MMHandleType hradio, MMRadioResourceTypes type);
+int mm_radio_rm_unregister(MMHandleType hradio);
+
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* __MM_RADIO_RM_H__ */
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);
-static int __resource_release_cb(mm_resource_manager_h rm,
- mm_resource_manager_res_h res, void *user_data);
static void __mmradio_msg_thread(mm_radio_t *radio);
static void __mmradio_msg_push(mm_radio_t *radio, MMRadioMsgTypes msg_type, int msg_data);
MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL);
/* initialize resource manager */
- ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
- __resource_release_cb, radio, &radio->resource_manager);
+ ret = mm_radio_rm_register((MMHandleType)radio);
if (ret) {
MMRADIO_LOG_ERROR("failed to create resource manager");
ret = MM_ERROR_RADIO_INTERNAL;
if (radio->msg_queue)
g_async_queue_unref(radio->msg_queue);
- ret = mm_resource_manager_destroy(radio->resource_manager);
+ ret = mm_radio_rm_unregister((MMHandleType)radio);
if (ret) {
MMRADIO_LOG_ERROR("failed to destroy resource manager");
return MM_ERROR_RADIO_INTERNAL;
MMRADIO_SLOG_DEBUG("now tune to frequency : %d", radio->freq);
- ret = mm_resource_manager_mark_for_acquire(radio->resource_manager,
- MM_RESOURCE_MANAGER_RES_TYPE_RADIO,
- MM_RESOURCE_MANAGER_RES_VOLUME_FULL, &radio->radio_resource);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- MMRADIO_LOG_ERROR("resource manager mark for acquire fail");
- return MM_ERROR_RADIO_INTERNAL;
- }
-
radio->interrupted_by_resource_conflict = FALSE;
- ret = mm_resource_manager_commit(radio->resource_manager);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- MMRADIO_LOG_ERROR("failed to commit resource manager");
- mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource);
- radio->radio_resource = NULL;
- return ret;
+ ret = mm_radio_rm_acquire((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE) {
+ MMRADIO_LOG_ERROR("resource manager acquire fail");
+ return MM_ERROR_RADIO_INTERNAL;
}
/* set stored frequency */
/* if( _mmradio_mute(radio) != MM_ERROR_NONE) */
/* return MM_ERROR_RADIO_NOT_INITIALIZED; */
- if (!radio->interrupted_by_resource_conflict && /* is being released */
- radio->radio_resource != NULL) {
- ret = mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource);
- radio->radio_resource = NULL;
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
- return ret;
- }
-
- ret = mm_resource_manager_commit(radio->resource_manager);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("resource manager commit fail");
+ if (!radio->interrupted_by_resource_conflict) {
+ ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager release fail");
}
MMRADIO_SET_STATE(radio, MM_RADIO_STATE_READY);
return val;
}
-static int __resource_release_cb(mm_resource_manager_h rm,
- mm_resource_manager_res_h res, void *user_data)
-{
- mm_radio_t *radio = NULL;
-
- MMRADIO_LOG_FENTER();
-
- if (!user_data) {
- MMRADIO_LOG_ERROR("user_data is null");
- return FALSE;
- }
-
- radio = (mm_radio_t *)user_data;
- radio->radio_resource = NULL;
-
- MMRADIO_LOG_DEBUG("radio resource conflict so, resource will be freed by _mmradio_stop");
-
- radio->interrupted_by_resource_conflict = TRUE;
-
- MMRADIO_CMD_LOCK(radio);
- if (_mmradio_stop(radio) != MM_ERROR_NONE)
- MMRADIO_LOG_ERROR("failed to stop radio");
- MMRADIO_CMD_UNLOCK(radio);
-
- MMRADIO_LOG_FLEAVE();
-
- return FALSE;
-}
-
int _mmradio_set_volume(mm_radio_t *radio, float volume)
{
MMRADIO_LOG_FENTER();
static int __mmradio_create_thread_type(mm_radio_t *radio, MMRadioThreadTypes type);
static void __mmradio_destroy_thread_type(mm_radio_t *radio, MMRadioThreadTypes type);
-static int __resource_release_cb(mm_resource_manager_h rm,
- mm_resource_manager_res_h res, void *user_data);
static void __mmradio_msg_thread(mm_radio_t *radio);
static void __mmradio_msg_push(mm_radio_t *radio, MMRadioMsgTypes msg_type, int msg_data);
static int __mmradio_prepare_radio_device(mm_radio_t *radio);
MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL);
/* initialize resource manager */
- ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
- __resource_release_cb, radio, &radio->resource_manager);
- if (ret) {
- MMRADIO_LOG_ERROR("failed to create resource manager");
+ ret = mm_radio_rm_register((MMHandleType)radio);
+ if (ret != MM_ERROR_NONE) {
+ MMRADIO_LOG_ERROR("failed to register resource manager");
ret = MM_ERROR_RADIO_INTERNAL;
goto ERROR_RESOURCE;
}
return MM_ERROR_NONE;
ERROR_HAL_INIT:
- mm_resource_manager_destroy(radio->resource_manager);
+ ret = mm_radio_rm_unregister((MMHandleType)radio);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("failed to unregister resource manager");
ERROR_RESOURCE:
__mmradio_destroy_threads(radio);
ERROR_THREAD:
if (ret)
MMRADIO_LOG_ERROR("failed to put radio hal backend");
- ret = mm_resource_manager_destroy(radio->resource_manager);
+ ret = mm_radio_rm_unregister((MMHandleType)radio);
if (ret) {
MMRADIO_LOG_ERROR("failed to destroy resource manager");
return MM_ERROR_RADIO_INTERNAL;
MMRADIO_LOG_INFO("now tune to frequency : %d", radio->freq);
- if (!radio->is_ready) {
-
- } else {
+ if (radio->is_ready)
MMRADIO_LOG_DEBUG("radio prepared and opened");
- }
ret = __mmradio_prepare_radio_device(radio);
if (ret != MM_ERROR_NONE)
hal_radio_close(radio->hal_radio);
hal_radio_unprepare(radio->hal_radio);
- if (!radio->interrupted_by_resource_conflict && /* is being released */
- radio->radio_resource != NULL) {
- if (mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource) != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
- radio->radio_resource = NULL;
-
+ if (!radio->interrupted_by_resource_conflict) {
+ ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager release fail");
}
- if (mm_resource_manager_commit(radio->resource_manager)
- != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("resource manager commit fail");
radio->is_ready = false;
return ret;
}
}
- if (!radio->interrupted_by_resource_conflict && /* is being released */
- radio->radio_resource != NULL) {
- ret = mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource);
- radio->radio_resource = NULL;
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
- return ret;
- }
-
- ret = mm_resource_manager_commit(radio->resource_manager);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("resource manager commit fail");
+ if (!radio->interrupted_by_resource_conflict) {
+ ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager release fail");
}
radio->is_ready = false;
}
return ret;
}
-static int __resource_release_cb(mm_resource_manager_h rm,
- mm_resource_manager_res_h res, void *user_data)
-{
- mm_radio_t *radio = NULL;
-
- MMRADIO_LOG_FENTER();
-
- if (!user_data) {
- MMRADIO_LOG_ERROR("user_data is null");
- return FALSE;
- }
-
- radio = (mm_radio_t *)user_data;
- radio->radio_resource = NULL;
-
- MMRADIO_LOG_DEBUG("radio resource conflict so, resource will be freed by _mmradio_stop");
-
- radio->interrupted_by_resource_conflict = TRUE;
-
- MMRADIO_CMD_LOCK(radio);
- if (_mmradio_stop(radio) != MM_ERROR_NONE)
- MMRADIO_LOG_ERROR("failed to stop radio");
- MMRADIO_CMD_UNLOCK(radio);
-
- MMRADIO_LOG_FLEAVE();
-
- return FALSE;
-}
-
static int __mmradio_create_thread_type(mm_radio_t *radio, MMRadioThreadTypes type)
{
MMRadioThread_t *p_thread = NULL;
return ret;
}
- ret = mm_resource_manager_mark_for_acquire(radio->resource_manager,
- MM_RESOURCE_MANAGER_RES_TYPE_RADIO,
- MM_RESOURCE_MANAGER_RES_VOLUME_FULL, &radio->radio_resource);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- MMRADIO_LOG_ERROR("resource manager mark for acquire fail");
- return MM_ERROR_RADIO_INTERNAL;
- }
-
radio->interrupted_by_resource_conflict = FALSE;
- ret = mm_resource_manager_commit(radio->resource_manager);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- MMRADIO_LOG_ERROR("failed to commit resource manager");
- radio->radio_resource = NULL;
+ ret = mm_radio_rm_acquire((MMHandleType)radio. MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE) {
+ MMRADIO_LOG_ERROR("failed to acquire resource manager");
return ret;
}
error2:
hal_radio_unprepare(radio->hal_radio);
- if (!radio->interrupted_by_resource_conflict && /* is being released */
- radio->radio_resource != NULL) {
- if (mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource) != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
- radio->radio_resource = NULL;
-
- }
-
- if (mm_resource_manager_commit(radio->resource_manager)
- != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("resource manager commit fail");
+ ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager release fail");
radio->is_ready = false;
return ret;
if (ret)
__convert_error_code(ret, (char *)__FUNCTION__);
- if (!radio->interrupted_by_resource_conflict && /* is being released */
- radio->radio_resource != NULL) {
- ret = mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource);
- radio->radio_resource = NULL;
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
- }
-
- ret = mm_resource_manager_commit(radio->resource_manager);
- if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
- MMRADIO_LOG_ERROR("resource manager commit fail");
+ ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+ if (ret != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("resource manager release fail");
radio->is_ready = false;
}
--- /dev/null
+/*
+ * mm_radio.c
+ *
+ * Copyright (c) 2024 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.
+ * 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 "mm_radio_rm.h"
+#include "mm_radio_priv_emul.h"
+#include "mm_radio_priv_hal.h"
+#include <mm_error.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <resource_center.h>
+
+static int
+__mmradio_get_appid_by_pid(int pid, char *name, size_t size)
+{
+ g_autofree gchar *cmdline = NULL;
+ g_autofree gchar *contents = NULL;
+ g_autofree gchar *base = NULL;
+ g_autoptr(GError) error = NULL;
+
+ MMRADIO_RETURN_VAL_IF_FAIL(name, MM_ERROR_INVALID_ARGUMENT);
+ MMRADIO_RETURN_VAL_IF_FAIL(size != 0, MM_ERROR_INVALID_ARGUMENT);
+
+ cmdline = g_strdup_printf("/proc/%d/cmdline", (int)pid);
+
+ if (!g_file_get_contents(cmdline, &contents, NULL, &error)) {
+ MMRADIO_LOG_ERROR("error : %s", error->message);
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ base = g_path_get_basename(contents);
+
+ if (g_strlcpy(name, base, size) >= size)
+ MMRADIO_LOG_ERROR("string truncated");
+
+ return MM_ERROR_NONE;
+}
+
+static void _mmradio_execute_resource_release(mm_radio_t *radio)
+{
+ MMRADIO_LOG_FENTER();
+
+ if (!radio) {
+ MMRADIO_LOG_ERROR("radio is null");
+ return;
+ }
+
+ MMRADIO_LOG_INFO("radio resource conflict so, resource will be freed by _mmradio_stop");
+
+ radio->interrupted_by_resource_conflict = TRUE;
+
+ MMRADIO_CMD_LOCK(radio);
+ if (_mmradio_stop(radio) != MM_ERROR_NONE)
+ MMRADIO_LOG_ERROR("failed to stop radio");
+ MMRADIO_CMD_UNLOCK(radio);
+
+ MMRADIO_LOG_FLEAVE();
+}
+
+
+static rm_cb_result
+__mmradio_rm_callback(int handle, rm_callback_type event_src, rm_device_request_s *info, void *cb_data)
+{
+ mm_radio_t *radio = (mm_radio_t *)cb_data;
+ g_autoptr(GMutexLocker) locker = NULL;
+
+ MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+ MMRADIO_LOG_INFO("rm callback info mm_radio_t [%p] handle : %d event_src : %d", radio, handle, event_src);
+
+ locker = g_mutex_locker_new(&radio->resource.rm_callback_lock);
+
+ switch (event_src) {
+ case RM_CALLBACK_TYPE_RESOURCE_CONFLICT:
+ case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD:
+ _mmradio_execute_resource_release(radio);
+ break;
+ default:
+ break;
+ }
+
+ MMRADIO_LOG_FLEAVE();
+
+ return RM_CB_RESULT_OK;
+}
+
+int mm_radio_rm_register(MMHandleType hradio)
+{
+ int ret;
+ mm_radio_t *radio = (mm_radio_t *)hradio;
+
+ MMRADIO_LOG_FENTER();
+
+ MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+ if (radio->resource.rm_h) {
+ MMRADIO_LOG_INFO("[%d] resource manager handle is already registered", radio->resource.rm_h);
+ return MM_ERROR_NONE;
+ }
+
+ memset(&radio->resource.rci, 0x00, sizeof(rm_consumer_info));
+
+ radio->resource.rci.app_pid = (int)getpid();
+
+ if (__mmradio_get_appid_by_pid(radio->resource.rci.app_pid, radio->resource.rci.app_id, sizeof(radio->resource.rci.app_id)) != MM_ERROR_NONE) {
+ MMRADIO_LOG_ERROR("__mmradio_get_appid_by_pid is failed");
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ MMRADIO_LOG_INFO("app pid %d app id %s", radio->resource.rci.app_pid, radio->resource.rci.app_id);
+
+ ret = rm_register((rm_resource_cb)__mmradio_rm_callback,
+ (void *)radio,
+ &(radio->resource.rm_h),
+ (radio->resource.rci.app_id[0] != '\0') ? &radio->resource.rci : NULL);
+ if (ret != RM_OK) {
+ MMRADIO_LOG_ERROR("rm_register fail %d", ret);
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ MMRADIO_LOG_FLEAVE();
+
+ return MM_ERROR_NONE;
+
+}
+
+int mm_radio_rm_acquire(MMHandleType hradio, MMRadioResourceTypes type)
+{
+ int ret = RM_OK;
+ int idx = 0;
+ int category_option = 0;
+ rm_rsc_category_e category_id = RM_CATEGORY_NONE;
+ rm_requests_resource_state_e state;
+ rm_category_request_s request_resources;
+ rm_device_return_s *returned_device;
+ g_autoptr(GMutexLocker) locker = NULL;
+ mm_radio_t *radio = (mm_radio_t *)hradio;
+
+ MMRADIO_LOG_FENTER();
+
+ MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+ locker = g_mutex_locker_new(&radio->resource.rm_control_lock);
+
+ MMRADIO_LOG_INFO("app id : %s type %d", radio->resource.rci.app_id, type);
+ memset(&request_resources, 0x0, sizeof(rm_category_request_s));
+
+ returned_device = &radio->resource.returned_devices[type];
+ memset(returned_device, 0x0, sizeof(rm_device_return_s));
+
+ switch (type) {
+ case MM_RADIO_RES_TYPE_RADIO:
+ state = RM_STATE_EXCLUSIVE;
+ category_id = RM_CATEGORY_RADIO;
+ break;
+ default:
+ MMRADIO_LOG_ERROR("category id can't set");
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ category_option = rc_get_capable_category_id(radio->resource.rm_h, radio->resource.rci.app_id, category_id);
+
+ request_resources.request_num = 1;
+ request_resources.state[0] = state;
+ request_resources.category_id[0] = category_id;
+ request_resources.category_option[0] = category_option;
+ MMRADIO_LOG_INFO("state %d category id 0x%x category option %d", state, category_id, category_option);
+
+ ret = rm_allocate_resources(radio->resource.rm_h, &request_resources, returned_device);
+ if (ret != RM_OK) {
+ MMRADIO_LOG_WARNING("Resource allocation request failed ret %d [error type %d]", ret, returned_device->error_type);
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ for (idx = 0; idx < returned_device->allocated_num; idx++)
+ MMRADIO_LOG_INFO("#%d / %d [%p] device %d %s %s", idx, returned_device->allocated_num, returned_device,
+ returned_device->device_id[idx], returned_device->device_node[idx],
+ returned_device->device_name[idx]);
+
+ MMRADIO_LOG_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+int mm_radio_rm_release(MMHandleType hradio, MMRadioResourceTypes type)
+{
+ int rm_ret = RM_OK;
+ int idx = 0;
+ rm_device_request_s requested;
+ rm_device_return_s *r_devices;
+ g_autoptr(GMutexLocker) locker = NULL;
+ mm_radio_t *radio = (mm_radio_t *)hradio;
+
+ MMRADIO_LOG_FENTER();
+
+ MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+ MMRADIO_RETURN_VAL_IF_FAIL(radio->resource.rm_h, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+ locker = g_mutex_locker_new(&radio->resource.rm_control_lock);
+
+ r_devices = &radio->resource.returned_devices[type];
+
+ MMRADIO_LOG_INFO("[%p] #%d (type %d) alloc num %d", r_devices, idx, type, r_devices->allocated_num);
+
+ if (r_devices->allocated_num > 0) {
+ memset(&requested, 0x0, sizeof(rm_device_request_s));
+ requested.request_num = r_devices->allocated_num;
+ for (idx = 0; idx < requested.request_num; idx++) {
+ requested.device_id[idx] = r_devices->device_id[idx];
+ MMRADIO_LOG_INFO("[device id %d] [device name %s]", r_devices->device_id[idx], r_devices->device_name[idx]);
+ }
+
+ rm_ret = rm_deallocate_resources(radio->resource.rm_h, &requested);
+ if (rm_ret != RM_OK) {
+ MMRADIO_LOG_ERROR("Resource deallocation request failed [%d] [request num %d]", rm_ret, requested.request_num);
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+ }
+
+ for (idx = 0; idx < r_devices->allocated_num; idx++) {
+ if (r_devices->device_node[idx]) {
+ free(r_devices->device_node[idx]);
+ r_devices->device_node[idx] = NULL;
+ }
+
+ if (r_devices->omx_comp_name[idx]) {
+ free(r_devices->omx_comp_name[idx]);
+ r_devices->omx_comp_name[idx] = NULL;
+ }
+ }
+
+ MMRADIO_LOG_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+int mm_radio_rm_unregister(MMHandleType hradio)
+{
+ int ret;
+ mm_radio_t *radio = (mm_radio_t *)hradio;
+
+ MMRADIO_LOG_FENTER();
+
+ MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+ if (!radio->resource.rm_h) {
+ MMRADIO_LOG_INFO("resource manager handle is not registered");
+ return MM_ERROR_NONE;
+ }
+
+ ret = rm_unregister(radio->resource.rm_h);
+ if (ret != RM_OK) {
+ MMRADIO_LOG_ERROR("rm_unregister fail %d", ret);
+ return MM_ERROR_RADIO_INTERNAL;
+ }
+
+ LOGD("rm_unregister[%d]", ret);
+
+ MMRADIO_LOG_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
gtest_libmm_radio_CXXFLAGS = -I$(top_srcdir)/src/include \
$(GTHREAD_CFLAGS) \
$(MMCOMMON_CFLAGS) \
- $(MM_RESOURCE_MANAGER_CFLAGS) \
+ $(RM_CFLAGS) \
+ $(RI_CFLAGS) \
+ $(RC_CFLAGS) \
$(DLOG_CFLAGS) \
$(GTESTS_CFLAGS) \
$(SOUNDMGR_CFLAGS) \
gtest_libmm_radio_LDADD = $(GTHREAD_LIBS) \
$(MMCOMMON_LIBS) \
- $(MM_RESOURCE_MANAGER_LIBS) \
+ $(RM_LIBS) \
+ $(RI_LIBS) \
+ $(RC_LIBS) \
$(DLOG_LIBS) \
$(GTESTS_LIBS) \
$(SOUNDMGR_LIBS) \