Skip to content

Commit

Permalink
Add vui property to QmlMetadata and connect it to GLWidget.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Aug 9, 2014
1 parent 44589f2 commit 9a0acb2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/docks/filtersdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void FiltersDock::onProducerOpened()
onModelChanged();
ui->addAudioButton->setEnabled(MLT.isClip());
ui->addVideoButton->setEnabled(MLT.isClip());
MLT.videoQuickView()->setSource(QUrl());
}

void FiltersDock::setProducer(Mlt::Producer *producer)
Expand Down Expand Up @@ -225,6 +226,7 @@ void FiltersDock::on_removeButton_clicked()
delete ui->scrollArea->widget();
ui->scrollArea->setWidget(0);
m_quickObject = 0;
MLT.videoQuickView()->setSource(QUrl());
}
}

Expand Down Expand Up @@ -290,4 +292,7 @@ void FiltersDock::loadQuickPanel(const QmlMetadata* metadata, int row)
container->setFocusPolicy(Qt::TabFocus);
loadWidgetsPanel(container);
m_quickObject = qqview->rootObject();

MLT.videoQuickView()->rootContext()->setContextProperty("filter", qmlFilter);
MLT.videoQuickView()->setSource(QUrl::fromLocalFile(metadata->vuiFilePath()));
}
55 changes: 38 additions & 17 deletions src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QOpenGLFunctions_3_2_Core>
#include <QUrl>
#include <QOffscreenSurface>
#include <QtQml>
#include <Mlt.h>
#include "glwidget.h"
#include "settings.h"
Expand All @@ -46,7 +47,6 @@ using namespace Mlt;
GLWidget::GLWidget(QObject *parent)
: QQuickView((QWindow*) parent)
, Controller()
, m_display_ratio(4.0/3.0)
, m_shader(0)
, m_glslManager(0)
, m_isInitialized(false)
Expand All @@ -63,6 +63,11 @@ GLWidget::GLWidget(QObject *parent)
setPersistentSceneGraph(true);
setClearBeforeRendering(false);
setResizeMode(QQuickView::SizeRootObjectToView);
QDir importPath = QmlUtilities::qmlDir();
importPath.cd("modules");
engine()->addImportPath(importPath.path());
QmlUtilities::setCommonProperties(rootContext());
rootContext()->setContextProperty("video", this);

