first commit

This commit is contained in:
2026-02-21 17:11:31 +09:00
commit 18b4338361
4001 changed files with 365464 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,87 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2015 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_GLWIDGETRENDERER_H
#define QTAV_GLWIDGETRENDERER_H
#if !(TEST_GRAPHIC_ACCEL)
#define REMOVE_RENDERER1 1
#endif
#if !(REMOVE_RENDERER1)
#include "global.h"
#include "../VideoRenderer.h"
#include <QtOpenGL/QGLWidget>
// TODO: QGLFunctions is in Qt4.8+. meego is 4.7
#define QTAV_HAVE_QGLFUNCTIONS QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
#if QTAV_HAVE(QGLFUNCTIONS)
#include <QtOpenGL/QGLFunctions>
#endif
namespace FAV {
class GLWidgetRendererPrivate;
class Q_AVWIDGETS_EXPORT GLWidgetRenderer : public QGLWidget, public VideoRenderer
#if QTAV_HAVE(QGLFUNCTIONS) //TODO: why use QT_VERSION will result in moc error?
, public QGLFunctions
#endif //QTAV_HAVE(QGLFUNCTIONS)
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(GLWidgetRenderer)
public:
GLWidgetRenderer(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const;
virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const;
virtual QWidget* widget() { return this; }
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool needUpdateBackground() const;
//called in paintEvent before drawFrame() when required
virtual void drawBackground();
//draw the current frame using the current paint engine. called by paintEvent()
virtual void drawFrame();
virtual void initializeGL();
virtual void paintGL();
virtual void resizeGL(int w, int h);
virtual void resizeEvent(QResizeEvent *);
virtual void showEvent(QShowEvent *);
private:
virtual void onSetOutAspectRatioMode(OutAspectRatioMode mode);
virtual void onSetOutAspectRatio(qreal ratio);
virtual bool onSetOrientation(int value);
/*!
* \brief onSetBrightness
* only works for GLSL. otherwise return false, means that do nothing, brightness() does not change.
* \return
*/
virtual bool onSetBrightness(qreal b);
virtual bool onSetContrast(qreal c);
virtual bool onSetHue(qreal h);
virtual bool onSetSaturation(qreal s);
};
typedef GLWidgetRenderer VideoRendererGLWidget;
} //namespace FAV
#endif // QTAV_GLWidgetRenderer_H
#endif // #if !(REMOVE_RENDERER1)

View File

@@ -0,0 +1,99 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2014)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "GLWidgetRenderer2.h"
#if !(REMOVE_RENDERER2)
#include "../OpenGLRendererBase_p.h"
#include <QResizeEvent>
namespace FAV {
class GLWidgetRenderer2Private : public OpenGLRendererBasePrivate
{
public:
GLWidgetRenderer2Private(QPaintDevice *pd)
: OpenGLRendererBasePrivate(pd)
{}
};
VideoRendererId GLWidgetRenderer2::id() const
{
return VideoRendererId_GLWidget2;
}
GLWidgetRenderer2::GLWidgetRenderer2(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFlags f):
QGLWidget(parent, shareWidget, f)
, OpenGLRendererBase(*new GLWidgetRenderer2Private(this))
{
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
/* To rapidly update custom widgets that constantly paint over their entire areas with
* opaque content, e.g., video streaming widgets, it is better to set the widget's
* Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead associated with repainting the
* widget's background
*/
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
//default: swap in qpainter dtor. we should swap before QPainter.endNativePainting()
setAutoBufferSwap(false);
setAutoFillBackground(false);
}
void GLWidgetRenderer2::initializeGL()
{
// already current
onInitializeGL();
}
void GLWidgetRenderer2::paintGL()
{
DPTR_D(GLWidgetRenderer2);
/* we can mix gl and qpainter.
* QPainter painter(this);
* painter.beginNativePainting();
* gl functions...
* painter.endNativePainting();
* swapBuffers();
*/
handlePaintEvent();
swapBuffers();
if (d.painter && d.painter->isActive())
d.painter->end();
}
void GLWidgetRenderer2::resizeGL(int w, int h)
{
onResizeGL(w, h);
}
void GLWidgetRenderer2::resizeEvent(QResizeEvent *e)
{
onResizeEvent(e->size().width(), e->size().height());
QGLWidget::resizeEvent(e); //will call resizeGL(). TODO:will call paintEvent()?
}
void GLWidgetRenderer2::showEvent(QShowEvent *)
{
onShowEvent();
resizeGL(width(), height());
}
} //namespace FAV
#endif // #if !(REMOVE_RENDERER2)

View File

@@ -0,0 +1,93 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2014)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_GLWIDGETRENDERER2_H
#define QTAV_GLWIDGETRENDERER2_H
#if !(TEST_GRAPHIC_ACCEL)
#define REMOVE_RENDERER2 1
#endif //
#if !(REMOVE_RENDERER2)
#ifndef QT_NO_OPENGL
#include "global.h"
#include <QtOpenGL/QGLWidget>
#include "../OpenGLRendererBase.h"
namespace FAV {
class GLWidgetRenderer2Private;
/*!
* \brief The GLWidgetRenderer2 class
* Renderering video frames using GLSL. A more generic high level class OpenGLVideo is used internally.
* TODO: for Qt5, no QtOpenGL, use QWindow instead.
*/
class Q_AVWIDGETS_EXPORT GLWidgetRenderer2 : public QGLWidget, public OpenGLRendererBase
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(GLWidgetRenderer2)
Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
//fillMode
// TODO: how to use enums in base class as property or Q_ENUM
Q_PROPERTY(OutAspectRatioMode outAspectRatioMode READ outAspectRatioMode WRITE setOutAspectRatioMode NOTIFY outAspectRatioModeChanged)
Q_ENUMS(OutAspectRatioMode)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(QRect videoRect READ videoRect NOTIFY videoRectChanged)
Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_ENUMS(Quality)
public:
GLWidgetRenderer2(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const Q_DECL_OVERRIDE;
virtual QWidget* widget() Q_DECL_OVERRIDE { return this; }
Q_SIGNALS:
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE Q_DECL_FINAL;
void regionOfInterestChanged() Q_DECL_OVERRIDE;
void outAspectRatioChanged() Q_DECL_OVERRIDE;
void outAspectRatioModeChanged() Q_DECL_OVERRIDE;
void brightnessChanged(qreal value) Q_DECL_OVERRIDE;
void contrastChanged(qreal) Q_DECL_OVERRIDE;
void hueChanged(qreal) Q_DECL_OVERRIDE;
void saturationChanged(qreal) Q_DECL_OVERRIDE;
void orientationChanged() Q_DECL_OVERRIDE;
void videoRectChanged() Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
protected:
virtual void initializeGL() Q_DECL_OVERRIDE;
virtual void paintGL() Q_DECL_OVERRIDE;
virtual void resizeGL(int w, int h) Q_DECL_OVERRIDE;
virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; // not virtual in QGLWidget (Qt<5.5)
virtual void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
};
typedef GLWidgetRenderer2 VideoRendererGLWidget2;
} //namespace FAV
#endif //QT_NO_OPENGL
#endif // QTAV_GLWIDGETRENDERER2_H
#endif // #if !(REMOVE_RENDERER2)

View File

@@ -0,0 +1,126 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QAV_GRAPHICSITEMRENDERER_H
#define QAV_GRAPHICSITEMRENDERER_H
#define REMOVE_GRAPHIC_ITEM_RENDERER 1
#if !(REMOVE_GRAPHIC_ITEM_RENDERER)
#include "global.h"
#include "../QPainterRenderer.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QGraphicsWidget>
#else
#include <QtGui/QGraphicsWidget>
#endif
//QGraphicsWidget will lose focus forever if TextItem inserted text. Why?
#define CONFIG_GRAPHICSWIDGET 0
#if CONFIG_GRAPHICSWIDGET
#define GraphicsWidget QGraphicsWidget
#else
#define GraphicsWidget QGraphicsObject
#endif
namespace FAV {
class GraphicsItemRendererPrivate;
class Q_AVWIDGETS_EXPORT GraphicsItemRenderer : public GraphicsWidget, public QPainterRenderer
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(GraphicsItemRenderer)
Q_PROPERTY(bool opengl READ isOpenGL WRITE setOpenGL NOTIFY openGLChanged)
Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
//fillMode
// TODO: how to use enums in base class as property or Q_ENUM
Q_PROPERTY(OutAspectRatioMode outAspectRatioMode READ outAspectRatioMode WRITE setOutAspectRatioMode NOTIFY outAspectRatioModeChanged)
Q_ENUMS(OutAspectRatioMode)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(QRect videoRect READ videoRect NOTIFY videoRectChanged)
Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_ENUMS(Quality)
public:
GraphicsItemRenderer(QGraphicsItem * parent = 0);
VideoRendererId id() const Q_DECL_OVERRIDE;
bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;
QRectF boundingRect() const Q_DECL_OVERRIDE;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
QGraphicsItem* graphicsItem() Q_DECL_OVERRIDE { return this; }
/*!
* \brief isOpenGL
* true: user set to enabling opengl renderering. if viewport is not GLWidget, nothing will be rendered
* false: otherwise. opengl resources in QtAV (e.g. shader manager) will be released later
*/
bool isOpenGL() const;
void setOpenGL(bool o);
OpenGLVideo* opengl() const Q_DECL_OVERRIDE;
Q_SIGNALS:
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE Q_DECL_FINAL;
void regionOfInterestChanged() Q_DECL_OVERRIDE;
void outAspectRatioChanged() Q_DECL_OVERRIDE;
void outAspectRatioModeChanged() Q_DECL_OVERRIDE;
void brightnessChanged(qreal value) Q_DECL_OVERRIDE;
void contrastChanged(qreal) Q_DECL_OVERRIDE;
void hueChanged(qreal) Q_DECL_OVERRIDE;
void saturationChanged(qreal) Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
void orientationChanged() Q_DECL_OVERRIDE;
void videoRectChanged() Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
void openGLChanged();
protected:
GraphicsItemRenderer(GraphicsItemRendererPrivate& d, QGraphicsItem *parent);
bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
void drawBackground() Q_DECL_OVERRIDE;
//draw the current frame using the current paint engine. called by paintEvent()
void drawFrame() Q_DECL_OVERRIDE;
#if CONFIG_GRAPHICSWIDGET
bool event(QEvent *event) Q_DECL_OVERRIDE;
#else
//bool sceneEvent(QEvent *event) Q_DECL_OVERRIDE;
#endif //CONFIG_GRAPHICSWIDGET
private:
void onSetOutAspectRatioMode(OutAspectRatioMode mode) Q_DECL_OVERRIDE;
void onSetOutAspectRatio(qreal ratio) Q_DECL_OVERRIDE;
bool onSetOrientation(int value) Q_DECL_OVERRIDE;
bool onSetBrightness(qreal b) Q_DECL_OVERRIDE;
bool onSetContrast(qreal c) Q_DECL_OVERRIDE;
bool onSetHue(qreal h) Q_DECL_OVERRIDE;
bool onSetSaturation(qreal s) Q_DECL_OVERRIDE;
};
typedef GraphicsItemRenderer VideoRendererGraphicsItem;
}
#endif // QAV_GRAPHICSITEMRENDERER_H
#endif // if !(REMOVE_GRAPHIC_ITEM_RENDERER)

View File

@@ -0,0 +1,90 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2014)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "OpenGLWidgetRenderer.h"
#include "../OpenGLRendererBase_p.h"
#include <QtGui/QGuiApplication>
#include <QtGui/QResizeEvent>
#include <QtGui/QScreen>
namespace FAV {
class OpenGLWidgetRendererPrivate : public OpenGLRendererBasePrivate
{
public:
OpenGLWidgetRendererPrivate(QPaintDevice *pd)
: OpenGLRendererBasePrivate(pd)
{}
};
VideoRendererId OpenGLWidgetRenderer::id() const
{
return VideoRendererId_OpenGLWidget;
}
OpenGLWidgetRenderer::OpenGLWidgetRenderer(QWidget *parent, Qt::WindowFlags f):
QOpenGLWidget(parent, f)
, OpenGLRendererBase(*new OpenGLWidgetRendererPrivate(this))
{
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
}
void OpenGLWidgetRenderer::initializeGL()
{
onInitializeGL();
}
void OpenGLWidgetRenderer::paintGL()
{
onPaintGL();
}
void OpenGLWidgetRenderer::resizeGL(int w, int h)
{
// QGLWidget uses window()->windowHandle()->devicePixelRatio() for resizeGL(), while QOpenGLWidget does not, so scale here
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
if (!context())
return;
const qreal dpr = context()->screen()->devicePixelRatio();
#elif QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
// qApp->devicePixelRatio() is global, window()->windowHandle()->devicePixelRatio() depends on screen, check window() and windowHandle() is required.
// QWidget.devicePixelRatio() is int, but float value is not implemented in old qt, so just use int is fine.
const qreal dpr = devicePixelRatio();
#else
const qreal dpr = qApp->devicePixelRatio();
#endif
onResizeGL(w*dpr, h*dpr);
}
void OpenGLWidgetRenderer::resizeEvent(QResizeEvent *e)
{
onResizeEvent(e->size().width(), e->size().height());
QOpenGLWidget::resizeEvent(e); //will call resizeGL(). TODO:will call paintEvent()?
}
void OpenGLWidgetRenderer::showEvent(QShowEvent *e)
{
Q_UNUSED(e);
onShowEvent(); // TODO: onShowEvent(w, h)?
resizeGL(width(), height());
}
} //namespace FAV

View File

@@ -0,0 +1,86 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2014)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_OPENGLWIDGETRENDERER_H
#define QTAV_OPENGLWIDGETRENDERER_H
#include "global.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QtWidgets/QOpenGLWidget>
#else
#include "QOpenGLWidget.h"
#endif //QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include "../OpenGLRendererBase.h"
namespace FAV {
// do not define QOpenGLWidget here with ifdef to avoid moc error
class OpenGLWidgetRendererPrivate;
class Q_AVWIDGETS_EXPORT OpenGLWidgetRenderer : public QOpenGLWidget, public OpenGLRendererBase
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(OpenGLWidgetRenderer)
Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
//fillMode
// TODO: how to use enums in base class as property or Q_ENUM
Q_PROPERTY(OutAspectRatioMode outAspectRatioMode READ outAspectRatioMode WRITE setOutAspectRatioMode NOTIFY outAspectRatioModeChanged)
Q_ENUMS(OutAspectRatioMode)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(QRect videoRect READ videoRect NOTIFY videoRectChanged)
Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_ENUMS(Quality)
public:
explicit OpenGLWidgetRenderer(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const Q_DECL_OVERRIDE;
virtual QWidget* widget() Q_DECL_OVERRIDE { return this; }
Q_SIGNALS:
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE Q_DECL_FINAL;
void regionOfInterestChanged() Q_DECL_OVERRIDE;
void outAspectRatioChanged() Q_DECL_OVERRIDE;
void outAspectRatioModeChanged() Q_DECL_OVERRIDE;
void brightnessChanged(qreal value) Q_DECL_OVERRIDE;
void contrastChanged(qreal) Q_DECL_OVERRIDE;
void hueChanged(qreal) Q_DECL_OVERRIDE;
void saturationChanged(qreal) Q_DECL_OVERRIDE;
void orientationChanged() Q_DECL_OVERRIDE;
void videoRectChanged() Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
protected:
virtual void initializeGL() Q_DECL_OVERRIDE;
virtual void paintGL() Q_DECL_OVERRIDE;
virtual void resizeGL(int w, int h) Q_DECL_OVERRIDE;
virtual void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
virtual void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
};
typedef OpenGLWidgetRenderer VideoRendererOpenGLWidget;
} //namespace FAV
#endif // QTAV_OPENGLWIDGETRENDERER_H

View File

@@ -0,0 +1,223 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2015 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "QOpenGLWidget.h"
#if !(REMOVE_OPENGL_WIDGET)
#include <QResizeEvent>
#include <QWindow>
#include <QDebug>
// for dynamicgl. qglfunctions before qt5.3 does not have portable gl functions
#ifdef QT_OPENGL_DYNAMIC
#define DYGL(glFunc) QOpenGLContext::currentContext()->functions()->glFunc
#else
#define DYGL(glFunc) glFunc
#endif
namespace FAV {
// TODO: is QOpenGLWidgetPaintDevice required?
class QOpenGLWidgetPaintDevice : public QOpenGLPaintDevice
{
public:
QOpenGLWidgetPaintDevice(QOpenGLWidget *widget)
: QOpenGLPaintDevice()
, w(widget)
{ }
void ensureActiveTarget() Q_DECL_OVERRIDE {
if (QOpenGLContext::currentContext() != w->context()) {
w->makeCurrent();
}
}
private:
QOpenGLWidget *w;
};
QOpenGLWidget::QOpenGLWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, m_initialized(false)
, m_fakeHidden(false)
, m_context(0)
, m_paintDevice(0)
{
setAttribute(Qt::WA_NativeWindow); // ensure windowHandle() is not null
// WA_PaintOnScreen: QWidget::paintEngine: Should no longer be called. This flag is only supported on X11 and it disables double buffering
//setAttribute(Qt::WA_PaintOnScreen); // enforce native window, so windowHandle() is not null
setAttribute(Qt::WA_NoSystemBackground);
//setAutoFillBackground(true); // for compatibility
// FIXME: why setSurfaceType crash?
//windowHandle()->setSurfaceType(QWindow::OpenGLSurface);
}
QOpenGLWidget::~QOpenGLWidget()
{
delete m_paintDevice;
}
void QOpenGLWidget::setFormat(const QSurfaceFormat &format)
{
m_requestedFormat = format;
}
QSurfaceFormat QOpenGLWidget::format() const
{
return m_requestedFormat;
}
bool QOpenGLWidget::isValid() const
{
return m_initialized && m_context->isValid();
}
void QOpenGLWidget::makeCurrent()
{
if (!m_initialized) {
qWarning("QOpenGLWidget: Cannot make uninitialized widget current");
return;
}
if (!windowHandle()) {
qWarning("QOpenGLWidget: No window handle");
return;
}
m_context->makeCurrent((QSurface*)windowHandle());
}
void QOpenGLWidget::doneCurrent()
{
if (!m_initialized)
return;
m_context->doneCurrent();
}
QOpenGLContext *QOpenGLWidget::context() const
{
return m_context;
}
QPaintDevice* QOpenGLWidget::redirected(QPoint *offset) const
{
Q_UNUSED(offset);
// TODO: check backing store like Qt does
return m_paintDevice;
}
void QOpenGLWidget::initializeGL()
{
}
void QOpenGLWidget::paintGL()
{
}
void QOpenGLWidget::resizeGL(int w, int h)
{
Q_UNUSED(w);
Q_UNUSED(h);
}
void QOpenGLWidget::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);
if (!m_initialized)
return;
if (updatesEnabled())
render();
}
void QOpenGLWidget::resizeEvent(QResizeEvent *e)
{
if (e->size().isEmpty()) {
m_fakeHidden = true;
return;
}
m_fakeHidden = false;
initialize();
if (!m_initialized)
return;
//recreateFbo();
resizeGL(width(), height());
invokeUserPaint();
//resolveSamples();
}
void QOpenGLWidget::initialize()
{
if (m_initialized)
return;
QWindow *win = windowHandle();
if (!win) {
qWarning("QOpenGLWidget: No window handle");
return;
}
m_context = new QOpenGLContext(this);
// TODO: shareContext()
m_context->setFormat(m_requestedFormat);
if (!m_context->create()) {
qWarning("QOpenGLWidget: Failed to create context");
return;
}
//m_context = QOpenGLContext::currentContext();
if (!m_context) {
qWarning("QOpenGLWidget: QOpenGLContext is null");
return;
}
if (!m_context->makeCurrent(win)) {
qWarning("QOpenGLWidget: Failed to make context current");
return;
}
m_paintDevice = new QOpenGLWidgetPaintDevice(this);
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
m_paintDevice->setSize(size() * devicePixelRatio());
m_paintDevice->setDevicePixelRatio(devicePixelRatio());
#else
m_paintDevice->setSize(size());
#endif
m_initialized = true;
initializeGL();
}
void QOpenGLWidget::render()
{
if (m_fakeHidden || !m_initialized)
return;
// QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined
QWindow *win = windowHandle();
if (!win || !win->isExposed())
return;
makeCurrent();
invokeUserPaint();
m_context->swapBuffers(win);
}
void QOpenGLWidget::invokeUserPaint()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 1 , 0)
DYGL(glViewport(0, 0, width()*devicePixelRatio(), height()*devicePixelRatio()));
#else
DYGL(glViewport(0, 0, width(), height()));
#endif
paintGL();
DYGL(glFlush());
}
} //namespace FAV
#endif // @REMOVE_OPENGL_WIDGET

View File

@@ -0,0 +1,80 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2015)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_QOPENGLWIDGET_H
#define QTAV_QOPENGLWIDGET_H
#define REMOVE_OPENGL_WIDGET 1
#if !(REMOVE_OPENGL_WIDGET)
#include "global.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#error "Qt5 is required!"
#endif
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLPaintDevice>
#include <QtGui/QSurfaceFormat>
#include <QtWidgets/QWidget>
namespace FAV {
/*!
* \brief The QOpenGLWidget class
* A widget for rendering OpenGL graphics without QtOpenGL module
*/
class Q_AVWIDGETS_EXPORT QOpenGLWidget : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY(QOpenGLWidget)
public:
explicit QOpenGLWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual ~QOpenGLWidget();
void setFormat(const QSurfaceFormat &format);
QSurfaceFormat format() const;
bool isValid() const;
void makeCurrent();
void doneCurrent();
QOpenGLContext *context() const;
protected:
QPaintDevice* redirected(QPoint *offset) const Q_DECL_OVERRIDE;
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
private:
void initialize();
void render();
void invokeUserPaint();
bool m_initialized;
bool m_fakeHidden;
QOpenGLContext *m_context;
QOpenGLPaintDevice *m_paintDevice;
QSurfaceFormat m_requestedFormat;
};
} //namespace FAV
#endif // @REMOVE_OPENGL_WIDGET
#endif //QTAV_QOPENGLWIDGET_H

View File

@@ -0,0 +1,33 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2015)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAVWIDGETS_H
#define QTAVWIDGETS_H
#include "version.h"
#include "global.h"
#include "GraphicsItemRenderer.h"
#include "WidgetRenderer.h"
#include "GLWidgetRenderer.h"
#include "GLWidgetRenderer2.h"
#include "VideoPreviewWidget.h"
#endif // QTAVWIDGETS_H

View File

@@ -0,0 +1,71 @@
/******************************************************************************
VideoRendererTypes: type id and manually id register function
Copyright (C) 2015 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_VIDEOPREVIEWWIDGET_H
#define QTAV_VIDEOPREVIEWWIDGET_H
#include "global.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QWidget>
#else
#include <QtGui/QWidget>
#endif
#define REMOVE_VIDEO_PREVIEW_WIDGET 1
#if !(REMOVE_VIDEO_PREVIEW_WIDGET)
namespace FAV {
class VideoFrame;
class VideoOutput;
class VideoFrameExtractor;
class Q_AVWIDGETS_EXPORT VideoPreviewWidget : public QWidget
{
Q_OBJECT
public:
explicit VideoPreviewWidget(QWidget *parent = 0);
void setTimestamp(qint64 msec);
qint64 timestamp() const;
void preview();
void setFile(const QString& file);
QString file() const;
// default is false
void setKeepAspectRatio(bool value = true);
bool isKeepAspectRatio() const;
Q_SIGNALS:
void timestampChanged();
void fileChanged();
protected:
virtual void resizeEvent(QResizeEvent *);
private Q_SLOTS:
void displayFrame(const FAV::VideoFrame& frame); //parameter VideoFrame
void displayNoFrame();
private:
bool m_keep_ar;
QString m_file;
VideoFrameExtractor *m_extractor;
VideoOutput *m_out;
};
} //namespace FAV
#endif // QTAV_VIDEOPREVIEWWIDGET_H
#endif #if !(REMOVE_VIDEO_PREVIEW_WIDGET)

View File

@@ -0,0 +1,116 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "WidgetRenderer.h"
#include "../QPainterRenderer_p.h"
#include <QtGui/QFont>
#include <QtGui/QPainter>
#include <QApplication>
#include <QResizeEvent>
#include "../Filter.h"
namespace FAV {
class WidgetRendererPrivate : public QPainterRendererPrivate
{
public:
virtual ~WidgetRendererPrivate(){}
};
VideoRendererId WidgetRenderer::id() const
{
return VideoRendererId_Widget;
}
WidgetRenderer::WidgetRenderer(QWidget *parent, Qt::WindowFlags f) :
QWidget(parent, f),QPainterRenderer(*new WidgetRendererPrivate())
{
DPTR_D(WidgetRenderer);
d.painter = new QPainter();
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
/* To rapidly update custom widgets that constantly paint over their entire areas with
* opaque content, e.g., video streaming widgets, it is better to set the widget's
* Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead associated with repainting the
* widget's background
*/
setAttribute(Qt::WA_OpaquePaintEvent);
setAutoFillBackground(false);
QPainterFilterContext *ctx = static_cast<QPainterFilterContext*>(d.filter_context);
if (ctx) {
ctx->painter = d.painter;
} else {
qWarning("FilterContext not available!");
}
}
WidgetRenderer::WidgetRenderer(WidgetRendererPrivate &d, QWidget *parent, Qt::WindowFlags f)
:QWidget(parent, f),QPainterRenderer(d)
{
d.painter = new QPainter();
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
setAutoFillBackground(false);
QPainterFilterContext *ctx = static_cast<QPainterFilterContext*>(d.filter_context);
if (ctx) {
ctx->painter = d.painter;
} else {
qWarning("FilterContext not available!");
}
}
bool WidgetRenderer::receiveFrame(const VideoFrame &frame)
{
preparePixmap(frame);
updateUi();
/*
* workaround for the widget not updated if has parent. don't know why it works and why update() can't
* Thanks to Vito Covito and Carlo Scarpato
* Now it's fixed by posting a QUpdateLaterEvent
*/
Q_EMIT imageReady();
return true;
}
void WidgetRenderer::resizeEvent(QResizeEvent *e)
{
DPTR_D(WidgetRenderer);
d.update_background = true;
resizeRenderer(e->size());
update();
}
void WidgetRenderer::paintEvent(QPaintEvent *)
{
DPTR_D(WidgetRenderer);
d.painter->begin(this); //Widget painting can only begin as a result of a paintEvent
handlePaintEvent();
if (d.painter->isActive())
d.painter->end();
}
bool WidgetRenderer::onSetOrientation(int value)
{
Q_UNUSED(value);
update();
return true;
}
} //namespace QtAV

View File

@@ -0,0 +1,83 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_WIDGETRENDERER_H
#define QTAV_WIDGETRENDERER_H
#include "global.h"
#include "../QPainterRenderer.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QWidget>
#else
#include <QtGui/QWidget>
#endif
namespace FAV {
class WidgetRendererPrivate;
class Q_AVWIDGETS_EXPORT WidgetRenderer : public QWidget, public QPainterRenderer
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(WidgetRenderer)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
//fillMode
// TODO: how to use enums in base class as property or Q_ENUM
Q_PROPERTY(OutAspectRatioMode outAspectRatioMode READ outAspectRatioMode WRITE setOutAspectRatioMode NOTIFY outAspectRatioModeChanged)
Q_ENUMS(OutAspectRatioMode)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(QRect videoRect READ videoRect NOTIFY videoRectChanged)
Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_ENUMS(Quality)
public:
explicit WidgetRenderer(QWidget *parent = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const Q_DECL_OVERRIDE;
virtual QWidget* widget() Q_DECL_OVERRIDE { return this; }
Q_SIGNALS:
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE Q_DECL_FINAL;
void regionOfInterestChanged() Q_DECL_OVERRIDE;
void outAspectRatioChanged() Q_DECL_OVERRIDE;
void outAspectRatioModeChanged() Q_DECL_OVERRIDE;
void brightnessChanged(qreal value) Q_DECL_OVERRIDE;
void contrastChanged(qreal) Q_DECL_OVERRIDE;
void hueChanged(qreal) Q_DECL_OVERRIDE;
void saturationChanged(qreal) Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
void orientationChanged() Q_DECL_OVERRIDE;
void videoRectChanged() Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
QTAVWIDGETS_DEPRECATED void imageReady(); // add frameReady() in the future?
protected:
bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
/*usually you don't need to reimplement paintEvent, just drawXXX() is ok. unless you want do all
*things yourself totally*/
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
bool onSetOrientation(int value) Q_DECL_OVERRIDE;
protected:
WidgetRenderer(WidgetRendererPrivate& d, QWidget *parent, Qt::WindowFlags f);
};
typedef WidgetRenderer VideoRendererWidget;
} //namespace FAV
#endif // QTAV_WIDGETRENDERER_H

View File

@@ -0,0 +1,175 @@
/******************************************************************************
VideoRendererTypes: type id and manually id register function
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2015)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "global.h"
#include <QApplication>
#include <QBoxLayout>
#include <QMessageBox>
#include <QPushButton>
#include <QTableWidget>
#include <QTextBrowser>
#include "WidgetRenderer.h"
#include "GraphicsItemRenderer.h"
#if QTAV_HAVE(GL)
#include "GLWidgetRenderer2.h"
#endif //QTAV_HAVE(GL)
#if QTAV_HAVE(GL1)
#include "GLWidgetRenderer.h"
#endif //QTAV_HAVE(GL1)
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifndef QT_NO_OPENGL
#include "OpenGLWidgetRenderer.h"
#endif //QT_NO_OPENGL
#endif
#include "../factory.h"
#include "../mkid.h"
namespace FAV {
VideoRendererId VideoRendererId_Widget = mkid::id32base36_6<'W', 'i', 'd', 'g', 'e', 't'>::value;
VideoRendererId VideoRendererId_OpenGLWidget = mkid::id32base36_6<'Q', 'O', 'G', 'L', 'W', 't'>::value;
#if (TEST_GRAPHIC_ACCEL)
VideoRendererId VideoRendererId_GLWidget = mkid::id32base36_6<'Q', 'G', 'L', 'W', 't', '1'>::value;
VideoRendererId VideoRendererId_GLWidget2 = mkid::id32base36_6<'Q', 'G', 'L', 'W', 't', '2'>::value;
#endif
//VideoRendererId VideoRendererId_GraphicsItem = mkid::id32base36_6<'Q', 'G', 'r', 'a', 'p', 'h'>::value;
//VideoRendererId VideoRendererId_GDI = mkid::id32base36_3<'G', 'D', 'I'>::value;
//VideoRendererId VideoRendererId_Direct2D = mkid::id32base36_3<'D', '2', 'D'>::value;
//VideoRendererId VideoRendererId_XV = mkid::id32base36_6<'X', 'V', 'i', 'd', 'e', 'o'>::value;
//VideoRendererId VideoRendererId_X11 = mkid::id32base36_3<'X', '1', '1'>::value;
//QPainterRenderer is abstract. So can not register(operator new will needed)
#if AUTO_REGISTER
FACTORY_REGISTER(VideoRenderer, Widget, "QWidegt")
FACTORY_REGISTER(VideoRenderer, GraphicsItem, "QGraphicsItem")
#if QTAV_HAVE(GL)
#if QTAV_HAVE(GL1)
FACTORY_REGISTER(VideoRenderer, GLWidget, "QGLWidegt")
#endif //QTAV_HAVE(GL1)
FACTORY_REGISTER(VideoRenderer, GLWidget2, "QGLWidegt2")
#endif //QTAV_HAVE(GL)
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#ifndef QT_NO_OPENGL
FACTORY_REGISTER(VideoRenderer, OpenGLWidget, "OpenGLWidget")
#endif //QT_NO_OPENGL
#endif
#endif
//extern void RegisterVideoRendererGDI_Man();
//extern void RegisterVideoRendererDirect2D_Man();
//extern void RegisterVideoRendererXV_Man();
//extern void RegisterVideoRendererX11_Man();
namespace Widgets {
void registerRenderers()
{
#if !defined(QT_NO_DEBUG)
#if !(OFF_OTHER_DEBUG)
qDebug("registerRenderers...........");
#endif
#endif
// check whether it is called
static bool initialized = false;
if (initialized)
return;
initialized = true;
// factory.h does not check whether an id is registered
if (VideoRenderer::name(VideoRendererId_Widget))
return;
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#ifndef QT_NO_OPENGL
VideoRenderer::Register<OpenGLWidgetRenderer>(VideoRendererId_OpenGLWidget, "OpenGLWidget");
#endif //QT_NO_OPENGL
#endif
#if QTAV_HAVE(GL)
VideoRenderer::Register<GLWidgetRenderer2>(VideoRendererId_GLWidget2, "QGLWidget2");
#endif //QTAV_HAVE(GL)
#if QTAV_HAVE(GL1)
VideoRenderer::Register<GLWidgetRenderer>(VideoRendererId_GLWidget, "QGLWidget");
#endif //QTAV_HAVE(GL1)
VideoRenderer::Register<WidgetRenderer>(VideoRendererId_Widget, "Widget");
#if QTAV_HAVE(GDIPLUS)
RegisterVideoRendererGDI_Man();
#endif //QTAV_HAVE(GDIPLUS)
#if QTAV_HAVE(DIRECT2D)
RegisterVideoRendererDirect2D_Man();
#endif //QTAV_HAVE(DIRECT2D)
#if QTAV_HAVE(XV)
RegisterVideoRendererXV_Man();
#endif //QTAV_HAVE(XV)
#if QTAV_HAVE(X11)
RegisterVideoRendererX11_Man();
#endif //QTAV_HAVE(XV)
#if !(REMOVE_GRAPHIC_ITEM_RENDERER)
VideoRenderer::Register<GraphicsItemRenderer>(VideoRendererId_GraphicsItem, "GraphicsItem");
#endif
}
} //namespace Widgets
namespace {
static const struct register_renderers {
inline register_renderers() {
FAV::Widgets::registerRenderers();
}
} sRegisterVO;
}
void about() {
//we should use new because a qobject will delete it's children
QTextBrowser *viewQtAV = new QTextBrowser;
QTextBrowser *viewFFmpeg = new QTextBrowser;
viewQtAV->setOpenExternalLinks(true);
viewFFmpeg->setOpenExternalLinks(true);
viewQtAV->setHtml(aboutQtAV_HTML());
viewFFmpeg->setHtml(aboutFFmpeg_HTML());
QTabWidget *tab = new QTabWidget;
tab->addTab(viewQtAV, QStringLiteral("QtAV"));
tab->addTab(viewFFmpeg, QStringLiteral("FFmpeg"));
QPushButton *qbtn = new QPushButton("About Qt");
QPushButton *btn = new QPushButton("Ok");
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addWidget(btn);
btnLayout->addStretch();
btnLayout->addWidget(qbtn);
btn->setFocus();
QDialog dialog;
dialog.setWindowTitle("About" + QStringLiteral(" FAV"));
QVBoxLayout *layout = new QVBoxLayout;
dialog.setLayout(layout);
layout->addWidget(tab);
layout->addLayout(btnLayout);
QObject::connect(qbtn, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
QObject::connect(btn, SIGNAL(clicked()), &dialog, SLOT(accept()));
dialog.exec();
}
void aboutFFmpeg()
{
QMessageBox::about(0, "About FFmpeg", aboutFFmpeg_HTML());
}
void aboutQtAV()
{
QMessageBox::about(0, "About QtAV", aboutQtAV_HTML());
}
}//namespace FAV

View File

@@ -0,0 +1,71 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2015 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAVWIDGETS_GLOBAL_H
#define QTAVWIDGETS_GLOBAL_H
#include "../VideoRenderer.h"
#ifdef BUILD_QTAVWIDGETS_STATIC
#define Q_AVWIDGETS_EXPORT
#else
#if defined(BUILD_QTAVWIDGETS_LIB)
# undef Q_AVWIDGETS_EXPORT
# define Q_AVWIDGETS_EXPORT Q_DECL_EXPORT
#else
#define Q_AVWIDGETS_EXPORT
//# undef Q_AVWIDGETS_EXPORT
//# define Q_AVWIDGETS_EXPORT Q_DECL_IMPORT //only for vc?
#endif
#endif //BUILD_QTAVWIDGETS_STATIC
#define Q_AVWIDGETS_PRIVATE_EXPORT Q_AVWIDGETS_EXPORT
#if defined(BUILD_QTAVWIDGETS_LIB)
#define QTAVWIDGETS_DEPRECATED
#else
#define QTAVWIDGETS_DEPRECATED Q_DECL_DEPRECATED
#endif
namespace FAV {
namespace Widgets {
/*!
* \brief registerRenderers
* register built-in renderers.
* If you do not explicitly use any var, function or class in this module in your code,
* QtAVWidgets module maybe not linked to your program and renderers will not be available.
* Then you have to call registerRenderers() to ensure QtAVWidgets module is linked.
*/
Q_AVWIDGETS_EXPORT void registerRenderers();
} // namespace Widgets
extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_Widget;
//extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_GraphicsItem;
//extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_GDI;
//extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_Direct2D;
//extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_XV;
//extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_X11;
#if (TEST_GRAPHIC_ACCEL)
extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_GLWidget;
extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_GLWidget2;
#endif
extern Q_AVWIDGETS_EXPORT VideoRendererId VideoRendererId_OpenGLWidget;
//popup a dialog
Q_AVWIDGETS_EXPORT void about();
Q_AVWIDGETS_EXPORT void aboutFFmpeg();
Q_AVWIDGETS_EXPORT void aboutQtAV();
} // namespace FAV
#endif //QTAVWIDGETS_GLOBAL_H

