zaheer - in flumotion/trunk: . flumotion/component/combiners/switch

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Mon Jul 2 12:14:15 CEST 2007


Author: zaheer
Date: Mon Jul  2 12:14:12 2007
New Revision: 5279

Added:
   flumotion/trunk/flumotion/component/combiners/switch/patternswitch.py
Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/flumotion/component/combiners/switch/Makefile.am
   flumotion/trunk/flumotion/component/combiners/switch/switch.py
   flumotion/trunk/flumotion/component/combiners/switch/switch.xml
Log:
	* flumotion/component/combiners/switch/Makefile.am:
	* flumotion/component/combiners/switch/patternswitch.py
	  (PatternEventSwitcher, PatternEventSwitcher.configure_pipeline,
	  PatternEventSwitcher._markers_event_probe):
	* flumotion/component/combiners/switch/switch.xml:
	New switch based component that switches based on patterns, similar
	to how the disker starts and stops based on patterns.
	* flumotion/component/combiners/switch/switch.py (Switch.eventStarted,
	  Switch.eventStopped, Switch.switch_to_for_event):
	Share code switch_to_for_event between ical event switching and
	"other" event based switching like pattern based.



Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Mon Jul  2 12:14:12 2007
@@ -1,3 +1,17 @@
+2007-07-02  Zaheer Abbas Merali  <zaheerabbas at merali dot org>
+
+	* flumotion/component/combiners/switch/Makefile.am:
+	* flumotion/component/combiners/switch/patternswitch.py
+	  (PatternEventSwitcher, PatternEventSwitcher.configure_pipeline,
+	  PatternEventSwitcher._markers_event_probe):
+	* flumotion/component/combiners/switch/switch.xml:
+	New switch based component that switches based on patterns, similar
+	to how the disker starts and stops based on patterns.
+	* flumotion/component/combiners/switch/switch.py (Switch.eventStarted,
+	  Switch.eventStopped, Switch.switch_to_for_event):
+	Share code switch_to_for_event between ical event switching and
+	"other" event based switching like pattern based.
+
 2007-06-28  Michael Smith <msmith at fluendo.com>
 
 	* flumotion/worker/job.py:

Modified: flumotion/trunk/flumotion/component/combiners/switch/Makefile.am
==============================================================================
--- flumotion/trunk/flumotion/component/combiners/switch/Makefile.am	(original)
+++ flumotion/trunk/flumotion/component/combiners/switch/Makefile.am	Mon Jul  2 12:14:12 2007
@@ -1,6 +1,6 @@
 include $(top_srcdir)/common/python.mk
 
-component_PYTHON = __init__.py switch.py basicwatchdog.py admin_gtk.py
+component_PYTHON = __init__.py switch.py basicwatchdog.py patternswitch.py admin_gtk.py
 componentdir = $(libdir)/flumotion/python/flumotion/component/combiners/switch
 component_DATA = \
 	switch.xml	

Added: flumotion/trunk/flumotion/component/combiners/switch/patternswitch.py
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/switch/patternswitch.py	Mon Jul  2 12:14:12 2007
@@ -0,0 +1,49 @@
+# -*- Mode: Python -*-
+# vi:si:et:sw=4:sts=4:ts=4
+#
+# Flumotion - a streaming media server
+# Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com).
+# All rights reserved.
+
+# This file may be distributed and/or modified under the terms of
+# the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+# This file is distributed without any warranty; without even the implied
+# warranty of merchantability or fitness for a particular purpose.
+# See "LICENSE.GPL" in the source distribution for more information.
+
+# Licensees having purchased or holding a valid Flumotion Advanced
+# Streaming Server license may use this file in accordance with the
+# Flumotion Advanced Streaming Server Commercial License Agreement.
+# See "LICENSE.Flumotion" in the source distribution for more information.
+
+# Headers in this file shall remain intact.
+
+from flumotion.component import feedcomponent
+from flumotion.common import errors
+
+from flumotion.component.combiners.switch import basicwatchdog
+import gst
+
+class PatternEventSwitcher(basicwatchdog.AVBasicWatchdog):
+    logCategory = "comb-av-pattern-switcher"
+
+    def configure_pipeline(self, pipeline, properties):
+        basicwatchdog.AVBasicWatchdog.configure_pipeline(self, pipeline, 
+            properties)
+        # set event probe to react to video mark events
+        eaterName = properties.get('eater-with-stream-markers', 
+            'video-backup')
+        sinkpad = self.switchPads[eaterName]
+        sinkpad.add_event_probe(self._markers_event_probe)
+
+    def _markers_event_probe(self, element, event):
+        if event.type == gst.EVENT_CUSTOM_DOWNSTREAM:
+            evt_struct = event.get_structure()
+            if evt_struct.get_name() == 'FluStreamMark':
+                if evt_struct['action'] == 'start':
+                    self.switch_to_for_event("backup", True)
+
+                elif evt_struct['action'] == 'stop':
+                    self.switch_to_for_event("master", False)
+        return True

Modified: flumotion/trunk/flumotion/component/combiners/switch/switch.py
==============================================================================
--- flumotion/trunk/flumotion/component/combiners/switch/switch.py	(original)
+++ flumotion/trunk/flumotion/component/combiners/switch/switch.py	Mon Jul  2 12:14:12 2007
@@ -69,9 +69,6 @@
                 self.addMessage(m)
             # if we have been passed an ical file to use for scheduling
             # then start the ical monitor
