#include <sound_manager.h>
#include <gst/allocators/gsttizenmemory.h>
#include <tbm_surface_internal.h>
+#ifdef RM_COMMON
+#include <resource_center.h>
+#include "mm_player_rm.h"
+#endif
/*===========================================================================================
| |
_mmplayer_set_state(mmplayer_t *player, int state)
{
MMMessageParamType msg = {0, };
-
MMPLAYER_RETURN_IF_FAIL(player);
if (MMPLAYER_CURRENT_STATE(player) == state) {
MMPLAYER_POST_MSG(player, MM_MESSAGE_STATE_INTERRUPTED, &msg);
else /* state changed by usecase */
MMPLAYER_POST_MSG(player, MM_MESSAGE_STATE_CHANGED, &msg);
-
} else {
LOGD("intermediate state, do nothing.");
MMPLAYER_PRINT_STATE(player);
return MM_ERROR_PLAYER_NO_OP;
}
-int _mmplayer_acquire_hw_resource(mmplayer_t *player, mmplayer_resource_type_e type)
-{
- int rm_ret = MM_RESOURCE_MANAGER_ERROR_NONE;
- mm_resource_manager_res_type_e rm_res_type = MM_RESOURCE_MANAGER_RES_TYPE_MAX;
-
- switch (type) {
- case MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER:
- rm_res_type = MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_DECODER;
- break;
- case MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY:
- rm_res_type = MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY;
- break;
- case MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD:
- rm_res_type = MM_RESOURCE_MANAGER_RES_TYPE_AUDIO_OFFLOAD;
- break;
- default:
- LOGE("invalid mmplayer resource type %d", type);
- return MM_ERROR_PLAYER_INTERNAL;
- }
-
- if (player->hw_resource[type] != NULL) {
- LOGD("[%d type] resource was already acquired", type);
- return MM_ERROR_NONE;
- }
-
- LOGD("mark for acquire [%d type] resource", type);
- rm_ret = mm_resource_manager_mark_for_acquire(player->resource_manager,
- rm_res_type, MM_RESOURCE_MANAGER_RES_VOLUME_FULL, &player->hw_resource[type]);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGE("failed to mark resource for acquire, ret(0x%x)", rm_ret);
- return MM_ERROR_PLAYER_INTERNAL;
- }
-
- LOGD("commit [%d type] resource", type);
- rm_ret = mm_resource_manager_commit(player->resource_manager);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGE("failed to commit of resource, ret(0x%x)", rm_ret);
- return MM_ERROR_PLAYER_INTERNAL;
- }
-
- MMPLAYER_FLEAVE();
- return MM_ERROR_NONE;
-}
-
-static void __mmplayer_destroy_hw_resource(mmplayer_t *player)
-{
- int rm_ret = MM_RESOURCE_MANAGER_ERROR_NONE;
-
- MMPLAYER_RETURN_IF_FAIL(player);
- MMPLAYER_RETURN_IF_FAIL(player->resource_manager);
-
- rm_ret = mm_resource_manager_mark_all_for_release(player->resource_manager);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGW("failed to mark all for release of resource, ret(0x%x)", rm_ret);
- goto rm_destroy;
- }
-
- rm_ret = mm_resource_manager_commit(player->resource_manager);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE)
- LOGW("failed to commit resource, ret(0x%x)", rm_ret);
-
-rm_destroy:
- /* de-initialize resource manager */
- rm_ret = mm_resource_manager_destroy(player->resource_manager);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGW("failed to destroy resource manager, ret(0x%x)", rm_ret);
- return;
- }
-
- player->resource_manager = NULL;
-
- LOGD("resource manager is destroyed");
-}
-
-static int __mmplayer_release_hw_resource(mmplayer_t *player, mmplayer_resource_type_e type)
-{
- int rm_ret = MM_RESOURCE_MANAGER_ERROR_NONE;
-
- MMPLAYER_FENTER();
-
- if (player->hw_resource[type] == NULL) {
- LOGD("there is no acquired [%d type] resource", type);
- return MM_ERROR_NONE;
- }
-
- LOGD("mark for release [%d type] resource", type);
- rm_ret = mm_resource_manager_mark_for_release(player->resource_manager, player->hw_resource[type]);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGE("failed to mark resource for release, ret(0x%x)", rm_ret);
- return MM_ERROR_PLAYER_INTERNAL;
- }
-
- player->hw_resource[type] = NULL;
-
- LOGD("commit [%d type] resource", type);
- rm_ret = mm_resource_manager_commit(player->resource_manager);
- if (rm_ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGE("failed to commit resource, ret(0x%x)", rm_ret);
- return MM_ERROR_PLAYER_INTERNAL;
- }
-
- MMPLAYER_FLEAVE();
- return MM_ERROR_NONE;
-}
-
static void
__mmplayer_initialize_gapless_play(mmplayer_t *player)
{
player->audio_decoders = NULL;
}
- __mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER);
+#ifdef RM_COMMON
+ if (_mmplayer_rm_deallocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
+ LOGE("[DECODER] _mmplayer_rm_deallocate failed [res handle %d]", player->res.handle);
+ return;
+ }
+
+ player->interrupted_by_resource = FALSE;
+#endif
MMPLAYER_FLEAVE();
}
gboolean reusing = FALSE;
gboolean caps_ret = TRUE;
gchar *sink_pad_name = "sink";
-
/* check handles */
player = (mmplayer_t *)data;
mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &surface_type);
LOGD("display_surface_type (%d)", surface_type);
+#ifdef RM_COMMON
if ((surface_type == MM_DISPLAY_SURFACE_OVERLAY || surface_type == MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) &&
- (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE)) {
+ (_mmplayer_rm_allocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE)) {
LOGE("failed to acquire video overlay resource");
goto ERROR;
}
-
- player->interrupted_by_resource = FALSE;
+#endif
if (__mmplayer_gst_create_video_sink_bin(player, caps, surface_type) != MM_ERROR_NONE) {
LOGE("failed to create videobin. continuing without video");
MMPLAYER_RETURN_IF_FAIL(handle);
gst_video_overlay_set_video_roi_area(
- GST_VIDEO_OVERLAY(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
- player->video_roi.scale_x, player->video_roi.scale_y, player->video_roi.scale_width, player->video_roi.scale_height);
+ GST_VIDEO_OVERLAY(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
+ player->video_roi.scale_x, player->video_roi.scale_y, player->video_roi.scale_width, player->video_roi.scale_height);
LOGD("set video param : video roi area scale value: x(%f) y(%f) width(%f) height(%f)",
player->video_roi.scale_x, player->video_roi.scale_y, player->video_roi.scale_width, player->video_roi.scale_height);
}
/* After setting window handle, set display roi area */
gst_video_overlay_set_display_roi_area(
- GST_VIDEO_OVERLAY(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
- win_roi_x, win_roi_y, win_roi_width, win_roi_height);
+ GST_VIDEO_OVERLAY(player->pipeline->videobin[MMPLAYER_V_SINK].gst),
+ win_roi_x, win_roi_y, win_roi_width, win_roi_height);
LOGD("set video param : roi area : x(%d) y(%d) width(%d) height(%d)",
win_roi_x, win_roi_y, win_roi_width, win_roi_height);
}
LOGE("disable overlay");
g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", TRUE, NULL);
+#ifdef RM_COMMON
/* release overlay resource */
- if (__mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
- LOGE("failed to release overlay resource");
- return MM_ERROR_PLAYER_INTERNAL;
+ if (_mmplayer_rm_deallocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
+ LOGE("[OVERLAY] _mmplayer_rm_deallocate failed [res handle %d]", player->res.handle);
+ return MM_ERROR_RESOURCE_INTERNAL;
}
+
+ player->interrupted_by_resource = FALSE;
+#endif
} else {
- if (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
+#ifdef RM_COMMON
+ if (_mmplayer_rm_allocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
LOGE("failed to acquire video overlay resource");
return MM_ERROR_PLAYER_INTERNAL;
}
- player->interrupted_by_resource = FALSE;
+#endif
LOGD("enable overlay");
__mmplayer_video_param_set_display_overlay(player);
__mmplayer_switch_stream(player, MM_PLAYER_TRACK_TYPE_VIDEO, INVALID_TRACK_INDEX);
/* release decoder resource */
- if (__mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
- LOGE("failed to release video decoder resources");
- return MM_ERROR_PLAYER_INTERNAL;
+#ifdef RM_COMMON
+ if (_mmplayer_rm_deallocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
+ LOGE("[DECODER] _mmplayer_rm_deallocate failed %d", player->res.handle);
+ return MM_ERROR_RESOURCE_INTERNAL;
}
+
+ player->interrupted_by_resource = FALSE;
+#endif
+
player->can_support_codec &= ~FOUND_PLUGIN_VIDEO;
} else {
__mmplayer_switch_stream(player, MM_PLAYER_TRACK_TYPE_VIDEO, DEFAULT_TRACK_INDEX);
if ((surface_type != MM_DISPLAY_SURFACE_OVERLAY &&
surface_type != MM_DISPLAY_SURFACE_OVERLAY_SYNC_UI) ||
player->set_mode.video_zc) {
- LOGD("skip creating the videoconv and rotator");
+ LOGD("[surface type %d] skip creating the videoconv and rotator", surface_type);
return MM_ERROR_NONE;
}
return ret;
}
-static int
-__resource_release_cb(mm_resource_manager_h rm, mm_resource_manager_res_h res,
- void *user_data)
+void _mmplayer_execute_resource_release(mmplayer_t *player)
{
- mmplayer_t *player = NULL;
- MMMessageParamType msg = {0, };
gint64 pos = 0;
- mmplayer_resource_type_e res_idx = MMPLAYER_RESOURCE_TYPE_MAX;
-
- MMPLAYER_FENTER();
-
- if (!user_data) {
- LOGE("user_data is null");
- return TRUE;
- }
-
- player = (mmplayer_t *)user_data;
-
- if (!player->pipeline || !player->attrs) {
- LOGW("not initialized");
- return TRUE;
- }
+ MMMessageParamType msg = {0,};
LOGD("cmd lock player, cmd state : %d", player->cmd);
MMPLAYER_CMD_LOCK(player);
|| MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_NONE) {
LOGW("player already destroyed");
MMPLAYER_CMD_UNLOCK(player);
- return TRUE;
+ return;
}
player->interrupted_by_resource = TRUE;
LOGE("failed to unrealize");
MMPLAYER_CMD_UNLOCK(player);
-
- for (res_idx = MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER; res_idx < MMPLAYER_RESOURCE_TYPE_MAX; res_idx++) {
- player->hw_resource[res_idx] = NULL;
- }
-
- MMPLAYER_FLEAVE();
- return TRUE; /* release all the resources */
}
static void
/* do not handle as error for headless profile */
}
- /* initialize resource manager */
- if (mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
- __resource_release_cb, player, &player->resource_manager)
- != MM_RESOURCE_MANAGER_ERROR_NONE) {
- LOGE("failed to create resource manager");
- ret = MM_ERROR_PLAYER_INTERNAL;
- goto ERROR;
- }
-
/* create video bo lock and cond */
g_mutex_init(&player->video_bo_mutex);
g_cond_init(&player->video_bo_cond);
return MM_ERROR_PLAYER_INTERNAL;
}
- __mmplayer_destroy_hw_resource(player);
+#ifdef RM_COMMON
+ if (_mmplayer_rm_release(player) != MM_ERROR_NONE)
+ LOGE("_mmplayer_rm_release is failed");
+#endif
g_queue_free(player->bus_msg_q);
/* check current state */
MMPLAYER_CHECK_STATE(player, MMPLAYER_COMMAND_REALIZE);
+#ifdef RM_COMMON
+ ret = _mmplayer_rm_create(player);
+ if (ret != MM_ERROR_NONE) {
+ LOGE("Resource create failed, ret : 0x%x", ret);
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+#endif
+
attrs = MMPLAYER_GET_ATTRS(player);
if (!attrs) {
LOGE("fail to get attributes.");
ret = __mmplayer_gst_unrealize(player);
for (res_idx = MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER; res_idx < MMPLAYER_RESOURCE_TYPE_MAX; res_idx++) {
- rm_ret = __mmplayer_release_hw_resource(player, res_idx);
- if (rm_ret != MM_ERROR_NONE)
- LOGE("failed to release [%d] resources", res_idx);
- }
+#ifdef RM_COMMON
+ if (_mmplayer_rm_deallocate(player, res_idx) != MM_ERROR_NONE) {
+ LOGE("[%d] _mmplayer_rm_deallocate failed [res handle %d]", res_idx, player->res.handle);
+ return MM_ERROR_RESOURCE_INTERNAL;
+ }
- player->interrupted_by_resource = FALSE;
+ player->interrupted_by_resource = FALSE;
+#endif
+ }
MMPLAYER_FLEAVE();
return ret;
}
gst_object_unref(factory);
- if (_mmplayer_acquire_hw_resource(player,
+#ifdef RM_COMMON
+ if (_mmplayer_rm_allocate(player,
MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD) != MM_ERROR_NONE) {
LOGE("failed to acquire audio offload decoder resource");
goto DONE;
}
+#endif
if (!__mmplayer_add_audio_device_connected_cb(player))
goto DONE;
ret = TRUE;
DONE:
- if (!ret)
- __mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD);
+ if (!ret) {
+#ifdef RM_COMMON
+ if (_mmplayer_rm_deallocate(player, MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD) != MM_ERROR_NONE) {
+ LOGE("[AUDIO_OFFLOAD] _mmplayer_rm_deallocate failed %d", player->res.handle);
+ return MM_ERROR_RESOURCE_INTERNAL;
+ }
+
+ player->interrupted_by_resource = FALSE;
+#endif
+ }
MMPLAYER_FLEAVE();
return ret;
if ((strlen(player->ini.videocodec_element_hw) > 0) &&
(g_strrstr(factory_name, player->ini.videocodec_element_hw))) {
- /* mark video decoder for acquire */
- if (player->hw_resource[MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER] != NULL) {
- LOGW("video decoder resource is already acquired, skip it.");
- ret = GST_AUTOPLUG_SELECT_SKIP;
- goto DONE;
- }
-
- if (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
+#ifdef RM_COMMON
+ if (_mmplayer_rm_allocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) {
LOGE("failed to acquire video decoder resource");
ret = GST_AUTOPLUG_SELECT_SKIP;
goto DONE;
}
- player->interrupted_by_resource = FALSE;
+#endif
}
/* update codec info */
GValueArray *new_factories = NULL;
GValue val = { 0, };
GstElementFactory *factory = NULL;
+ guint new_pos = DEFAULT_IDX;
+ guint rm_pos = DEFAULT_IDX;
const gchar *klass = NULL;
gchar *factory_name = NULL;
guint hw_dec_idx = DEFAULT_IDX;
guint first_sw_dec_idx = DEFAULT_IDX;
guint last_sw_dec_idx = DEFAULT_IDX;
- guint new_pos = DEFAULT_IDX;
- guint rm_pos = DEFAULT_IDX;
int audio_codec_type;
int video_codec_type;
mmplayer_codec_type_e codec_type = MM_PLAYER_CODEC_TYPE_DEFAULT;
#ifdef __DEBUG__
LOGD("num of factory : %d, codec type %d, %d", factories->n_values, video_codec_type, audio_codec_type);
#endif
+
for (int i = 0 ; i < factories->n_values ; i++) {
gchar *hw_dec_info = NULL;
gchar (*sw_dec_info)[PLAYER_INI_MAX_STRLEN] = {NULL, };
-
factory = g_value_get_object(g_value_array_get_nth(factories, i));
if (!factory) {
LOGW("failed to get factory object");
}
klass = gst_element_factory_get_klass(factory);
factory_name = GST_OBJECT_NAME(factory);
-
#ifdef __DEBUG__
LOGD("Klass [%s] Factory [%s]", klass, factory_name);
#endif
hw_dec_idx = i;
} else {
for (int j = 0; sw_dec_info[j][0] != '\0'; j++) {
- if (strstr(factory_name, sw_dec_info[j])) {
+ if (factory_name && strstr(factory_name, sw_dec_info[j])) {
last_sw_dec_idx = i;
if (first_sw_dec_idx == DEFAULT_IDX) {
first_sw_dec_idx = i;
}
}
- if (first_sw_dec_idx == DEFAULT_IDX)
- LOGW("unknown codec %s", factory_name);
+ if (first_sw_dec_idx == DEFAULT_IDX) {
+ if (factory_name)
+ LOGW("unknown codec %s", factory_name);
+ }
}
}
mainbin[MMPLAYER_M_V_CONCAT].id = 0;
MMPLAYER_FREEIF(player->pipeline->videobin);
- ret = __mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY);
- if (ret != MM_ERROR_NONE)
- LOGE("failed to release overlay resources");
+#ifdef RM_COMMON
+ if (_mmplayer_rm_deallocate(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) {
+ LOGE("[OVERLAY] _mmplayer_rm_deallocate failed %d", player->res.handle);
+ return;
+ }
+
+ player->interrupted_by_resource = FALSE;
+#endif
player->videodec_linked = 0;
--- /dev/null
+/*
+ * libmm-player
+ *
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@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 FILES |
+========================================================================================*/
+#ifdef RM_COMMON
+#include <rm_api.h>
+#include <rm_type.h>
+#include <resource_center.h>
+#include "mm_player_utils.h"
+#include "mm_player_gst.h"
+#include "mm_player_rm.h"
+#include <mm_error.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "MM_PLAYER_RM"
+#endif
+
+#define STR_LEN_MAX 128
+
+static int
+__mmplayer_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;
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(name, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(size != 0, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ cmdline = g_strdup_printf("/proc/%d/cmdline", (int)pid);
+
+ if (!g_file_get_contents(cmdline, &contents, NULL, &error)) {
+ LOGE("error : %s", error->message);
+ return MM_ERROR_PLAYER_NOT_INITIALIZED;
+ }
+
+ base = g_path_get_basename(contents);
+
+ if (g_strlcpy(name, base, size) >= size)
+ LOGE("string truncated");
+
+ return MM_ERROR_NONE;
+}
+
+static rm_cb_result
+__mmplayer_rm_callback(int handle, rm_callback_type event_src, rm_device_request_s *info, void *cb_data)
+{
+ mmplayer_t *player = MM_PLAYER_CAST(cb_data);
+ g_autoptr(GMutexLocker) locker = NULL;
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ LOGI("rm callback info mm_player_t [%p] handle : %d event_src : %d", player, handle, event_src);
+
+ locker = g_mutex_locker_new(&player->res.callback_lock);
+
+ switch (event_src) {
+ case RM_CALLBACK_TYPE_RESOURCE_CONFLICT:
+ case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD:
+ _mmplayer_execute_resource_release(player);
+ break;
+ default:
+ break;
+ }
+
+ MMPLAYER_FLEAVE();
+
+ LOGI("RM_CB_RESULT_OK");
+ return RM_CB_RESULT_OK;
+}
+
+int _mmplayer_rm_create(mmplayer_t *player)
+{
+ int ret;
+
+ MMPLAYER_FENTER();
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (player->res.handle) {
+ LOGI("[%d] resource manager handle is already registered", player->res.handle);
+ return MM_ERROR_NONE;
+ }
+
+ g_mutex_init(&player->res.control_lock);
+ g_mutex_init(&player->res.callback_lock);
+
+ memset(&player->res.rci, 0x00, sizeof(rm_consumer_info));
+
+ player->res.rci.app_pid = player->client_pid;
+
+ if (__mmplayer_get_appid_by_pid(player->res.rci.app_pid, player->res.rci.app_id, sizeof(player->res.rci.app_id)) != MM_ERROR_NONE) {
+ LOGE("__mmplayer_get_appid_by_pid is failed");
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+
+ LOGI("app pid %d app id %s", player->res.rci.app_pid, player->res.rci.app_id);
+
+ ret = rm_register((rm_resource_cb)__mmplayer_rm_callback,
+ (void *)player,
+ &(player->res.handle),
+ (player->res.rci.app_id[0] != '\0') ? &player->res.rci : NULL);
+ if (ret != RM_OK) {
+ LOGE("rm_register fail %d", ret);
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+
+ MMPLAYER_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+int _mmplayer_rm_allocate(mmplayer_t *player, mmplayer_resource_type_e 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 *device;
+ g_autoptr(GMutexLocker) locker = NULL;
+
+ MMPLAYER_FENTER();
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ locker = g_mutex_locker_new(&player->res.control_lock);
+
+ LOGI("app id : %s type %d", player->res.rci.app_id, type);
+ memset(&request_resources, 0x0, sizeof(rm_category_request_s));
+
+ device = &player->res.devices[type];
+ memset(device, 0x0, sizeof(rm_device_return_s));
+
+ switch (type) {
+ case MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER:
+ state = RM_STATE_EXCLUSIVE;
+ category_id = RM_CATEGORY_VIDEO_DECODER;
+ break;
+ case MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY:
+ state = RM_STATE_EXCLUSIVE;
+ category_id = RM_CATEGORY_SCALER;
+ break;
+ case MMPLAYER_RESOURCE_TYPE_AUDIO_OFFLOAD:
+ state = RM_STATE_EXCLUSIVE;
+ category_id = RM_CATEGORY_AUDIO_OFFLOAD;
+ break;
+ default:
+ LOGE("category id can't set");
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+
+ category_option = rc_get_capable_category_id(player->res.handle, player->res.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;
+ LOGI("state %d category id 0x%x category option %d", state, category_id, category_option);
+
+ ret = rm_allocate_resources(player->res.handle, &request_resources, device);
+ if (ret != RM_OK) {
+ LOGW("Resource allocation request failed ret %d [error type %d]", ret, device->error_type);
+ MM_ERROR_PLAYER_INTERNAL;
+ }
+
+ for (idx = 0; idx < device->allocated_num; idx++)
+ LOGI("#%d / %d [%p] device %d %s %s", idx, device->allocated_num, device,
+ device->device_id[idx], device->device_node[idx],
+ device->device_name[idx]);
+
+ MMPLAYER_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+int _mmplayer_rm_deallocate(mmplayer_t *player, mmplayer_resource_type_e type)
+{
+ int rm_ret = RM_OK;
+ int idx = 0;
+ rm_device_request_s requested;
+ rm_device_return_s *devices;
+ g_autoptr(GMutexLocker) locker = NULL;
+
+ MMPLAYER_FENTER();
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(player->res.handle, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ locker = g_mutex_locker_new(&player->res.control_lock);
+
+ devices = &player->res.devices[type];
+
+ LOGI("[%p] #%d (type %d) alloc num %d", devices, idx, type, devices->allocated_num);
+
+ if (devices->allocated_num > 0) {
+ memset(&requested, 0x0, sizeof(rm_device_request_s));
+ requested.request_num = devices->allocated_num;
+ for (idx = 0; idx < requested.request_num; idx++) {
+ requested.device_id[idx] = devices->device_id[idx];
+ LOGI("[device id %d] [device name %s]", devices->device_id[idx], devices->device_name[idx]);
+ }
+
+ rm_ret = rm_deallocate_resources(player->res.handle, &requested);
+ if (rm_ret != RM_OK) {
+ LOGE("Resource deallocation request failed [%d] [request num %d]", rm_ret, requested.request_num);
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+ }
+
+ for (idx = 0; idx < devices->allocated_num; idx++) {
+ if (devices->device_node[idx]) {
+ free(devices->device_node[idx]);
+ devices->device_node[idx] = NULL;
+ }
+
+ if (devices->omx_comp_name[idx]) {
+ free(devices->omx_comp_name[idx]);
+ devices->omx_comp_name[idx] = NULL;
+ }
+ }
+
+ MMPLAYER_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+
+int _mmplayer_rm_release(mmplayer_t *player)
+{
+ int ret;
+
+ MMPLAYER_FENTER();
+
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (!player->res.handle) {
+ LOGI("resource manager handle is not registered");
+ return MM_ERROR_NONE;
+ }
+
+ ret = rm_unregister(player->res.handle);
+ if (ret != RM_OK) {
+ LOGE("rm_unregister fail %d", ret);
+ return MM_ERROR_PLAYER_INTERNAL;
+ }
+
+ g_mutex_clear(&player->res.control_lock);
+ g_mutex_clear(&player->res.callback_lock);
+
+ LOGD("rm_unregister[%d]", ret);
+
+ MMPLAYER_FLEAVE();
+
+ return MM_ERROR_NONE;
+}
+#endif /* RM_COMMON */
+