qmlglsrc: some enhancements for qmlglsrc

1. Need set use-default-fbo to qquickwindow during set property
   to support change render target on the fly.
2. Calculate qmlglsrc refresh frame rate in qtglwindow

https://bugzilla.gnome.org/show_bug.cgi?id=774035
This commit is contained in:
Haihua Hu 2016-11-07 14:47:22 +08:00 committed by Matthew Waters
parent 389e386d50
commit 4450152a9e
4 changed files with 27 additions and 28 deletions

View file

@ -145,8 +145,11 @@ gst_qt_src_set_property (GObject * object, guint prop_id,
qt_src->qwindow = qt_src->qwindow =
static_cast < QQuickWindow * >(g_value_get_pointer (value)); static_cast < QQuickWindow * >(g_value_get_pointer (value));
if (qt_src->window) if (qt_src->window) {
delete qt_src->window; delete qt_src->window;
qt_src->window = NULL;
}
if (qt_src->qwindow) if (qt_src->qwindow)
qt_src->window = new QtGLWindow (NULL, qt_src->qwindow); qt_src->window = new QtGLWindow (NULL, qt_src->qwindow);
@ -154,6 +157,8 @@ gst_qt_src_set_property (GObject * object, guint prop_id,
} }
case PROP_DEFAULT_FBO: case PROP_DEFAULT_FBO:
qt_src->default_fbo = g_value_get_boolean (value); qt_src->default_fbo = g_value_get_boolean (value);
if (qt_src->window)
qt_window_use_default_fbo (qt_src->window, qt_src->default_fbo);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -508,7 +513,6 @@ gst_qt_src_change_state (GstElement * element, GstStateChange transition)
GstQtSrc *qt_src = GST_QT_SRC (element); GstQtSrc *qt_src = GST_QT_SRC (element);
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
QGuiApplication *app; QGuiApplication *app;
guint64 frames_rendered = 0;
GST_DEBUG ("changing state: %s => %s", GST_DEBUG ("changing state: %s => %s",
gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)), gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
@ -553,18 +557,10 @@ gst_qt_src_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
qt_src->run_time = gst_element_get_start_time (GST_ELEMENT (qt_src));
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
break; break;
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
qt_window_get_total_frames (qt_src->window, &frames_rendered);
if (qt_src->run_time > 0) {
GST_DEBUG ("qmlglsrc Total refresh frames (%ld), playing for (%"
GST_TIME_FORMAT "), fps (%.3f).\n", frames_rendered,
GST_TIME_ARGS (qt_src->run_time),
(gfloat) GST_SECOND * frames_rendered / qt_src->run_time);
}
break; break;
default: default:
break; break;

View file

@ -62,8 +62,6 @@ struct _GstQtSrc
gboolean default_fbo; gboolean default_fbo;
gboolean downstream_supports_affine_meta; gboolean downstream_supports_affine_meta;
gboolean pending_image_orientation; gboolean pending_image_orientation;
/* fps print support */
GstClockTime run_time;
}; };
/** /**

View file

@ -29,6 +29,7 @@
#include "gstqsgtexture.h" #include "gstqsgtexture.h"
#include "gstqtglutility.h" #include "gstqtglutility.h"
#include <QtCore/QDateTime>
#include <QtCore/QRunnable> #include <QtCore/QRunnable>
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtQuick/QQuickWindow> #include <QtQuick/QQuickWindow>
@ -67,7 +68,9 @@ struct _QtGLWindowPrivate
GstGLContext *other_context; GstGLContext *other_context;
/* frames that qmlview rendered in its gl thread */ /* frames that qmlview rendered in its gl thread */
guint64 frames_rendered; quint64 frames_rendered;
quint64 start;
quint64 stop;
}; };
class InitQtGLContext : public QRunnable class InitQtGLContext : public QRunnable
@ -141,6 +144,12 @@ QtGLWindow::beforeRendering()
g_mutex_lock (&this->priv->lock); g_mutex_lock (&this->priv->lock);
static volatile gsize once = 0;
if (g_once_init_enter(&once)) {
this->priv->start = QDateTime::currentDateTime().toMSecsSinceEpoch();
g_once_init_leave(&once,1);
}
if (!fbo && !this->priv->useDefaultFbo) { if (!fbo && !this->priv->useDefaultFbo) {
width = source->width(); width = source->width();
@ -152,6 +161,10 @@ QtGLWindow::beforeRendering()
QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGBA)); QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGBA));
source->setRenderTarget(fbo.data()); source->setRenderTarget(fbo.data());
} else if (this->priv->useDefaultFbo) {
GST_DEBUG ("use default fbo for render target");
fbo.reset(NULL);
source->setRenderTarget(NULL);
} }
g_mutex_unlock (&this->priv->lock); g_mutex_unlock (&this->priv->lock);
@ -236,9 +249,14 @@ QtGLWindow::aboutToQuit()
this->priv->quit = TRUE; this->priv->quit = TRUE;
g_cond_signal (&this->priv->update_cond); g_cond_signal (&this->priv->update_cond);
g_mutex_unlock (&this->priv->lock); this->priv->stop = QDateTime::currentDateTime().toMSecsSinceEpoch();
qint64 duration = this->priv->stop - this->priv->start;
float fps = ((float)this->priv->frames_rendered / duration * 1000);
GST_DEBUG("about to quit"); GST_DEBUG("about to quit, total refresh frames (%lld) in (%0.3f) seconds, fps: %0.3f",
this->priv->frames_rendered, (float)duration / 1000, fps);
g_mutex_unlock (&this->priv->lock);
} }
void void
@ -362,15 +380,3 @@ qt_window_use_default_fbo (QtGLWindow * qt_window, gboolean useDefaultFbo)
g_mutex_unlock (&qt_window->priv->lock); g_mutex_unlock (&qt_window->priv->lock);
} }
void
qt_window_get_total_frames (QtGLWindow * qt_window, guint64 *frames)
{
g_return_if_fail (qt_window != NULL);
g_mutex_lock (&qt_window->priv->lock);
*frames = qt_window->priv->frames_rendered;
g_mutex_unlock (&qt_window->priv->lock);
}

View file

@ -64,7 +64,6 @@ GstGLContext * qt_window_get_qt_context (QtGLWindow * qt_window);
GstGLDisplay * qt_window_get_display (QtGLWindow * qt_window); GstGLDisplay * qt_window_get_display (QtGLWindow * qt_window);
gboolean qt_window_is_scenegraph_initialized (QtGLWindow * qt_window); gboolean qt_window_is_scenegraph_initialized (QtGLWindow * qt_window);
void qt_window_use_default_fbo (QtGLWindow * qt_window, gboolean useDefaultFbo); void qt_window_use_default_fbo (QtGLWindow * qt_window, gboolean useDefaultFbo);
void qt_window_get_total_frames (QtGLWindow * qt_window, guint64 *frames);
} }
#endif /* __QT_WINDOW_H__ */ #endif /* __QT_WINDOW_H__ */