client: ref the context until rtsp watch is alive

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=731569
This commit is contained in:
Ognyan Tonchev 2014-06-12 13:49:17 +02:00 committed by Wim Taymans
parent 9715252588
commit f2b1aa8c81

View file

@ -61,6 +61,7 @@ struct _GstRTSPClientPrivate
GMutex send_lock; GMutex send_lock;
GstRTSPConnection *connection; GstRTSPConnection *connection;
GstRTSPWatch *watch; GstRTSPWatch *watch;
GMainContext *watch_context;
guint close_seq; guint close_seq;
gchar *server_ip; gchar *server_ip;
gboolean is_ipv6; gboolean is_ipv6;
@ -364,6 +365,9 @@ gst_rtsp_client_finalize (GObject * obj)
if (priv->watch) if (priv->watch)
g_source_destroy ((GSource *) priv->watch); g_source_destroy ((GSource *) priv->watch);
if (priv->watch_context)
g_main_context_unref (priv->watch_context);
client_cleanup_sessions (client); client_cleanup_sessions (client);
if (priv->connection) if (priv->connection)
@ -3230,6 +3234,8 @@ handle_tunnel (GstRTSPClient * client)
/* the old client owns the tunnel now, the new one will be freed */ /* the old client owns the tunnel now, the new one will be freed */
g_source_destroy ((GSource *) priv->watch); g_source_destroy ((GSource *) priv->watch);
priv->watch = NULL; priv->watch = NULL;
g_main_context_unref (priv->watch_context);
priv->watch_context = NULL;
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL); gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
} }
@ -3314,6 +3320,8 @@ client_watch_notify (GstRTSPClient * client)
GST_INFO ("client %p: watch destroyed", client); GST_INFO ("client %p: watch destroyed", client);
priv->watch = NULL; priv->watch = NULL;
g_main_context_unref (priv->watch_context);
priv->watch_context = NULL;
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL); g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
g_object_unref (client); g_object_unref (client);
} }
@ -3343,6 +3351,9 @@ gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
g_return_val_if_fail (priv->connection != NULL, 0); g_return_val_if_fail (priv->connection != NULL, 0);
g_return_val_if_fail (priv->watch == NULL, 0); g_return_val_if_fail (priv->watch == NULL, 0);
/* make sure noone will free the context before the watch is destroyed */
priv->watch_context = g_main_context_ref (context);
/* create watch for the connection and attach */ /* create watch for the connection and attach */
priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs, priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
g_object_ref (client), (GDestroyNotify) client_watch_notify); g_object_ref (client), (GDestroyNotify) client_watch_notify);