-            # FIXME: need to handle cases where cannot switch (and hence
-            # post a message to uistate and also store so switch can be
-            # made as soon as it can switch)
             props = self.config['properties']
             icalfn = props.get('ical-schedule')
             if icalfn:
@@ -119,28 +116,12 @@
     def eventStarted(self, event):
         self.debug("event started %r", event)
         if self.pipeline:
-            self._idealEater = "backup"
-            res = self.switch_to("backup")
-            if not res:
-                self.warning("Event started but could not switch to backup"
-                    ", will switch when backup is back")
-                self._eaterReadyDefers["backup"] = defer.Deferred()
-                self._eaterReadyDefers["backup"].addCallback(
-                    lambda x: self.switch_to("backup"))
-                self._eaterReadyDefers["master"] = None
+            self.switch_to_for_event("backup", True)
 
     def eventStopped(self, event):
         self.debug("event stopped %r", event)
         if self.pipeline:
-            self._idealEater = "master"
-            res = self.switch_to("master")
-            if not res:
-                self.warning("Event stopped but could not switch to master"
-                    ", will switch when master is back")
-                self._eaterReadyDefers["master"] = defer.Deferred()
-                self._eaterReadyDefers["master"].addCallback(
-                    lambda x: self.switch_to("master"))
-                self._eaterReadyDefers["backup"] = None
+            self.switch_to_for_event("master", False)
 
     def do_pipeline_playing(self):
         feedcomponent.MultiInputParseLaunchComponent.do_pipeline_playing(self)
@@ -154,6 +135,36 @@
         if not self._started and moods.get(self.getMood()) == moods.happy:
             self._started = True
 
+    def switch_to_for_event(self, eaterSubstring, startOrStop):
+        """
+        @param eaterSubstring: either "master" or "backup"
+        @param startOrStop: True if start of event, False if stop
+        """
+        if eaterSubstring != "master" or eaterSubstring != "backup":
+            self.warning("switch_to_for_event should be called with 'master'"
+                " or 'backup'")
+            return
+        self._idealEater = eaterSubstring
+        res = self.switch_to(eaterSubstring)
+        if not res:
+            startOrStopStr = "stopped"
+            if startOrStop:
+                startOrStopStr = "started"
+            warnStr = "Event %s but could not switch to %s" \
+                ", will switch when %s is back" % (startOrStopStr,
+                eaterSubstring, eaterSubstring)
+            self.warning(warnStr)
+            m = messages.Warning(T_(N_(warnStr)), 
+                        id="error-scheduling-event")
+            self.addMessage(m)
+            self._eaterReadyDefers[eaterSubstring] = defer.Deferred()
+            self._eaterReadyDefers[eaterSubstring].addCallback(
+                lambda x: self.switch_to(eaterSubstring))
+            otherEater = "backup"
+            if eaterSubstring == "backup":
+                otherEater = "master"
+            self._eaterReadyDefers[otherEater] = None
+
 class SingleSwitch(Switch):
     logCategory = "comb-single-switch"
 

Modified: flumotion/trunk/flumotion/component/combiners/switch/switch.xml
==============================================================================
--- flumotion/trunk/flumotion/component/combiners/switch/switch.xml	(original)
+++ flumotion/trunk/flumotion/component/combiners/switch/switch.xml	Mon Jul  2 12:14:12 2007
@@ -89,6 +89,34 @@
 	<property name="audio-channels" type="int" required="no" />
       </properties>
     </component>
+    <component type="av-pattern-switch-combiner"
+               base="flumotion/component/combiners/switch"
+               description="An audio/video switching based on pattern component">
+      <source location="flumotion.component.combiners.switch.patternswitch" />
+      <eater name="video-master" />
+      <eater name="video-backup" />
+      <eater name="audio-master" />
+      <eater name="audio-backup" />
+      <feeder name="video" />
+      <feeder name="audio" />
+      <entries>
+        <entry type="component" location="patternswitch.py"
+               function="PatternEventSwitcher" />
+	<entry type="admin/gtk" location="admin_gtk.py"
+               function="GUIClass" />
+      </entries>
+      <properties>
+        <property name="ical-schedule" type="string" required="no" />
+	<property name="video-width" type="int" required="no" />
+	<property name="video-height" type="int" required="no" />
+	<property name="video-framerate" type="fraction" required="no" />
+	<property name="video-pixel-aspect-ratio" type="fraction" 
+	          required="no" />
+	<property name="audio-samplerate" type="int" required="no" />
+	<property name="audio-channels" type="int" required="no" />
+	<property name="eater-with-stream-markers" type="string" required="yes" />
+      </properties>
+    </component>
 
   </components>
 
@@ -132,6 +160,17 @@
 	</directories>
     </bundle>
 
+    <bundle name="switch-combiner-pattern">
+        <dependencies>
+	    <dependency name="switch-combiner-basic-watchdog" />
+	</dependencies>
+	<directories>
+	    <directory name="flumotion/component/combiners/switch">
+	        <filename location="patternswitch.py" />
+	    </directory>
+	</directories>
+    </bundle>
+
     <bundle name="switch-combiner-admin-gtk">
         <dependencies>
             <dependency name="base-admin-gtk"/>


More information about the flumotion-commit mailing list