Changeset - e20419d637d5
[Not reviewed]
default
0 0 6
drewp@bigasterisk.com - 15 years ago 2010-06-08 06:52:59
drewp@bigasterisk.com
initial vidref tests
Ignore-this: f3ca12ad8071d889ed71689be0716827
6 files changed with 514 insertions and 0 deletions:
0 comments (0 inline, 0 general)
bin/vidref
Show inline comments
 
new file 100644
 
#!/usr/bin/python
 
import gtk
 
from light9.vidref.main import Main
 

	
 

	
 
start=Main()
 
gtk.main()
 

	
light9/vidref/__init__.py
Show inline comments
 
new file 100644
light9/vidref/main.py
Show inline comments
 
new file 100644
 
#!/usr/bin/python
 
import pygst
 
pygst.require("0.10")
 
import gst, gobject
 
import pygtk
 
import gtk
 
from twisted.python.util import sibpath
 
import Image
 

	
 
otherPic = None
 

	
 

	
 
import StringIO
 
# gtk.gdk.pixbuf_new_from_data(img.tostring() seems like it would be better
 
# http://www.daa.com.au/pipermail/pygtk/2003-June/005268.html
 
def Image_to_GdkPixbuf (image):
 
    file = StringIO.StringIO ()
 
    image.save (file, 'ppm')
 
    contents = file.getvalue()
 
    file.close ()
 
    loader = gtk.gdk.PixbufLoader ('pnm')
 
    loader.write (contents, len (contents))
 
    pixbuf = loader.get_pixbuf ()
 
    loader.close ()
 
    return pixbuf
 

	
 
class MySink(gst.Element):
 
    _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate",
 
                                        gst.PAD_SINK,
 
                                        gst.PAD_ALWAYS,
 
                                        gst.caps_new_any())
 

	
 
    def __init__(self):
 
        gst.Element.__init__(self)
 
        self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink")
 
        self.add_pad(self.sinkpad)
 
        self.sinkpad.set_chain_function(self.chainfunc)
 
        
 
    def chainfunc(self, pad, buffer):
 
        global nextImageCb
 
        self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp))
 
        
 
        if 1:
 
            try:
 
                cap = buffer.caps[0]
 
                img = Image.fromstring('RGB', (cap['width'], cap['height']),
 
                                       buffer.data)
 
            except:
 
                import traceback
 
                traceback.print_exc()
 
                raise
 

	
 
            print "got image to save"
 
            #pixbuf = Image_to_GdkPixbuf(img)
 
            #otherPic.set_from_pixbuf(pixbuf)
 
            
 
        return gst.FLOW_OK
 
gobject.type_register(MySink)
 

	
 
class Main(object):
 
    def __init__(self):
 
        global otherPic
 
        wtree = gtk.Builder()
 
        wtree.add_from_file(sibpath(__file__, "vidref.glade"))
 
        mainwin = wtree.get_object("MainWindow")
 
        otherPic = wtree.get_object("liveVideo")
 
        mainwin.connect("destroy", gtk.main_quit)
 
        wtree.connect_signals({
 
            "foo" : self.OnPlay,
 
            })
 

	
 
        pipeline = gst.Pipeline("player")
 

	
 
        def makeElem(t, n=None):
 
            e = gst.element_factory_make(t, n)
 
            pipeline.add(e)
 
            return e
 
        
 
        if 0:
 
            source = makeElem("videotestsrc", "video")
 
        else:
 
            source = makeElem("v4l2src", "vsource")
 
            source.set_property("device", "/dev/video0")
 

	
 
        csp = makeElem("ffmpegcolorspace")
 

	
 
        caps = makeElem("capsfilter")
 
        caps.set_property('caps', gst.caps_from_string('video/x-raw-rgb'))
 

	
 
        sink = makeElem("xvimagesink", "sink")
 

	
 
        recSink = MySink()
 
        pipeline.add(recSink)
 

	
 
        # using this adds 5% cpu; not sure the advantage
 
        scaler = makeElem("videoscale", "vscale")
 
        
 
        tee = makeElem("tee")
 

	
 
        source.link(csp)
 
        csp.link(caps)
 
        caps.link(tee)
 
        tee.link(sink)
 

	
 
        tee.link(recSink)
 
