Saturday, March 9, 2013

Displaying a Videotestsrc in a Qt Application

Since quite a while I am trying to get gstreamer working properly inside of Qt applications. Whereas I am not taking sound into account, solely video. I wanted to use gstreamer-1.0 and since the QtGstreamer binding is only binding gstreamer-0.10 this was not possible to use. Honestly speaking QtGstreamer with the older gstreamer might have been the better choice. But I also wanted to know how it works and switch later to the Qt binding. There is also hope that the developer will port the Qt binding to gstreamer-1.0. My first testing application I wrote with QtCreator. Here is the source code:


videotest.pro



main.cpp



capture.h


capture.cpp

The Capture class is a subclass of QLabel only because I intended to include a signal which is emitted each time a frame arrives. The approach is based on the gst_app_sink plugin. With the caps "video/x-raw, format=RGB, bpp=8" and the correct dimension the data can be safely mapped to a QImage with QImage::Format_RGB888 format. The whole code of getting the data from the gstBuffer in newSample() is very different from the approach in gstreamer-0.10. I find the way of gstreamer-1.0 pretty tedious. Several problems remain here:
  • The mutex might be not optimally designed since its a producer newSample() and a consumer getFrame()
  • The QImage construction should be done with const data since the data is not intended to get changed
  • A serious problem is that the data of the QImage must remain valid also if the image is used from the Display class. This is not given here since the lifetime of the GstBuffer is unknown


display.h


display.cpp


The Display class is a subclassed QLabel. For the testing purpose it is sufficient to display the QLabel widget only. In a real applications this widget can be included in a QMainWindow or QDialog easily. The paintEvent is overwritten to enable the rendering of the pixmap. I don't know why the paintEvent occurs frequently enough without doing nothing. There is no explicit update() or repaint() slot executed.

1 comment:

  1. Your post helped me a lot, thanks!
    (It would be great if gstreamer 1.0 docs mentioned somewhere that signal handlers should now return GST_FLOW_OK, yep)

    ReplyDelete