Add resource manager state, and check resource manager state using resrource manager... 37/53137/7
authorGilbok Lee <gilbok.lee@samsung.com>
Wed, 2 Dec 2015 05:21:30 +0000 (14:21 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Fri, 4 Dec 2015 02:05:01 +0000 (11:05 +0900)
Change-Id: I4658abed508c61001409aecb704300b4a4fb9ed8
Signed-off-by: Gilbok Lee <gilbok.lee@samsung.com>
src/include/mm_player_resource.h
src/server/mm_player_priv.c
src/server/mm_player_resource.c

index 0b1c883..f8d0dc7 100644 (file)
@@ -34,10 +34,20 @@ typedef enum {
        RESOURCE_TYPE_VIDEO_OVERLAY,
 } MMPlayerResourceType;
 
+typedef enum {
+       RESOURCE_STATE_NONE,
+       RESOURCE_STATE_INITIALIZED,
+       RESOURCE_STATE_PREPARED,
+       RESOURCE_STATE_ACQUIRED,
+       RESOURCE_STATE_MAX,
+} MMPlayerResourceState;
+
+
 typedef struct {
        mrp_mainloop_t *mloop;
        mrp_res_context_t *context;
        mrp_res_resource_set_t *rset;
+       MMPlayerResourceState state;
        bool is_connected;
        void *user_data;
        bool by_rm_cb;
@@ -49,6 +59,8 @@ int _mmplayer_resource_manager_acquire(MMPlayerResourceManager *resource_manager
 int _mmplayer_resource_manager_release(MMPlayerResourceManager *resource_manager);
 int _mmplayer_resource_manager_unprepare(MMPlayerResourceManager *resource_manager);
 int _mmplayer_resource_manager_deinit(MMPlayerResourceManager *resource_manager);
+int _mmplayer_resource_manager_get_state(MMPlayerResourceManager *resource_manager, MMPlayerResourceState *state);
+
 
 #ifdef __cplusplus
 }
index fb4667b..4c84294 100644 (file)
@@ -3743,6 +3743,7 @@ __mmplayer_gst_decode_callback(GstElement *elem, GstPad *pad, gpointer data) //
        GstElement* sinkbin = NULL;
        gboolean reusing = FALSE;
        GstElement *text_selector = NULL;
+       MMPlayerResourceState resource_state = RESOURCE_STATE_NONE;
 
        /* check handles */
        player = (mm_player_t*) data;
@@ -3839,22 +3840,38 @@ __mmplayer_gst_decode_callback(GstElement *elem, GstPad *pad, gpointer data) //
                                LOGD("not make videobin because it dose not want\n");
                                goto ERROR;
                        }
+
                        if (surface_client_type == MM_DISPLAY_SURFACE_X)
                        {
-                               /* prepare resource manager for video overlay */
-                               if((_mmplayer_resource_manager_prepare(&player->resource_manager, RESOURCE_TYPE_VIDEO_OVERLAY)))
+                               if (_mmplayer_resource_manager_get_state(&player->resource_manager, &resource_state) == MM_ERROR_NONE)
                                {
-                                       LOGE("could not prepare for video_overlay resource\n");
-                                       goto ERROR;
+                                       /* prepare resource manager for video overlay */
+                                       if (resource_state >= RESOURCE_STATE_INITIALIZED)
+                                       {
+                                               if (_mmplayer_resource_manager_prepare(&player->resource_manager, RESOURCE_TYPE_VIDEO_OVERLAY)
+                                                       != MM_ERROR_NONE)
+                                               {
+                                                       LOGE("could not prepare for video_overlay resource\n");
+                                                       goto ERROR;
+                                               }
+                                       }
                                }
                        }
 
-                       /* acquire resources for video playing */
-                       if((player->resource_manager.rset && _mmplayer_resource_manager_acquire(&player->resource_manager)))
+                       if (_mmplayer_resource_manager_get_state(&player->resource_manager, &resource_state)
+                               == MM_ERROR_NONE)
                        {
-                               LOGE("could not acquire resources for video playing\n");
-                               _mmplayer_resource_manager_unprepare(&player->resource_manager);
-                               goto ERROR;
+                               /* acquire resources for video playing */
+                               if (resource_state >= RESOURCE_STATE_PREPARED)
+                               {
+                                       if (_mmplayer_resource_manager_acquire(&player->resource_manager)
+                                               != MM_ERROR_NONE)
+                                       {
+                                               LOGE("could not acquire resources for video playing\n");
+                                               _mmplayer_resource_manager_unprepare(&player->resource_manager);
+                                               goto ERROR;
+                                       }
+                               }
                        }
 
                        if (MM_ERROR_NONE !=  __mmplayer_gst_create_video_pipeline(player, caps, surface_type) )
@@ -9969,6 +9986,7 @@ int
 _mmplayer_unrealize(MMHandleType hplayer)
 {
        mm_player_t* player = (mm_player_t*)hplayer;
+       MMPlayerResourceState resource_state = RESOURCE_STATE_NONE;
        int ret = MM_ERROR_NONE;
 
        MMPLAYER_FENTER();
@@ -9992,20 +10010,28 @@ _mmplayer_unrealize(MMHandleType hplayer)
                        LOGE("failed to release sound focus, ret(0x%x)\n", ret);
                }
 
-               ret = _mmplayer_resource_manager_release(&player->resource_manager);
-               if (ret == MM_ERROR_RESOURCE_INVALID_STATE)
+               if (_mmplayer_resource_manager_get_state(&player->resource_manager, &resource_state) == MM_ERROR_NONE)
                {
-                       LOGW("it could be in the middle of resource callback or there's no acquired resource\n");
-                       ret = MM_ERROR_NONE;
-               }
-               else if (ret != MM_ERROR_NONE)
-               {
-                       LOGE("failed to release resource, ret(0x%x)\n", ret);
+                       if (resource_state >= RESOURCE_STATE_ACQUIRED)
+                       {
+                               ret = _mmplayer_resource_manager_release(&player->resource_manager);
+                               if (ret != MM_ERROR_NONE)
+                               {
+                                       LOGE("failed to release resource, ret(0x%x)\n", ret);
+                               }
+                       }
                }
-               ret = _mmplayer_resource_manager_unprepare(&player->resource_manager);
-               if (ret != MM_ERROR_NONE)
+
+               if (_mmplayer_resource_manager_get_state(&player->resource_manager, &resource_state) == MM_ERROR_NONE)
                {
-                       LOGE("failed to unprepare resource, ret(0x%x)\n", ret);
+                       if (resource_state == RESOURCE_STATE_PREPARED)
+                       {
+                               ret = _mmplayer_resource_manager_unprepare(&player->resource_manager);
+                               if (ret != MM_ERROR_NONE)
+                               {
+                                       LOGE("failed to unprepare resource, ret(0x%x)\n", ret);
+                               }
+                       }
                }
        }
        else