if (Settings.playerGPU())
m_glslManager = new Filter(profile(), "glsl.manager");
Expand Down Expand Up @@ -98,6 +103,7 @@ GLWidget::~GLWidget()
delete m_threadJoinEvent;
delete m_lastFrame;
if (m_frameRenderer && m_frameRenderer->isRunning()) {
QMetaObject::invokeMethod(m_frameRenderer, "cleanup");
m_frameRenderer->quit();
m_frameRenderer->wait();
delete m_frameRenderer;
Expand Down Expand Up @@ -152,31 +158,35 @@ void GLWidget::initializeGL()

void GLWidget::resizeGL(int width, int height)
{
int x, y, w, h;
width *= devicePixelRatio();
height *= devicePixelRatio();
qDebug() << width << 'x' << height;
double this_aspect = (double) width / height;
double video_aspect = profile().dar();
qDebug() << width << 'x' << height;

// Special case optimisation to negate odd effect of sample aspect ratio
// not corresponding exactly with image resolution.
if ((int) (this_aspect * 1000) == (int) (m_display_ratio * 1000))
if ((int) (this_aspect * 1000) == (int) (video_aspect * 1000))
{
w = width;
h = height;
}
// Use OpenGL to normalise sample aspect ratio
else if (height * m_display_ratio > width)
else if (height * video_aspect > width)
{
w = width;
h = width / m_display_ratio;
h = width / video_aspect;
}
else
{
w = height * m_display_ratio;
w = height * video_aspect;
h = height;
}
x = (width - w) / 2;
y = (height - h) / 2;
m_rect.setRect(x, y, w, h);
emit rectChanged();
}

void GLWidget::resizeEvent(QResizeEvent* event)
Expand Down Expand Up @@ -256,6 +266,8 @@ void GLWidget::paintGL()
glClear(GL_COLOR_BUFFER_BIT);
check_error();

if (!m_texture[0]) return;

// Bind textures.
for (int i = 0; i < 3; ++i) {
if (m_texture[i]) {
Expand Down Expand Up @@ -285,10 +297,10 @@ void GLWidget::paintGL()

// Provide vertices of triangle strip.
QVector<QVector2D> vertices;
vertices << QVector2D(float(-w)/2.0f, float(-h)/2.0f);
vertices << QVector2D(float(-w)/2.0f, float( h)/2.0f);
vertices << QVector2D(float( w)/2.0f, float(-h)/2.0f);
vertices << QVector2D(float( w)/2.0f, float( h)/2.0f);
vertices << QVector2D(float(-m_rect.width())/2.0f, float(-m_rect.height())/2.0f);
vertices << QVector2D(float(-m_rect.width())/2.0f, float( m_rect.height())/2.0f);
vertices << QVector2D(float( m_rect.width())/2.0f, float(-m_rect.height())/2.0f);
vertices << QVector2D(float( m_rect.width())/2.0f, float( m_rect.height())/2.0f);
m_shader->enableAttributeArray(m_vertexLocation);
check_error();
m_shader->setAttributeArray(m_vertexLocation, vertices.constData());
Expand Down Expand Up @@ -327,6 +339,7 @@ void GLWidget::paintGL()
void GLWidget::mousePressEvent(QMouseEvent* event)
{
QQuickView::mousePressEvent(event);
if (event->isAccepted()) return;
if (event->button() == Qt::LeftButton)
m_dragStart = event->pos();
if (MLT.isClip())
Expand All @@ -336,6 +349,7 @@ void GLWidget::mousePressEvent(QMouseEvent* event)
void GLWidget::mouseMoveEvent(QMouseEvent* event)
{
QQuickView::mouseMoveEvent(event);
if (event->isAccepted()) return;
if (event->modifiers() == Qt::ShiftModifier && m_producer) {
emit seekTo(m_producer->get_length() * event->x() / width());
return;
Expand Down Expand Up @@ -437,8 +451,10 @@ int GLWidget::setProducer(Mlt::Producer* producer, bool isMulti)

if (!error) {
error = reconfigure(isMulti);
if (!error)
if (!error) {
// The profile display aspect ratio may have changed.
resizeGL(width(), height());
}
}
return error;
}
Expand Down Expand Up @@ -494,7 +510,6 @@ int GLWidget::reconfigure(bool isMulti)
}
m_consumer->set("mlt_image_format", "yuv422");
m_consumer->set("color_trc", Settings.playerGamma().toLatin1().constData());
m_display_ratio = profile().dar();

if (isMulti) {
m_consumer->set("terminate_on_pause", 0);
Expand Down Expand Up @@ -633,11 +648,6 @@ FrameRenderer::FrameRenderer(QOpenGLContext* shareContext)
FrameRenderer::~FrameRenderer()
{
qDebug();
if (m_texture[0] && m_texture[1] && m_texture[2]) {
m_context->makeCurrent(m_surface);
glDeleteTextures(3, m_texture);
m_context->doneCurrent();
}
delete m_context;
delete m_gl32;
delete m_frame;
Expand Down Expand Up @@ -748,3 +758,14 @@ void FrameRenderer::showFrame(Mlt::QFrame frame)
}
m_semaphore.release();
}

void FrameRenderer::cleanup()
{
qDebug();
if (m_texture[0] && m_texture[1] && m_texture[2]) {
m_context->makeCurrent(m_surface);
glDeleteTextures(3, m_texture);
m_context->doneCurrent();
m_texture[0] = m_texture[1] = m_texture[2] = 0;
}
}
12 changes: 8 additions & 4 deletions src/glwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QMutex>
#include <QWaitCondition>
#include <QThread>
#include <QRect>
#include "mltcontroller.h"

class QOpenGLFunctions_3_2_Core;
Expand All @@ -45,6 +46,7 @@ typedef void* ( *thread_function_t )( void* );
class GLWidget : public QQuickView, public Controller, protected QOpenGLFunctions
{
Q_OBJECT
Q_PROPERTY(QRect rect MEMBER m_rect NOTIFY rectChanged)

public:
GLWidget(QObject *parent = 0);
Expand Down Expand Up @@ -72,10 +74,11 @@ class GLWidget : public QQuickView, public Controller, protected QOpenGLFunction
Controller::pause();
emit paused();
}
int displayWidth() const { return w / devicePixelRatio(); }
int displayHeight() const { return h / devicePixelRatio(); }
int displayWidth() const { return m_rect.width() / devicePixelRatio(); }
int displayHeight() const { return m_rect.height() / devicePixelRatio(); }

QObject* videoWidget() { return this; }
QQuickView* videoQuickView() { return this; }
Filter* glslManager() const { return m_glslManager; }
FrameRenderer* frameRenderer() const { return m_frameRenderer; }

Expand All @@ -91,11 +94,11 @@ class GLWidget : public QQuickView, public Controller, protected QOpenGLFunction
void started();
void paused();
void playing();
void rectChanged();

private:
int x, y, w, h;
QRect m_rect;
GLuint m_texture[3];
double m_display_ratio;
QOpenGLShaderProgram* m_shader;
QPoint m_dragStart;
Filter* m_glslManager;
Expand Down Expand Up @@ -156,6 +159,7 @@ class FrameRenderer : public QThread

public slots:
void showFrame(Mlt::QFrame frame);
void cleanup();

signals:
void textureReady(GLuint yName, GLuint uName = 0, GLuint vName = 0);
Expand Down
3 changes: 2 additions & 1 deletion src/mltcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "transportcontrol.h"

// forward declarations
class QWidget;
class QQuickView;

namespace Mlt {

Expand Down Expand Up @@ -87,6 +87,7 @@ class Controller
static void destroy();

virtual QObject* videoWidget() = 0;
virtual QQuickView* videoQuickView() = 0;
virtual int setProducer(Mlt::Producer*, bool isMulti = false);
virtual int open(const QString& url);
bool openXML(const QString& filename);
Expand Down
11 changes: 11 additions & 0 deletions src/qmltypes/qmlmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ QmlMetadata::QmlMetadata(QObject *parent)
, m_type(Filter)
, m_needsGPU(false)
, m_qmlFileName("ui.qml")
, m_vuiFileName("vui.qml")
, m_isAudio(false)
, m_isHidden(false)
{
Expand Down Expand Up @@ -53,6 +54,11 @@ void QmlMetadata::setQmlFileName(const QString &fileName)
m_qmlFileName = fileName;
}

void QmlMetadata::setVuiFileName(const QString &fileName)
{
m_vuiFileName = fileName;
}

void QmlMetadata::setPath(const QDir &path)
{
m_path = path;
Expand All @@ -63,6 +69,11 @@ QString QmlMetadata::qmlFilePath() const
return m_path.absoluteFilePath(m_qmlFileName);
}

QString QmlMetadata::vuiFilePath() const
{
return m_path.absoluteFilePath(m_vuiFileName);
}

void QmlMetadata::setIsAudio(bool isAudio)
{
m_isAudio = isAudio;
Expand Down
5 changes: 5 additions & 0 deletions src/qmltypes/qmlmetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class QmlMetadata : public QObject
Q_PROPERTY(QString mlt_service READ mlt_service WRITE set_mlt_service)
Q_PROPERTY(bool needsGPU READ needsGPU WRITE setNeedsGPU)
Q_PROPERTY(QString qml READ qmlFileName WRITE setQmlFileName)
Q_PROPERTY(QString vui READ vuiFileName WRITE setVuiFileName)
Q_PROPERTY(bool isAudio READ isAudio WRITE setIsAudio)
Q_PROPERTY(bool isHidden READ isHidden WRITE setIsHidden)

Expand All @@ -54,9 +55,12 @@ class QmlMetadata : public QObject
void setNeedsGPU(bool);
QString qmlFileName() const { return m_qmlFileName; }
void setQmlFileName(const QString&);
QString vuiFileName() const { return m_vuiFileName; }
void setVuiFileName(const QString&);
QDir path() const { return m_path; }
void setPath(const QDir& path);
QString qmlFilePath() const;
QString vuiFilePath() const;
bool isAudio() const { return m_isAudio; }
void setIsAudio(bool isAudio);
bool isHidden() const { return m_isHidden; }
Expand All @@ -68,6 +72,7 @@ class QmlMetadata : public QObject
QString m_mlt_service;
bool m_needsGPU;
QString m_qmlFileName;
QString m_vuiFileName;
QDir m_path;
bool m_isAudio;
bool m_isHidden;
Expand Down

0 comments on commit 9a0acb2

Please sign in to comment.