GStreamer: refactored widget and window control.
Instead of always using xvimagesink as GStreamer backend for the widget and window control (works only with X11), we now try to pick a video sink that fits the current configuration. It first tries a set of known video sinks that can work with the Qt platform plugin in use. If none is available, it dynamically picks a video sink available on the system that can be used with our backend. Even if the video sink is now picked in a smarter way, xcb is still the only supported platform plugin. The reason is that it's the only Unix plugin which can provide a valid native window handle. Additional work is needed to support other plugins like wayland or directfb. Change-Id: I3843dea363d6a0b85a6cc1f2952783b743e48ac6 Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
@@ -35,52 +35,33 @@
|
||||
#include <private/qgstutils_p.h>
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#if !GST_CHECK_VERSION(1,0,0)
|
||||
#include <gst/interfaces/xoverlay.h>
|
||||
#include <gst/interfaces/propertyprobe.h>
|
||||
#else
|
||||
#include <gst/video/videooverlay.h>
|
||||
#endif
|
||||
|
||||
|
||||
QGstreamerVideoWindow::QGstreamerVideoWindow(QObject *parent, const char *elementName)
|
||||
QGstreamerVideoWindow::QGstreamerVideoWindow(QObject *parent, const QByteArray &elementName)
|
||||
: QVideoWindowControl(parent)
|
||||
, QGstreamerBufferProbe(QGstreamerBufferProbe::ProbeCaps)
|
||||
, m_videoSink(0)
|
||||
, m_videoOverlay(this, !elementName.isEmpty() ? elementName : qgetenv("QT_GSTREAMER_WINDOW_VIDEOSINK"))
|
||||
, m_windowId(0)
|
||||
, m_aspectRatioMode(Qt::KeepAspectRatio)
|
||||
, m_fullScreen(false)
|
||||
, m_colorKey(QColor::Invalid)
|
||||
{
|
||||
if (elementName) {
|
||||
m_videoSink = gst_element_factory_make(elementName, NULL);
|
||||
} else if (QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0) {
|
||||
// We need a native X window handle to be able to use xvimagesink.
|
||||
// Bail out if Qt is not using xcb (the control will then be ignored by the plugin)
|
||||
m_videoSink = gst_element_factory_make("xvimagesink", NULL);
|
||||
}
|
||||
|
||||
if (m_videoSink) {
|
||||
qt_gst_object_ref_sink(GST_OBJECT(m_videoSink)); //Take ownership
|
||||
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink, "sink");
|
||||
addProbeToPad(pad);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
}
|
||||
connect(&m_videoOverlay, &QGstreamerVideoOverlay::nativeVideoSizeChanged,
|
||||
this, &QGstreamerVideoWindow::nativeSizeChanged);
|
||||
connect(&m_videoOverlay, &QGstreamerVideoOverlay::brightnessChanged,
|
||||
this, &QGstreamerVideoWindow::brightnessChanged);
|
||||
connect(&m_videoOverlay, &QGstreamerVideoOverlay::contrastChanged,
|
||||
this, &QGstreamerVideoWindow::contrastChanged);
|
||||
connect(&m_videoOverlay, &QGstreamerVideoOverlay::hueChanged,
|
||||
this, &QGstreamerVideoWindow::hueChanged);
|
||||
connect(&m_videoOverlay, &QGstreamerVideoOverlay::saturationChanged,
|
||||
this, &QGstreamerVideoWindow::saturationChanged);
|
||||
}
|
||||
|
||||
QGstreamerVideoWindow::~QGstreamerVideoWindow()
|
||||
{
|
||||
if (m_videoSink) {
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink");
|
||||
removeProbeFromPad(pad);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
gst_object_unref(GST_OBJECT(m_videoSink));
|
||||
}
|
||||
}
|
||||
|
||||
GstElement *QGstreamerVideoWindow::videoSink()
|
||||
{
|
||||
return m_videoOverlay.videoSink();
|
||||
}
|
||||
|
||||
WId QGstreamerVideoWindow::winId() const
|
||||
@@ -94,17 +75,8 @@ void QGstreamerVideoWindow::setWinId(WId id)
|
||||
return;
|
||||
|
||||
WId oldId = m_windowId;
|
||||
m_videoOverlay.setWindowHandle(m_windowId = id);
|
||||
|
||||
m_windowId = id;
|
||||
#if GST_CHECK_VERSION(1,0,0)
|
||||
if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink)) {
|
||||
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(m_videoSink), m_windowId);
|
||||
}
|
||||
#else
|
||||
if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) {
|
||||
gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), m_windowId);
|
||||
}
|
||||
#endif
|
||||
if (!oldId)
|
||||
emit readyChanged(true);
|
||||
|
||||
@@ -114,28 +86,12 @@ void QGstreamerVideoWindow::setWinId(WId id)
|
||||
|
||||
bool QGstreamerVideoWindow::processSyncMessage(const QGstreamerMessage &message)
|
||||
{
|
||||
GstMessage* gm = message.rawMessage();
|
||||
#if GST_CHECK_VERSION(1,0,0)
|
||||
const GstStructure *s = gst_message_get_structure(gm);
|
||||
if ((GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) &&
|
||||
gst_structure_has_name(s, "prepare-window-handle") &&
|
||||
m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink)) {
|
||||
return m_videoOverlay.processSyncMessage(message);
|
||||
}
|
||||
|
||||
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(m_videoSink), m_windowId);
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if ((GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) &&
|
||||
gst_structure_has_name(gm->structure, "prepare-xwindow-id") &&
|
||||
m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) {
|
||||
|
||||
gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), m_windowId);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
bool QGstreamerVideoWindow::processBusMessage(const QGstreamerMessage &message)
|
||||
{
|
||||
return m_videoOverlay.processBusMessage(message);
|
||||
}
|
||||
|
||||
QRect QGstreamerVideoWindow::displayRect() const
|
||||
@@ -145,188 +101,63 @@ QRect QGstreamerVideoWindow::displayRect() const
|
||||
|
||||
void QGstreamerVideoWindow::setDisplayRect(const QRect &rect)
|
||||
{
|
||||
m_displayRect = rect;
|
||||
#if GST_CHECK_VERSION(1,0,0)
|
||||
if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink)) {
|
||||
if (m_displayRect.isEmpty())
|
||||
gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(m_videoSink), -1, -1, -1, -1);
|
||||
else
|
||||
gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(m_videoSink),
|
||||
m_displayRect.x(),
|
||||
m_displayRect.y(),
|
||||
m_displayRect.width(),
|
||||
m_displayRect.height());
|
||||
repaint();
|
||||
}
|
||||
#else
|
||||
if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) {
|
||||
#if GST_VERSION_MICRO >= 29
|
||||
if (m_displayRect.isEmpty())
|
||||
gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), -1, -1, -1, -1);
|
||||
else
|
||||
gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink),
|
||||
m_displayRect.x(),
|
||||
m_displayRect.y(),
|
||||
m_displayRect.width(),
|
||||
m_displayRect.height());
|
||||
repaint();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
m_videoOverlay.setRenderRectangle(m_displayRect = rect);
|
||||
repaint();
|
||||
}
|
||||
|
||||
Qt::AspectRatioMode QGstreamerVideoWindow::aspectRatioMode() const
|
||||
{
|
||||
return m_aspectRatioMode;
|
||||
return m_videoOverlay.aspectRatioMode();
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setAspectRatioMode(Qt::AspectRatioMode mode)
|
||||
{
|
||||
m_aspectRatioMode = mode;
|
||||
|
||||
if (m_videoSink) {
|
||||
g_object_set(G_OBJECT(m_videoSink),
|
||||
"force-aspect-ratio",
|
||||
(m_aspectRatioMode == Qt::KeepAspectRatio),
|
||||
(const char*)NULL);
|
||||
}
|
||||
m_videoOverlay.setAspectRatioMode(mode);
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::repaint()
|
||||
{
|
||||
#if GST_CHECK_VERSION(1,0,0)
|
||||
if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink)) {
|
||||
//don't call gst_x_overlay_expose if the sink is in null state
|
||||
GstState state = GST_STATE_NULL;
|
||||
GstStateChangeReturn res = gst_element_get_state(m_videoSink, &state, NULL, 1000000);
|
||||
if (res != GST_STATE_CHANGE_FAILURE && state != GST_STATE_NULL) {
|
||||
gst_video_overlay_expose(GST_VIDEO_OVERLAY(m_videoSink));
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) {
|
||||
//don't call gst_x_overlay_expose if the sink is in null state
|
||||
GstState state = GST_STATE_NULL;
|
||||
GstStateChangeReturn res = gst_element_get_state(m_videoSink, &state, NULL, 1000000);
|
||||
if (res != GST_STATE_CHANGE_FAILURE && state != GST_STATE_NULL) {
|
||||
gst_x_overlay_expose(GST_X_OVERLAY(m_videoSink));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QColor QGstreamerVideoWindow::colorKey() const
|
||||
{
|
||||
if (!m_colorKey.isValid()) {
|
||||
gint colorkey = 0;
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "colorkey"))
|
||||
g_object_get(G_OBJECT(m_videoSink), "colorkey", &colorkey, NULL);
|
||||
|
||||
if (colorkey > 0)
|
||||
m_colorKey.setRgb(colorkey);
|
||||
}
|
||||
|
||||
return m_colorKey;
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setColorKey(const QColor &color)
|
||||
{
|
||||
m_colorKey = color;
|
||||
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "colorkey"))
|
||||
g_object_set(G_OBJECT(m_videoSink), "colorkey", color.rgba(), NULL);
|
||||
}
|
||||
|
||||
bool QGstreamerVideoWindow::autopaintColorKey() const
|
||||
{
|
||||
bool enabled = true;
|
||||
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "autopaint-colorkey"))
|
||||
g_object_get(G_OBJECT(m_videoSink), "autopaint-colorkey", &enabled, NULL);
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setAutopaintColorKey(bool enabled)
|
||||
{
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "autopaint-colorkey"))
|
||||
g_object_set(G_OBJECT(m_videoSink), "autopaint-colorkey", enabled, NULL);
|
||||
m_videoOverlay.expose();
|
||||
}
|
||||
|
||||
int QGstreamerVideoWindow::brightness() const
|
||||
{
|
||||
int brightness = 0;
|
||||
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness"))
|
||||
g_object_get(G_OBJECT(m_videoSink), "brightness", &brightness, NULL);
|
||||
|
||||
return brightness / 10;
|
||||
return m_videoOverlay.brightness();
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setBrightness(int brightness)
|
||||
{
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness")) {
|
||||
g_object_set(G_OBJECT(m_videoSink), "brightness", brightness * 10, NULL);
|
||||
|
||||
emit brightnessChanged(brightness);
|
||||
}
|
||||
m_videoOverlay.setBrightness(brightness);
|
||||
}
|
||||
|
||||
int QGstreamerVideoWindow::contrast() const
|
||||
{
|
||||
int contrast = 0;
|
||||
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast"))
|
||||
g_object_get(G_OBJECT(m_videoSink), "contrast", &contrast, NULL);
|
||||
|
||||
return contrast / 10;
|
||||
return m_videoOverlay.contrast();
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setContrast(int contrast)
|
||||
{
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast")) {
|
||||
g_object_set(G_OBJECT(m_videoSink), "contrast", contrast * 10, NULL);
|
||||
|
||||
emit contrastChanged(contrast);
|
||||
}
|
||||
m_videoOverlay.setContrast(contrast);
|
||||
}
|
||||
|
||||
int QGstreamerVideoWindow::hue() const
|
||||
{
|
||||
int hue = 0;
|
||||
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue"))
|
||||
g_object_get(G_OBJECT(m_videoSink), "hue", &hue, NULL);
|
||||
|
||||
return hue / 10;
|
||||
return m_videoOverlay.hue();
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setHue(int hue)
|
||||
{
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue")) {
|
||||
g_object_set(G_OBJECT(m_videoSink), "hue", hue * 10, NULL);
|
||||
|
||||
emit hueChanged(hue);
|
||||
}
|
||||
m_videoOverlay.setHue(hue);
|
||||
}
|
||||
|
||||
int QGstreamerVideoWindow::saturation() const
|
||||
{
|
||||
int saturation = 0;
|
||||
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation"))
|
||||
g_object_get(G_OBJECT(m_videoSink), "saturation", &saturation, NULL);
|
||||
|
||||
return saturation / 10;
|
||||
return m_videoOverlay.saturation();
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::setSaturation(int saturation)
|
||||
{
|
||||
if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation")) {
|
||||
g_object_set(G_OBJECT(m_videoSink), "saturation", saturation * 10, NULL);
|
||||
|
||||
emit saturationChanged(saturation);
|
||||
}
|
||||
m_videoOverlay.setSaturation(saturation);
|
||||
}
|
||||
|
||||
bool QGstreamerVideoWindow::isFullScreen() const
|
||||
@@ -341,28 +172,5 @@ void QGstreamerVideoWindow::setFullScreen(bool fullScreen)
|
||||
|
||||
QSize QGstreamerVideoWindow::nativeSize() const
|
||||
{
|
||||
return m_nativeSize;
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::probeCaps(GstCaps *caps)
|
||||
{
|
||||
QSize resolution = QGstUtils::capsCorrectedResolution(caps);
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
"updateNativeVideoSize",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(QSize, resolution));
|
||||
}
|
||||
|
||||
void QGstreamerVideoWindow::updateNativeVideoSize(const QSize &size)
|
||||
{
|
||||
if (m_nativeSize != size) {
|
||||
m_nativeSize = size;
|
||||
emit nativeSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
GstElement *QGstreamerVideoWindow::videoSink()
|
||||
{
|
||||
return m_videoSink;
|
||||
return m_videoOverlay.nativeVideoSize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user