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

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Thu May 10 16:14:23 CEST 2007


Author: zaheer
Date: Thu May 10 16:14:19 2007
New Revision: 4928

Added:
   flumotion/trunk/flumotion/component/combiners/Makefile.am
   flumotion/trunk/flumotion/component/combiners/__init__.py
   flumotion/trunk/flumotion/component/combiners/switch/Makefile.am
   flumotion/trunk/flumotion/component/combiners/switch/__init__.py
   flumotion/trunk/flumotion/component/combiners/switch/admin_gtk.py
   flumotion/trunk/flumotion/component/combiners/switch/switch.py
   flumotion/trunk/flumotion/component/combiners/switch/switch.xml
Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/configure.ac
Log:
	* configure.ac:
	* flumotion/component/combiners/Makefile.am:
	* flumotion/component/combiners/__init__.py:
	* flumotion/component/combiners/switch/Makefile.am:
	* flumotion/component/combiners/switch/__init__.py:
	* flumotion/component/combiners/switch/admin_gtk.py (SwitchingNode,
	  SwitchingNode.__init__, SwitchingNode.cb_toggled,
	  SwitchingNode.setUIState, SwitchingNode.stateSet, SwitcherAdminGtk,
	  SwitcherAdminGtk.setup):
	* flumotion/component/combiners/switch/switch.py (SwitchMedium,
	  SwitchMedium.remote_switchToMaster,
	  SwitchMedium.remote_switchToBackup, Switch, Switch.init,
	  Switch.do_check, Switch.cb, Switch.switchToMaster,
	  Switch.switchToBackup, SingleSwitch, SingleSwitch.init,
	  SingleSwitch.get_pipeline_string, SingleSwitch.configure_pipeline,
	  SingleSwitch.switchToMaster, SingleSwitch.switchToBackup, AVSwitch,
	  AVSwitch.init, AVSwitch.get_pipeline_string,
	  AVSwitch.configure_pipeline, AVSwitch.switchToMaster,
	  AVSwitch.switchToBackup):
	* flumotion/component/combiners/switch/switch.xml:
	Add switching components with very simple gtk admin for now.



Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Thu May 10 16:14:19 2007
@@ -1,3 +1,27 @@
+2007-05-10  Zaheer Abbas Merali  <<zaheerabbas at merali dot org>>
+
+	* configure.ac:
+	* flumotion/component/combiners/Makefile.am:
+	* flumotion/component/combiners/__init__.py:
+	* flumotion/component/combiners/switch/Makefile.am:
+	* flumotion/component/combiners/switch/__init__.py:
+	* flumotion/component/combiners/switch/admin_gtk.py (SwitchingNode,
+	  SwitchingNode.__init__, SwitchingNode.cb_toggled,
+	  SwitchingNode.setUIState, SwitchingNode.stateSet, SwitcherAdminGtk,
+	  SwitcherAdminGtk.setup):
+	* flumotion/component/combiners/switch/switch.py (SwitchMedium,
+	  SwitchMedium.remote_switchToMaster,
+	  SwitchMedium.remote_switchToBackup, Switch, Switch.init,
+	  Switch.do_check, Switch.cb, Switch.switchToMaster,
+	  Switch.switchToBackup, SingleSwitch, SingleSwitch.init,
+	  SingleSwitch.get_pipeline_string, SingleSwitch.configure_pipeline,
+	  SingleSwitch.switchToMaster, SingleSwitch.switchToBackup, AVSwitch,
+	  AVSwitch.init, AVSwitch.get_pipeline_string,
+	  AVSwitch.configure_pipeline, AVSwitch.switchToMaster,
+	  AVSwitch.switchToBackup):
+	* flumotion/component/combiners/switch/switch.xml:
+	Add switching components with very simple gtk admin for now.
+
 2007-05-10  Sebastien Merle  <sebastien at fluendo.com>
 
 	* flumotion/common/enum.py: 

Modified: flumotion/trunk/configure.ac
==============================================================================
--- flumotion/trunk/configure.ac	(original)
+++ flumotion/trunk/configure.ac	Thu May 10 16:14:19 2007
@@ -174,6 +174,8 @@
 flumotion/component/effects/colorbalance/Makefile
 flumotion/component/effects/volume/Makefile
 flumotion/component/encoders/Makefile
+flumotion/component/combiners/Makefile
+flumotion/component/combiners/switch/Makefile
 flumotion/component/consumers/Makefile
 flumotion/component/consumers/disker/Makefile
 flumotion/component/consumers/httpstreamer/Makefile

