Package flumotion :: Package common :: Module gstreamer
[hide private]

Source Code for Module flumotion.common.gstreamer

  1  # -*- Mode: Python; test-case-name: flumotion.test.test_common_gstreamer -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  """ 
 23  GStreamer helper functionality 
 24  """ 
 25   
 26  # moving this down causes havoc when running this file directly for some reason 
 27  from flumotion.common import errors 
 28   
 29  import gobject 
 30  import gst 
 31   
32 -def caps_repr(caps):
33 """ 34 Represent L{gst.Caps} as a string. 35 36 @rtype: string 37 """ 38 value = str(caps) 39 pos = value.find('streamheader') 40 if pos != -1: 41 return 'streamheader=<...>' 42 else: 43 return value
44
45 -def verbose_deep_notify_cb(object, orig, pspec, component):
46 """ 47 A default deep-notify signal handler for pipelines. 48 """ 49 value = orig.get_property(pspec.name) 50 if pspec.value_type == gobject.TYPE_BOOLEAN: 51 if value: 52 value = 'TRUE' 53 else: 54 value = 'FALSE' 55 output = value 56 elif pspec.value_type == gst.Caps.__gtype__: 57 output = caps_repr(value) 58 else: 59 output = value 60 61 # Filters 62 if pspec.name == 'active': 63 return 64 if pspec.name == 'caps' and output == 'None': 65 return 66 67 component.debug('%s: %s = %s' % (orig.get_path_string(), pspec.name, output))
68
69 -def element_factory_has_property(element_factory, property_name):
70 """ 71 Check if the given element factory has the given property. 72 73 @rtype: boolean 74 """ 75 # FIXME: find a better way than instantiating one 76 e = gst.element_factory_make(element_factory) 77 for pspec in gobject.list_properties(e): 78 if pspec.name == property_name: 79 return True 80 return False
81
82 -def element_factory_has_property_value(element_factory, property_name, value):
83 """ 84 Check if the given element factory allows the given value for the given property. 85 86 @rtype: boolean 87 """ 88 # FIXME: find a better way than instantiating one 89 e = gst.element_factory_make(element_factory) 90 try: 91 e.set_property(property_name, value) 92 except TypeError: 93 return False 94 95 return True
96
97 -def element_factory_exists(name):
98 """ 99 Check if the given element factory name exists. 100 101 @rtype: boolean 102 """ 103 registry = gst.registry_get_default() 104 factory = registry.find_feature(name, gst.TYPE_ELEMENT_FACTORY) 105 106 if factory: 107 return True 108 109 return False
110
111 -def get_plugin_version(plugin_name):
112 """ 113 Find the version of the given plugin. 114 115 @rtype: tuple of (major, minor, micro, nano), or None if it could not be 116 found or determined 117 """ 118 plugin = gst.registry_get_default().find_plugin(plugin_name) 119 120 if not plugin: 121 return None 122 123 versionTuple = tuple([int(x) for x in plugin.get_version().split('.')]) 124 if len(versionTuple) < 4: 125 versionTuple = versionTuple + (0,) 126 return versionTuple
127