From f1c9cd3a6a76c34d247d9b88ecd9adaa1b9003d2 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Thu, 4 Sep 2014 00:12:46 +0800 Subject: [PATCH] build without widgets module support --- QtAV.pro | 8 ++--- root.pri | 11 ++++-- src/AVPlayer.cpp | 9 +++-- src/QtAV/QPainterRenderer.h | 1 - src/QtAV/QtAV_Global.h | 6 ++++ src/QtAV/VideoRenderer.h | 1 + src/QtAV/VideoRendererTypes.h | 1 - src/QtAV_Global.cpp | 16 +++++++++ src/VideoRenderer.cpp | 67 ++++++++++++----------------------- src/VideoRendererTypes.cpp | 16 +++++---- src/libQtAV.pro | 36 ++++++++++++------- 11 files changed, 95 insertions(+), 77 deletions(-) diff --git a/QtAV.pro b/QtAV.pro index 8943db4de..71d1142b6 100644 --- a/QtAV.pro +++ b/QtAV.pro @@ -35,19 +35,19 @@ OptionalDepends = \ swresample \ avresample # QtOpenGL module. In Qt5 we can disable it and still have opengl support -!no-gl: OptionalDepends *= gl +!no-gl:!no-widgets: OptionalDepends *= gl !no-avfilter: OptionalDepends *= avfilter ## sse2 sse4_1 may be defined in Qt5 qmodule.pri but is not included. Qt4 defines sse and sse2 !no-sse4_1:!sse4_1: OptionalDepends *= sse4_1 # no-xxx can set in $$PWD/user.conf !no-openal: OptionalDepends *= openal !no-portaudio: OptionalDepends *= portaudio -!no-direct2d: OptionalDepends *= direct2d -!no-gdiplus: OptionalDepends *= gdiplus +!no-direct2d:!no-widgets: OptionalDepends *= direct2d +!no-gdiplus:!no-widgets: OptionalDepends *= gdiplus # why win32 is false? !no-dxva: OptionalDepends *= dxva unix { - !no-xv: OptionalDepends *= xv + !no-xv:!no-widgets: OptionalDepends *= xv !no-vaapi: OptionalDepends *= vaapi !no-cedarv: OptionalDepends *= libcedarv } diff --git a/root.pri b/root.pri index b0f21286f..912b73cef 100644 --- a/root.pri +++ b/root.pri @@ -85,7 +85,7 @@ defineTest(testArch) { #cache mkspecs. compare mkspec with cached one. if not equal, remove old cache to run new compile tests #Qt5 does not have QMAKE_MKSPECS, use QMAKE_SPEC, QMAKE_XSPEC -isEmpty(mkspecs_cached)|!isEmpty(mkspecs_cached):!isEqual(mkspecs_cached, $$mkspecs_build) { +isEmpty(mkspecs_cached)|!isEqual(mkspecs_cached, $$mkspecs_build) { CONFIG += recheck testArch() } else { @@ -98,13 +98,18 @@ cache(SOURCE_ROOT, set, SOURCE_ROOT) cache(mkspecs_cached, set, mkspecs_build) # no-framework can be defined in user.conf. default is the same as QT_CONFIG - MAC_LIB = mac_dylib +MAC_LIB = mac_dylib no-framework { cache(CONFIG, add, MAC_LIB) } else { cache(CONFIG, sub, MAC_LIB) } - +NO_WIDGETS = no_widgets +no-widgets { + cache(CONFIG, add, NO_WIDGETS) +} else { + cache(CONFIG, sub, NO_WIDGETS) +} defineTest(runConfigTests) { no_config_tests:return(false) #config.tests diff --git a/src/AVPlayer.cpp b/src/AVPlayer.cpp index 7b8b6632b..b1e0c233a 100644 --- a/src/AVPlayer.cpp +++ b/src/AVPlayer.cpp @@ -23,11 +23,13 @@ #include -#include +#include #include #include #include - +#if QTAV_HAVE(WIDGETS) +#include +#endif //QTAV_HAVE(WIDGETS) #include "QtAV/AVDemuxer.h" #include "QtAV/AudioFormat.h" #include "QtAV/AudioResampler.h" @@ -38,7 +40,6 @@ #include "QtAV/AVClock.h" #include "QtAV/VideoCapture.h" #include "QtAV/VideoDecoderTypes.h" -#include "QtAV/WidgetRenderer.h" #include "QtAV/VideoThread.h" #include "QtAV/AVDemuxThread.h" #include "QtAV/VideoCapture.h" @@ -184,6 +185,7 @@ void AVPlayer::addVideoRenderer(VideoRenderer *renderer) return; } renderer->setStatistics(&mStatistics); +#if QTAV_HAVE(WIDGETS) QObject *voo = renderer->widget(); if (voo) { //TODO: how to delete filter if no parent? @@ -191,6 +193,7 @@ void AVPlayer::addVideoRenderer(VideoRenderer *renderer) if (renderer->widget()) voo->installEventFilter(new VideoOutputEventFilter(renderer)); } +#endif //QTAV_HAVE(WIDGETS) mpVOSet->addOutput(renderer); } diff --git a/src/QtAV/QPainterRenderer.h b/src/QtAV/QPainterRenderer.h index a6ecfbce9..59d203b4b 100644 --- a/src/QtAV/QPainterRenderer.h +++ b/src/QtAV/QPainterRenderer.h @@ -33,7 +33,6 @@ class Q_AV_EXPORT QPainterRenderer : public VideoRenderer DPTR_DECLARE_PRIVATE(QPainterRenderer) public: QPainterRenderer(); - virtual VideoRendererId id () const; virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const; //virtual QImage currentFrameImage() const; protected: diff --git a/src/QtAV/QtAV_Global.h b/src/QtAV/QtAV_Global.h index 19023fd84..15fdde19d 100644 --- a/src/QtAV/QtAV_Global.h +++ b/src/QtAV/QtAV_Global.h @@ -71,5 +71,11 @@ Q_AV_EXPORT void setFFmpegLogHandler(void(*)(void *, int, const char *, va_list) #define GCC_VERSION_AT_LEAST(major, minor, patch) 0 #endif +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) || defined(QT_WIDGETS_LIB) +#ifndef QTAV_HAVE_WIDGETS +#define QTAV_HAVE_WIDGETS 1 +#endif //QTAV_HAVE_WIDGETS +#endif + #endif // QTAV_GLOBAL_H diff --git a/src/QtAV/VideoRenderer.h b/src/QtAV/VideoRenderer.h index a72aa265a..59ade14c3 100644 --- a/src/QtAV/VideoRenderer.h +++ b/src/QtAV/VideoRenderer.h @@ -225,6 +225,7 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput virtual bool onSetContrast(qreal contrast); virtual bool onSetHue(qreal hue); virtual bool onSetSaturation(qreal saturation); + void updateUi(); private: friend class VideoOutput; //the size of decoded frame. get called in receiveFrame(). internal use only diff --git a/src/QtAV/VideoRendererTypes.h b/src/QtAV/VideoRendererTypes.h index f9e494441..25551b216 100644 --- a/src/QtAV/VideoRendererTypes.h +++ b/src/QtAV/VideoRendererTypes.h @@ -28,7 +28,6 @@ namespace QtAV { //Q_AV_EXPORT(dllexport/import) is needed if used out of the library //TODO graphics item? -extern Q_AV_EXPORT VideoRendererId VideoRendererId_QPainter; extern Q_AV_EXPORT VideoRendererId VideoRendererId_Widget; extern Q_AV_EXPORT VideoRendererId VideoRendererId_GraphicsItem; extern Q_AV_EXPORT VideoRendererId VideoRendererId_GLWidget; diff --git a/src/QtAV_Global.cpp b/src/QtAV_Global.cpp index 20addb9ca..c78869b8c 100644 --- a/src/QtAV_Global.cpp +++ b/src/QtAV_Global.cpp @@ -22,11 +22,14 @@ #include "QtAV/QtAV_Global.h" #include #include +#include +#if QTAV_HAVE(WIDGETS) #include #include #include #include #include +#endif //QTAV_HAVE(WIDGETS) #include "QtAV/version.h" #include "QtAV/private/AVCompat.h" @@ -50,6 +53,7 @@ namespace QtAV { //TODO: auto add new depend libraries information void about() { +#if QTAV_HAVE(WIDGETS) //we should use new because a qobject will delete it's children QTextBrowser *viewQtAV = new QTextBrowser; QTextBrowser *viewFFmpeg = new QTextBrowser; @@ -72,11 +76,19 @@ void about() layout->addLayout(btnLayout); QObject::connect(btn, SIGNAL(clicked()), &dialog, SLOT(accept())); dialog.exec(); +#else + aboutQtAV(); + aboutFFmpeg(); +#endif //QTAV_HAVE(WIDGETS) } void aboutFFmpeg() { +#if QTAV_HAVE(WIDGETS) QMessageBox::about(0, QObject::tr("About FFmpeg"), aboutFFmpeg_HTML()); +#else + qDebug() << aboutFFmpeg_PlainText(); +#endif } QString aboutFFmpeg_PlainText() @@ -134,7 +146,11 @@ QString aboutFFmpeg_HTML() void aboutQtAV() { +#if QTAV_HAVE(WIDGETS) QMessageBox::about(0, QObject::tr("About QtAV"), aboutQtAV_HTML()); +#else + qDebug() << aboutQtAV_PlainText(); +#endif //QTAV_HAVE(WIDGETS) } QString aboutQtAV_PlainText() diff --git a/src/VideoRenderer.cpp b/src/VideoRenderer.cpp index 184354086..ff395642a 100644 --- a/src/VideoRenderer.cpp +++ b/src/VideoRenderer.cpp @@ -23,8 +23,10 @@ #include #include #include +#if QTAV_HAVE(WIDGETS) #include #include +#endif //QTAV_HAVE(WIDGETS) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #include #endif @@ -481,17 +483,7 @@ bool VideoRenderer::setBrightness(qreal brightness) d.brightness = old; return false; } - // TODO: qwindow() and widget() can both use event? -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - if (qwindow()) { - qApp->postEvent(qwindow(), new QEvent(QEvent::UpdateRequest)); - } -#endif - if (widget()) { - widget()->update(); - } else if (graphicsItem()) { - graphicsItem()->update(); - } + updateUi(); return true; } @@ -512,17 +504,7 @@ bool VideoRenderer::setContrast(qreal contrast) d.contrast = old; return false; } - // TODO: qwindow() and widget() can both use event? -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - if (qwindow()) { - qApp->postEvent(qwindow(), new QEvent(QEvent::UpdateRequest)); - } -#endif - if (widget()) { - widget()->update(); - } else if (graphicsItem()) { - graphicsItem()->update(); - } + updateUi(); return true; } @@ -540,21 +522,10 @@ bool VideoRenderer::setHue(qreal hue) qreal old = d.hue; d.hue = hue; if (!onSetHue(hue)) { - qWarning("onSetHue failed"); d.hue = old; return false; } - // TODO: qwindow() and widget() can both use event? -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - if (qwindow()) { - qApp->postEvent(qwindow(), new QEvent(QEvent::UpdateRequest)); - } -#endif - if (widget()) { - widget()->update(); - } else if (graphicsItem()) { - graphicsItem()->update(); - } + updateUi(); return true; } @@ -575,17 +546,7 @@ bool VideoRenderer::setSaturation(qreal saturation) d.saturation = old; return false; } - // TODO: qwindow() and widget() can both use event? -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - if (qwindow()) { - qApp->postEvent(qwindow(), new QEvent(QEvent::UpdateRequest)); - } -#endif - if (widget()) { - widget()->update(); - } else if (graphicsItem()) { - graphicsItem()->update(); - } + updateUi(); return true; } @@ -613,5 +574,21 @@ bool VideoRenderer::onSetSaturation(qreal s) return false; } +void VideoRenderer::updateUi() +{ + // TODO: qwindow() and widget() can both use event? +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + if (qwindow()) { + qApp->postEvent(qwindow(), new QEvent(QEvent::UpdateRequest)); + } +#endif +#if QTAV_HAVE(WIDGETS) + if (widget()) { + widget()->update(); + } else if (graphicsItem()) { + graphicsItem()->update(); + } +#endif //QTAV_HAVE(WIDGETS) +} } //namespace QtAV diff --git a/src/VideoRendererTypes.cpp b/src/VideoRendererTypes.cpp index d877d60bd..d426fc7ea 100644 --- a/src/VideoRendererTypes.cpp +++ b/src/VideoRendererTypes.cpp @@ -23,8 +23,10 @@ #include #include #include "QtAV/prepost.h" +#if QTAV_HAVE(WIDGETS) #include "QtAV/WidgetRenderer.h" #include "QtAV/GraphicsItemRenderer.h" +#endif #if QTAV_HAVE(GL) #include "QtAV/GLWidgetRenderer2.h" #endif //QTAV_HAVE(GL) @@ -43,7 +45,6 @@ namespace QtAV { FACTORY_DEFINE(VideoRenderer) -VideoRendererId VideoRendererId_QPainter = 1; VideoRendererId VideoRendererId_Widget = 2; VideoRendererId VideoRendererId_GraphicsItem = 3; VideoRendererId VideoRendererId_GLWidget = 4; @@ -54,6 +55,7 @@ VideoRendererId VideoRendererId_GLWidget2 = 8; VideoRendererId VideoRendererId_OpenGLWindow = 9; VideoRendererId VideoRendererId_OpenGLWidget = 10; +#if QTAV_HAVE(WIDGETS) //QPainterRenderer is abstract. So can not register(operator new will needed) FACTORY_REGISTER_ID_AUTO(VideoRenderer, Widget, "QWidegt") @@ -78,11 +80,7 @@ VideoRendererId GraphicsItemRenderer::id() const { return VideoRendererId_GraphicsItem; } - -VideoRendererId QPainterRenderer::id() const -{ - return VideoRendererId_QPainter; -} +#endif //QTAV_HAVE(WIDGETS) #if QTAV_HAVE(GL) #if QTAV_HAVE(GL1) @@ -97,7 +95,7 @@ VideoRendererId GLWidgetRenderer::id() const return VideoRendererId_GLWidget; } #endif //QTAV_HAVE(GL1) - +#if QTAV_HAVE(WIDGETS) FACTORY_REGISTER_ID_AUTO(VideoRenderer, GLWidget2, "QGLWidegt2") void RegisterVideoRendererGLWidget2_Man() @@ -109,6 +107,7 @@ VideoRendererId GLWidgetRenderer2::id() const { return VideoRendererId_GLWidget2; } +#endif #endif //QTAV_HAVE(GL) #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) FACTORY_REGISTER_ID_AUTO(VideoRenderer, OpenGLWindow, "OpenGLWindow") @@ -143,7 +142,10 @@ extern void RegisterVideoRendererXV_Man(); void VideoRenderer_RegisterAll() { +#if QTAV_HAVE(WIDGETS) RegisterVideoRendererWidget_Man(); + RegisterVideoRendererGraphicsItem_Man(); +#endif //QTAV_HAVE(WIDGETS) #if QTAV_HAVE(GL) RegisterVideoRendererGLWidget2_Man(); #endif //QTAV_HAVE(GL) diff --git a/src/libQtAV.pro b/src/libQtAV.pro index 0943934d8..9d71ca4b6 100644 --- a/src/libQtAV.pro +++ b/src/libQtAV.pro @@ -3,7 +3,12 @@ MODULE_INCNAME = QtAV # for mac framework. also used in install_sdk.pro TARGET = QtAV QT += core gui greaterThan(QT_MAJOR_VERSION, 4) { - QT += widgets + qtHaveModule(widgets):!no_widgets { + QT += widgets + DEFINES *= QTAV_HAVE_WIDGETS=1 + } else { + CONFIG *= gui_only + } CONFIG *= config_opengl greaterThan(QT_MINOR_VERSION, 3) { CONFIG *= config_openglwindow @@ -151,22 +156,33 @@ config_opensl { DEFINES *= QTAV_HAVE_OPENSL=1 LIBS += -lOpenSLES } -config_gdiplus { +!gui_only: { + SDK_HEADERS *= \ + QtAV/GraphicsItemRenderer.h \ + QtAV/WidgetRenderer.h + HEADERS *= QtAV/private/VideoOutputEventFilter.h + SOURCES *= \ + VideoOutputEventFilter.cpp \ + GraphicsItemRenderer.cpp \ + WidgetRenderer.cpp + config_gdiplus { DEFINES *= QTAV_HAVE_GDIPLUS=1 SOURCES += GDIRenderer.cpp LIBS += -lgdiplus -lgdi32 -} -config_direct2d { + } + config_direct2d { DEFINES *= QTAV_HAVE_DIRECT2D=1 !*msvc*: INCLUDEPATH += $$PROJECTROOT/contrib/d2d1headers SOURCES += Direct2DRenderer.cpp #LIBS += -lD2d1 -} -config_xv { + } + config_xv { DEFINES *= QTAV_HAVE_XV=1 SOURCES += XVRenderer.cpp LIBS += -lXv + } } + CONFIG += config_cuda #config_dllapi config_dllapi_cuda #CONFIG += config_cuda_link config_cuda { @@ -246,7 +262,7 @@ config_gl|config_opengl { config_openglwindow { SDK_HEADERS *= QtAV/OpenGLWindowRenderer.h SOURCES *= OpenGLWindowRenderer.cpp - qtHaveModule(widgets) { + !gui_only { SDK_HEADERS *= QtAV/OpenGLWidgetRenderer.h SOURCES *= OpenGLWidgetRenderer.cpp } @@ -278,7 +294,6 @@ SOURCES += \ filter/FilterManager.cpp \ filter/LibAVFilter.cpp \ filter/SubtitleFilter.cpp \ - GraphicsItemRenderer.cpp \ ImageConverter.cpp \ ImageConverterFF.cpp \ QPainterRenderer.cpp \ @@ -292,8 +307,6 @@ SOURCES += \ VideoRenderer.cpp \ VideoRendererTypes.cpp \ VideoOutput.cpp \ - VideoOutputEventFilter.cpp \ - WidgetRenderer.cpp \ AVOutput.cpp \ OutputSet.cpp \ Statistics.cpp \ @@ -324,7 +337,6 @@ SDK_HEADERS *= \ QtAV/FilterContext.h \ QtAV/LibAVFilter.h \ QtAV/Frame.h \ - QtAV/GraphicsItemRenderer.h \ QtAV/ImageConverter.h \ QtAV/ImageConverterTypes.h \ QtAV/QPainterRenderer.h \ @@ -335,7 +347,6 @@ SDK_HEADERS *= \ QtAV/VideoRenderer.h \ QtAV/VideoRendererTypes.h \ QtAV/VideoOutput.h \ - QtAV/WidgetRenderer.h \ QtAV/AVOutput.h \ QtAV/AVClock.h \ QtAV/VideoDecoder.h \ @@ -367,7 +378,6 @@ SDK_PRIVATE_HEADERS *= \ QtAV/private/VideoShader_p.h \ QtAV/private/VideoDecoder_p.h \ QtAV/private/VideoDecoderFFmpegHW_p.h \ - QtAV/private/VideoOutputEventFilter.h \ QtAV/private/VideoRenderer_p.h \ QtAV/private/QPainterRenderer_p.h