add resource limit return during player create 73/78573/3
authorEunhae Choi <eunhae1.choi@samsung.com>
Wed, 6 Jul 2016 06:32:37 +0000 (15:32 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Wed, 6 Jul 2016 06:49:28 +0000 (15:49 +0900)
- add resource limit return
- add exception hanling about bo list control(sw codec)

Change-Id: I778aba3b615cc4c4073bf619887927961e7f5f79

packaging/libmm-player.spec
src/include/mm_player_priv.h
src/include/mm_player_utils.h
src/mm_player.c
src/mm_player_capture.c
src/mm_player_priv.c

index 5443f93f5ff429c60193c11360941f12af6d4428..e935fa83103e936e624817caa8cadc5adc4ecf04 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.5.87
+Version:    0.5.88
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 8d43d0b682ad90a3f36a14b74e13b08bb8384a33..cd77c8a5f6c14b843f82f69d0172d757d679647a 100644 (file)
@@ -509,7 +509,6 @@ typedef struct {
        /* message callback */
        MMMessageCallback msg_cb;
        void* msg_cb_param;
-       GMutex msg_cb_lock;
 
        /* progressive download */
        mm_player_pd_t *pd_downloader;
index d81199b0640c49858ded4a80d9490b98537241b5..94da65c242e09dcfbab630c7b063c621e05b3b80 100644 (file)
@@ -54,8 +54,6 @@ x = NULL;
 
 #define MMPLAYER_CMD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->cmd_lock)
 #define MMPLAYER_CMD_UNLOCK(x_player)  g_mutex_unlock( &((mm_player_t*)x_player)->cmd_lock )
-#define MMPLAYER_MSG_POST_LOCK(x_player)       g_mutex_lock( &((mm_player_t*)x_player)->msg_cb_lock )
-#define MMPLAYER_MSG_POST_UNLOCK(x_player)     g_mutex_unlock( &((mm_player_t*)x_player)->msg_cb_lock )
 #define MMPLAYER_PLAYBACK_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->playback_lock)
 #define MMPLAYER_PLAYBACK_UNLOCK(x_player) g_mutex_unlock( &((mm_player_t*)x_player)->playback_lock )
 #define MMPLAYER_GET_ATTRS(x_player)           ((mm_player_t*)x_player)->attrs
index d243294b87d9962ef4413f7392d5a5829da01c95..e1acd4c336dea6e4080b5bad56bb69891dc89a06 100644 (file)
 
 int mm_player_create(MMHandleType *player)
 {
-       int result = MM_ERROR_NONE;
+       int result = MM_ERROR_PLAYER_INTERNAL;
        mm_player_t* new_player = NULL;
 
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
-
        /* alloc player structure */
        new_player = g_malloc(sizeof(mm_player_t));
-       if ( ! new_player )
+       if (!new_player)
        {
                LOGE("Cannot allocate memory for player\n");
+               result = MM_ERROR_PLAYER_RESOURCE_LIMIT;
                goto ERROR;
        }
        memset(new_player, 0, sizeof(mm_player_t));
@@ -59,38 +59,32 @@ int mm_player_create(MMHandleType *player)
        /* create player lock */
        g_mutex_init(&new_player->playback_lock);
 
-
-       /* create msg callback lock */
-       g_mutex_init(&new_player->msg_cb_lock);
-
        /* load ini files */
-       result = mm_player_ini_load(&new_player->ini);
-       if(result != MM_ERROR_NONE)
+       if (MM_ERROR_NONE != mm_player_ini_load(&new_player->ini))
        {
                LOGE("can't load ini");
                goto ERROR;
        }
 
-       result = mm_player_audio_effect_ini_load(&new_player->ini);
-       if(result != MM_ERROR_NONE)
+       if (MM_ERROR_NONE != mm_player_audio_effect_ini_load(&new_player->ini))
        {
                LOGE("can't load audio ini");
                goto ERROR;
        }
 
-
        /* create player */
        result = _mmplayer_create_player((MMHandleType)new_player);
-
        if(result != MM_ERROR_NONE)
        {
                LOGE("failed to create player");
+               if (result != MM_ERROR_PLAYER_RESOURCE_LIMIT)
+                       result = MM_ERROR_PLAYER_INTERNAL;
                goto ERROR;
        }
 
        *player = (MMHandleType)new_player;
 
-       return result;
+       return MM_ERROR_NONE;
 
 ERROR:
 
@@ -104,7 +98,7 @@ ERROR:
        }
 
        *player = (MMHandleType)0;
-       return MM_ERROR_PLAYER_NO_FREE_SPACE; // are you sure?
+       return result; /* MM_ERROR_PLAYER_INTERNAL or MM_ERROR_PLAYER_RESOURCE_LIMIT */
 }
 
 int  mm_player_destroy(MMHandleType player)
index 840095e9481306d8ac450945b88b983635e2898a..be80a750717cf9319b9de3b279dd242d4aca1670 100644 (file)
@@ -55,6 +55,7 @@ static int __mm_player_convert_colorspace(mm_player_t* player, unsigned char* sr
 int
 _mmplayer_initialize_video_capture(mm_player_t* player)
 {
+       int ret = MM_ERROR_NONE;
        MMPLAYER_RETURN_VAL_IF_FAIL ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
        /* create capture mutex */
        g_mutex_init(&player->capture_thread_mutex);
@@ -71,10 +72,11 @@ _mmplayer_initialize_video_capture(mm_player_t* player)
 
        if ( ! player->capture_thread )
        {
+               ret = MM_ERROR_PLAYER_RESOURCE_LIMIT;
                goto ERROR;
        }
 
-       return MM_ERROR_NONE;
+       return ret;
 
 ERROR:
        /* capture thread */
@@ -82,7 +84,7 @@ ERROR:
 
        g_cond_clear (&player->capture_thread_cond );
 
-       return MM_ERROR_PLAYER_INTERNAL;
+       return ret;
 }
 
 int
index c706ba244f87fe44caf8bd9ac97b24ca2bb445ee..eaa341b63dbfbfad4c15d987ebf46ba5a8dc1d00 100644 (file)
@@ -5487,25 +5487,44 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size)
 
        g_mutex_lock(&player->video_bo_mutex);
 
-       if (!player->video_bo_list) {
+       if ((!player->video_bo_list) ||
+               (g_list_length(player->video_bo_list) < player->ini.num_of_video_bo)) {
+
                /* create bo list */
                int idx = 0;
                LOGD("Create bo list for decoded video stream(num:%d)", player->ini.num_of_video_bo);
 
-               for (idx=0 ; idx<player->ini.num_of_video_bo ; idx++) {
+               if (player->video_bo_list) {
+                       /* if bo list did not created all, try it again. */
+                       idx = g_list_length(player->video_bo_list);
+                       LOGD("bo list exist (len: %d)", idx);
+               }
+
+               for (; idx<player->ini.num_of_video_bo ; idx++) {
                        mm_player_video_bo_info_t* bo_info = g_new(mm_player_video_bo_info_t, 1);
+                       if (!bo_info) {
+                               LOGE("Fail to alloc bo_info.");
+                               break;
+                       }
                        bo_info->bo = tbm_bo_alloc(player->bufmgr, size, TBM_BO_DEFAULT);
                        if (!bo_info->bo) {
                                LOGE("Fail to tbm_bo_alloc.");
-                               return NULL;
+                               g_free(bo_info);
+                               break;
                        }
                        bo_info->using = FALSE;
                        player->video_bo_list = g_list_append(player->video_bo_list, bo_info);
                }
 
                /* update video num buffers */
-               player->video_num_buffers = player->ini.num_of_video_bo;
-               player->video_extra_num_buffers = (player->ini.num_of_video_bo)/2;
+               player->video_num_buffers = idx;
+               if (idx == player->ini.num_of_video_bo)
+                       player->video_extra_num_buffers = player->ini.num_of_video_bo/2;
+
+               if (idx == 0) {
+                       g_mutex_unlock(&player->video_bo_mutex);
+                       return NULL;
+               }
 
                LOGD("Num of video buffers(%d/%d)", player->video_num_buffers, player->video_extra_num_buffers);
        }
@@ -9382,6 +9401,7 @@ EXIT_WITHOUT_UNLOCK:
 int
 _mmplayer_create_player(MMHandleType handle) // @
 {
+       int ret = MM_ERROR_PLAYER_INTERNAL;
        mm_player_t* player = MM_PLAYER_CAST(handle);
 
        MMPLAYER_FENTER();
@@ -9403,14 +9423,15 @@ _mmplayer_create_player(MMHandleType handle) // @
        if ( !player->attrs )
        {
                LOGE("Failed to construct attributes\n");
-               goto ERROR;
+               return ret;
        }
 
        /* initialize gstreamer with configured parameter */
        if ( ! __mmplayer_init_gstreamer(player) )
        {
                LOGE("Initializing gstreamer failed\n");
-               goto ERROR;
+               _mmplayer_deconstruct_attribute(handle);
+               return ret;
        }
 
        /* initialize factories if not using decodebin */
@@ -9429,7 +9450,14 @@ _mmplayer_create_player(MMHandleType handle) // @
        /* create repeat thread */
        player->repeat_thread =
                g_thread_try_new ("repeat_thread", __mmplayer_repeat_thread, (gpointer)player, NULL);
-
+       if (!player->repeat_thread)
+       {
+               LOGE("failed to create repeat_thread(%s)");
+               g_mutex_clear(&player->repeat_thread_mutex);
+               g_cond_clear(&player->repeat_thread_cond);
+               ret = MM_ERROR_PLAYER_RESOURCE_LIMIT;
+               goto ERROR;
+       }
 
        /* create next play mutex */
        g_mutex_init(&player->next_play_thread_mutex);
@@ -9440,13 +9468,17 @@ _mmplayer_create_player(MMHandleType handle) // @
        /* create next play thread */
        player->next_play_thread =
                g_thread_try_new ("next_play_thread", __mmplayer_next_play_thread, (gpointer)player, NULL);
-       if ( ! player->next_play_thread )
+       if (!player->next_play_thread)
        {
                LOGE("failed to create next play thread");
+               ret = MM_ERROR_PLAYER_RESOURCE_LIMIT;
+               g_mutex_clear(&player->next_play_thread_mutex);
+               g_cond_clear(&player->next_play_thread_cond);
                goto ERROR;
        }
 
-       if ( MM_ERROR_NONE != _mmplayer_initialize_video_capture(player))
+       ret = _mmplayer_initialize_video_capture(player);
+       if (ret != MM_ERROR_NONE)
        {
                LOGE("failed to initialize video capture\n");
                goto ERROR;
@@ -9515,42 +9547,29 @@ ERROR:
                g_thread_join( player->repeat_thread );
                player->repeat_thread = NULL;
 
-               g_mutex_clear(&player->repeat_thread_mutex );
-
-               g_cond_clear (&player->repeat_thread_cond );
+               g_mutex_clear(&player->repeat_thread_mutex);
+               g_cond_clear(&player->repeat_thread_cond);
        }
-       /* clear repeat thread mutex/cond if still alive
-        * this can happen if only thread creating has failed
-        */
-       g_mutex_clear(&player->repeat_thread_mutex );
-       g_cond_clear ( &player->repeat_thread_cond );
 
        /* free next play thread */
-       if ( player->next_play_thread )
+       if (player->next_play_thread)
        {
                player->next_play_thread_exit = TRUE;
-               g_cond_signal( &player->next_play_thread_cond );
+               g_cond_signal(&player->next_play_thread_cond);
 
-               g_thread_join( player->next_play_thread );
+               g_thread_join(player->next_play_thread);
                player->next_play_thread = NULL;
 
-               g_mutex_clear(&player->next_play_thread_mutex );
-
-               g_cond_clear ( &player->next_play_thread_cond );
+               g_mutex_clear(&player->next_play_thread_mutex);
+               g_cond_clear(&player->next_play_thread_cond);
        }
-       /* clear next play thread mutex/cond if still alive
-        * this can happen if only thread creating has failed
-        */
-       g_mutex_clear(&player->next_play_thread_mutex );
-
-       g_cond_clear ( &player->next_play_thread_cond );
 
        /* release attributes */
        _mmplayer_deconstruct_attribute(handle);
 
        MMPLAYER_FLEAVE();
 
-       return MM_ERROR_PLAYER_INTERNAL;
+       return ret;
 }
 
 static gboolean
@@ -9804,8 +9823,6 @@ _mmplayer_destroy(MMHandleType handle) // @
        /* release lock */
        g_mutex_clear(&player->fsink_lock );
 
-       g_mutex_clear(&player->msg_cb_lock );
-
        /* release video bo lock and cond */
        g_mutex_clear(&player->video_bo_mutex);
        g_cond_clear(&player->video_bo_cond);