gst minor changes.

This commit is contained in:
Miroslav Šedivý 2021-12-01 19:55:57 +01:00
parent 75b1e08874
commit 065a7a2e84
3 changed files with 28 additions and 25 deletions

View File

@ -10,25 +10,25 @@ void gstreamer_init(void) {
static gboolean gstreamer_bus_call(GstBus *bus, GstMessage *msg, gpointer data) { static gboolean gstreamer_bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
switch (GST_MESSAGE_TYPE(msg)) { switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS: {
g_print("End of stream\n");
exit(1);
}
case GST_MESSAGE_EOS: case GST_MESSAGE_ERROR: {
g_print("End of stream\n"); gchar *debug;
exit(1); GError *error;
break;
case GST_MESSAGE_ERROR: { gst_message_parse_error(msg, &error, &debug);
gchar *debug; g_free(debug);
GError *error;
gst_message_parse_error(msg, &error, &debug); g_printerr("Error: %s\n", error->message);
g_free(debug); g_error_free(error);
exit(1);
}
g_printerr("Error: %s\n", error->message); default:
g_error_free(error); break;
exit(1);
}
default:
break;
} }
return TRUE; 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 *gstreamer_pipeline_create(char *pipelineStr, GError **error) {
GstElement *pipeline = gst_parse_launch(pipelineStr, error); GstElement *pipeline = gst_parse_launch(pipelineStr, error);
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); if (pipeline != NULL) {
gst_bus_add_watch(bus, gstreamer_bus_call, NULL); GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_object_unref(bus); gst_bus_add_watch(bus, gstreamer_bus_call, NULL);
gst_object_unref(bus);
}
return pipeline; return pipeline;
} }
@ -83,8 +85,9 @@ void gstreamer_pipeline_stop(GstElement *pipeline) {
gst_object_unref(pipeline); gst_object_unref(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) {
GstElement *src = gst_bin_get_by_name(GST_BIN(pipeline), sinkName); GstElement *src = gst_bin_get_by_name(GST_BIN(pipeline), srcName);
if (src != NULL) { if (src != NULL) {
gpointer p = g_memdup(buffer, bufferLen); gpointer p = g_memdup(buffer, bufferLen);
GstBuffer *buffer = gst_buffer_new_wrapped(p, bufferLen); GstBuffer *buffer = gst_buffer_new_wrapped(p, bufferLen);

View File

@ -74,14 +74,14 @@ func (p *Pipeline) Stop() {
C.gstreamer_pipeline_stop(p.Pipeline) C.gstreamer_pipeline_stop(p.Pipeline)
} }
func (p *Pipeline) Push(sinkName string, buffer []byte) { func (p *Pipeline) Push(srcName string, buffer []byte) {
sinkNameUnsafe := C.CString(sinkName) srcNameUnsafe := C.CString(srcName)
defer C.free(unsafe.Pointer(sinkNameUnsafe)) defer C.free(unsafe.Pointer(srcNameUnsafe))
bytes := C.CBytes(buffer) bytes := C.CBytes(buffer)
defer C.free(bytes) 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 // gst-inspect-1.0

View File

@ -9,6 +9,6 @@ void gstreamer_pipeline_attach_appsink(GstElement *pipeline, char *sinkName, int
GstElement *gstreamer_pipeline_create(char *pipelineStr, GError **error); GstElement *gstreamer_pipeline_create(char *pipelineStr, GError **error);
void gstreamer_pipeline_play(GstElement *pipeline); void gstreamer_pipeline_play(GstElement *pipeline);
void gstreamer_pipeline_stop(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); void gstreamer_init(void);