Skip to content

Instantly share code, notes, and snippets.

@rubenrua
Created February 27, 2013 10:33
Show Gist options
  • Save rubenrua/5046986 to your computer and use it in GitHub Desktop.
Save rubenrua/5046986 to your computer and use it in GitHub Desktop.
Bug in GStreamer Python Bindings in gst.parse_bin_from_description
/*
gcc stress_simple.c `pkg-config --cflags --libs gstreamer-0.10 gtk+-2.0`
*/
#include <gst/gst.h>
#include <gtk/gtk.h>
typedef struct _CustomData {
GstElement *pipeline;
int s;
} CustomData;
static GstElement *test_gst_element_factory_make() {
GstElement *pipeline, *bin;
GstElement *source, *sink;
pipeline = gst_pipeline_new ("test-pipeline");
bin = gst_bin_new ("test-bin");
source = gst_element_factory_make ("videotestsrc", "source");
sink = gst_element_factory_make ("autovideosink", "sink");
gst_bin_add_many (GST_BIN (bin), source, sink, NULL);
gst_bin_add_many (GST_BIN (pipeline), bin, NULL);
return pipeline;
}
static GstElement *test_gst_parse_launch() {
GstElement *pipeline, *bin;
GstElement *source, *sink;
pipeline = gst_pipeline_new ("test-pipeline");
bin = gst_parse_launch ("(audiotestsrc ! alsasink)", NULL);
gst_bin_add_many (GST_BIN (pipeline), bin, NULL);
return pipeline;
}
static GstElement *test_gst_parse_bin_from_description() {
GstElement *pipeline, *bin;
GstElement *source, *sink;
GError *err = NULL;
pipeline = gst_pipeline_new ("test-pipeline");
bin = gst_parse_bin_from_description ("audiotestsrc ! alsasink", FALSE, &err);
gst_bin_add_many (GST_BIN (pipeline), bin, NULL);
return pipeline;
}
void record(GstElement *pipeline) {
gst_element_set_state (pipeline, GST_STATE_PLAYING);
}
void stop(GstElement *pipeline) {
gst_element_set_state (pipeline, GST_STATE_NULL);
}
static int loop(CustomData *data) {
printf("Tengo %d\n", data->s);
if (data->s == 0) {
printf("init\n");
data->s = 1;
data->pipeline = test_gst_parse_bin_from_description();
}else if(data->s == 1) {
printf("record\n");
data->s = 2;
record(data->pipeline);
}else if(data->s == 2) {
printf("stop\n");
data->s = 3;
stop(data->pipeline);
}else if(data->s == 3) {
printf("null\n");
data->s = 0;
gst_object_unref (data->pipeline);
}
return 1;
}
int main(int argc, char *argv[]) {
CustomData data;
/* Initialize GStreamer */
gst_init (&argc, &argv);
printf("start\n");
g_timeout_add_seconds (1, (GSourceFunc)loop, &data);
gtk_main ();
gst_object_unref(data.pipeline);
return 0;
}
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
TO see the bug:
$cd /proc/`pgrep python`/fd; while true; do ls | wc -l; sleep 1; done
"""
import gst
import gtk
import gobject
class Test():
def __init__(self):
# Build the pipeline
self.pipeline = gst.Pipeline()
aux = "audiotestsrc ! alsasink"
self.bin = gst.parse_bin_from_description(aux, False)
self.pipeline.add(self.bin)
def __del__(self):
print "__del__"
def record(self):
self.pipeline.set_state(gst.STATE_PLAYING)
def stop(self):
self.pipeline.set_state(gst.STATE_NULL)
t = None
s = 0
def test():
global t, s
print "Loop:"
if s == 0:
print " 1.- Preview"
s = 1
t = Test()
elif s == 1:
print " 2.- Record"
s = 2
t.record()
elif s == 2:
print " 3.- Stop"
s = 0
t.stop()
return True
gobject.timeout_add_seconds(1, test)
gtk.main()
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
TO see the bug:
$cd /proc/`pgrep python`/fd; while true; do ls | wc -l; sleep 1; done
"""
import gst
import gtk
import gobject
class Test():
def __init__(self):
# Build the pipeline
self.pipeline = gst.Pipeline()
src = gst.element_factory_make('audiotestsrc')
sink = gst.element_factory_make('alsasink')
mbin = gst.Bin()
mbin.add(src, sink)
self.pipeline.add(mbin)
src.link(sink)
def __del__(self):
print "__del__"
def record(self):
self.pipeline.set_state(gst.STATE_PLAYING)
def stop(self):
self.pipeline.set_state(gst.STATE_NULL)
t = None
s = 0
def test():
global t, s
print "Loop:"
if s == 0:
print " 1.- Preview"
s = 1
t = Test()
elif s == 1:
print " 2.- Record"
s = 2
t.record()
elif s == 2:
print " 3.- Stop"
s = 0
t.stop()
return True
gobject.timeout_add_seconds(1, test)
gtk.main()
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
TO see the bug:
$cd /proc/`pgrep python`/fd; while true; do ls | wc -l; sleep 1; done
"""
import gst
import gtk
import gobject
class Test():
def __init__(self):
# Build the pipeline
self.pipeline = gst.Pipeline()
aux = "(audiotestsrc ! alsasink)"
self.bin = gst.parse_launch(aux)
self.pipeline.add(self.bin)
def __del__(self):
print "__del__"
def record(self):
self.pipeline.set_state(gst.STATE_PLAYING)
def stop(self):
self.pipeline.set_state(gst.STATE_NULL)
t = None
s = 0
def test():
global t, s
print "Loop:"
if s == 0:
print " 1.- Preview"
s = 1
t = Test()
elif s == 1:
print " 2.- Record"
s = 2
t.record()
elif s == 2:
print " 3.- Stop"
s = 0
t.stop()
return True
gobject.timeout_add_seconds(1, test)
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment