Package flumotion :: Package component :: Package encoders :: Package vorbis :: Module vorbis010
[hide private]

Source Code for Module flumotion.component.encoders.vorbis.vorbis010

 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: 8561 $" 
29   
30   
31 -class Vorbis(feedcomponent.EncoderComponent):
32 checkTimestamp = True 33 checkOffset = True 34
35 - def do_check(self):
36 self.debug('running Vorbis check') 37 from flumotion.worker.checks import encoder 38 d = encoder.checkVorbis() 39 40 d.addCallback(self._checkCallback) 41 42 return d
43
44 - def _checkCallback(self, result):
45 for m in result.messages: 46 self.addMessage(m)
47
48 - def get_pipeline_string(self, properties):
49 self.bitrate = properties.get('bitrate', -1) 50 self.quality = properties.get('quality', 0.3) 51 self.channels = properties.get('channels', 2) 52 resampler = 'audioresample' 53 if gstreamer.element_factory_exists('legacyresample'): 54 resampler = 'legacyresample' 55 return ('%s name=ar ! audioconvert ! capsfilter name=cf ' 56 '! vorbisenc name=enc' % resampler)
57
58 - def configure_pipeline(self, pipeline, properties):
59 enc = pipeline.get_by_name('enc') 60 cf = pipeline.get_by_name('cf') 61 ar = pipeline.get_by_name('ar') 62 63 assert enc and cf and ar 64 65 if self.bitrate > -1: 66 enc.set_property('bitrate', self.bitrate) 67 else: 68 enc.set_property('quality', self.quality) 69 70 pad = ar.get_pad('sink') 71 handle = None 72 73 def buffer_probe(pad, buffer): 74 # this comes from another thread 75 caps = buffer.get_caps() 76 in_rate = caps[0]['rate'] 77 78 # now do necessary filtercaps 79 rate = in_rate 80 if self.bitrate > -1: 81 maxsamplerate = get_max_sample_rate( 82 self.bitrate, self.channels) 83 if in_rate > maxsamplerate: 84 rate = get_preferred_sample_rate(maxsamplerate) 85 self.debug( 86 'rate %d > max rate %d (for %d kbit/sec), ' 87 'selecting rate %d instead' % ( 88 in_rate, maxsamplerate, self.bitrate, rate)) 89 90 caps_str = 'audio/x-raw-float, rate=%d, channels=%d' % (rate, 91 self.channels) 92 cf.set_property('caps', 93 gst.caps_from_string(caps_str)) 94 pad.remove_buffer_probe(handle) 95 return True
96 97 handle = pad.add_buffer_probe(buffer_probe)
98