summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2014-07-17 12:01:21 (GMT)
committerNirbheek Chauhan <nirbheek@centricular.com>2014-07-17 12:01:23 (GMT)
commitba9064de9af710f1215cf8ad0c7094d190dbfade (patch)
tree4460400edae5e6b3d425a664b1dd2dae5278ef29
parente9e577c4aba08656a6cc3afe0c51d101ce01b730 (diff)
downloadsoup-transcoding-proxy-ba9064de9af710f1215cf8ad0c7094d190dbfade.zip
soup-transcoding-proxy-ba9064de9af710f1215cf8ad0c7094d190dbfade.tar.gz
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
-rw-r--r--Makefile2
-rw-r--r--src/main.c18
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 <glib-unix.h>
+#include <gst/video/video.h>
#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",