[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 d6f8567..7978600 100644 (file)
@@ -2785,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);
@@ -2802,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 &&
@@ -2811,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);
@@ -2836,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;
 }
 
@@ -3899,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();