#        tee.link(sink2)
 

	
 
        mainwin.show_all()
 

	
 
#        sink2.set_xwindow_id(wtree.get_object("liveVideo").window.xid)
 
        sink.set_xwindow_id(wtree.get_object("vid3").window.xid)
 

	
 
        pipeline.set_state(gst.STATE_PLAYING)
 

	
 
    def OnPlay(self, widget):
 
        print "play"
 
       # Tell the video sink to display the output in our DrawingArea
 
        self.sinkx.set_xwindow_id(self.da.window.xid)
 
        self.pipeline.set_state(gst.STATE_PLAYING)
 

	
 
    def OnStop(self, widget):
 
        print "stop"
 
        self.pipeline.set_state(gst.STATE_READY)
 

	
 
    def OnQuit(self, widget):
 
        gtk.main_quit()
light9/vidref/qt_test.py
Show inline comments
 
new file 100644
 
#!/usr/bin/env python
 

	
 
from PyQt4 import QtCore, QtGui, uic
 
import gst
 
import gobject
 

	
 
class Vid(object):
 
    def __init__(self, windowId):
 
        self.player = gst.Pipeline("player")
 
        self.source = gst.element_factory_make("v4l2src", "vsource")
 
        self.sink = gst.element_factory_make("autovideosink", "outsink")
 
        self.source.set_property("device", "/dev/video0")
 
        self.scaler = gst.element_factory_make("videoscale", "vscale")
 
        self.window_id = None
 
        self.windowId = windowId
 

	
 
        self.fvidscale_cap = gst.element_factory_make("capsfilter", "fvidscale_cap")
 
        self.fvidscale_cap.set_property('caps', gst.caps_from_string('video/x-raw-yuv, width=320, height=240'))
 
        
 
        self.player.add(self.source, self.scaler, self.fvidscale_cap, self.sink)
 
        gst.element_link_many(self.source,self.scaler, self.fvidscale_cap, self.sink)
 

	
 
        self.s = MySink()
 
        self.player.add(self.s)
 
#        self.scaler.link(self.s)
 

	
 
        bus = self.player.get_bus()
 
        bus.add_signal_watch()
 
#        bus.enable_sync_message_emission() # with this we segv
 
#        bus.connect("message", self.on_message) # with this we segv
 
        bus.connect("sync-message::element", self.on_sync_message)
 

	
 
    def on_message(self, bus, message):
 
        print "msg", bus, message
 
        t = message.type
 
        if t == gst.MESSAGE_EOS:
 
            self.player.set_state(gst.STATE_NULL)
 
        elif t == gst.MESSAGE_ERROR:
 
           err, debug = message.parse_error()
 
           print "Error: %s" % err, debug
 
           self.player.set_state(gst.STATE_NULL)
 

	
 
    def on_sync_message(self, bus, message):
 
        print "syncmsg", bus, message
 
        if message.structure is None:
 
            return
 
        message_name = message.structure.get_name()
 
        if message_name == "prepare-xwindow-id":
 
            print "pxi"
 
            win_id = self.windowId
 
            assert win_id
 
            imagesink = message.src
 
            imagesink.set_property("force-aspect-ratio", True)
 
            print "set_xwindow_id"
 
            imagesink.set_xwindow_id(win_id)
 
            print "dnoe msg"
 

	
 
    def startPrev(self):
 
        self.player.set_state(gst.STATE_PLAYING)
 
        print "should be playing"
 
        
 

	
 
class MainWin(QtGui.QMainWindow):
 
    def __init__(self, *args):
 
        super(MainWin, self).__init__(*args)
 

	
 
        uic.loadUi('light9/vidref/vidref.ui', self)
 
        v = Vid(self.liveView.winId())
 
        v.startPrev()
 

	
 
    @QtCore.pyqtSlot()
 
    def startLiveView(self):
 
        print "slv"
 

	
 

	
light9/vidref/vidref.glade
Show inline comments
 
new file 100644
 
<?xml version="1.0"?>
 
