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,11 +10,10 @@ void gstreamer_init(void) {
static gboolean gstreamer_bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
case GST_MESSAGE_EOS: {
g_print("End of stream\n");
exit(1);
break;
}
case GST_MESSAGE_ERROR: {
gchar *debug;
@ -27,6 +26,7 @@ static gboolean gstreamer_bus_call(GstBus *bus, GstMessage *msg, gpointer data)
g_error_free(error);
exit(1);
}
default:
break;
}
@ -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);
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);

View File

@ -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

View File

@ -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);