Trees | Indices | Help |
---|
|
1 # -*- Mode: Python -*- 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 import gst 23 24 from flumotion.common import gstreamer 25 from flumotion.component import feedcomponent 26 from vorbisutils import get_max_sample_rate, get_preferred_sample_rate 27 28 __version__ = "$Rev$" 29 3032 checkTimestamp = True 33 checkOffset = True 34 # Add a tolerance of 20ms to audiorate to fix cracking audio 35 DEFAULT_TOLERANCE = 20000000 #20ms 3610538 self.debug('running Vorbis check') 39 from flumotion.worker.checks import encoder 40 d = encoder.checkVorbis() 41 42 d.addCallback(self._checkCallback) 43 44 return d45 4951 self.bitrate = properties.get('bitrate', -1) 52 self.quality = properties.get('quality', 0.3) 53 self.channels = properties.get('channels', 2) 54 resampler = 'audioresample' 55 if gstreamer.element_factory_exists('legacyresample'): 56 resampler = 'legacyresample' 57 return ('audiorate name=art ! ' 58 '%s name=ar ! audioconvert ! capsfilter name=cf ' 59 '! vorbisenc name=enc' % resampler)6062 enc = pipeline.get_by_name('enc') 63 cf = pipeline.get_by_name('cf') 64 ar = pipeline.get_by_name('ar') 65 art = pipeline.get_by_name('art') 66 67 assert enc and cf and ar and art 68 69 if self.bitrate > -1: 70 enc.set_property('bitrate', self.bitrate) 71 else: 72 enc.set_property('quality', self.quality) 73 74 if gstreamer.element_has_property(art, 'tolerance'): 75 art.set_property('tolerance', self.DEFAULT_TOLERANCE) 76 77 pad = ar.get_pad('sink') 78 handle = None 79 80 def buffer_probe(pad, buffer): 81 # this comes from another thread 82 caps = buffer.get_caps() 83 in_rate = caps[0]['rate'] 84 85 # now do necessary filtercaps 86 rate = in_rate 87 if self.bitrate > -1: 88 maxsamplerate = get_max_sample_rate( 89 self.bitrate, self.channels) 90 if in_rate > maxsamplerate: 91 rate = get_preferred_sample_rate(maxsamplerate) 92 self.debug( 93 'rate %d > max rate %d (for %d kbit/sec), ' 94 'selecting rate %d instead' % ( 95 in_rate, maxsamplerate, self.bitrate, rate)) 96 97 caps_str = 'audio/x-raw-float, rate=%d, channels=%d' % (rate, 98 self.channels) 99 cf.set_property('caps', 100 gst.caps_from_string(caps_str)) 101 pad.remove_buffer_probe(handle) 102 return True103 104 handle = pad.add_buffer_probe(buffer_probe)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jun 17 12:32:41 2011 | http://epydoc.sourceforge.net |