From ba9064de9af710f1215cf8ad0c7094d190dbfade Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 17 Jul 2014 17:31:21 +0530 Subject: appsink: Force encodebin to create a keyframe when a client connects This avoids long waits when, for instance, the fps is 3, since the keyframe-max-dist is 128 --- Makefile | 2 +- src/main.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c73b121..daf90c8 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ DEBUG_CFLAGS := -O0 -ggdb -Wall -fsanitize=address -fno-omit-frame-pointer -DENC CFLAGS := -O0 -ggdb -Wall -fno-omit-frame-pointer -DENCODE_DEBUG #CFLAGS := -O3 -march=native -Wall PKGCONFIG := pkg-config -LIBS := $(shell $(PKGCONFIG) --libs --cflags glib-2.0 gio-unix-2.0 libsoup-2.4 gstreamer-pbutils-1.0) -lrt +LIBS := $(shell $(PKGCONFIG) --libs --cflags glib-2.0 gio-unix-2.0 libsoup-2.4 gstreamer-pbutils-1.0 gstreamer-video-1.0) -lrt SERVER_NAME := stp-server SRC_OBJS := $(addprefix src/,debug/local-play.o lib.o encode.o) diff --git a/src/main.c b/src/main.c index c489f55..2d3e537 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,7 @@ */ #include +#include #include "lib.h" #include "encode.h" @@ -240,10 +241,11 @@ GET: /* A GET request was received. We connect from the pipeline to the * client requesting the stream and start writing the response. */ GstCaps *caps = NULL; + GstEvent *event; GstBuffer *buffer; GstFlowReturn ret; GstStateChangeReturn state_change; - GstElement *bin, *tee, *q2, *appsink; + GstElement *encodebin, *bin, *tee, *q2, *appsink; GstPadTemplate *template; GstPad *srcpad, *sinkpadq2; TranscodeClientCtx *client_ctx; @@ -322,7 +324,7 @@ GET: buffer = stp_get_streamheader_from_caps (caps); if (!buffer) { g_critical ("Unable to get streamheader from caps"); - goto nostreamheader; + goto force_key_unit; } ret = gst_pad_push (srcpad, buffer); @@ -332,7 +334,17 @@ GET: goto err; } -nostreamheader: +force_key_unit: + encodebin = gst_bin_get_by_name (GST_BIN (server_ctx->pipeline), + "encodebin"); + event = gst_video_event_new_downstream_force_key_unit (GST_CLOCK_TIME_NONE, + GST_CLOCK_TIME_NONE, + GST_CLOCK_TIME_NONE, + FALSE, 1); + if (!gst_element_send_event (encodebin, event)) + g_critical ("Couldn't send upstream key unit event!"); + gst_object_unref (encodebin); + client_ctx->appsink = appsink; g_signal_connect (appsink, "new-sample", -- cgit v0.11.2-2-gd1dd