-
-
Save dpeite/44f5b0d58b242d6ec1e47dcd88e77615 to your computer and use it in GitHub Desktop.
Bug in GStreamer 1.0 Python Bindings (Related to: https://github.com/teltek/Galicaster/issues/29)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
gcc gst_c_version.c -o gst_c_version `pkg-config --cflags --libs gstreamer-1.0 gtk+-3.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(); | |
/* data->pipeline = test_gst_parse_launch(); */ | |
/* data->pipeline = test_gst_element_factory_make(); */ | |
}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; | |
data.s = 0; | |
/* 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 gi | |
gi.require_version('Gst', '1.0') | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import Gst | |
from gi.repository import GObject | |
from gi.repository import Gtk | |
class Test(): | |
def __init__(self): | |
Gst.init(None) | |
# Build the pipeline | |
self.pipeline = Gst.Pipeline() | |
src = Gst.ElementFactory.make('audiotestsrc', None) | |
sink = Gst.ElementFactory.make('alsasink', None) | |
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 gi | |
gi.require_version('Gst', '1.0') | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import Gst | |
from gi.repository import GObject | |
from gi.repository import Gtk | |
class Test(): | |
def __init__(self): | |
# Build the pipeline | |
Gst.init(None) | |
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 gi | |
gi.require_version('Gst', '1.0') | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import Gst | |
from gi.repository import GObject | |
from gi.repository import Gtk | |
class Test(): | |
def __init__(self): | |
# Build the pipeline | |
Gst.init(None) | |
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