From 7bc9a4067779ca5fdb78865a26d18b90c9242cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 28 Nov 2021 22:37:17 +0100 Subject: [PATCH] gst push function. --- internal/capture/gst/gst.c | 10 ++++++++++ internal/capture/gst/gst.go | 10 ++++++++++ internal/capture/gst/gst.h | 1 + 3 files changed, 21 insertions(+) diff --git a/internal/capture/gst/gst.c b/internal/capture/gst/gst.c index 1407d57f..24275fe2 100644 --- a/internal/capture/gst/gst.c +++ b/internal/capture/gst/gst.c @@ -82,3 +82,13 @@ void gstreamer_pipeline_stop(GstElement *pipeline) { gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); } + +void gstreamer_pipeline_push(GstElement *pipeline, char *sinkName, void *buffer, int bufferLen) { + GstElement *src = gst_bin_get_by_name(GST_BIN(pipeline), sinkName); + if (src != NULL) { + gpointer p = g_memdup(buffer, bufferLen); + GstBuffer *buffer = gst_buffer_new_wrapped(p, bufferLen); + gst_app_src_push_buffer(GST_APP_SRC(src), buffer); + gst_object_unref(src); + } +} diff --git a/internal/capture/gst/gst.go b/internal/capture/gst/gst.go index 5eb926f7..fdfd7952 100644 --- a/internal/capture/gst/gst.go +++ b/internal/capture/gst/gst.go @@ -74,6 +74,16 @@ func (p *Pipeline) Stop() { C.gstreamer_pipeline_stop(p.Pipeline) } +func (p *Pipeline) Push(sinkName string, buffer []byte) { + sinkNameUnsafe := C.CString(sinkName) + defer C.free(unsafe.Pointer(sinkNameUnsafe)) + + bytes := C.CBytes(buffer) + defer C.free(bytes) + + C.gstreamer_pipeline_push(p.Pipeline, sinkNameUnsafe, bytes, C.int(len(buffer))) +} + // gst-inspect-1.0 func CheckPlugins(plugins []string) error { var plugin *C.GstPlugin diff --git a/internal/capture/gst/gst.h b/internal/capture/gst/gst.h index 87e4fa74..4f7a674f 100644 --- a/internal/capture/gst/gst.h +++ b/internal/capture/gst/gst.h @@ -9,5 +9,6 @@ void gstreamer_pipeline_attach_appsink(GstElement *pipeline, char *sinkName, int GstElement *gstreamer_pipeline_create(char *pipelineStr, GError **error); void gstreamer_pipeline_play(GstElement *pipeline); void gstreamer_pipeline_stop(GstElement *pipeline); +void gstreamer_pipeline_push(GstElement *pipeline, char *sinkName, void *buffer, int bufferLen); void gstreamer_init(void);