TARGET = ../libmltqt$(LIBSUF)
OBJS = factory.o producer_qimage.o producer_kdenlivetitle.o
-CPPOBJS = qimage_wrapper.o \
+CPPOBJS = common.o \
+ qimage_wrapper.o \
kdenlivetitle_wrapper.o \
consumer_qglsl.o \
producer_qtext.o
--- /dev/null
+/*
+ * Copyright (C) 2014 Dan Dennedy <dan@dennedy.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "common.h"
+#include <QApplication>
+#include <QLocale>
+
+#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+#include <X11/Xlib.h>
+#endif
+
+bool createQApplicationIfNeeded(mlt_service service)
+{
+ if (!qApp) {
+#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+ XInitThreads();
+ if (getenv("DISPLAY") == 0) {
+ mlt_log_error(service,
+ "The MLT Qt module requires a X11 environment.\n"
+ "Please either run melt from an X session or use a fake X server like xvfb:\n"
+ "xvfb-run -a melt (...)\n" );
+ return false;
+ }
+#endif
+ if (!mlt_properties_get(mlt_global_properties(), "qt_argv"))
+ mlt_properties_set(mlt_global_properties(), "qt_argv", "MLT");
+ static int argc = 1;
+ static char* argv[] = { mlt_properties_get(mlt_global_properties(), "Qt argv") };
+ new QApplication(argc, argv);
+ const char *localename = mlt_properties_get_lcnumeric(MLT_SERVICE_PROPERTIES(service));
+ QLocale::setDefault(QLocale(localename));
+ }
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Dan Dennedy <dan@dennedy.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <framework/mlt.h>
+
+bool createQApplicationIfNeeded(mlt_service service);
+
+#endif // COMMON_H
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "common.h"
#include <framework/mlt.h>
#include <QApplication>
-#include <QLocale>
#include <QGLWidget>
#include <QMutex>
#include <QWaitCondition>
#include <QtGlobal>
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
-#include <X11/Xlib.h>
-#endif
-
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
class GLWidget : public QGLWidget
mlt_events_listen(properties, consumer, "consumer-thread-started", (mlt_listener) onThreadStarted);
mlt_events_listen(properties, consumer, "consumer-thread-stopped", (mlt_listener) onThreadStopped);
mlt_events_listen(properties, consumer, "consumer-cleanup", (mlt_listener) onCleanup);
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
- XInitThreads();
- if ( getenv("DISPLAY") == 0 ) {
- mlt_log_error(MLT_CONSUMER_SERVICE(consumer), "The qglsl consumer requires a X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
- } else
-#endif
- if (!qApp) {
- int argc = 1;
- char* argv[1];
- argv[0] = (char*) "MLT qglsl consumer";
- new QApplication(argc, argv);
- const char *localename = mlt_properties_get_lcnumeric(properties);
- QLocale::setDefault(QLocale(localename));
+ if (!createQApplicationIfNeeded(MLT_CONSUMER_SERVICE(consumer))) {
+ mlt_filter_close(filter);
+ mlt_consumer_close(consumer);
+ return NULL;
}
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
mlt_properties_set_data(properties, "GLWidget", new GLWidget, 0, NULL, NULL);
*/
#include "kdenlivetitle_wrapper.h"
+#include "common.h"
#include <QImage>
#include <QPainter>
#include <QDebug>
-#include <QApplication>
#include <QMutex>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QGraphicsDropShadowEffect>
#endif
-static QApplication *app = NULL;
Q_DECLARE_METATYPE(QTextCursor);
class ImageItem: public QGraphicsItem
if ( scene == NULL )
{
- int argc = 1;
- char* argv[1];
- argv[0] = (char*) "xxx";
-
- // Warning: all Qt graphic objects (QRect, ...) must be initialized AFTER
- // the QApplication is created, otherwise their will be NULL
-
- if ( app == NULL ) {
- if ( qApp ) {
- app = qApp;
- }
- else {
-#ifdef linux
- if ( getenv("DISPLAY") == 0 )
- {
- mlt_log_panic( MLT_PRODUCER_SERVICE( producer ), "Error, cannot render titles without an X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
- pthread_mutex_unlock( &self->mutex );
- return;
- }
-#endif
- app = new QApplication( argc, argv );
- const char *localename = mlt_properties_get_lcnumeric( MLT_SERVICE_PROPERTIES( MLT_PRODUCER_SERVICE( producer ) ) );
- QLocale::setDefault( QLocale( localename ) );
- }
+ if ( !createQApplicationIfNeeded( MLT_PRODUCER_SERVICE(producer) ) )
+ return;
+ if ( QMetaType::UnknownType == QMetaType::type("QTextCursor") )
qRegisterMetaType<QTextCursor>( "QTextCursor" );
- }
scene = new QGraphicsScene();
scene->setItemIndexMethod( QGraphicsScene::NoIndex );
scene->setSceneRect(0, 0, mlt_properties_get_int( properties, "width" ), mlt_properties_get_int( properties, "height" ));
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "common.h"
#include <framework/mlt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <QApplication>
#include <QImage>
#include <QColor>
-#include <QLocale>
#include <QPainter>
#include <QFont>
#include <QString>
#include <QTextCodec>
#include <QTextDecoder>
-/** Init QT (if necessary)
-*/
-
-static bool init_qt( mlt_producer producer )
-{
- int argc = 1;
- char* argv[1];
- argv[0] = (char*) "xxx";
-
- if ( !qApp )
- {
-#ifdef linux
- if ( getenv("DISPLAY") == 0 )
- {
- mlt_log_panic( MLT_PRODUCER_SERVICE( producer ), "Error, cannot render titles without an X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
- return false;
- }
-#endif
- new QApplication( argc, argv );
- const char *localename = mlt_properties_get_lcnumeric( MLT_SERVICE_PROPERTIES( MLT_PRODUCER_SERVICE( producer ) ) );
- QLocale::setDefault( QLocale( localename ) );
- }
- return true;
-}
-
static void close_qimg( void* qimg )
{
delete static_cast<QImage*>( qimg );
// Initialize the producer
if ( producer )
{
- if( init_qt( producer ) == false )
+ if ( !createQApplicationIfNeeded( MLT_PRODUCER_SERVICE(producer) ) )
{
mlt_producer_close( producer );
return NULL;
*/
#include "qimage_wrapper.h"
+#include "common.h"
#ifdef USE_KDE4
#include <kcomponentdata.h>
#include <QImage>
#include <QSysInfo>
-#include <QApplication>
#include <QMutex>
#include <QtEndian>
#include <QTemporaryFile>
-#include <QLocale>
#ifdef USE_EXIF
#include <libexif/exif-data.h>
static KComponentData *instance = 0L;
#endif
-static QApplication *app = NULL;
-
static void qimage_delete( void *data )
{
QImage *image = ( QImage * )data;
sprintf( image_key, "%d", image_idx );
int disable_exif = mlt_properties_get_int( producer_props, "disable_exif" );
-
-
- if ( app == NULL )
- {
- if ( qApp )
- {
- app = qApp;
- }
- else
- {
-#ifdef linux
- if ( getenv("DISPLAY") == 0 )
- {
- mlt_log_panic( MLT_PRODUCER_SERVICE( producer ), "Error, cannot render titles without an X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
- return -1;
- }
-#endif
- int argc = 1;
- char* argv[1];
- argv[0] = (char*) "xxx";
- app = new QApplication( argc, argv );
- const char *localename = mlt_properties_get_lcnumeric( MLT_SERVICE_PROPERTIES( MLT_PRODUCER_SERVICE( producer ) ) );
- QLocale::setDefault( QLocale( localename ) );
- }
- }
+
+ if ( !createQApplicationIfNeeded( MLT_PRODUCER_SERVICE(producer) ) )
+ return -1;
if ( image_idx != self->qimage_idx )
self->qimage = NULL;
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
+#include "common.h"
#include <framework/mlt.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
-#include <QApplication>
#include <QImage>
#include <QColor>
-#include <QLocale>
#include <QPainter>
#include <QPalette>
#include <QFont>
#include <QString>
-static QApplication *app = 0;
-
static double calc_psnr( const uint8_t *a, const uint8_t *b, int size, int bpp )
{
double mse = 0.0;
}
}
- // create QApplication, if needed
- if ( !app )
- {
- if ( qApp )
- {
- app = qApp;
- }
- else
- {
- int argc = 1;
- char* argv[] = { strdup( "unknown" ) };
-
- app = new QApplication( argc, argv );
- const char *localename = mlt_properties_get_lcnumeric( MLT_TRANSITION_PROPERTIES(transition) );
- QLocale::setDefault( QLocale( localename ) );
- free( argv[0] );
- }
- }
-
// setup Qt drawing
QPainter painter;
painter.begin( &img );
{
mlt_properties properties = MLT_TRANSITION_PROPERTIES( transition );
+ if ( !createQApplicationIfNeeded( MLT_TRANSITION_SERVICE(transition) ) )
+ {
+ mlt_transition_close( transition );
+ return NULL;
+ }
transition->process = process;
mlt_properties_set_int( properties, "_transition_type", 1 ); // video only
mlt_properties_set_int( properties, "window_size", 8 );