summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2014-07-14 16:39:22 (GMT)
committerNirbheek Chauhan <nirbheek@centricular.com>2014-07-14 16:39:22 (GMT)
commite24395dd55d601211c27646b4ebde4e95fda72af (patch)
tree2488c1cd3fe30f580f1d521063fdb8511790e1f9
parent306a94bebeded036a788e6d4b682bf442b5f8bb1 (diff)
downloadsoup-transcoding-proxy-e24395dd55d601211c27646b4ebde4e95fda72af.zip
soup-transcoding-proxy-e24395dd55d601211c27646b4ebde4e95fda72af.tar.gz
appsink: Pull and write samples in the libsoup main context
-rw-r--r--src/lib.c2
-rw-r--r--src/lib.h1
-rw-r--r--src/main.c37
3 files changed, 17 insertions, 23 deletions
diff --git a/src/lib.c b/src/lib.c
index f527e04..fa23256 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -140,7 +140,6 @@ stp_cleanup_transcode_client_ctx (TranscodeClientCtx *ctx)
(GstPadProbeCallback) pad_blocked_cleanup_cb,
ctx, (GDestroyNotify)g_free);
- g_mutex_clear (&ctx->can_write_chunk);
gst_object_unref (sinkbin);
stp_print_status (".");
}
@@ -159,7 +158,6 @@ stp_disconnect_cleanup_client (TranscodeClientCtx *ctx)
soup_message_body_complete (ctx->msg->response_body);
g_source_remove (ctx->timeout_handler_id);
- g_mutex_clear (&ctx->can_write_chunk);
g_free (ctx);
}
diff --git a/src/lib.h b/src/lib.h
index 815d18a..db57354 100644
--- a/src/lib.h
+++ b/src/lib.h
@@ -59,7 +59,6 @@ struct _TranscodeClientCtx {
GstElement *appsink; /* We hold an extra ref to this */
GstPad *ghostsinkpad;
- GMutex can_write_chunk;
guint timeout_handler_id;
guint seconds_since_write;
/* The transcode server context; we don't hold a ref to this */
diff --git a/src/main.c b/src/main.c
index 21843db..c0dbd7a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -105,33 +105,19 @@ static void
can_write_next_client_chunk_cb (SoupMessage *msg,
TranscodeClientCtx *ctx)
{
- g_mutex_unlock (&ctx->can_write_chunk);
ctx->seconds_since_write = 0;
ctx->msg = msg;
stp_print_status ("_");
}
-static GstFlowReturn
-write_client_chunk_cb (GstElement *appsink,
- TranscodeClientCtx *ctx)
+static gboolean
+invoke_write_client_chunk (TranscodeClientCtx *ctx)
{
GstMapInfo info;
GstSample *sample;
GstBuffer *buffer;
gboolean eos;
- /* FIXME: Maybe dispatch to libsoup's main loop and do
- * everything from there instead?
- */
- if (!g_mutex_trylock (&ctx->can_write_chunk)) {
- stp_print_status ("!");
- /* We cannot safely append to the message body till
- * the previous chunk is written out, otherwise we get
- * a segfault. This is likely because SoupMessageBody
- * uses a GSList for the chunks, which isn't MT-safe. */
- return GST_FLOW_OK;
- }
-
stp_print_status ("*");
g_signal_emit_by_name (ctx->appsink, "pull-sample", &sample);
if (!sample) {
@@ -142,7 +128,7 @@ write_client_chunk_cb (GstElement *appsink,
else
soup_message_set_status (ctx->msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
soup_message_body_complete (ctx->msg->response_body);
- return GST_FLOW_OK;
+ return FALSE;
}
buffer = gst_sample_get_buffer (sample);
@@ -156,7 +142,16 @@ write_client_chunk_cb (GstElement *appsink,
soup_server_unpause_message (server, ctx->msg);
stp_print_status (".");
+ return FALSE;
+}
+static GstFlowReturn
+write_client_chunk_cb (GstElement *appsink,
+ TranscodeClientCtx *ctx)
+{
+ g_main_context_invoke_full (NULL, G_PRIORITY_HIGH,
+ (GSourceFunc)invoke_write_client_chunk,
+ ctx, NULL);
return GST_FLOW_OK;
}
@@ -164,8 +159,11 @@ static void
client_finished_cb (SoupMessage *msg,
TranscodeClientCtx *ctx)
{
- g_debug ("Client finished/aborted, doing cleanup...\n");
- stp_cleanup_transcode_client_ctx (ctx);
+ stp_print_status ("Client finished/aborted, doing cleanup...\n");
+ /* Make sure not to double-free. If the server
+ * has shut down, this will be 0. */
+ if (ctx->timeout_handler_id)
+ stp_cleanup_transcode_client_ctx (ctx);
}
static void
@@ -268,7 +266,6 @@ GET:
client_ctx = g_new0 (TranscodeClientCtx, 1);
client_ctx->msg = msg;
client_ctx->server_ctx = server_ctx;
- g_mutex_init (&client_ctx->can_write_chunk);
bin = gst_bin_new (NULL);