Package elisa :: Package core :: Module player_engine_registry
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.player_engine_registry

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17  """ 
 18  Find a usable Player Engine with the PlayerEngineRegistry 
 19  """ 
 20   
 21  __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>' 
 22   
 23   
 24  from elisa.core import log, common 
 25  from elisa.core.utils import classinit 
 26   
 27  import pygst 
 28  pygst.require('0.10') 
 29  import gst 
 30   
31 -class NoEngineFound(Exception):
32 pass
33 34
35 -class PlayerEngineRegistry(log.Loggable):
36 """ 37 The PlayerEngineRegistry has the responsability to create 38 L{elisa.base_components.player_engine.PlayerEngine} instances 39 given URI schemes. 40 """ 41 42 # Allows property fget/fset/fdel/doc overriding 43 __metaclass__ = classinit.ClassInitMeta 44 __classinit__ = classinit.build_properties 45
46 - def __init__(self):
47 log.Loggable.__init__(self) 48 self._engines_by_scheme = {} 49 # FIXME: This should be configurable 50 self._audiosink = 'autoaudiosink' 51 self._audiosettings = {}
52 53
54 - def initialize(self):
55 self.info("Initializing") 56 self._load_providers()
57
58 - def _load_providers(self):
59 """ Ask the plugin registry to create all the providers 60 components defined in section 'general' of the config 61 """ 62 63 # FIXME: the default value is just temporary. Remove it soon! 64 application = common.application 65 engine_names = application.config.get_option('player_engines', 66 section='general', 67 default=['base:playbin_engine']) 68 69 plugin_registry = application.plugin_registry 70 71 for name in engine_names: 72 engine_class = plugin_registry.get_component_class(name) 73 74 if not engine_class: 75 # the class could not be found 76 self.warning("Could not find the class for the player engine" 77 " component %s" % name) 78 continue 79 80 schemes = engine_class.uri_schemes 81 for key, value in schemes.iteritems(): 82 if key in self._engines_by_scheme.keys(): 83 before_engine_class = plugin_registry.get_component_class( 84 self._engines_by_scheme[key]) 85 86 if before_engine_class.uri_schemes[key] > value: 87 self.debug("Replacing %s with %s for scheme %s" % 88 ( self._engines_by_scheme[key], name, key) ) 89 90 self._engines_by_scheme[key] = name 91 else: 92 self.debug("Adding %s for scheme %s" % (name, key)) 93 self._engines_by_scheme[key] = name
94
95 - def deinitialize(self):
96 pass
97
98 - def create_engine_for_scheme(self, scheme):
99 """ 100 Create a B{new} player engine instance for the given URI scheme. 101 102 @param scheme: the uri scheme that the new engine has to support 103 @type scheme: string 104 105 @raise: L{elisa.core.player_engine_registry.NoEngineFound} 106 if no engine is found 107 108 @rtype: L{elisa.base_components.player_engine.PlayerEngine} or 109 None 110 """ 111 self.debug("Creating new engine for %s" % scheme) 112 113 if scheme not in self._engines_by_scheme.keys(): 114 raise NoEngineFound() 115 116 plugin_registry = common.application.plugin_registry 117 component = self._engines_by_scheme[scheme] 118 119 return plugin_registry.create_component(component)
120