Added: flumotion/trunk/flumotion/component/combiners/Makefile.am
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/Makefile.am	Thu May 10 16:14:19 2007
@@ -0,0 +1,13 @@
+include $(top_srcdir)/common/python.mk
+                                                                                
+combinersdir = $(libdir)/flumotion/python/flumotion/component/combiners
+combiners_PYTHON = \
+	__init__.py
+
+TAGS_FILES = $(component_PYTHON)
+
+clean-local:
+	rm -rf *.pyc *.pyo
+
+SUBDIRS = \
+	switch

Added: flumotion/trunk/flumotion/component/combiners/__init__.py
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/__init__.py	Thu May 10 16:14:19 2007
@@ -0,0 +1,20 @@
+# -*- 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.

Added: flumotion/trunk/flumotion/component/combiners/switch/Makefile.am
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/switch/Makefile.am	Thu May 10 16:14:19 2007
@@ -0,0 +1,11 @@
+include $(top_srcdir)/common/python.mk
+
+component_PYTHON = __init__.py switch.py
+componentdir = $(libdir)/flumotion/python/flumotion/component/combiners/switch
+component_DATA = \
+	switch.xml	
+
+clean-local:
+	rm -rf *.pyc *.pyo
+
+EXTRA_DIST = $(component_DATA)

Added: flumotion/trunk/flumotion/component/combiners/switch/__init__.py
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/switch/__init__.py	Thu May 10 16:14:19 2007
@@ -0,0 +1,20 @@
+# -*- 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.

Added: flumotion/trunk/flumotion/component/combiners/switch/admin_gtk.py
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/switch/admin_gtk.py	Thu May 10 16:14:19 2007
@@ -0,0 +1,71 @@
+# -*- 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.
+
+import os
+import gtk
+
+from flumotion.common import errors
+
+from flumotion.component.base.admin_gtk import BaseAdminGtk, BaseAdminGtkNode
+
+class SwitchingNode(BaseAdminGtkNode):
+
+    def __init__(self, state, admin, title=None):
+        BaseAdminGtkNode.__init__(self, state, admin, title)
+        # create widget
+        self.widget = gtk.Table(2, 1)
+        self.radioButton = {}
+        self.radioButton["backup"] = gtk.RadioButton(label="Backup")
+        self.radioButton["master"] = gtk.RadioButton(self.radioButton["backup"],
+            label="Master")
+        currentRow = 0
+        for eaterName in self.radioButton:
+            self.widget.attach(self.radioButton[eaterName], 0, 1, currentRow, 
+                currentRow+1, yoptions=gtk.FILL, xpadding=6, ypadding=6)
+            currentRow = currentRow + 1
+            self.radioButton[eaterName].show()
+            self.radioButton[eaterName].connect("toggled", 
+                self.cb_toggled, eaterName)
+        self.widget.show()
+
+    def cb_toggled(self, button, eaterName):
+        if button.get_active():
+            if eaterName == "master":
+                self.callRemote("switchToMaster")
+            else:
+                self.callRemote("switchToBackup")
+
+    def setUIState(self, state):
+        BaseAdminGtkNode.setUIState(self, state)
+        self.stateSet(state, 'active-eater', state.get('active-eater'))
+
+    def stateSet(self, state, key, value):
+        if key == 'active-eater':
+            if not self.radioButton[value].get_active():
+                self.radioButton[value].set_active(True)
+    
+class SwitcherAdminGtk(BaseAdminGtk):
+    def setup(self):
+        swNode = SwitchingNode(self.state, self.admin, "Switching")
+        self.nodes['Switcher'] = swNode
+        return BaseAdminGtk.setup(self)
+
+GUIClass = SwitcherAdminGtk

