Commit a37dede0 authored by Johan Dahlin's avatar Johan Dahlin

examples/gstreamer/filesrc.py,player.py: New examples

Original commit message from CVS:
* examples/gstreamer/filesrc.py,player.py: New examples

* gstreamer/gstreamer.override: Add a dict like interface to GstTagList

* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override

* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.

* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.

* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)

* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7

* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*

* gstreamer/Makefile.am: Clean up, remove versioning support.
parent b27c464e
2004-02-27 Johan Dahlin <johan@gnome.org>
* examples/gstreamer/filesrc.py,player.py: New examples
* gstreamer/gstreamer.override: Add a dict like interface to GstTagList
* gstreamer/gstpad-handlers.override: New file, split out from gstreamer.override
* gstreamer/gst-types.defs: Don't use
gst_buffer_free/gst_data_free, use gst_data_unref instead.
* gstreamer/gst-types.c (PyGstData_to_value): Don't send address here.
* gstreamer/arg-types.py (GstDataPtrArg.write_param): Send the
address to stuff, since we really want to avoid segfaults :)
* gstreamer/0.6.[c,defs,h,override]: Remove, we're focusing on 0.7
* gstreamer/0.7.[c,defs,h,override]: Remove, merge with
gstreamer.*
* gstreamer/Makefile.am: Clean up, remove versioning support.
2004-02-25 Johan Dahlin <johan@gnome.org>
* gstreamer/gstreamer.override:
......
common @ 874dab5c
Subproject commit 0945c85c4c9139e2e5b8e04d0fc841b8aa1e6e9b
Subproject commit 874dab5c3461ad7487f1ae029256b6da82dddf6d
import sys
import gobject
import gst
class FileSource(gst.Element):
blocksize = 4096
fd = None
def __init__(self, name):
self.__gobject_init__()
self.set_name(name)
self.srcpad = gst.Pad('src', gst.PAD_SRC)
self.srcpad.set_get_function(self.srcpad_get)
self.add_pad(self.srcpad)
def set_property(self, name, value):
if name == 'location':
self.fd = open(value, 'r')
def srcpad_get(self, pad):
data = self.fd.read(self.blocksize)
if data:
return gst.Buffer(data)
else:
self.set_eos()
return gst.Event(gst.EVENT_EOS)
gobject.type_register(FileSource)
def main(args):
if len(args) != 3:
print 'Usage: %s input output' % (args[0])
return -1
bin = gst.Pipeline('pipeline')
filesrc = FileSource('filesource')
#filesrc = gst.Element('filesrc', 'src')
filesrc.set_property('location', args[1])
filesink = gst.Element('filesink', 'sink')
filesink.set_property('location', args[2])
bin.add_many(filesrc, filesink)
gst.element_link_many(filesrc, filesink)
bin.set_state(gst.STATE_PLAYING);
while bin.iterate():
pass
bin.set_state(gst.STATE_NULL)
if __name__ == '__main__':
sys.exit(main(sys.argv))
......@@ -2,6 +2,7 @@
#
# gst-python
# Copyright (C) 2002 David I. Lehn
# 2004 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
......@@ -57,8 +58,13 @@ def filter(element):
filesrc = gst.Element('sinesrc', 'source');
filesink = gst.Element('fakesink', 'sink')
bin.add_many(filesrc, element, filesink)
gst.element_link_many(filesrc, element, filesink)
stats = gst.Element('statistics', 'stats');
stats.set_property('silent', False)
stats.set_property('buffer_update_freq', True)
stats.set_property('update_on_eos', True)
bin.add_many(filesrc, element, stats, filesink)
gst.element_link_many(filesrc, element, stats, filesink)
# start playing
bin.set_state(gst.STATE_PLAYING);
......
import os
import sys
import gst
def found_tags(element, source, tags):
print 'Artist:', tags.get('artist')
print 'Title: ', tags.get('title')
print 'Album: ', tags.get('album')
def playfile(filename):
bin = gst.Pipeline('player')
source = gst.Element('filesrc', 'src')
source.set_property('location', filename)
spider = gst.Element('spider', 'spider')
spider.connect('found-tag', found_tags)
sink = gst.Element('osssink', 'sink')
bin.add_many(source, spider, sink)
gst.element_link_many(source, spider, sink)
print 'Playing:', os.path.basename(filename)
bin.set_state(gst.STATE_PLAYING)
try:
while bin.iterate():
pass
except KeyboardInterrupt:
pass
bin.set_state(gst.STATE_NULL)
def main(args):
map(playfile, args[1:])
if __name__ == '__main__':
sys.exit(main(sys.argv))
import sys
import gobject
import gst
class FileSource(gst.Element):
blocksize = 4096
fd = None
def __init__(self, name):
self.__gobject_init__()
self.set_name(name)
self.srcpad = gst.Pad('src', gst.PAD_SRC)
self.srcpad.set_get_function(self.srcpad_get)
self.add_pad(self.srcpad)
def set_property(self, name, value):
if name == 'location':
self.fd = open(value, 'r')
def srcpad_get(self, pad):
data = self.fd.read(self.blocksize)
if data:
return gst.Buffer(data)
else:
self.set_eos()
return gst.Event(gst.EVENT_EOS)
gobject.type_register(FileSource)
def main(args):
if len(args) != 3:
print 'Usage: %s input output' % (args[0])
return -1
bin = gst.Pipeline('pipeline')
filesrc = FileSource('filesource')
#filesrc = gst.Element('filesrc', 'src')
filesrc.set_property('location', args[1])
filesink = gst.Element('filesink', 'sink')
filesink.set_property('location', args[2])
bin.add_many(filesrc, filesink)
gst.element_link_many(filesrc, filesink)
bin.set_state(gst.STATE_PLAYING);
while bin.iterate():
pass
bin.set_state(gst.STATE_NULL)
if __name__ == '__main__':
sys.exit(main(sys.argv))
......@@ -2,6 +2,7 @@
#
# gst-python
# Copyright (C) 2002 David I. Lehn
# 2004 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
......@@ -57,8 +58,13 @@ def filter(element):
filesrc = gst.Element('sinesrc', 'source');
filesink = gst.Element('fakesink', 'sink')
bin.add_many(filesrc, element, filesink)
gst.element_link_many(filesrc, element, filesink)
stats = gst.Element('statistics', 'stats');
stats.set_property('silent', False)
stats.set_property('buffer_update_freq', True)
stats.set_property('update_on_eos', True)
bin.add_many(filesrc, element, stats, filesink)
gst.element_link_many(filesrc, element, stats, filesink)
# start playing
bin.set_state(gst.STATE_PLAYING);
......
import os
import sys
import gst
def found_tags(element, source, tags):
print 'Artist:', tags.get('artist')
print 'Title: ', tags.get('title')
print 'Album: ', tags.get('album')
def playfile(filename):
bin = gst.Pipeline('player')
source = gst.Element('filesrc', 'src')
source.set_property('location', filename)
spider = gst.Element('spider', 'spider')
spider.connect('found-tag', found_tags)
sink = gst.Element('osssink', 'sink')
bin.add_many(source, spider, sink)
gst.element_link_many(source, spider, sink)
print 'Playing:', os.path.basename(filename)
bin.set_state(gst.STATE_PLAYING)
try:
while bin.iterate():
pass
except KeyboardInterrupt:
pass
bin.set_state(gst.STATE_NULL)
def main(args):
map(playfile, args[1:])
if __name__ == '__main__':
sys.exit(main(sys.argv))
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
#include "pygobject.h"
#include <gst/gst.h>
#include "0.6.h"
GstPropsType gst_props_entry_get_props_type(GstPropsEntry *entry)
{
return gst_props_entry_get_type(entry);
}
;;
;; Override normal *_get_type handling via rename
;;
(define-method get_props_type
(of-object "GstPropsEntry")
(c-name "gst_props_entry_get_props_type")
(return-type "GstPropsType")
)
;;
;; Access GstProps properties list
;;
(define-method get_list
(of-object "GstProps")
(c-name "gst_props_get_list")
(return-type "const-GList*")
)
;;
;; 0.6 Boxed types
;;
(define-boxed BufferPool
(in-module "Gst")
(c-name "GstBufferPool")
(gtype-id "GST_TYPE_BUFFER_POOL")
)
(define-boxed Props
(in-module "Gst")
(c-name "GstProps")
(gtype-id "GST_TYPE_PROPS")
)
(define-boxed PropsEntry
(in-module "Gst")
(c-name "GstPropsEntry")
(gtype-id "GST_TYPE_PROPS_ENTRY")
)
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
#include <gst/gst.h>
GstPropsType gst_props_entry_get_props_type(GstPropsEntry *entry);
/* -*- Mode: C; c-basic-offset: 4 -*- */
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
%%
headers
#include <Python.h>
#include "pygobject.h"
#include <gst/gst.h>
#include "0.6.h"
%%
override gst_props_entry_get_int
static PyObject *
_wrap_gst_props_entry_get_int(PyObject *self)
{
gboolean ret;
gint val;
val = 0;
ret = gst_props_entry_get_int(pyg_boxed_get(self, GstPropsEntry), &val);
return Py_BuildValue("(bi)", ret, val);
}
%%
override gst_props_entry_get_float
static PyObject *
_wrap_gst_props_entry_get_float(PyObject *self)
{
gboolean ret;
gfloat val;
val = 0.0f;
ret = gst_props_entry_get_float(pyg_boxed_get(self, GstPropsEntry), &val);
return Py_BuildValue("(bf)", ret, val);
}
%%
override gst_props_entry_get_fourcc_int
static PyObject *
_wrap_gst_props_entry_get_fourcc_int(PyObject *self)
{
gboolean ret;
gint32 val;
val = 0;
ret = gst_props_entry_get_fourcc_int(pyg_boxed_get(self, GstPropsEntry), &val);
return Py_BuildValue("(bi)", ret, val);
}
%%
override gst_props_entry_get_boolean
static PyObject *
_wrap_gst_props_entry_get_boolean(PyObject *self)
{
gboolean ret;
gboolean val;
PyObject *py_val;
val = FALSE;
ret = gst_props_entry_get_boolean(pyg_boxed_get(self, GstPropsEntry), &val);
py_val = val ? Py_True : Py_False;
return Py_BuildValue("(bO)", ret, py_val);
}
%%
override gst_props_entry_get_string
static PyObject *
_wrap_gst_props_entry_get_string(PyObject *self)
{
gboolean ret;
const gchar *val;
val = NULL;
ret = gst_props_entry_get_string(pyg_boxed_get(self, GstPropsEntry), &val);
if (ret) {
return Py_BuildValue("(bs)", ret, val);
} else {
return Py_BuildValue("(bO)", ret, Py_None);
}
}
%%
override gst_props_entry_get_int_range
static PyObject *
_wrap_gst_props_entry_get_int_range(PyObject *self)
{
gboolean ret;
gint min, max;
min = max = 0;
ret = gst_props_entry_get_int_range(pyg_boxed_get(self, GstPropsEntry), &min, &max);
return Py_BuildValue("(bii)", ret, min, max);
}
%%
override gst_props_entry_get_float_range
static PyObject *
_wrap_gst_props_entry_get_float_range(PyObject *self)
{
gboolean ret;
gfloat min, max;
min = max = 0.0f;
ret = gst_props_entry_get_float_range(pyg_boxed_get(self, GstPropsEntry), &min, &max);
return Py_BuildValue("(bff)", ret, min, max);
}
%%
override gst_props_entry_get_list
static PyObject *
_wrap_gst_props_entry_get_list(PyObject *self)
{
gboolean ret;
const GList *list;
PyObject *tuple, *obj;
int i;
list = NULL;
ret = gst_props_entry_get_list(pyg_boxed_get(self, GstPropsEntry), &list);
if (ret == TRUE) {
tuple = PyTuple_New(g_list_length((GList *) list));
for (i = 0; list != NULL; i++, list = g_list_next(list)) {
obj = pyg_boxed_new(GST_TYPE_PROPS_ENTRY, list->data, TRUE, TRUE);
PyTuple_SET_ITEM(tuple, i, obj);
}
} else {
tuple = Py_None;
Py_INCREF(tuple);
}
return Py_BuildValue("(bO)", ret, tuple);
}
%%
override gst_props_get_list
static gboolean
gst_props_get_list(GstProps *props, GList **list)
{
*list = GST_PROPS_PROPERTIES(props);
return TRUE;
}
static PyObject *
_wrap_gst_props_get_list(PyObject *self)
{
gboolean ret;
GList *list;
PyObject *tuple, *obj;
int i;
list = NULL;
ret = gst_props_get_list(pyg_boxed_get(self, GstProps), &list);
if (ret == TRUE) {
tuple = PyTuple_New(g_list_length(list));
for (i = 0; list != NULL; i++, list = g_list_next(list)) {
obj = pyg_boxed_new(GST_TYPE_PROPS_ENTRY, list->data, TRUE, TRUE);
PyTuple_SET_ITEM(tuple, i, obj);
}
} else {
tuple = Py_None;
Py_INCREF(tuple);
}
return Py_BuildValue("(bO)", ret, tuple);
}
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
#include "pygobject.h"
#include <gst/gst.h>
#include "0.7.h"
;;
;; 0.7 Boxed types
;;
(define-boxed Structure
(in-module "Gst")
(c-name "GstStructure")
(gtype-id "GST_TYPE_STRUCTURE")
)
(define-boxed TagList
(in-module "Gst")
(c-name "GstTagList")
(gtype-id "GST_TYPE_TAG_LIST")
)
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
/* -*- Mode: C; c-basic-offset: 4 -*- */
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
%%
headers
#include <Python.h>
#include "pygobject.h"
#include <gst/gst.h>
#include "0.7.h"
%%
override gst_structure_new kwargs
static int
_wrap_gst_structure_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "name", NULL };
char *name;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:GstStructure.__init__", kwlist, &name))
return -1;
self->gtype = GST_TYPE_STRUCTURE;
self->free_on_dealloc = FALSE;
self->boxed = gst_structure_new(name, NULL);
if (!self->boxed) {
PyErr_SetString(PyExc_RuntimeError, "could not create GstStructure object");
return -1;
}
self->free_on_dealloc = TRUE;
return 0;
}
%%
override gst_structure_set_value kwargs
static PyObject *
_wrap_gst_structure_set_value(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "field", "value", NULL };
char *field;
PyObject *py_value = NULL;
GValue value = { 0 };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:GstStructure.set_value", kwlist, &field, &py_value))
return NULL;
g_value_init(&value, G_TYPE_STRING);
if (pyg_value_from_pyobject(&value, py_value) != 0) {
return NULL;
}
gst_structure_set_value(pyg_boxed_get(self, GstStructure), field, &value);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gst_structure_foreach kwargs
static gboolean
pygst_structure_foreach_marshal(GQuark field_id,
GValue *value,
gpointer user_data)
{
PyGstCustomNotify *cunote = user_data;
PyObject *py_field, *py_value, *retobj;
gboolean retval = TRUE;
g_assert(cunote->func);
pyg_block_threads();
//py_model = pygobject_new((GObject *)model);
//py_path = pygtk_tree_path_to_pyobject(path);
//py_iter = pyg_boxed_new(GTK_TYPE_TREE_ITER, iter, TRUE, TRUE);
py_field = Py_BuildValue("s", g_quark_to_string(field_id));
py_value = pyg_value_as_pyobject(value, FALSE);
if (cunote->data)
retobj = PyEval_CallFunction(cunote->func, "(NNO)",
py_field, py_value,
cunote->data);
else
retobj = PyEval_CallFunction(cunote->func, "(NN)",
py_field, py_value);
if (PyErr_Occurred () || (retobj == NULL) || (retobj == Py_None)) {
PyErr_Print ();
retval = FALSE;
} else if (retobj != Py_None) {
retval = PyInt_AsLong(retobj);
}
Py_XDECREF(retobj);
pyg_unblock_threads();
return retval;
}
static PyObject *
_wrap_gst_structure_foreach (PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "foreach_function", "args", NULL };
PyObject *pyfunc, *pyarg = NULL;
PyGstCustomNotify cunote;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|O:GstStructure.foreach",
kwlist,
&pyfunc, &pyarg)) {