msmith - in flumotion/branches/playlist-1: .
flumotion/component/producers/playlist
flumotion-commit at lists.fluendo.com
flumotion-commit at lists.fluendo.com
Thu May 3 12:19:33 CEST 2007
Author: msmith
Date: Thu May 3 12:19:31 2007
New Revision: 4872
Modified:
flumotion/branches/playlist-1/ChangeLog
flumotion/branches/playlist-1/flumotion/component/producers/playlist/playlist.py
Log:
* flumotion/component/producers/playlist/playlist.py:
Factor out clock setup properly, and file scheduling.
Now we just have a single test scheduling method, which can now be
replaced by actual playlist code.
Modified: flumotion/branches/playlist-1/ChangeLog
==============================================================================
--- flumotion/branches/playlist-1/ChangeLog (original)
+++ flumotion/branches/playlist-1/ChangeLog Thu May 3 12:19:31 2007
@@ -1,6 +1,13 @@
2007-05-03 Michael Smith <msmith at fluendo.com>
* flumotion/component/producers/playlist/playlist.py:
+ Factor out clock setup properly, and file scheduling.
+ Now we just have a single test scheduling method, which can now be
+ replaced by actual playlist code.
+
+2007-05-03 Michael Smith <msmith at fluendo.com>
+
+ * flumotion/component/producers/playlist/playlist.py:
Another checkpoint, now with modified clocking and basetime
distribution working.
Modified: flumotion/branches/playlist-1/flumotion/component/producers/playlist/playlist.py
==============================================================================
--- flumotion/branches/playlist-1/flumotion/component/producers/playlist/playlist.py (original)
+++ flumotion/branches/playlist-1/flumotion/component/producers/playlist/playlist.py Thu May 3 12:19:31 2007
@@ -37,6 +37,8 @@
def videotest_gnl_src(name, start, duration, priority):
src = gst.element_factory_make('videotestsrc')
+ # Set videotestsrc to all black. Not doing this yet to make debugging easier
+ #src.props.patten = 2
gnlsrc = gst.element_factory_make('gnlsource', name)
gnlsrc.props.start = start
gnlsrc.props.duration = duration
@@ -47,8 +49,10 @@
return gnlsrc
-def file_gnl_src(name, uri, caps, start, duration, priority):
- src = singledecodebin.SingleDecodeBin(caps, uri)
+def audiotest_gnl_src(name, start, duration, priority):
+ src = gst.element_factory_make('audiotestsrc')
+ # Set audiotestsrc to use silence. Not doing this yet for debugging ease.
+ #src.props.wave = 4
gnlsrc = gst.element_factory_make('gnlsource', name)
gnlsrc.props.start = start
gnlsrc.props.duration = duration
@@ -59,18 +63,19 @@
return gnlsrc
-def audiotest_gnl_src(name, start, duration, priority):
- src = gst.element_factory_make('audiotestsrc')
+def file_gnl_src(name, uri, caps, start, duration, offset, priority):
+ src = singledecodebin.SingleDecodeBin(caps, uri)
gnlsrc = gst.element_factory_make('gnlsource', name)
gnlsrc.props.start = start
gnlsrc.props.duration = duration
- gnlsrc.props.media_start = 0
+ gnlsrc.props.media_start = offset
gnlsrc.props.media_duration = duration
gnlsrc.props.priority = priority
gnlsrc.add(src)
return gnlsrc
+
class PlaylistMedium(feedcomponent.FeedComponentMedium):
def __init__(self, comp):
feedcomponent.FeedComponentMedium.__init__(self, comp)
@@ -80,7 +85,15 @@
componentMediumClass = PlaylistMedium
def init(self):
- pass
+ self.basetime = -1
+ self.pipeline = None
+
+ # The gnlcompositions for audio and video
+ self.videocomp = None
+ self.audiocomp = None
+
+ self.videocaps = gst.Caps("video/x-raw-yuv;video/x-raw-rgb")
+ self.audiocaps = gst.Caps("audio/x-raw-int;audio/x-raw-float")
def _buildAudioPipeline(self, pipeline, queue):
audioconvert = gst.element_factory_make('audioconvert')
@@ -135,13 +148,9 @@
if mediatype == 'audio':
self.audiocomp = composition
- self.audiocomp.props.caps = \
- gst.Caps("audio/x-raw-int;audio/x-raw-float")
srcpad = self._buildAudioPipeline(pipeline, queue)
else:
self.videocomp = composition
- self.videocomp.props.caps = \
- gst.Caps("video/x-raw-yuv;video/x-raw-rgb")
srcpad = self._buildVideoPipeline(pipeline, queue)
feedername = 'feeder:%s:%s' % (self.name, mediatype)
@@ -168,63 +177,74 @@
2**31 - 1)
self.audiocomp.add(asrc)
- def _testScheduling(self, pipeline):
- # Now, we want to schedule something for a particular date...
- uri = "file:///home/msmith/media/testfiles/matrix.avi"
- caps = gst.Caps("video/x-raw-yuv")
-
- # For testing, try 10 seconds into the future.
+ def _setupClock(self, pipeline):
+ # Configure our pipeline to use a known basetime and clock.
clock = gst.SystemClock()
- basetime = clock.get_time()
+ # It doesn't matter too much what this basetime is, so long as we know
+ # the value.
+ self.basetime = clock.get_time()
- # We force usage of a system clock.
+ # We force usage of the system clock.
pipeline.use_clock(clock)
# Now we disable default basetime distribution
pipeline.set_new_stream_time(gst.CLOCK_TIME_NONE)
# And we choose our own basetime...
- self.debug("Setting basetime of %d", basetime)
- pipeline.set_base_time(basetime)
+ self.debug("Setting basetime of %d", self.basetime)
+ pipeline.set_base_time(self.basetime)
-# when = basetime + (10 * gst.SECOND)
+ def scheduleFile(self, uri, starttime, duration, offset,
+ video=True, audio=True):
+ """
+ Schedule a file at a given URI to start playback at starttime
+ (specified as nanoseconds since the epoch), for the given duration.
+ Use audio and/or video.
+ """
+ start = starttime - self.basetime
+ # This works around a bug somewhere. TODO!
+ start = (start / gst.SECOND) * gst.SECOND
+ if start < 0:
+ if start + duration < 0:
+ return
+ else:
+ # If we're not too late for part of the file to be playable,
+ # then play it!
+ offset = -start
+ duration = duration + start
+ start = 0
+
+ if video:
+ vsrc = file_gnl_src(None, uri, self.videocaps,
+ start, duration, offset, 0)
+ self.videocomp.add(vsrc)
+ if audio:
+ asrc = file_gnl_src(None, uri, self.audiocaps,
+ start, duration, offset, 0)
+ self.videocomp.add(asrc)
- for minute in xrange(35, 50):
- when = (2007, 5, 3, 10, minute, 0, 0, 123, 0)
- whengst = int(time.mktime(when)) * gst.SECOND
+ def testSchedule(self, pipeline):
+ # Now, we want to schedule something for a particular date...
+ uri = "file:///home/msmith/media/testfiles/matrix.avi"
- starttime = whengst - basetime
+ for minute in xrange(8, 50):
+ when = (2007, 5, 3, 11, minute, 0, 0, 123, 0)
+ whengst = int(time.mktime(when)) * gst.SECOND
- # This works around a bug somewhere. TODO!
- starttime = (starttime / gst.SECOND) * gst.SECOND
- self.debug("when -> whengst -> starttime = %r, %d, %d", when, whengst, starttime)
- # For this to work, we must distribute this basetime!
-
- self.debug("Scheduling start for 10 seconds after startup: %d", starttime)
- vsrc = file_gnl_src('testgnlfile%d'%minute, uri, caps, starttime,
- 45 * gst.SECOND, 0)
- self.videocomp.add(vsrc)
+ duration = 45 * gst.SECOND
+ self.scheduleFile(uri, whengst, duration, 0, True, False)
def create_pipeline(self):
pipeline = self._buildPipeline()
+ self._setupClock(pipeline)
self._createDefaultSources()
- uri = "file:///home/msmith/media/testfiles/matrix.avi"
- caps = gst.Caps("video/x-raw-yuv")
-# vsrc = file_gnl_src('testgnlfile', uri, caps, 10 * gst.SECOND,
-# 15 * gst.SECOND, 0)
-# self.videocomp.add(vsrc)
- self._testScheduling(pipeline)
+ self.testSchedule(pipeline)
self.connect_feeders(pipeline)
return pipeline
def do_start(self, clocking):
- #if clocking:
- # self.debug("Slaving to clock")
- # self.set_master_clock(*clocking)
-
self.link()
-
return defer.succeed(None)
def do_stop(self):
More information about the flumotion-commit
mailing list