diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.c | 2 | ||||
-rw-r--r-- | src/lib.h | 1 | ||||
-rw-r--r-- | src/main.c | 37 |
3 files changed, 17 insertions, 23 deletions
@@ -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); } @@ -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 */ @@ -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); |