title: Usage of Coherence (or GUPnP)? to stream A/V?
body: <p>After looking for some time to a solution for streaming audio/video via uPnP, Coherence seems to be the most promising option: For example: <a href="http://coherence.beebits.net/browser/trunk/Coherence/coherence/backends/gstreamer_renderer.py" rel="nofollow">http://coherence.beebits.net/browser/trunk/Coherence/coherence/backends/gstreamer_renderer.py</a> seems to be what would be required to play a file directly to a HDMI TV dongle.</p>
  
  <p>Oddly enough, after installing the Ubuntu coherence package, running <code>import coherence</code> in Python terminal doesn't really show anything like this module. Tab completion in bpython shows:</p>
  
  <pre><code>&gt;&gt;&gt; coherence.
  ┌───────────────────────────────────────────────────────────────────────────┐
  │SERVER_ID           Version             platform                           │
  │sys                 twisted_version     twisted_web_version                │
  └───────────────────────────────────────────────────────────────────────────┘
  </code></pre>
  
  <p>and those submodules seem to just give info about the system. How do I import and use Coherence to stream the desktop, or a video, to a uPnP screen? Is there a basic getting started guide?</p>
  
  <p><strong>Update</strong></p>
  
  <p>It looks like GUPnP has ability to link in to Python:</p>
  
  <pre><code>&gt;&gt;&gt; from gi.repository import GUPnP
  &gt;&gt;&gt; GUPnP.ControlPoint.new()
  Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
  TypeError: new() takes exactly 2 arguments (0 given)
  </code></pre>
  
  <p>Which is apparently calling the function documented here:
  <a href="https://developer.gnome.org/gupnp/unstable/GUPnPControlPoint.html" rel="nofollow">https://developer.gnome.org/gupnp/unstable/GUPnPControlPoint.html</a></p>
  
  <p>Unfortunately the docs don't have any full examples of how to stream to a video receiver - specifically, how does it initiate sending the video file over the network?</p>
  
  <p>Update: This is the first step I use to detect the device:</p>
  
  <pre><code>import socket
  import threading
  import time
  
  Addr = None;
  StartLock = threading.Lock()
  
  def DoUDP():
      global Addr
      global StartLock
      s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #Internet, UDP
      s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
      while 1:
          s.sendto('0:0',('192.168.0.255',63630))
          data,addr = s.recvfrom(1024)
          print data
          print 'from', addr
          Addr = addr
          try:
              StartLock.release()
          except:
              pass
          time.sleep(1)
          return
  
  StartLock.acquire()
  print 'starting...'
  udpthread = threading.Thread(target=DoUDP)
  udpthread.start();
  
  #... knowing address of the device... send stuff?
  </code></pre>