View File

@@ -0,0 +1,42 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV (from 2015)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAVWIDGETS_VERSION_H
#define QTAVWIDGETS_VERSION_H
#include "version.h"
#define QTAVWIDGETS_MAJOR QTAV_MAJOR //((QTAV_VERSION&0xff0000)>>16)
#define QTAVWIDGETS_MINOR QTAV_MAJOR //((QTAV_VERSION&0xff00)>>8)
#define QTAVWIDGETS_PATCH QTAV_MAJOR //(QTAV_VERSION&0xff)
#define QTAVWIDGETS_VERSION_MAJOR(V) ((V & 0xff0000) >> 16)
#define QTAVWIDGETS_VERSION_MINOR(V) ((V & 0xff00) >> 8)
#define QTAVWIDGETS_VERSION_PATCH(V) (V & 0xff)
#define QTAVWIDGETS_VERSION QTAV_VERSION_CHK(QTAVWIDGETS_MAJOR, QTAVWIDGETS_MINOR, QTAVWIDGETS_PATCH)
/* the following are compile time version */
/* C++11 requires a space between literal and identifier */
#define QTAVWIDGETS_VERSION_STR TOSTR(QTAVWIDGETS_MAJOR) "." TOSTR(QTAVWIDGETS_MINOR) "." TOSTR(QTAVWIDGETS_PATCH)
#endif // QTAVWIDGETS_VERSION_H