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