Added: flumotion/trunk/flumotion/component/combiners/switch/switch.py
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/switch/switch.py	Thu May 10 16:14:19 2007
@@ -0,0 +1,195 @@
+# -*- 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
+
+class SwitchMedium(feedcomponent.FeedComponentMedium):
+    def remote_switchToMaster(self):
+        return self.comp.switchToMaster()
+    
+    def remote_switchToBackup(self):
+        return self.comp.switchToBackup()
+
+class Switch(feedcomponent.MultiInputParseLaunchComponent):
+    logCategory = 'conv-switch'
+    componentMediumClass = SwitchMedium
+
+    def init(self):
+        self.uiState.addKey("active-eater")
+        
+    def do_check(self):
+        self.debug("checking whether switch element exists")
+        from flumotion.worker.checks import check
+        d = check.checkPlugin('switch', 'gst-plugins-bad')
+        def cb(result):
+            for m in result.messages:
+                self.addMessage(m)
+            d.addCallback(cb)
+            return d
+        
+    def switchToMaster(self):
+        raise errors.NotImplementedError('subclasses should implement '
+                                         'switchToMaster')
+
+    def switchToBackup(self):
+        raise errors.NotImplementedError('subclasses should implement '
+                                         'switchToBackup')
+
+class SingleSwitch(Switch):
+    logCategory = "conv-single-switch"
+
+    def init(self):
+        Switch.init(self)
+        self.switchElement = None
+        # eater name -> name of sink pad on switch element
+        self.switchPads = {}
+
+    def get_pipeline_string(self, properties):
+        eaters = self.eater_names
+
+        pipeline = "switch name=switch ! " \
+            "identity silent=true single-segment=true name=iden "
+        for eater in eaters:
+            tmpl = '@ eater:%s @ ! switch. '
+            pipeline += tmpl % eater
+
+        pipeline += 'iden.'
+
+        return pipeline
+
+    def configure_pipeline(self, pipeline, properties):
+        self.switchElement = sw = pipeline.get_by_name("switch")
+        # figure out the pads connected for the eaters
+        padPeers = {} # padName -> peer element name
+        for sinkPadNumber in range(0, len(self.eater_names)):
+            padPeers["sink%d" % sinkPadNumber] = sw.get_pad("sink%d" % (
+                sinkPadNumber)).get_peer().get_parent().get_name()
+
+        for feedid in self.eater_names:
+            eaterName = self.get_eater_name_for_feedid(feedid)
+            self.debug("feedid %s is mapped to eater name %s", feedid, 
+                eaterName)
+            if eaterName:
+                for sinkPad in padPeers:
+                    if feedid in padPeers[sinkPad]:
+                        self.switchPads[eaterName] = sinkPad
+                if not self.switchPads.has_key(eaterName):    
+                    self.warning("could not find sink pad for eater %s", 
+                        eaterName )
+        # make sure switch has the correct sink pad as active
+        self.debug("Setting switch's active-pad to %s", 
+            self.switchPads["master"])
+        self.switchElement.set_property("active-pad", 
+            self.switchPads["master"])
+        self.uiState.set("active-eater", "master")
+
+    def switchToMaster(self):
+        self.switchElement.set_property("active-pad",
+            self.switchPads["master"])
+        self.uiState.set("active-eater", "master")
+        
+    def switchToBackup(self):
+        self.switchElement.set_property("active-pad",
+            self.switchPads["backup"])
+        self.uiState.set("active-eater", "backup")
+
+class AVSwitch(Switch):
+    logCategory = "conv-av-switch"
+
+    def init(self):
+        Switch.init(self)
+        self.audioSwitchElement = None
+        self.videoSwitchElement = None
+        # eater name -> name of sink pad on switch element
+        self.switchPads = {}
+
+    def get_pipeline_string(self, properties):
+        eaters = self.eater_names
+
+        pipeline = "switch name=vswitch ! " \
+            "identity silent=true single-segment=true name=viden " \
+            "switch name=aswitch ! " \
+            "identity silent=true single-segment=true name=aiden "
+        for eater in eaters:
+            if "video" in eater:
+                tmpl = '@ eater:%s @ ! vswitch. '
+            if "audio" in eater:
+                tmpl = '@ eater:%s @ ! aswitch. '
+            pipeline += tmpl % eater
+
+        pipeline += 'viden. ! @feeder::video@ aiden. ! @feeder::audio@'
+
+        return pipeline
+
+    def configure_pipeline(self, pipeline, properties):
+        self.videoSwitchElement = vsw = pipeline.get_by_name("vswitch")
+        self.audioSwitchElement = asw = pipeline.get_by_name("aswitch")
+
+        # figure out how many pads should be connected for the eaters
+        # 1 + number of eaters with eaterName *-backup
+        numVideoPads = 1 + len(self.config["eater"]["video-backup"])
+        numAudioPads = 1 + len(self.config["eater"]["audio-backup"]) 
+        padPeers = {} # (padName, switchElement) -> peer element name
+        for sinkPadNumber in range(0, numVideoPads):
+            padPeers[("sink%d" % sinkPadNumber, vsw)] = \
+                vsw.get_pad("sink%d" % (
+                sinkPadNumber)).get_peer().get_parent().get_name()
+        for sinkPadNumber in range(0, numAudioPads):
+            padPeers[("sink%d" % sinkPadNumber, asw)] = \
+                asw.get_pad("sink%d" % (
+                sinkPadNumber)).get_peer().get_parent().get_name()
+
+        for feedid in self.eater_names:
+            eaterName = self.get_eater_name_for_feedid(feedid)
+            self.debug("feedid %s is mapped to eater name %s", feedid, 
+                eaterName)
+            if eaterName:
+                for sinkPadName, switchElement in padPeers:
+                    if feedid in padPeers[(sinkPadName, switchElement)]:
+                        self.switchPads[eaterName] = sinkPadName
+                if not self.switchPads.has_key(eaterName):
+                    self.warning("could not find sink pad for eater %s", 
+                        eaterName )
+        # make sure switch has the correct sink pad as active
+        self.debug("Setting video switch's active-pad to %s", 
+            self.switchPads["video-master"])
+        vsw.set_property("active-pad", 
+            self.switchPads["video-master"])
+        self.debug("Setting audio switch's active-pad to %s",
+            self.switchPads["audio-master"])
+        asw.set_property("active-pad",
+            self.switchPads["audio-master"])
+        self.uiState.set("active-eater", "master")
+
+    def switchToMaster(self):
+        self.videoSwitchElement.set_property("active-pad",
+            self.switchPads["video-master"])
+        self.audioSwitchElement.set_property("active-pad",
+            self.switchPads["audio-master"])
+        self.uiState.set("active-eater", "master")
+        
+    def switchToBackup(self):
+        self.videoSwitchElement.set_property("active-pad",
+            self.switchPads["video-backup"])
+        self.audioSwitchElement.set_property("active-pad",
+            self.switchPads["audio-backup"])
+        self.uiState.set("active-eater", "backup")

