2004-09-13 07:31:31 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2002-03-24 11:41:24 +00:00
|
|
|
#
|
|
|
|
# gst-python
|
|
|
|
# Copyright (C) 2002 David I. Lehn
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Library General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
#
|
2002-12-17 17:40:42 +00:00
|
|
|
# Author: David I. Lehn <dlehn@users.sourceforge.net>
|
2002-03-24 11:41:24 +00:00
|
|
|
|
2004-03-31 14:00:54 +00:00
|
|
|
try:
|
2009-04-11 14:20:11 +00:00
|
|
|
import gstlibtoolimporter
|
|
|
|
gstlibtoolimporter.install()
|
|
|
|
except ImportError:
|
|
|
|
gstlibtoolimporter = None
|
2002-03-24 07:57:00 +00:00
|
|
|
|
2005-10-05 09:02:19 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
# we always require 2.0 of pygtk; so if pygtk is not imported anywhere
|
|
|
|
# yet, we import pygtk here and .require
|
2005-10-07 16:48:26 +00:00
|
|
|
if 'gobject' not in sys.modules:
|
2005-10-05 09:02:19 +00:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
2004-05-03 16:51:50 +00:00
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
class Value:
|
2008-05-08 14:03:17 +00:00
|
|
|
def __init__(self, type):
|
|
|
|
assert type in ('fourcc', 'intrange', 'doublerange', 'fractionrange', 'fraction')
|
|
|
|
self.type = type
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
class Fourcc(Value):
|
2008-05-08 14:03:17 +00:00
|
|
|
def __init__(self, string):
|
|
|
|
Value.__init__(self, 'fourcc')
|
|
|
|
self.fourcc = string
|
2008-12-09 14:30:43 +00:00
|
|
|
|
2008-05-08 14:03:17 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return '<gst.Fourcc %s>' % self.fourcc
|
2008-12-09 14:30:43 +00:00
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
if isinstance(other, Fourcc):
|
|
|
|
return self.fourcc == other.fourcc
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self.__eq__(other)
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
class IntRange(Value):
|
2008-05-08 14:03:17 +00:00
|
|
|
def __init__(self, low, high):
|
|
|
|
Value.__init__(self, 'intrange')
|
|
|
|
self.low = low
|
|
|
|
self.high = high
|
|
|
|
def __repr__(self):
|
|
|
|
return '<gst.IntRange [%d, %d]>' % (self.low, self.high)
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
class DoubleRange(Value):
|
2008-05-08 14:03:17 +00:00
|
|
|
def __init__(self, low, high):
|
|
|
|
Value.__init__(self, 'doublerange')
|
|
|
|
self.low = low
|
|
|
|
self.high = high
|
|
|
|
def __repr__(self):
|
|
|
|
return '<gst.DoubleRange [%f, %f]>' % (self.low, self.high)
|
2005-06-17 10:59:47 +00:00
|
|
|
|
2005-11-22 14:15:03 +00:00
|
|
|
class FractionRange(Value):
|
2008-05-08 14:03:17 +00:00
|
|
|
def __init__(self, low, high):
|
|
|
|
Value.__init__(self, 'fractionrange')
|
|
|
|
self.low = low
|
|
|
|
self.high = high
|
|
|
|
def __repr__(self):
|
|
|
|
return '<gst.FractionRange [%d/%d, %d/%d]>' % (self.low.num,
|
|
|
|
self.low.denom,
|
|
|
|
self.high.num,
|
|
|
|
self.high.denom)
|
2005-11-22 14:15:03 +00:00
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
class Fraction(Value):
|
2007-03-18 17:45:16 +00:00
|
|
|
def __init__(self, num, denom=1):
|
2008-05-14 16:00:39 +00:00
|
|
|
def __gcd(a,b):
|
|
|
|
while b != 0:
|
|
|
|
tmp = a
|
|
|
|
a = b
|
|
|
|
b = tmp % b
|
|
|
|
return abs(a)
|
|
|
|
|
|
|
|
def __simplify():
|
|
|
|
num = self.num
|
|
|
|
denom = self.denom
|
|
|
|
|
|
|
|
if num < 0:
|
|
|
|
num = -num
|
|
|
|
denom = -denom
|
|
|
|
|
|
|
|
# Compute greatest common divisor
|
|
|
|
gcd = __gcd(num,denom)
|
|
|
|
if gcd != 0:
|
|
|
|
num /= gcd
|
|
|
|
denom /= gcd
|
|
|
|
|
|
|
|
self.num = num
|
|
|
|
self.denom = denom
|
|
|
|
|
2007-03-18 17:45:16 +00:00
|
|
|
Value.__init__(self, 'fraction')
|
2008-05-14 16:00:39 +00:00
|
|
|
|
2007-03-18 17:45:16 +00:00
|
|
|
self.num = num
|
|
|
|
self.denom = denom
|
|
|
|
|
2008-05-14 16:00:39 +00:00
|
|
|
__simplify()
|
|
|
|
|
2007-03-18 17:45:16 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return '<gst.Fraction %d/%d>' % (self.num, self.denom)
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
if isinstance(other, Fraction):
|
|
|
|
return self.num * other.denom == other.num * self.denom
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
|
|
|
def __mul__(self, other):
|
|
|
|
if isinstance(other, Fraction):
|
|
|
|
return Fraction(self.num * other.num,
|
|
|
|
self.denom * other.denom)
|
|
|
|
elif isinstance(other, int):
|
|
|
|
return Fraction(self.num * other, self.denom)
|
|
|
|
raise TypeError
|
|
|
|
|
|
|
|
__rmul__ = __mul__
|
|
|
|
|
|
|
|
def __div__(self, other):
|
|
|
|
if isinstance(other, Fraction):
|
|
|
|
return Fraction(self.num * other.denom,
|
|
|
|
self.denom * other.num)
|
|
|
|
elif isinstance(other, int):
|
|
|
|
return Fraction(self.num, self.denom * other)
|
|
|
|
return TypeError
|
|
|
|
|
|
|
|
def __rdiv__(self, other):
|
|
|
|
if isinstance(other, int):
|
|
|
|
return Fraction(self.denom * other, self.num)
|
|
|
|
return TypeError
|
|
|
|
|
|
|
|
def __float__(self):
|
|
|
|
return float(self.num) / float(self.denom)
|
|
|
|
|
2006-05-27 12:18:54 +00:00
|
|
|
try:
|
2008-11-08 11:49:30 +00:00
|
|
|
dlsave = sys.getdlopenflags()
|
2006-05-27 12:18:54 +00:00
|
|
|
from DLFCN import RTLD_GLOBAL, RTLD_LAZY
|
2008-11-08 11:49:30 +00:00
|
|
|
except AttributeError:
|
|
|
|
# windows doesn't have sys.getdlopenflags()
|
|
|
|
RTLD_GLOBAL = -1
|
|
|
|
RTLD_LAZY = -1
|
2006-05-27 12:18:54 +00:00
|
|
|
except ImportError:
|
|
|
|
RTLD_GLOBAL = -1
|
|
|
|
RTLD_LAZY = -1
|
|
|
|
import os
|
|
|
|
osname = os.uname()[0]
|
|
|
|
if osname == 'Linux' or osname == 'SunOS' or osname == 'FreeBSD':
|
2008-10-05 08:16:38 +00:00
|
|
|
machinename = os.uname()[4]
|
|
|
|
if machinename == 'mips' or machinename == 'mips64':
|
|
|
|
RTLD_GLOBAL = 0x4
|
|
|
|
RTLD_LAZY = 0x1
|
|
|
|
else:
|
|
|
|
RTLD_GLOBAL = 0x100
|
|
|
|
RTLD_LAZY = 0x1
|
2006-05-27 12:18:54 +00:00
|
|
|
elif osname == 'Darwin':
|
|
|
|
RTLD_GLOBAL = 0x8
|
|
|
|
RTLD_LAZY = 0x1
|
|
|
|
del os
|
|
|
|
except:
|
|
|
|
RTLD_GLOBAL = -1
|
|
|
|
RTLD_LAZY = -1
|
2006-01-30 12:57:02 +00:00
|
|
|
|
2006-05-27 12:18:54 +00:00
|
|
|
if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
|
|
|
|
sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)
|
2007-03-18 17:45:16 +00:00
|
|
|
|
2008-11-08 11:49:30 +00:00
|
|
|
try:
|
|
|
|
import libxml2
|
|
|
|
except:
|
|
|
|
pass
|
2009-04-11 14:08:51 +00:00
|
|
|
|
2008-11-08 11:49:30 +00:00
|
|
|
from _gst import *
|
|
|
|
import interfaces
|
2006-04-05 11:55:48 +00:00
|
|
|
|
2008-11-08 11:49:30 +00:00
|
|
|
if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
|
|
|
|
sys.setdlopenflags(dlsave)
|
2006-05-27 12:18:54 +00:00
|
|
|
del sys
|
2006-01-30 12:57:02 +00:00
|
|
|
|
2008-11-08 11:49:30 +00:00
|
|
|
version = get_gst_version
|
|
|
|
|
2007-06-12 19:01:25 +00:00
|
|
|
# Fixes for API cleanups that would cause an API breakage.
|
|
|
|
# See #446674
|
|
|
|
|
|
|
|
import warnings
|
2007-06-14 14:53:28 +00:00
|
|
|
if locals().has_key("parse_bin_from_description"):
|
2007-06-12 19:01:25 +00:00
|
|
|
def gst_parse_bin_from_description(*args, **kwargs):
|
|
|
|
warnings.warn("gst_parse_bin_from_description() is deprecated, please use parse_bin_from_description instead",
|
|
|
|
DeprecationWarning)
|
|
|
|
return parse_bin_from_description(*args, **kwargs)
|
|
|
|
|
2007-06-14 14:53:28 +00:00
|
|
|
if locals().has_key("message_new_buffering"):
|
2007-06-12 19:01:25 +00:00
|
|
|
def gst_message_new_buffering(*args, **kwargs):
|
|
|
|
warnings.warn("gst_message_new_buffering() is deprecated, please use message_new_buffering() instead",
|
|
|
|
DeprecationWarning)
|
|
|
|
return message_new_buffering(*args, **kwargs)
|
|
|
|
|
2005-08-31 15:28:37 +00:00
|
|
|
# this restores previously installed importhooks, so we don't interfere
|
|
|
|
# with other people's module importers
|
|
|
|
# it also clears out the module completely as if it were never loaded,
|
2006-09-23 10:43:18 +00:00
|
|
|
# so that if anyone else imports gstltihooks the hooks get installed
|
2009-04-11 14:20:11 +00:00
|
|
|
if gstlibtoolimporter is not None:
|
|
|
|
import audio
|
|
|
|
import pbutils
|
|
|
|
import tag
|
|
|
|
import video
|
|
|
|
gstlibtoolimporter.uninstall()
|
2005-08-31 15:28:37 +00:00
|
|
|
import sys
|
2009-04-11 14:20:11 +00:00
|
|
|
del sys.modules["gstlibtoolimporter"]
|