summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2014-07-10 15:14:23 (GMT)
committerNirbheek Chauhan <nirbheek@centricular.com>2014-07-10 15:15:57 (GMT)
commita405f25389ad94a75ac7adf476fe35db32e475b4 (patch)
tree729d34e717c58f43c621cf9bc6702a5a65e470e5
parentaefc695d53e0d519d438741ca96923b95212f73a (diff)
downloadsoup-transcoding-proxy-a405f25389ad94a75ac7adf476fe35db32e475b4.zip
soup-transcoding-proxy-a405f25389ad94a75ac7adf476fe35db32e475b4.tar.gz
cleanup: Fix client shutdown on server exit
-rw-r--r--src/lib.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/lib.c b/src/lib.c
index b36015d..98e35cf 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -3,6 +3,9 @@
#include "lib.h"
+static void
+stp_shutdown_client (TranscodeClientCtx *ctx);
+
gboolean
stp_on_gst_bus_message (GstBus *bus,
GstMessage *msg,
@@ -37,12 +40,15 @@ stp_on_gst_bus_message (GstBus *bus,
return TRUE;
}
+/* When the incoming stream reaches EOS, we call this
+ * which initiates a shutdown for all clients and then
+ * the server itself */
void
stp_cleanup_transcode_server_ctx (TranscodeServerCtx *ctx)
{
g_print (">>> Doing server cleanup\n");
- g_list_foreach (ctx->clients, (GFunc)stp_cleanup_transcode_client_ctx, NULL);
+ g_list_foreach (ctx->clients, (GFunc)stp_shutdown_client, NULL);
g_list_free (ctx->clients);
/* Cleanup gstreamer pipeline */
@@ -62,7 +68,7 @@ pad_blocked_cleanup_cb (GstPad *srcpad,
GstElement *sinkbin = GST_ELEMENT (gst_element_get_parent (ctx->appsink));
g_print (".");
- /* Remove the probe, XXX: hence unblocking the pipeline? */
+ /* Remove the probe */
gst_pad_remove_probe (srcpad, GST_PAD_PROBE_INFO_ID (info));
tee = gst_pad_get_parent_element (srcpad);
@@ -81,6 +87,10 @@ pad_blocked_cleanup_cb (GstPad *srcpad,
return GST_PAD_PROBE_OK;
}
+/* When a client leaves or is kicked, we set the response status
+ * and then call cleanup here. This involves removing the appsink
+ * branch for the client from the pipeline, and then freeing the
+ * context. */
void
stp_cleanup_transcode_client_ctx (TranscodeClientCtx *ctx)
{
@@ -104,6 +114,25 @@ stp_cleanup_transcode_client_ctx (TranscodeClientCtx *ctx)
g_print (".");
}
+/* When shutting down a client due to a server shutdown, we
+ * don't need to bother with removing the appsink branch of
+ * the pipeline, and the response is set by the "eos" callback
+ * on the appsink, so we just free the context */
+static void
+stp_shutdown_client (TranscodeClientCtx *ctx)
+{
+ TranscodeServerCtx *server_ctx = ctx->server_ctx;
+
+ g_print (">>> Doing client cleanup on server shutdown\n");
+
+ g_source_remove (ctx->timeout_handler_id);
+
+ server_ctx->clients = g_list_remove (server_ctx->clients, ctx);
+
+ gst_object_unref (ctx->appsink);
+ g_free (ctx);
+}
+
/* Returns a copy of the streamheader GstBuffer */
GstBuffer*
stp_get_streamheader_from_caps (GstCaps *caps)