<interface>
 
  <requires lib="gtk+" version="2.16"/>
 
  <!-- interface-naming-policy project-wide -->
 
  <object class="GtkWindow" id="MainWindow">
 
    <property name="default_width">500</property>
 
    <property name="default_height">500</property>
 
    <child>
 
      <object class="GtkFixed" id="fixed1">
 
        <property name="visible">True</property>
 
        <child>
 
          <object class="GtkLabel" id="label1">
 
            <property name="width_request">85</property>
 
            <property name="height_request">20</property>
 
            <property name="visible">True</property>
 
            <property name="yalign">0.47999998927116394</property>
 
            <property name="label" translatable="yes">Live view</property>
 
          </object>
 
          <packing>
 
            <property name="x">5</property>
 
            <property name="y">16</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkImage" id="liveVideo">
 
            <property name="width_request">320</property>
 
            <property name="height_request">240</property>
 
            <property name="visible">True</property>
 
          </object>
 
          <packing>
 
            <property name="x">6</property>
 
            <property name="y">40</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkFrame" id="frame1">
 
            <property name="width_request">338</property>
 
            <property name="height_request">269</property>
 
            <property name="visible">True</property>
 
            <property name="label_xalign">0</property>
 
            <property name="shadow_type">out</property>
 
            <child>
 
              <object class="GtkAlignment" id="alignment1">
 
                <property name="visible">True</property>
 
                <property name="left_padding">12</property>
 
                <child>
 
                  <object class="GtkDrawingArea" id="vid3">
 
                    <property name="width_request">100</property>
 
                    <property name="height_request">80</property>
 
                    <property name="visible">True</property>
 
                  </object>
 
                </child>
 
              </object>
 
            </child>
 
            <child type="label">
 
              <object class="GtkLabel" id="label2">
 
                <property name="visible">True</property>
 
                <property name="label" translatable="yes">&lt;b&gt;Live view&lt;/b&gt;</property>
 
                <property name="use_markup">True</property>
 
              </object>
 
            </child>
 
          </object>
 
          <packing>
 
            <property name="x">332</property>
 
            <property name="y">28</property>
 
          </packing>
 
        </child>
 
      </object>
 
    </child>
 
  </object>
 
</interface>
light9/vidref/vidref.ui
Show inline comments
 
