2015-07-06 13:10:51 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <gst/video/video.h>
|
2015-09-02 13:45:07 +00:00
|
|
|
#include "qtitem.h"
|
|
|
|
#include "gstqsgtexture.h"
|
2016-07-27 00:16:47 +00:00
|
|
|
#include "gstqtglutility.h"
|
2015-09-02 13:45:07 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
#include <QtCore/QMutexLocker>
|
2020-10-16 23:05:45 +00:00
|
|
|
#include <QtCore/QPointer>
|
2015-09-14 17:14:37 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtQuick/QQuickWindow>
|
|
|
|
#include <QtQuick/QSGSimpleTextureNode>
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-15 09:38:04 +00:00
|
|
|
* SECTION:QtGLVideoItem
|
|
|
|
* @short_description: a Qt5 QtQuick item that renders GStreamer video #GstBuffers
|
2015-07-06 13:10:51 +00:00
|
|
|
*
|
2017-06-21 15:01:40 +00:00
|
|
|
* #QtGLVideoItem is an #QQuickItem that renders GStreamer video buffers.
|
2015-07-06 13:10:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT qt_item_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
|
|
|
#define DEFAULT_FORCE_ASPECT_RATIO TRUE
|
|
|
|
#define DEFAULT_PAR_N 0
|
|
|
|
#define DEFAULT_PAR_D 1
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_FORCE_ASPECT_RATIO,
|
|
|
|
PROP_PIXEL_ASPECT_RATIO,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _QtGLVideoItemPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
gboolean force_aspect_ratio;
|
|
|
|
gint par_n, par_d;
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
GWeakRef sink;
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
gint display_width;
|
|
|
|
gint display_height;
|
|
|
|
|
|
|
|
GstBuffer *buffer;
|
2021-11-11 04:49:19 +00:00
|
|
|
GstCaps *new_caps;
|
2015-07-06 13:10:51 +00:00
|
|
|
GstCaps *caps;
|
2021-11-11 04:49:19 +00:00
|
|
|
GstVideoInfo new_v_info;
|
2015-07-06 13:10:51 +00:00
|
|
|
GstVideoInfo v_info;
|
|
|
|
|
|
|
|
gboolean initted;
|
|
|
|
GstGLDisplay *display;
|
|
|
|
QOpenGLContext *qt_context;
|
|
|
|
GstGLContext *other_context;
|
|
|
|
GstGLContext *context;
|
2020-11-03 13:58:30 +00:00
|
|
|
|
|
|
|
/* buffers with textures that were bound by QML */
|
|
|
|
GQueue bound_buffers;
|
|
|
|
/* buffers that were previously bound but in the meantime a new one was
|
|
|
|
* bound so this one is most likely not used anymore
|
|
|
|
* FIXME: Ideally we would use fences for this but there seems to be no
|
|
|
|
* way to reliably "try wait" on a fence */
|
|
|
|
GQueue potentially_unbound_buffers;
|
2015-07-06 13:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
QtGLVideoItem::QtGLVideoItem()
|
|
|
|
{
|
2021-03-18 08:52:53 +00:00
|
|
|
static gsize _debug;
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&_debug)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglwidget", 0, "Qt GL Widget");
|
|
|
|
g_once_init_leave (&_debug, 1);
|
|
|
|
}
|
2021-07-30 10:21:46 +00:00
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
this->setFlag (QQuickItem::ItemHasContents, true);
|
|
|
|
|
|
|
|
this->priv = g_new0 (QtGLVideoItemPrivate, 1);
|
|
|
|
|
|
|
|
this->priv->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO;
|
|
|
|
this->priv->par_n = DEFAULT_PAR_N;
|
|
|
|
this->priv->par_d = DEFAULT_PAR_D;
|
|
|
|
|
2021-07-30 10:21:46 +00:00
|
|
|
this->priv->initted = FALSE;
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
g_mutex_init (&this->priv->lock);
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
g_weak_ref_init (&priv->sink, NULL);
|
|
|
|
|
2021-05-03 07:39:05 +00:00
|
|
|
this->priv->display = gst_qt_get_gl_display(TRUE);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this,
|
|
|
|
SLOT(handleWindowChanged(QQuickWindow*)));
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
this->proxy = QSharedPointer<QtGLVideoItemInterface>(new QtGLVideoItemInterface(this));
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
setFlag(ItemHasContents, true);
|
|
|
|
setAcceptedMouseButtons(Qt::AllButtons);
|
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
|
2022-02-23 11:53:04 +00:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
|
|
setAcceptTouchEvents(true);
|
|
|
|
#else
|
|
|
|
GST_INFO ("Qt version is below 5.10, touchscreen events will not work");
|
|
|
|
#endif
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
GST_DEBUG ("%p init Qt Video Item", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QtGLVideoItem::~QtGLVideoItem()
|
|
|
|
{
|
2021-06-03 10:33:45 +00:00
|
|
|
GstBuffer *tmp_buffer;
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
/* Before destroying the priv info, make sure
|
|
|
|
* no qmlglsink's will call in again, and that
|
|
|
|
* any ongoing calls are done by invalidating the proxy
|
|
|
|
* pointer */
|
2020-07-15 11:40:42 +00:00
|
|
|
GST_INFO ("%p Destroying QtGLVideoItem and invalidating the proxy %p", this, proxy.data());
|
2017-07-12 05:29:32 +00:00
|
|
|
proxy->invalidateRef();
|
|
|
|
proxy.clear();
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
g_mutex_clear (&this->priv->lock);
|
2016-03-01 15:22:37 +00:00
|
|
|
if (this->priv->context)
|
|
|
|
gst_object_unref(this->priv->context);
|
|
|
|
if (this->priv->other_context)
|
|
|
|
gst_object_unref(this->priv->other_context);
|
2016-12-07 11:55:46 +00:00
|
|
|
if (this->priv->display)
|
|
|
|
gst_object_unref(this->priv->display);
|
2020-02-03 04:59:34 +00:00
|
|
|
|
2021-06-03 10:33:45 +00:00
|
|
|
while ((tmp_buffer = (GstBuffer*) g_queue_pop_head (&this->priv->potentially_unbound_buffers))) {
|
|
|
|
GST_TRACE ("old buffer %p should be unbound now, unreffing", tmp_buffer);
|
|
|
|
gst_buffer_unref (tmp_buffer);
|
|
|
|
}
|
|
|
|
while ((tmp_buffer = (GstBuffer*) g_queue_pop_head (&this->priv->bound_buffers))) {
|
|
|
|
GST_TRACE ("old buffer %p should be unbound now, unreffing", tmp_buffer);
|
|
|
|
gst_buffer_unref (tmp_buffer);
|
|
|
|
}
|
|
|
|
|
2020-02-26 07:29:06 +00:00
|
|
|
gst_buffer_replace (&this->priv->buffer, NULL);
|
|
|
|
|
2020-02-03 04:59:34 +00:00
|
|
|
gst_caps_replace (&this->priv->caps, NULL);
|
2021-11-11 04:49:19 +00:00
|
|
|
gst_caps_replace (&this->priv->new_caps, NULL);
|
2020-04-15 09:38:04 +00:00
|
|
|
|
|
|
|
g_weak_ref_clear (&this->priv->sink);
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
g_free (this->priv);
|
|
|
|
this->priv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::setDAR(gint num, gint den)
|
|
|
|
{
|
|
|
|
this->priv->par_n = num;
|
|
|
|
this->priv->par_d = den;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::getDAR(gint * num, gint * den)
|
|
|
|
{
|
|
|
|
if (num)
|
|
|
|
*num = this->priv->par_n;
|
|
|
|
if (den)
|
|
|
|
*den = this->priv->par_d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-16 05:13:02 +00:00
|
|
|
QtGLVideoItem::setForceAspectRatio(bool force_aspect_ratio)
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2016-06-16 05:13:02 +00:00
|
|
|
this->priv->force_aspect_ratio = !!force_aspect_ratio;
|
2021-03-31 08:52:14 +00:00
|
|
|
|
|
|
|
emit forceAspectRatioChanged(force_aspect_ratio);
|
2015-07-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
QtGLVideoItem::getForceAspectRatio()
|
|
|
|
{
|
|
|
|
return this->priv->force_aspect_ratio;
|
|
|
|
}
|
|
|
|
|
2017-09-06 07:59:56 +00:00
|
|
|
bool
|
|
|
|
QtGLVideoItem::itemInitialized()
|
|
|
|
{
|
2021-07-30 10:21:46 +00:00
|
|
|
return this->priv->initted;
|
2017-09-06 07:59:56 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 04:49:19 +00:00
|
|
|
static gboolean
|
|
|
|
_calculate_par (QtGLVideoItem * widget, GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
gboolean ok;
|
|
|
|
gint width, height;
|
|
|
|
gint par_n, par_d;
|
|
|
|
gint display_par_n, display_par_d;
|
|
|
|
guint display_ratio_num, display_ratio_den;
|
|
|
|
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (info);
|
|
|
|
|
|
|
|
par_n = GST_VIDEO_INFO_PAR_N (info);
|
|
|
|
par_d = GST_VIDEO_INFO_PAR_D (info);
|
|
|
|
|
|
|
|
if (!par_n)
|
|
|
|
par_n = 1;
|
|
|
|
|
|
|
|
/* get display's PAR */
|
|
|
|
if (widget->priv->par_n != 0 && widget->priv->par_d != 0) {
|
|
|
|
display_par_n = widget->priv->par_n;
|
|
|
|
display_par_d = widget->priv->par_d;
|
|
|
|
} else {
|
|
|
|
display_par_n = 1;
|
|
|
|
display_par_d = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = gst_video_calculate_display_ratio (&display_ratio_num,
|
|
|
|
&display_ratio_den, width, height, par_n, par_d, display_par_n,
|
|
|
|
display_par_d);
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
widget->setImplicitWidth (width);
|
|
|
|
widget->setImplicitHeight (height);
|
|
|
|
|
|
|
|
GST_LOG ("%p PAR: %u/%u DAR:%u/%u", widget, par_n, par_d, display_par_n,
|
|
|
|
display_par_d);
|
|
|
|
|
|
|
|
if (height % display_ratio_den == 0) {
|
|
|
|
GST_DEBUG ("%p keeping video height", widget);
|
|
|
|
widget->priv->display_width = (guint)
|
|
|
|
gst_util_uint64_scale_int (height, display_ratio_num,
|
|
|
|
display_ratio_den);
|
|
|
|
widget->priv->display_height = height;
|
|
|
|
} else if (width % display_ratio_num == 0) {
|
|
|
|
GST_DEBUG ("%p keeping video width", widget);
|
|
|
|
widget->priv->display_width = width;
|
|
|
|
widget->priv->display_height = (guint)
|
|
|
|
gst_util_uint64_scale_int (width, display_ratio_den, display_ratio_num);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("%p approximating while keeping video height", widget);
|
|
|
|
widget->priv->display_width = (guint)
|
|
|
|
gst_util_uint64_scale_int (height, display_ratio_num,
|
|
|
|
display_ratio_den);
|
|
|
|
widget->priv->display_height = height;
|
|
|
|
}
|
|
|
|
GST_DEBUG ("%p scaling to %dx%d", widget, widget->priv->display_width,
|
|
|
|
widget->priv->display_height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
QSGNode *
|
|
|
|
QtGLVideoItem::updatePaintNode(QSGNode * oldNode,
|
|
|
|
UpdatePaintNodeData * updatePaintNodeData)
|
|
|
|
{
|
2020-11-03 13:58:30 +00:00
|
|
|
GstBuffer *old_buffer;
|
|
|
|
gboolean was_bound = FALSE;
|
|
|
|
|
2021-07-30 10:21:46 +00:00
|
|
|
if (!this->priv->initted)
|
2016-01-24 14:40:37 +00:00
|
|
|
return oldNode;
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
QSGSimpleTextureNode *texNode = static_cast<QSGSimpleTextureNode *> (oldNode);
|
|
|
|
GstVideoRectangle src, dst, result;
|
|
|
|
GstQSGTexture *tex;
|
|
|
|
|
|
|
|
g_mutex_lock (&this->priv->lock);
|
2020-02-25 10:47:14 +00:00
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
GST_TRACE ("%p updatePaintNode", this);
|
|
|
|
|
|
|
|
if (!this->priv->caps) {
|
2021-11-11 04:49:19 +00:00
|
|
|
GST_LOG ("%p no caps yet", this);
|
2015-07-06 13:10:51 +00:00
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-11 04:49:19 +00:00
|
|
|
if (gst_gl_context_get_current() == NULL)
|
|
|
|
gst_gl_context_activate (this->priv->other_context, TRUE);
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
if (!texNode) {
|
|
|
|
texNode = new QSGSimpleTextureNode ();
|
2015-08-08 15:28:03 +00:00
|
|
|
texNode->setOwnsTexture (true);
|
2015-11-20 00:18:43 +00:00
|
|
|
texNode->setTexture (new GstQSGTexture ());
|
2015-07-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 00:18:43 +00:00
|
|
|
tex = static_cast<GstQSGTexture *> (texNode->texture());
|
2020-11-03 13:58:30 +00:00
|
|
|
|
|
|
|
if ((old_buffer = tex->getBuffer(&was_bound))) {
|
|
|
|
if (old_buffer == this->priv->buffer) {
|
|
|
|
/* same buffer */
|
|
|
|
gst_buffer_unref (old_buffer);
|
|
|
|
} else if (!was_bound) {
|
|
|
|
GST_TRACE ("old buffer %p was not bound yet, unreffing", old_buffer);
|
|
|
|
gst_buffer_unref (old_buffer);
|
|
|
|
} else {
|
|
|
|
GstBuffer *tmp_buffer;
|
|
|
|
|
|
|
|
GST_TRACE ("old buffer %p was bound, queueing up for later", old_buffer);
|
|
|
|
/* Unref all buffers that were previously not bound anymore. At least
|
|
|
|
* one more buffer was bound in the meantime so this one is most likely
|
|
|
|
* not in use anymore. */
|
|
|
|
while ((tmp_buffer = (GstBuffer*) g_queue_pop_head (&this->priv->potentially_unbound_buffers))) {
|
|
|
|
GST_TRACE ("old buffer %p should be unbound now, unreffing", tmp_buffer);
|
|
|
|
gst_buffer_unref (tmp_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move previous bound buffers to the next queue. We now know that
|
|
|
|
* another buffer was bound in the meantime and will free them on
|
|
|
|
* the next iteration above. */
|
|
|
|
while ((tmp_buffer = (GstBuffer*) g_queue_pop_head (&this->priv->bound_buffers))) {
|
|
|
|
GST_TRACE ("old buffer %p is potentially unbound now", tmp_buffer);
|
|
|
|
g_queue_push_tail (&this->priv->potentially_unbound_buffers, tmp_buffer);
|
|
|
|
}
|
|
|
|
g_queue_push_tail (&this->priv->bound_buffers, old_buffer);
|
|
|
|
}
|
|
|
|
old_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
tex->setCaps (this->priv->caps);
|
|
|
|
tex->setBuffer (this->priv->buffer);
|
2016-01-08 19:19:06 +00:00
|
|
|
texNode->markDirty(QSGNode::DirtyMaterial);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
if (this->priv->force_aspect_ratio) {
|
|
|
|
src.w = this->priv->display_width;
|
|
|
|
src.h = this->priv->display_height;
|
|
|
|
|
|
|
|
dst.x = boundingRect().x();
|
|
|
|
dst.y = boundingRect().y();
|
|
|
|
dst.w = boundingRect().width();
|
|
|
|
dst.h = boundingRect().height();
|
|
|
|
|
|
|
|
gst_video_sink_center_rect (src, dst, &result, TRUE);
|
|
|
|
} else {
|
|
|
|
result.x = boundingRect().x();
|
|
|
|
result.y = boundingRect().y();
|
|
|
|
result.w = boundingRect().width();
|
|
|
|
result.h = boundingRect().height();
|
|
|
|
}
|
|
|
|
|
|
|
|
texNode->setRect (QRectF (result.x, result.y, result.w, result.h));
|
|
|
|
|
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
|
|
|
|
return texNode;
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
/* This method has to be invoked with the the priv->lock taken */
|
|
|
|
void
|
|
|
|
QtGLVideoItem::fitStreamToAllocatedSize(GstVideoRectangle * result)
|
|
|
|
{
|
|
|
|
if (this->priv->force_aspect_ratio) {
|
|
|
|
GstVideoRectangle src, dst;
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
src.y = 0;
|
|
|
|
src.w = this->priv->display_width;
|
|
|
|
src.h = this->priv->display_height;
|
|
|
|
|
|
|
|
dst.x = 0;
|
|
|
|
dst.y = 0;
|
2021-08-31 10:05:16 +00:00
|
|
|
dst.w = width();
|
|
|
|
dst.h = height();
|
2020-04-15 09:38:04 +00:00
|
|
|
|
|
|
|
gst_video_sink_center_rect (src, dst, result, TRUE);
|
|
|
|
} else {
|
|
|
|
result->x = 0;
|
|
|
|
result->y = 0;
|
2021-08-31 10:05:16 +00:00
|
|
|
result->w = width();
|
|
|
|
result->h = height();
|
2020-04-15 09:38:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This method has to be invoked with the the priv->lock taken */
|
|
|
|
QPointF
|
|
|
|
QtGLVideoItem::mapPointToStreamSize(QPointF pos)
|
|
|
|
{
|
|
|
|
gdouble stream_width, stream_height;
|
|
|
|
GstVideoRectangle result;
|
|
|
|
double stream_x, stream_y;
|
|
|
|
double x, y;
|
|
|
|
|
|
|
|
fitStreamToAllocatedSize(&result);
|
|
|
|
|
|
|
|
stream_width = (gdouble) GST_VIDEO_INFO_WIDTH (&this->priv->v_info);
|
|
|
|
stream_height = (gdouble) GST_VIDEO_INFO_HEIGHT (&this->priv->v_info);
|
|
|
|
x = pos.x();
|
|
|
|
y = pos.y();
|
|
|
|
|
|
|
|
/* from display coordinates to stream coordinates */
|
|
|
|
if (result.w > 0)
|
|
|
|
stream_x = (x - result.x) / result.w * stream_width;
|
|
|
|
else
|
|
|
|
stream_x = 0.;
|
|
|
|
|
|
|
|
/* clip to stream size */
|
|
|
|
stream_x = CLAMP(stream_x, 0., stream_width);
|
|
|
|
|
|
|
|
/* same for y-axis */
|
|
|
|
if (result.h > 0)
|
|
|
|
stream_y = (y - result.y) / result.h * stream_height;
|
|
|
|
else
|
|
|
|
stream_y = 0.;
|
|
|
|
|
|
|
|
stream_y = CLAMP(stream_y, 0., stream_height);
|
|
|
|
GST_TRACE ("transform %fx%f into %fx%f", x, y, stream_x, stream_y);
|
2021-08-27 03:30:57 +00:00
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
return QPointF(stream_x, stream_y);
|
|
|
|
}
|
|
|
|
|
2022-03-18 16:59:32 +00:00
|
|
|
static GstNavigationModifierType
|
|
|
|
translateModifiers(Qt::KeyboardModifiers modifiers)
|
|
|
|
{
|
|
|
|
return (GstNavigationModifierType)(
|
|
|
|
((modifiers & Qt::KeyboardModifier::ShiftModifier) ? GST_NAVIGATION_MODIFIER_SHIFT_MASK : 0) |
|
|
|
|
((modifiers & Qt::KeyboardModifier::ControlModifier) ? GST_NAVIGATION_MODIFIER_CONTROL_MASK : 0) |
|
2022-12-13 11:23:56 +00:00
|
|
|
((modifiers & Qt::KeyboardModifier::AltModifier) ? GST_NAVIGATION_MODIFIER_MOD1_MASK : 0) |
|
2022-03-18 16:59:32 +00:00
|
|
|
((modifiers & Qt::KeyboardModifier::MetaModifier) ? GST_NAVIGATION_MODIFIER_META_MASK : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstNavigationModifierType
|
|
|
|
translateMouseButtons(Qt::MouseButtons buttons)
|
|
|
|
{
|
|
|
|
return (GstNavigationModifierType)(
|
|
|
|
((buttons & Qt::LeftButton) ? GST_NAVIGATION_MODIFIER_BUTTON1_MASK : 0) |
|
|
|
|
((buttons & Qt::RightButton) ? GST_NAVIGATION_MODIFIER_BUTTON2_MASK : 0) |
|
|
|
|
((buttons & Qt::MiddleButton) ? GST_NAVIGATION_MODIFIER_BUTTON3_MASK : 0) |
|
|
|
|
((buttons & Qt::BackButton) ? GST_NAVIGATION_MODIFIER_BUTTON4_MASK : 0) |
|
|
|
|
((buttons & Qt::ForwardButton) ? GST_NAVIGATION_MODIFIER_BUTTON5_MASK : 0));
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
void
|
|
|
|
QtGLVideoItem::wheelEvent(QWheelEvent * event)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&this->priv->lock);
|
|
|
|
QPoint delta = event->angleDelta();
|
|
|
|
GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink));
|
|
|
|
|
|
|
|
if (element != NULL) {
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK (5, 14, 0))
|
|
|
|
auto position = event->position();
|
|
|
|
#else
|
|
|
|
auto position = *event;
|
|
|
|
#endif
|
2022-02-14 15:08:23 +00:00
|
|
|
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
|
|
|
gst_navigation_event_new_mouse_scroll (position.x(), position.y(),
|
2022-03-18 16:59:32 +00:00
|
|
|
delta.x(), delta.y(),
|
|
|
|
(GstNavigationModifierType) (
|
|
|
|
translateModifiers(event->modifiers()) | translateMouseButtons(event->buttons()))));
|
2020-04-15 09:38:04 +00:00
|
|
|
g_object_unref (element);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::hoverEnterEvent(QHoverEvent *)
|
|
|
|
{
|
2021-07-30 10:21:46 +00:00
|
|
|
mouseHovering = true;
|
2020-04-15 09:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::hoverLeaveEvent(QHoverEvent *)
|
|
|
|
{
|
2021-07-30 10:21:46 +00:00
|
|
|
mouseHovering = false;
|
2020-04-15 09:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::hoverMoveEvent(QHoverEvent * event)
|
|
|
|
{
|
2021-07-30 10:21:46 +00:00
|
|
|
if (!mouseHovering)
|
2020-04-15 09:38:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_mutex_lock (&this->priv->lock);
|
2021-08-27 03:30:57 +00:00
|
|
|
|
|
|
|
/* can't do anything when we don't have input format */
|
2021-11-11 04:49:19 +00:00
|
|
|
if (!this->priv->caps) {
|
2021-08-27 03:30:57 +00:00
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
if (event->pos() != event->oldPos()) {
|
|
|
|
QPointF pos = mapPointToStreamSize(event->pos());
|
|
|
|
GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink));
|
|
|
|
|
|
|
|
if (element != NULL) {
|
2022-02-14 15:08:23 +00:00
|
|
|
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
2022-03-18 16:59:32 +00:00
|
|
|
gst_navigation_event_new_mouse_move (pos.x(), pos.y(),
|
|
|
|
translateModifiers(event->modifiers())));
|
2020-04-15 09:38:04 +00:00
|
|
|
g_object_unref (element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
}
|
|
|
|
|
2022-02-23 11:53:04 +00:00
|
|
|
void
|
|
|
|
QtGLVideoItem::touchEvent(QTouchEvent * event)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&this->priv->lock);
|
|
|
|
|
|
|
|
/* can't do anything when we don't have input format */
|
|
|
|
if (!this->priv->caps) {
|
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink));
|
|
|
|
if (element == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event->type() == QEvent::TouchCancel) {
|
|
|
|
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
2022-03-18 16:59:32 +00:00
|
|
|
gst_navigation_event_new_touch_cancel (translateModifiers(event->modifiers())));
|
2022-02-23 11:53:04 +00:00
|
|
|
} else {
|
|
|
|
const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
|
|
|
|
gboolean sent_event = FALSE;
|
|
|
|
|
|
|
|
for (int i = 0; i < points.count(); i++) {
|
|
|
|
GstEvent *nav_event;
|
|
|
|
QPointF pos = mapPointToStreamSize(points[i].pos());
|
|
|
|
|
|
|
|
switch (points[i].state()) {
|
|
|
|
case Qt::TouchPointPressed:
|
|
|
|
nav_event = gst_navigation_event_new_touch_down ((guint) points[i].id(),
|
2022-03-18 16:59:32 +00:00
|
|
|
pos.x(), pos.y(), (gdouble) points[i].pressure(), translateModifiers(event->modifiers()));
|
2022-02-23 11:53:04 +00:00
|
|
|
break;
|
|
|
|
case Qt::TouchPointMoved:
|
|
|
|
nav_event = gst_navigation_event_new_touch_motion ((guint) points[i].id(),
|
2022-03-18 16:59:32 +00:00
|
|
|
pos.x(), pos.y(), (gdouble) points[i].pressure(), translateModifiers(event->modifiers()));
|
2022-02-23 11:53:04 +00:00
|
|
|
break;
|
|
|
|
case Qt::TouchPointReleased:
|
|
|
|
nav_event = gst_navigation_event_new_touch_up ((guint) points[i].id(),
|
2022-03-18 16:59:32 +00:00
|
|
|
pos.x(), pos.y(), translateModifiers(event->modifiers()));
|
2022-02-23 11:53:04 +00:00
|
|
|
break;
|
|
|
|
/* Don't send an event if the point did not change */
|
|
|
|
default:
|
|
|
|
nav_event = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nav_event) {
|
|
|
|
gst_navigation_send_event_simple (GST_NAVIGATION (element), nav_event);
|
|
|
|
sent_event = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Group simultaneos touch events with a frame event */
|
|
|
|
if (sent_event) {
|
|
|
|
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
2022-03-18 16:59:32 +00:00
|
|
|
gst_navigation_event_new_touch_frame (translateModifiers(event->modifiers())));
|
2022-02-23 11:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (element);
|
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
void
|
2022-02-14 15:08:23 +00:00
|
|
|
QtGLVideoItem::sendMouseEvent(QMouseEvent * event, gboolean is_press)
|
2020-04-15 09:38:04 +00:00
|
|
|
{
|
2021-07-30 10:21:46 +00:00
|
|
|
quint32 button = 0;
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::LeftButton:
|
|
|
|
button = 1;
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
button = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-07-30 10:21:46 +00:00
|
|
|
|
|
|
|
mousePressedButton = button;
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
g_mutex_lock (&this->priv->lock);
|
|
|
|
|
2021-08-27 03:30:57 +00:00
|
|
|
/* can't do anything when we don't have input format */
|
2021-11-11 04:49:19 +00:00
|
|
|
if (!this->priv->caps) {
|
2021-08-27 03:30:57 +00:00
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:38:04 +00:00
|
|
|
QPointF pos = mapPointToStreamSize(event->pos());
|
|
|
|
GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink));
|
|
|
|
|
|
|
|
if (element != NULL) {
|
2022-02-14 15:08:23 +00:00
|
|
|
gst_navigation_send_event_simple (GST_NAVIGATION (element),
|
|
|
|
(is_press) ? gst_navigation_event_new_mouse_button_press (button,
|
2022-03-18 16:59:32 +00:00
|
|
|
pos.x(), pos.y(),
|
|
|
|
(GstNavigationModifierType) (
|
|
|
|
translateModifiers(event->modifiers()) | translateMouseButtons(event->buttons()))) :
|
2022-02-14 15:08:23 +00:00
|
|
|
gst_navigation_event_new_mouse_button_release (button, pos.x(),
|
2022-03-18 16:59:32 +00:00
|
|
|
pos.y(),
|
|
|
|
(GstNavigationModifierType) (
|
|
|
|
translateModifiers(event->modifiers()) | translateMouseButtons(event->buttons()))));
|
2020-04-15 09:38:04 +00:00
|
|
|
g_object_unref (element);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&this->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::mousePressEvent(QMouseEvent * event)
|
|
|
|
{
|
|
|
|
forceActiveFocus();
|
2022-02-14 15:08:23 +00:00
|
|
|
sendMouseEvent(event, TRUE);
|
2020-04-15 09:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::mouseReleaseEvent(QMouseEvent * event)
|
|
|
|
{
|
2022-02-14 15:08:23 +00:00
|
|
|
sendMouseEvent(event, FALSE);
|
2020-04-15 09:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItemInterface::setSink (GstElement * sink)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
if (qt_item == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_mutex_lock (&qt_item->priv->lock);
|
|
|
|
g_weak_ref_set (&qt_item->priv->sink, sink);
|
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:10:51 +00:00
|
|
|
void
|
2017-07-12 05:29:32 +00:00
|
|
|
QtGLVideoItemInterface::setBuffer (GstBuffer * buffer)
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2017-07-12 05:29:32 +00:00
|
|
|
QMutexLocker locker(&lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2020-02-26 07:29:06 +00:00
|
|
|
if (qt_item == NULL) {
|
|
|
|
GST_WARNING ("%p actual item is NULL. setBuffer call ignored", this);
|
2017-07-12 05:29:32 +00:00
|
|
|
return;
|
2020-02-26 07:29:06 +00:00
|
|
|
}
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2021-11-11 04:49:19 +00:00
|
|
|
if (!qt_item->priv->caps && !qt_item->priv->new_caps) {
|
2020-02-26 07:29:06 +00:00
|
|
|
GST_WARNING ("%p Got buffer on unnegotiated QtGLVideoItem. Dropping", this);
|
2017-07-12 05:29:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_lock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2021-11-15 03:39:14 +00:00
|
|
|
if (qt_item->priv->new_caps) {
|
|
|
|
GST_DEBUG ("%p caps change from %" GST_PTR_FORMAT " to %" GST_PTR_FORMAT,
|
|
|
|
this, qt_item->priv->caps, qt_item->priv->new_caps);
|
|
|
|
gst_caps_take (&qt_item->priv->caps, qt_item->priv->new_caps);
|
|
|
|
qt_item->priv->new_caps = NULL;
|
|
|
|
qt_item->priv->v_info = qt_item->priv->new_v_info;
|
|
|
|
|
|
|
|
if (!_calculate_par (qt_item, &qt_item->priv->v_info)) {
|
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
gst_buffer_replace (&qt_item->priv->buffer, buffer);
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(qt_item, "update", Qt::QueuedConnection);
|
|
|
|
|
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::onSceneGraphInitialized ()
|
|
|
|
{
|
2020-10-16 23:05:45 +00:00
|
|
|
if (this->window() == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-02-26 07:29:06 +00:00
|
|
|
GST_DEBUG ("%p scene graph initialization with Qt GL context %p", this,
|
2015-07-06 13:10:51 +00:00
|
|
|
this->window()->openglContext ());
|
|
|
|
|
|
|
|
if (this->priv->qt_context == this->window()->openglContext ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->priv->qt_context = this->window()->openglContext ();
|
|
|
|
if (this->priv->qt_context == NULL) {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-30 10:21:46 +00:00
|
|
|
this->priv->initted = gst_qt_get_gl_wrapcontext (this->priv->display,
|
2016-07-27 00:16:47 +00:00
|
|
|
&this->priv->other_context, &this->priv->context);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("%p created wrapped GL context %" GST_PTR_FORMAT, this,
|
|
|
|
this->priv->other_context);
|
2017-05-21 14:01:14 +00:00
|
|
|
|
2017-09-06 07:59:56 +00:00
|
|
|
emit itemInitializedChanged();
|
2015-07-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItem::onSceneGraphInvalidated ()
|
|
|
|
{
|
|
|
|
GST_FIXME ("%p scene graph invalidated", this);
|
|
|
|
}
|
|
|
|
|
2020-02-26 07:29:06 +00:00
|
|
|
/**
|
|
|
|
* Retrieve and populate the GL context information from the current
|
|
|
|
* OpenGL context.
|
|
|
|
*/
|
2015-07-06 13:10:51 +00:00
|
|
|
gboolean
|
2017-07-12 05:29:32 +00:00
|
|
|
QtGLVideoItemInterface::initWinSys ()
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2017-07-12 05:29:32 +00:00
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
|
2016-06-15 14:44:48 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (qt_item == NULL)
|
|
|
|
return FALSE;
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_lock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (qt_item->priv->display && qt_item->priv->qt_context
|
|
|
|
&& qt_item->priv->other_context && qt_item->priv->context) {
|
2015-07-06 13:10:51 +00:00
|
|
|
/* already have the necessary state */
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!GST_IS_GL_DISPLAY (qt_item->priv->display)) {
|
2015-08-31 17:06:31 +00:00
|
|
|
GST_ERROR ("%p failed to retrieve display connection %" GST_PTR_FORMAT,
|
2017-07-12 05:29:32 +00:00
|
|
|
qt_item, qt_item->priv->display);
|
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!GST_IS_GL_CONTEXT (qt_item->priv->other_context)) {
|
|
|
|
GST_ERROR ("%p failed to retrieve wrapped context %" GST_PTR_FORMAT, qt_item,
|
|
|
|
qt_item->priv->other_context);
|
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
qt_item->priv->context = gst_gl_context_new (qt_item->priv->display);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!qt_item->priv->context) {
|
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!gst_gl_context_create (qt_item->priv->context, qt_item->priv->other_context,
|
2016-06-15 14:44:48 +00:00
|
|
|
&error)) {
|
|
|
|
GST_ERROR ("%s", error->message);
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2016-06-15 14:44:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-08-04 05:33:06 +00:00
|
|
|
QtGLVideoItem::handleWindowChanged (QQuickWindow * win)
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
|
|
|
if (win) {
|
2021-08-04 05:33:06 +00:00
|
|
|
if (win->isSceneGraphInitialized ())
|
|
|
|
win->scheduleRenderJob (new RenderJob (std::
|
|
|
|
bind (&QtGLVideoItem::onSceneGraphInitialized, this)),
|
|
|
|
QQuickWindow::BeforeSynchronizingStage);
|
2015-11-19 10:55:19 +00:00
|
|
|
else
|
2021-08-04 05:33:06 +00:00
|
|
|
connect (win, SIGNAL (sceneGraphInitialized ()), this,
|
|
|
|
SLOT (onSceneGraphInitialized ()), Qt::DirectConnection);
|
2015-11-19 10:55:19 +00:00
|
|
|
|
2021-08-04 05:33:06 +00:00
|
|
|
connect (win, SIGNAL (sceneGraphInvalidated ()), this,
|
|
|
|
SLOT (onSceneGraphInvalidated ()), Qt::DirectConnection);
|
2015-07-06 13:10:51 +00:00
|
|
|
} else {
|
|
|
|
this->priv->qt_context = NULL;
|
2021-08-04 05:33:06 +00:00
|
|
|
this->priv->initted = FALSE;
|
2015-07-06 13:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2017-07-12 05:29:32 +00:00
|
|
|
QtGLVideoItemInterface::setCaps (GstCaps * caps)
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2017-07-12 05:29:32 +00:00
|
|
|
QMutexLocker locker(&lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
GstVideoInfo v_info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
|
|
|
|
g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (qt_item == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (qt_item->priv->caps && gst_caps_is_equal_fixed (qt_item->priv->caps, caps))
|
2015-07-06 13:10:51 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&v_info, caps))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_lock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2021-11-11 04:49:19 +00:00
|
|
|
GST_DEBUG ("%p set caps %" GST_PTR_FORMAT, qt_item, caps);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2021-11-11 04:49:19 +00:00
|
|
|
gst_caps_replace (&qt_item->priv->new_caps, caps);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2021-11-11 04:49:19 +00:00
|
|
|
qt_item->priv->new_v_info = v_info;
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
g_mutex_unlock (&qt_item->priv->lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstGLContext *
|
2017-07-12 05:29:32 +00:00
|
|
|
QtGLVideoItemInterface::getQtContext ()
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2017-07-12 05:29:32 +00:00
|
|
|
QMutexLocker locker(&lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!qt_item || !qt_item->priv->other_context)
|
2015-07-06 13:10:51 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (GstGLContext *) gst_object_ref (qt_item->priv->other_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstGLContext *
|
2017-07-12 05:29:32 +00:00
|
|
|
QtGLVideoItemInterface::getContext ()
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2017-07-12 05:29:32 +00:00
|
|
|
QMutexLocker locker(&lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!qt_item || !qt_item->priv->context)
|
2015-07-06 13:10:51 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (GstGLContext *) gst_object_ref (qt_item->priv->context);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstGLDisplay *
|
2020-07-15 11:40:42 +00:00
|
|
|
QtGLVideoItemInterface::getDisplay()
|
2015-07-06 13:10:51 +00:00
|
|
|
{
|
2017-07-12 05:29:32 +00:00
|
|
|
QMutexLocker locker(&lock);
|
2015-07-06 13:10:51 +00:00
|
|
|
|
2017-07-12 05:29:32 +00:00
|
|
|
if (!qt_item || !qt_item->priv->display)
|
2015-07-06 13:10:51 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (GstGLDisplay *) gst_object_ref (qt_item->priv->display);
|
|
|
|
}
|
2017-07-12 05:29:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItemInterface::setDAR(gint num, gint den)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
if (!qt_item)
|
|
|
|
return;
|
|
|
|
qt_item->setDAR(num, den);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItemInterface::getDAR(gint * num, gint * den)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
if (!qt_item)
|
|
|
|
return;
|
|
|
|
qt_item->getDAR (num, den);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItemInterface::setForceAspectRatio(bool force_aspect_ratio)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
if (!qt_item)
|
|
|
|
return;
|
|
|
|
qt_item->setForceAspectRatio(force_aspect_ratio);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
QtGLVideoItemInterface::getForceAspectRatio()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
if (!qt_item)
|
|
|
|
return FALSE;
|
|
|
|
return qt_item->getForceAspectRatio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QtGLVideoItemInterface::invalidateRef()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&lock);
|
|
|
|
qt_item = NULL;
|
|
|
|
}
|
|
|
|
|