From 04acf63252c0512c52c776c5babf392df5a1455f Mon Sep 17 00:00:00 2001 From: flavio Date: Wed, 05 Dec 2012 19:23:02 +0000 Subject: Record more than one video in one session Screencast. --- diff --git a/ScreencastActivity.py b/ScreencastActivity.py index 6b7543b..d02f226 100644 --- a/ScreencastActivity.py +++ b/ScreencastActivity.py @@ -41,18 +41,12 @@ import i18n class ScreencastActivity(activity.Activity): - # Attributes - _state = None - _ui = None - _gst = None - _videofile = None - def __init__(self, handle): """ Constructor """ # Call super class "Activity" constructor method super(ScreencastActivity, self).__init__(handle) - + # User interface object self._ui = sc_ui.ScreencastUserInterface(self) @@ -64,7 +58,7 @@ class ScreencastActivity(activity.Activity): self._videofile = os.path.join( directory, "screencast.ogg" ) # Gstreamer interface object - self._gst = sc_gst.ScreencastGstreamer(self, self._videofile) + self._gst = sc_gst.ScreencastGstreamer(self._videofile) # State self._state = "stopped" diff --git a/sc_gst.py b/sc_gst.py index 8653cb6..192afe9 100644 --- a/sc_gst.py +++ b/sc_gst.py @@ -30,48 +30,53 @@ import time class ScreencastGstreamer(gobject.GObject): - # Attributes - _pipeline = None - _videofile = None - _timer = None - _videoitems = None - _audioitems = None - _oggmux = None - _filesink = None - _startclock = None - - # Custom signals __gsignals__ = { - "update-info": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING,gobject.TYPE_STRING,)) + "update-info": (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, (gobject.TYPE_STRING,gobject.TYPE_STRING,)) } - def __init__(self, activity, videofile): + def __init__(self, videofile): """ Constructor """ + super(ScreencastGstreamer, self).__init__() - - self._activity = activity + + self._audioitems = False + self._startclock = False self._videofile = videofile - self.createPipeline() + self._pipeline = False + self._timer = False + self._oggmux = False + self._videoitems = False + self._filesink = False def stop(self): """ Stop recording """ - self._pipeline.set_state(gst.STATE_PAUSED) - self._pipeline.set_state(gst.STATE_NULL) - del(self._pipeline) - self._pipeline = None - + if self._timer: gobject.source_remove(self._timer) - self._timer = None + self._timer = False + + self._pipeline.set_state(gst.STATE_PAUSED) + self._pipeline.set_state(gst.STATE_NULL) def start(self, recordsound): """ Start recording """ - self._pipeline = gst.Pipeline("screencast-pipeline") + + if self._pipeline: + del(self._pipeline) + + if self._timer: + gobject.source_remove(self._timer) + self._timer = None + + self.createPipeline() + self.addItems(recordsound) self.linkItems(recordsound) + self._pipeline.set_state(gst.STATE_PLAYING) self._startclock = time.time() self._timer = gobject.timeout_add(1000, self.updateInfo) @@ -118,11 +123,12 @@ class ScreencastGstreamer(gobject.GObject): def updateInfo(self): """ Update info """ + videofilesize = "0 Kb" - videolength = "%d s" % ( time.time() - self._startclock ) + videolength = "%s s" % ( int(time.time() - self._startclock)) if os.path.exists(self._videofile): - videofilesize = "%d Kb" % ( int(os.path.getsize(self._videofile)/1024) ) + videofilesize = "%s Kb" % ( int(int(os.path.getsize(self._videofile)) / 1024)) self.emit('update-info', videofilesize, videolength) @@ -132,6 +138,7 @@ class ScreencastGstreamer(gobject.GObject): def createVideoItems(self): """ Create video items """ + ximagesrc = gst.element_factory_make('ximagesrc', "ximagesrc") ximagesrc.set_property('startx', 0) ximagesrc.set_property('endx', 1200) @@ -197,10 +204,12 @@ class ScreencastGstreamer(gobject.GObject): mux. mux. ! \ filesink location=video.ogg """ - + + self._pipeline = gst.Pipeline("player") + self.createVideoItems() self.createAudioItems() + self._oggmux = gst.element_factory_make('oggmux', "oggmux") self._filesink = gst.element_factory_make('filesink', "filesink") self._filesink.set_property("location", self._videofile) - diff --git a/sc_ui.py b/sc_ui.py index a9d2489..33923af 100644 --- a/sc_ui.py +++ b/sc_ui.py @@ -35,35 +35,29 @@ from sugar.graphics.alert import NotifyAlert class ScreencastUserInterface(gobject.GObject): - # Attributes - _activity = None - - _toolbox = None - _toolbar = None - - _recordbutton = None - _stopbutton = None - _buttonsbox = None - - _box = None - _boxalign = None - - _checkbox = None - _label = None - - # Custom signals __gsignals__ = { - 'recordbutton-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()), - 'stopbutton-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()), - } + 'recordbutton-clicked': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ()), + 'stopbutton-clicked': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ())} def __init__(self, activity): """ Constructor """ super(ScreencastUserInterface, self).__init__() + self._toolbox = None + self._toolbar = None + self._recordbutton = None + self._stopbutton = None + self._buttonsbox = None + self._box = None + self._boxalign = None + self._checkbox = None + self._label = None + self._activity = activity - + # Widgets self.buildToolbar() self.buildButtons() -- cgit v0.9.1