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