class_docstr: Live source Decoder based on Gstreamer
  capturing audio from alsasrc
  
   Construct a new LiveDecoder capturing audio from alsasrc
  
   Parameters
   ----------
   num_buffers : int, optional
       Number of buffers to output before sending End Of Stream signal
       (-1 = unlimited).
       (Allowed values: >= -1, Default value: -1)
  
   input_src : str, optional
       Gstreamer source element
       default to 'alsasrc'
       possible values :  'autoaudiosrc', 'alsasrc', 'osssrc'
  
   Examples
   --------
  
   # >>> import timeside
  
   # >>> from timeside.core import get_processor
   # >>> live_decoder = get_processor('live_decoder')(num_buffers=5)
   # >>> waveform = get_processor('waveform_analyzer')()
   # >>> mp3_encoder = timeside.plugins.encoder.mp3.Mp3Encoder('/tmp/test_live.mp3',
   # ...                                               overwrite=True)
   # >>> pipe = (live_decoder | waveform | mp3_encoder)
   # >>> pipe.run()  # doctest: +SKIP
   # >>> # Show the audio as captured by the decoder
   # >>> import matplotlib.pyplot as plt # doctest: +SKIP
   # >>> plt.plot(a.results['waveform_analyzer'].time, # doctest: +SKIP
   #          a.results['waveform_analyzer'].data) # doctest: +SKIP
   # >>> plt.show() # doctest: +SKIP
  
   
class_docstr_tok: ["Live","source","Decoder","based","on","Gstreamer","capturing","audio","from","alsasrc","Construct","a","new","LiveDecoder","capturing","audio","from","alsasrc","Parameters","--","--","--","--","--","num_buffers",":","int",",","optional","Number","of","buffers","to","output","before","sending","End","Of","Stream","signal","(","-1","=","unlimited",")",".","(","Allowed","values",":",">","=","-1",",","Default","value",":","-1",")","input_src",":","str",",","optional","Gstreamer","source","element","default","to","'alsasrc'","possible","values",":","'autoaudiosrc","'",",","'alsasrc","'",",","'osssrc'","Examples","--","--","--","--","#",">",">",">","import","timeside","#",">",">",">","from","timeside.core","import","get_processor","#",">",">",">","live_decoder","=","get_processor","(","'live_decoder","'",")","(","num_buffers=5",")","#",">",">",">","waveform","=","get_processor","(","'waveform_analyzer","'",")","(",")","#",">",">",">","mp3_encoder","=","timeside.plugins.encoder.mp3.Mp3Encoder","(","'\/tmp\/test_live.mp3","'",",","#","...","overwrite=True",")","#",">",">",">","pipe","=","(","live_decoder","|","waveform","|","mp3_encoder",")","#",">",">",">","pipe.run","(",")","#","doctest",":","+SKIP","#",">",">",">","#","Show","the","audio","as","captured","by","the","decoder","#",">",">",">","import","matplotlib.pyplot","as","plt","#","doctest",":","+SKIP","#",">",">",">","plt.plot","(","a.results","[","'waveform_analyzer","'","]",".time",",","#","doctest",":","+SKIP","#","a.results","[","'waveform_analyzer","'","]",".data",")","#","doctest",":","+SKIP","#",">",">",">","plt.show","(",")","#","doctest",":","+SKIP"]
code: def setup(self, channels=None, samplerate=None, blocksize=None):
      self.eod = False
      self.last_buffer = None
  
      # a lock to wait wait for gstreamer thread to be ready
      self.discovered_cond = threading.Condition(threading.Lock())
      self.discovered = False
  
      # the output data format we want
      if blocksize:
          self.output_blocksize = blocksize
      if samplerate:
          self.output_samplerate = int(samplerate)
      if channels:
          self.output_channels = int(channels)
  
      # Create the pipe with standard Gstreamer uridecodbin
      self.pipe = """%s num-buffers=%d name=src
                         ! audioconvert name=audioconvert
                         ! audioresample
                         ! appsink name=sink sync=False async=True
                         """ % (
          self.input_src,
          self.num_buffers,
      )
  
      self.pipeline = Gst.parse_launch(self.pipe)
  
      if self.output_channels:
          caps_channels = int(self.output_channels)
      else:
          caps_channels = "[ 1, 2 ]"
      if self.output_samplerate:
          caps_samplerate = int(self.output_samplerate)
      else:
          caps_samplerate = "{ 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 96000 }"
      sink_caps = Gst.Caps(
          """audio/x-raw,
              format=F32LE,
              channels=(int)%s,
              rate=(int)%s"""
          % (caps_channels, caps_samplerate)
      )
  
      self.src = self.pipeline.get_by_name("src")
      self.conv = self.pipeline.get_by_name("audioconvert")
      self.conv.get_pad("sink").connect(
          "notify::caps", self._notify_caps_cb
      )
  
      self.sink = self.pipeline.get_by_name("sink")
      self.sink.set_property("caps", sink_caps)
      self.sink.set_property("max-buffers", GST_APPSINK_MAX_BUFFERS)
      self.sink.set_property("drop", False)
      self.sink.set_property("emit-signals", True)
      self.sink.connect("new-buffer", self._on_new_buffer_cb)
  
      self.bus = self.pipeline.get_bus()
      self.bus.add_signal_watch()
      self.bus.connect("message", self._on_message_cb)
  
      self.queue = queue.Queue(QUEUE_SIZE)
  
      self.mainloop = GLib.MainLoop()
      self.mainloopthread = MainloopThread(self.mainloop)
      self.mainloopthread.start()
      # self.mainloopthread = get_loop_thread()
      ##self.mainloop = self.mainloopthread.mainloop
  
      # start pipeline
      self.pipeline.set_state(Gst.State.PLAYING)
  
      self.discovered_cond.acquire()
      while not self.discovered:
          # print 'waiting'
          self.discovered_cond.wait()
      self.discovered_cond.release()
  
      if not hasattr(self, "input_samplerate"):
          if hasattr(self, "error_msg"):
              raise IOError(self.error_msg)
          else:
              raise IOError("no known audio stream found")
  
file_path: TimeSide/timeside/plugins/decoder/live.py
imports: from __future__ import division
  from timeside.core.decoder import Decoder, IDecoder, interfacedoc, implements
  from timeside.core.tools.gstutils import MainloopThread, GLib, Gst
  import threading
label_desc: Use image node_id 4 for calling the LiveDecoder obj's underlying member method code with example usage: obj.setup(channels, samplerate, blocksize) without return types