[0.6.219] Fix g_mutex_clear crash when destroying bus msg thread
[platform/core/multimedia/libmm-player.git] / src / mm_player_gst.c
index 79af3f2..7978600 100644 (file)
@@ -243,9 +243,6 @@ __mmplayer_gst_transform_gsterror(mmplayer_t *player, GstMessage *message, GErro
                                                                player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        src_element = GST_ELEMENT_CAST(message->src);
-       if (!src_element)
-               return MM_ERROR_PLAYER_INTERNAL;
-
        src_element_name = GST_ELEMENT_NAME(src_element);
        if (!src_element_name)
                return MM_ERROR_PLAYER_INTERNAL;
@@ -1820,18 +1817,12 @@ __mmplayer_gst_handle_element_message(mmplayer_t *player, GstMessage *msg)
                                        "rtsp_video_frame_size", G_TYPE_STRING, &video_frame_size, NULL);
                LOGD("rtsp_video_frame_size : %s", video_frame_size);
                if (video_frame_size) {
-                       char *seperator = strchr(video_frame_size, '-');
-                       if (seperator) {
-                               char video_width[10] = {0,};
-                               int frame_size_len = strlen(video_frame_size);
-                               int separtor_len = strlen(seperator);
-
-                               strncpy(video_width, video_frame_size, (frame_size_len - separtor_len));
-                               seperator++;
-
-                               mm_player_set_attribute((MMHandleType)player, NULL, MM_PLAYER_VIDEO_WIDTH,
-                                               atoi(video_width), MM_PLAYER_VIDEO_HEIGHT, atoi(seperator), NULL);
-                       }
+                       gchar **res_str = g_strsplit(video_frame_size, "-", 0);
+                       mm_player_set_attribute((MMHandleType)player, NULL,
+                               MM_PLAYER_VIDEO_WIDTH, atoi(res_str[0]),
+                               MM_PLAYER_VIDEO_HEIGHT, atoi(res_str[1]),
+                               NULL);
+                       g_strfreev(res_str);
                }
        }
 
@@ -1922,6 +1913,7 @@ __mmplayer_gst_bus_msg_callback(GstMessage *msg, gpointer data)
                break;
 
        case GST_MESSAGE_ERROR:
+               _mmplayer_set_reconfigure_state(player, FALSE);
                __mmplayer_gst_handle_error_message(player, msg);
                break;
 
@@ -2074,6 +2066,18 @@ __mmplayer_gst_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data
        case GST_MESSAGE_DURATION_CHANGED:
                __mmplayer_gst_handle_duration(player, message);
                break;
+       case GST_MESSAGE_ELEMENT:
+               {
+                       const gchar *klass = NULL;
+                       klass = gst_element_factory_get_metadata
+                               (gst_element_get_factory((GstElement *)message->src), GST_ELEMENT_METADATA_KLASS);
+                       if (!klass || !g_strrstr(klass, "Codec/Decoder")) {
+                               reply = GST_BUS_PASS;
+                               break;
+                       }
+                       __mmplayer_gst_handle_element_message(player, message);
+               }
+               break;
        case GST_MESSAGE_ASYNC_DONE:
                /* NOTE:Don't call gst_callback directly
                 * because previous frame can be showed even though this message is received for seek.
@@ -2781,7 +2785,6 @@ __mmplayer_gst_msg_push(GstBus *bus, GstMessage *msg, gpointer data)
 
        g_return_val_if_fail(player, FALSE);
        g_return_val_if_fail(msg && GST_IS_MESSAGE(msg), FALSE);
-
        gst_message_ref(msg);
 
        g_mutex_lock(&player->bus_msg_q_lock);
@@ -2798,7 +2801,6 @@ static gpointer __mmplayer_gst_bus_msg_thread(gpointer data)
 {
        mmplayer_t *player = (mmplayer_t *)(data);
        GstMessage *msg = NULL;
-       GstBus *bus = NULL;
 
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_VAL_IF_FAIL(player &&
@@ -2807,12 +2809,6 @@ static gpointer __mmplayer_gst_bus_msg_thread(gpointer data)
                                                player->pipeline->mainbin[MMPLAYER_M_PIPE].gst,
                                                NULL);
 
-       bus = gst_pipeline_get_bus(GST_PIPELINE(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst));
-       if (!bus) {
-               LOGE("cannot get BUS from the pipeline");
-               return NULL;
-       }
-
        MMPLAYER_BUS_MSG_THREAD_LOCK(player);
 
        LOGD("[handle: %p] gst bus msg thread will be started.", player);
@@ -2832,9 +2828,8 @@ static gpointer __mmplayer_gst_bus_msg_thread(gpointer data)
        }
 
        MMPLAYER_BUS_MSG_THREAD_UNLOCK(player);
-       gst_object_unref(GST_OBJECT(bus));
-
        MMPLAYER_FLEAVE();
+
        return NULL;
 }
 
@@ -3895,7 +3890,17 @@ _mmplayer_gst_add_bus_watch(mmplayer_t *player)
                return MM_ERROR_PLAYER_INTERNAL;
        }
 
-       player->bus_watcher = gst_bus_add_watch(bus, (GstBusFunc)__mmplayer_gst_msg_push, player);
+       player->bus_watcher = gst_bus_add_watch_full(bus, G_PRIORITY_DEFAULT,
+                                                       (GstBusFunc)__mmplayer_gst_msg_push, player,
+                                                       (GDestroyNotify)_mmplayer_watcher_removed_notify);
+       if (player->bus_watcher == 0) {
+               LOGE("failed to add bus watch");
+               return MM_ERROR_PLAYER_INTERNAL;
+       }
+
+       g_mutex_init(&player->bus_watcher_mutex);
+       g_cond_init(&player->bus_watcher_cond);
+
        player->context.thread_default = g_main_context_get_thread_default();
        if (player->context.thread_default == NULL) {
                player->context.thread_default = g_main_context_default();
@@ -4020,11 +4025,6 @@ _mmplayer_activate_next_source(mmplayer_t *player, GstState target)
                goto ERROR;
        }
 
-       if (gst_element_set_state(mainbin[MMPLAYER_M_SRC].gst, target) == GST_STATE_CHANGE_FAILURE) {
-               LOGE("Failed to change state of src element");
-               goto ERROR;
-       }
-
        if (!MMPLAYER_IS_HTTP_STREAMING(player)) {
                if (gst_element_set_state(mainbin[MMPLAYER_M_AUTOPLUG].gst, target) == GST_STATE_CHANGE_FAILURE) {
                        LOGE("Failed to change state of decodebin");
@@ -4037,6 +4037,11 @@ _mmplayer_activate_next_source(mmplayer_t *player, GstState target)
                }
        }
 
+       if (gst_element_set_state(mainbin[MMPLAYER_M_SRC].gst, target) == GST_STATE_CHANGE_FAILURE) {
+               LOGE("Failed to change state of src element");
+               goto ERROR;
+       }
+
        player->gapless.stream_changed = TRUE;
        player->gapless.running = TRUE;
        MMPLAYER_FLEAVE();
@@ -4044,8 +4049,7 @@ _mmplayer_activate_next_source(mmplayer_t *player, GstState target)
 
 ERROR:
        if (player) {
-               MMPLAYER_PLAYBACK_UNLOCK(player);
-
+               _mmplayer_set_reconfigure_state(player, FALSE);
                if (!player->msg_posted) {
                        MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);
                        player->msg_posted = TRUE;