+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;
+}
+