new file 100644
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>MainWindow</class>
 
 <widget class="QMainWindow" name="MainWindow">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>863</width>
 
    <height>728</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
   <string>MainWindow</string>
 
  </property>
 
  <widget class="QWidget" name="centralwidget">
 
   <widget class="QLabel" name="label">
 
    <property name="geometry">
 
     <rect>
 
      <x>20</x>
 
      <y>260</y>
 
      <width>251</width>
 
      <height>16</height>
 
     </rect>
 
    </property>
 
    <property name="text">
 
     <string>Live view</string>
 
    </property>
 
   </widget>
 
   <widget class="QWidget" name="liveView" native="true">
 
    <property name="geometry">
 
     <rect>
 
      <x>20</x>
 
      <y>10</y>
 
      <width>320</width>
 
      <height>240</height>
 
     </rect>
 
    </property>
 
   </widget>
 
   <widget class="QCheckBox" name="checkBox">
 
    <property name="geometry">
 
     <rect>
 
      <x>50</x>
 
      <y>280</y>
 
      <width>121</width>
 
      <height>19</height>
 
     </rect>
 
    </property>
 
    <property name="text">
 
     <string>enabled</string>
 
    </property>
 
    <property name="checked">
 
     <bool>true</bool>
 
    </property>
 
   </widget>
 
   <widget class="QTableWidget" name="tableWidget">
 
    <property name="geometry">
 
     <rect>
 
      <x>50</x>
 
      <y>470</y>
 
      <width>171</width>
 
      <height>121</height>
 
     </rect>
 
    </property>
 
    <row>
 
     <property name="text">
 
      <string>song</string>
 
     </property>
 
    </row>
 
    <row>
 
     <property name="text">
 
      <string>time</string>
 
     </property>
 
    </row>
 
    <column>
 
     <property name="text">
 
      <string>value</string>
 
     </property>
 
    </column>
 
    <item row="0" column="0">
 
     <property name="text">
 
      <string>whatever</string>
 
     </property>
 
    </item>
 
   </widget>
 
   <widget class="QLabel" name="label_3">
 
    <property name="geometry">
 
     <rect>
 
      <x>40</x>
 
      <y>340</y>
 
      <width>52</width>
 
      <height>13</height>
 
     </rect>
 
    </property>
 
    <property name="text">
 
     <string>Song</string>
 
    </property>
 
   </widget>
 
   <widget class="QLabel" name="label_4">
 
    <property name="geometry">
 
     <rect>
 
      <x>40</x>
 
      <y>360</y>
 
      <width>52</width>
 
      <height>13</height>
 
     </rect>
 
    </property>
 
    <property name="text">
 
     <string>Time</string>
 
    </property>
 
   </widget>
 
   <widget class="QLineEdit" name="lineEdit">
 
    <property name="geometry">
 
     <rect>
 
      <x>90</x>
 
      <y>330</y>
 
      <width>113</width>
 
      <height>23</height>
 
     </rect>
 
    </property>
 
   </widget>
 
   <widget class="QLineEdit" name="lineEdit_2">
 
    <property name="geometry">
 
     <rect>
 
      <x>90</x>
 
      <y>360</y>
 
      <width>113</width>
 
      <height>23</height>
 
     </rect>
 
    </property>
 
   </widget>
 
   <widget class="QScrollArea" name="scrollArea">
 
    <property name="geometry">
 
     <rect>
 
      <x>570</x>
 
      <y>330</y>
 
      <width>191</width>
 
      <height>191</height>
 
     </rect>
 
    </property>
 
    <property name="widgetResizable">
 
     <bool>true</bool>
 
    </property>
 
    <widget class="QWidget" name="scrollAreaWidgetContents">
 
     <property name="geometry">
 
      <rect>
 
       <x>0</x>
 
       <y>0</y>
 
       <width>189</width>
 
       <height>189</height>
 
      </rect>
 
     </property>
 
    </widget>
 
   </widget>
 
   <widget class="QGroupBox" name="groupBox">
 
    <property name="geometry">
 
     <rect>
 
      <x>270</x>
 
      <y>310</y>
 
      <width>411</width>
 
      <height>331</height>
 
     </rect>
 
    </property>
 
    <property name="title">
 
     <string>Replay from 16:10</string>
 
    </property>
 
    <widget class="QGraphicsView" name="graphicsView_2">
 
     <property name="geometry">
 
      <rect>
 
       <x>20</x>
 
       <y>30</y>
 
       <width>311</width>
 
       <height>231</height>
 
      </rect>
 
     </property>
 
    </widget>
 
    <widget class="QCheckBox" name="checkBox_2">
 
     <property name="geometry">
 
      <rect>
 
       <x>60</x>
 
       <y>270</y>
 
       <width>191</width>
 
       <height>19</height>
 
      </rect>
 
     </property>
 
     <property name="text">
 
      <string>follow current time</string>
 
     </property>
 
    </widget>
 
    <zorder>graphicsView_2</zorder>
 
    <zorder>graphicsView_2</zorder>
 
    <zorder>checkBox_2</zorder>
 
   </widget>
 
  </widget>
 
  <widget class="QMenuBar" name="menubar">
 
   <property name="geometry">
 
    <rect>
 
     <x>0</x>
 
     <y>0</y>
 
     <width>863</width>
 
     <height>21</height>
 
    </rect>
 
   </property>
 
  </widget>
 
  <widget class="QStatusBar" name="statusbar"/>
 
  <widget class="QToolBar" name="toolBar">
 
   <property name="windowTitle">
 
    <string>toolBar</string>
 
   </property>
 
   <attribute name="toolBarArea">
 
    <enum>TopToolBarArea</enum>
 
   </attribute>
 
   <attribute name="toolBarBreak">
 
    <bool>false</bool>
 
   </attribute>
 
  </widget>
 
  <widget class="QToolBar" name="toolBar_2">
 
   <property name="windowTitle">
 
    <string>toolBar_2</string>
 
   </property>
 
   <attribute name="toolBarArea">
 
    <enum>TopToolBarArea</enum>
 
   </attribute>
 
   <attribute name="toolBarBreak">
 
    <bool>false</bool>
 
   </attribute>
 
  </widget>
 
 </widget>
 
 <resources/>
 
 <connections/>
 
 <slots>
 
  <slot>startLiveView()</slot>
 
 </slots>
 
</ui>
0 comments (0 inline, 0 general)