@@ -12943,11 +12969,21 @@ GstCaps* caps, GstElementFactory* factory, gpointer data)
                        }
 
                        /* prepare resource manager for video decoder */
-                       if((_mmplayer_resource_manager_prepare(&player->resource_manager, RESOURCE_TYPE_VIDEO_DECODER)))
+                       MMPlayerResourceState resource_state = RESOURCE_STATE_NONE;
+
+                       if (_mmplayer_resource_manager_get_state(&player->resource_manager, &resource_state) == MM_ERROR_NONE)
                        {
-                               LOGW ("could not prepare for video_decoder resource, skip it.");
-                               result = GST_AUTOPLUG_SELECT_SKIP;
-                               goto DONE;
+                               /* prepare resource manager for video overlay */
+                               if (resource_state >= RESOURCE_STATE_INITIALIZED)
+                               {
+                                       if (_mmplayer_resource_manager_prepare(&player->resource_manager, RESOURCE_TYPE_VIDEO_DECODER)
+                                               != MM_ERROR_NONE)
+                                       {
+                                               LOGW ("could not prepare for video_decoder resource, skip it.");
+                                               result = GST_AUTOPLUG_SELECT_SKIP;
+                                               goto DONE;
+                                       }
+                               }
                        }
                }
        }
index ffcddd9..f922738 100644 (file)
@@ -167,6 +167,9 @@ static void mrp_rset_state_callback(mrp_res_context_t *cx, const mrp_res_resourc
                return;
        }
 
+       if (rs->state == MRP_RES_RESOURCE_ACQUIRED)
+               player->resource_manager.state = RESOURCE_STATE_ACQUIRED;
+
        LOGD(" - resource set state of player(%p) is changed to [%s]\n", player, state_to_str(rs->state));
        for (i = 0; i < MRP_RESOURCE_MAX; i++)
        {
@@ -331,6 +334,8 @@ int _mmplayer_resource_manager_init(MMPlayerResourceManager *resource_manager, v
                return MM_ERROR_RESOURCE_INTERNAL;
        }
 
+       resource_manager->state = RESOURCE_STATE_INITIALIZED;
+
        MMPLAYER_FLEAVE();
 
        return MM_ERROR_NONE;
@@ -360,6 +365,8 @@ int _mmplayer_resource_manager_prepare(MMPlayerResourceManager *resource_manager
                }
        }
 
+       resource_manager->state = RESOURCE_STATE_PREPARED;
+
        MMPLAYER_FLEAVE();
 
        return ret;
@@ -431,6 +438,8 @@ int _mmplayer_resource_manager_release(MMPlayerResourceManager *resource_manager
                }
        }
 
+       resource_manager->state = RESOURCE_STATE_PREPARED;
+
        MMPLAYER_FLEAVE();
 
        return ret;
@@ -454,6 +463,8 @@ int _mmplayer_resource_manager_unprepare(MMPlayerResourceManager *resource_manag
                resource_manager->rset = NULL;
        }
 
+       resource_manager->state = RESOURCE_STATE_INITIALIZED;
+
        MMPLAYER_FLEAVE();
 
        return ret;
@@ -486,7 +497,26 @@ int _mmplayer_resource_manager_deinit(MMPlayerResourceManager *resource_manager)
                resource_manager->mloop = NULL;
        }
 
+       resource_manager->state = RESOURCE_STATE_NONE;
+
        MMPLAYER_FLEAVE();
 
        return MM_ERROR_NONE;
 }
+
+int _mmplayer_resource_manager_get_state(MMPlayerResourceManager *resource_manager, MMPlayerResourceState *state)
+{
+
+       MMPLAYER_FENTER();
+       MMPLAYER_CHECK_RESOURCE_MANAGER_INSTANCE(resource_manager);
+       MMPLAYER_RETURN_VAL_IF_FAIL(state, MM_ERROR_INVALID_ARGUMENT);
+
+       LOGD("resource_state is %d", resource_manager->state);
+
+       *state = resource_manager->state;
+
+       MMPLAYER_FLEAVE();
+
+       return MM_ERROR_NONE;
+}
+