From bfabee12e202edc6c85c949b7075c6e922ca33b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Tue, 7 Feb 2023 21:43:14 +0100 Subject: [PATCH] gst emit video keyframe on demand. (#27) --- pkg/gst/gst.c | 12 ++++++++++++ pkg/gst/gst.go | 9 ++++++++- pkg/gst/gst.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/gst/gst.c b/pkg/gst/gst.c index e538f5d1..86e97dce 100644 --- a/pkg/gst/gst.c +++ b/pkg/gst/gst.c @@ -200,3 +200,15 @@ gboolean gstreamer_pipeline_set_caps_resolution(GstPipelineCtx *ctx, const gchar gst_object_unref(el); return TRUE; } + +gboolean gstreamer_pipeline_emit_video_keyframe(GstPipelineCtx *ctx) { + GstClock *clock = gst_pipeline_get_clock(GST_PIPELINE(ctx->pipeline)); + gst_object_ref(clock); + + GstClockTime time = gst_clock_get_time(clock); + GstClockTime now = time - gst_element_get_base_time(ctx->pipeline); + gst_object_unref(clock); + + GstEvent *keyFrameEvent = gst_video_event_new_downstream_force_key_unit(now, time, now, TRUE, 0); + return gst_element_send_event(GST_ELEMENT(ctx->pipeline), keyFrameEvent); +} diff --git a/pkg/gst/gst.go b/pkg/gst/gst.go index 3a9e686a..14bdc6dd 100644 --- a/pkg/gst/gst.go +++ b/pkg/gst/gst.go @@ -1,7 +1,7 @@ package gst /* -#cgo pkg-config: gstreamer-1.0 gstreamer-app-1.0 +#cgo pkg-config: gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0 #include "gst.h" */ @@ -46,6 +46,8 @@ type Pipeline interface { SetPropInt(binName string, prop string, value int) bool SetCapsFramerate(binName string, numerator, denominator int) bool SetCapsResolution(binName string, width, height int) bool + // emit video keyframe + EmitVideoKeyframe() bool } type pipeline struct { @@ -177,6 +179,11 @@ func (p *pipeline) SetCapsResolution(binName string, width, height int) bool { return ok == C.TRUE } +func (p *pipeline) EmitVideoKeyframe() bool { + ok := C.gstreamer_pipeline_emit_video_keyframe(p.ctx) + return ok == C.TRUE +} + // gst-inspect-1.0 func CheckPlugins(plugins []string) error { var plugin *C.GstPlugin diff --git a/pkg/gst/gst.h b/pkg/gst/gst.h index a562ec34..619170e7 100644 --- a/pkg/gst/gst.h +++ b/pkg/gst/gst.h @@ -3,6 +3,7 @@ #include #include #include +#include typedef struct GstPipelineCtx { int pipelineId; @@ -25,3 +26,4 @@ void gstreamer_pipeline_push(GstPipelineCtx *ctx, void *buffer, int bufferLen); gboolean gstreamer_pipeline_set_prop_int(GstPipelineCtx *ctx, char *binName, char *prop, gint value); gboolean gstreamer_pipeline_set_caps_framerate(GstPipelineCtx *ctx, const gchar* binName, gint numerator, gint denominator); gboolean gstreamer_pipeline_set_caps_resolution(GstPipelineCtx *ctx, const gchar* binName, gint width, gint height); +gboolean gstreamer_pipeline_emit_video_keyframe(GstPipelineCtx *ctx);