Added: flumotion/trunk/flumotion/component/combiners/switch/switch.xml
==============================================================================
--- (empty file)
+++ flumotion/trunk/flumotion/component/combiners/switch/switch.xml	Thu May 10 16:14:19 2007
@@ -0,0 +1,84 @@
+<registry>
+
+  <components>
+    <component type="single-switch-combiner"
+               base="flumotion/component/combiners/switch"
+               description="A single stream type switching component">
+      <source location="flumotion.component.combiners.switch.switch" />
+      <eater name="master" />
+      <eater name="backup" />
+      <feeder name="default" />
+      <entries>
+        <entry type="component" location="switch.py"
+               function="SingleSwitch" />
+	<entry type="admin/gtk" location="admin_gtk.py"
+               function="GUIClass" />
+      </entries>
+      <properties>
+      </properties>
+    </component>
+    <component type="av-switch-combiner"
+               base="flumotion/component/combiners/switch"
+	       description="An audio/video switching component">
+      <source location="flumotion.component.combiners.switch.switch" />
+      <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="switch.py"
+	       function="AVSwitch" />
+	<entry type="admin/gtk" location="admin_gtk.py"
+               function="GUIClass" />
+      </entries>
+      <properties>
+      </properties>
+    </component>
+  </components>
+
+
+  <bundles>
+
+    <bundle name="switch-combiner-base">
+        <dependencies>
+            <dependency name="component-base" />
+        </dependencies>
+
+        <directories>
+            <directory name="flumotion/component/combiners/switch">
+                <filename location="__init__.py" />
+            </directory>
+        </directories>
+    </bundle>
+
+    <bundle name="switch-combiner-component">
+        <dependencies>
+            <dependency name="component" />
+            <dependency name="switch-converter-base" />
+        </dependencies>
+
+        <directories>
+            <directory name="flumotion/component/combiners/switch">
+                <filename location="switch.py" />
+            </directory>
+        </directories>
+    </bundle>
+    <bundle name="switch-combiner-admin-gtk">
+        <dependencies>
+            <dependency name="base-admin-gtk"/>
+	    <dependency name="switch-combiner-base"/>
+        </dependencies>
+        
+        <directories>
+            <directory name="flumotion/component/combiners/switch">
+                <filename location="admin_gtk.py"/>
+            </directory>
+        </directories>
+    </bundle>
+
+
+  </bundles>
+
+</registry> 


More information about the flumotion-commit mailing list