#! /usr/bin/env python """ This is a gstreamer source element which draws its data from an internal python dictionary variable. Copyright (C) 2006 Scott Shawcroft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ import gobject import pygst pygst.require("0.10") import gst from cliplistiter import cliplistiter class TextSource (gst.PushSrc): """This gstreamer element pushes buffers out of the cliplist given. """ __gsttemplates__ = ( gst.PadTemplate("src", gst.PAD_SRC, gst.PAD_ALWAYS, gst.Caps("text/plain")), ) def __init__(self, cliplist=None, name="TextSource"): self.__gobject_init__() self.set_name(name) self.set_format(gst.FORMAT_TIME) self.set_cliplist(cliplist) def do_check_get_range(self): return True def do_create(self, offset, length): if self.__iter and self.__iter.has_next(): clip = self.__iter.next() buf = gst.Buffer(clip.get_text()) buf.timestamp = clip.get_start()*gst.MSECOND buf.duration = clip.get_duration()*gst.MSECOND return gst.FLOW_OK, buf elif self.__cliplist.length()>0: buf = gst.Buffer(" ") last = self.__cliplist.get_last_clip() buf.timestamp = last.get_end() buf.duration = 9999999*gst.SECOND # A really long time. (FIXME) return gst.FLOW_OK, buf else: buf = gst.Buffer(" ") buf.timestamp = 0*gst.SECOND buf.duration = 9999999*gst.SECOND # A really long time. (FIXME) return gst.FLOW_OK, buf def do_do_seek(self, segment): self.__iter.reset_iter() return True def do_is_seekable(self): return True def get_cliplist(self): return self.__cliplist def set_cliplist(self,cliplist): self.__iter = cliplistiter(cliplist) self.__cliplist = cliplist