diff --git a/internal/capture/gst/gst.c b/internal/capture/gst/gst.c index 24275fe2..1e28e86d 100644 --- a/internal/capture/gst/gst.c +++ b/internal/capture/gst/gst.c @@ -10,25 +10,25 @@ void gstreamer_init(void) { static gboolean gstreamer_bus_call(GstBus *bus, GstMessage *msg, gpointer data) { switch (GST_MESSAGE_TYPE(msg)) { + case GST_MESSAGE_EOS: { + g_print("End of stream\n"); + exit(1); + } - case GST_MESSAGE_EOS: - g_print("End of stream\n"); - exit(1); - break; + case GST_MESSAGE_ERROR: { + gchar *debug; + GError *error; - case GST_MESSAGE_ERROR: { - gchar *debug; - GError *error; + gst_message_parse_error(msg, &error, &debug); + g_free(debug); - gst_message_parse_error(msg, &error, &debug); - g_free(debug); + g_printerr("Error: %s\n", error->message); + g_error_free(error); + exit(1); + } - g_printerr("Error: %s\n", error->message); - g_error_free(error); - exit(1); - } - default: - break; + default: + break; } return TRUE; @@ -67,9 +67,11 @@ void gstreamer_pipeline_attach_appsink(GstElement *pipeline, char *sinkName, int GstElement *gstreamer_pipeline_create(char *pipelineStr, GError **error) { GstElement *pipeline = gst_parse_launch(pipelineStr, error); - GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); - gst_bus_add_watch(bus, gstreamer_bus_call, NULL); - gst_object_unref(bus); + if (pipeline != NULL) { + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); + gst_bus_add_watch(bus, gstreamer_bus_call, NULL); + gst_object_unref(bus); + } return pipeline; } @@ -83,8 +85,9 @@ void gstreamer_pipeline_stop(GstElement *pipeline) { 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); +void gstreamer_pipeline_push(GstElement *pipeline, char *srcName, void *buffer, int bufferLen) { + GstElement *src = gst_bin_get_by_name(GST_BIN(pipeline), srcName); + if (src != NULL) { gpointer p = g_memdup(buffer, bufferLen); GstBuffer *buffer = gst_buffer_new_wrapped(p, bufferLen); diff --git a/internal/capture/gst/gst.go b/internal/capture/gst/gst.go index fdfd7952..d0f5d05a 100644 --- a/internal/capture/gst/gst.go +++ b/internal/capture/gst/gst.go @@ -74,14 +74,14 @@ 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)) +func (p *Pipeline) Push(srcName string, buffer []byte) { + srcNameUnsafe := C.CString(srcName) + defer C.free(unsafe.Pointer(srcNameUnsafe)) bytes := C.CBytes(buffer) defer C.free(bytes) - C.gstreamer_pipeline_push(p.Pipeline, sinkNameUnsafe, bytes, C.int(len(buffer))) + C.gstreamer_pipeline_push(p.Pipeline, srcNameUnsafe, bytes, C.int(len(buffer))) } // gst-inspect-1.0 diff --git a/internal/capture/gst/gst.h b/internal/capture/gst/gst.h index 4f7a674f..a51d7682 100644 --- a/internal/capture/gst/gst.h +++ b/internal/capture/gst/gst.h @@ -9,6 +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_pipeline_push(GstElement *pipeline, char *srcName, void *buffer, int bufferLen); void gstreamer_init(void);