Skip to content

Commit

Permalink
vo: do not call update() off gui thread wang-bin#532
Browse files Browse the repository at this point in the history
update() also do backing store things.
TODO:
what about update() in a user event?
why posting an UpdateRequest event is not enough for WidgetRenderer and
OpenGLWidgetRenderer(not tested for other renderers)?
  • Loading branch information
wang-bin committed Oct 25, 2015
1 parent 511e9ff commit 5294c21
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/QtAV/OpenGLRendererBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Q_AV_EXPORT OpenGLRendererBase : public VideoRenderer
public:
virtual ~OpenGLRendererBase();
virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const;
virtual void onUpdate() = 0;
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool needUpdateBackground() const;
Expand Down
2 changes: 0 additions & 2 deletions src/QtAV/OpenGLWindowRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class Q_AV_EXPORT OpenGLWindowRenderer : public QOpenGLWindow, public OpenGLRend
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
public:
explicit OpenGLWindowRenderer(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0);
virtual void onUpdate() Q_DECL_OVERRIDE;

virtual VideoRendererId id() const Q_DECL_OVERRIDE;
QWindow* qwindow() Q_DECL_OVERRIDE Q_DECL_FINAL { return this; }
Q_SIGNALS:
Expand Down
2 changes: 1 addition & 1 deletion src/QtAV/VideoRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput
// TODO: parameter VideoFrame
virtual void drawFrame() = 0; //You MUST reimplement this to display a frame. Other draw functions are not essential
virtual void handlePaintEvent(); //has default. User don't have to implement it
void updateUi(); // schedual an UpdateRequest event on ui thread
virtual void updateUi(); // by default schedual an UpdateRequest event on ui thread

private: //used by VideoOutput class
// property change
Expand Down
2 changes: 1 addition & 1 deletion src/output/video/Direct2DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ bool Direct2DRenderer::receiveFrame(const VideoFrame& frame)
if (hr != S_OK) {
qWarning("Failed to copy from memory to bitmap (%ld)", hr);
}
update();
updateUi();
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/output/video/GDIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool GDIRenderer::receiveFrame(const VideoFrame& frame)
d.video_frame = frame;
else
d.video_frame = frame.to(frame.pixelFormat());
update();
updateUi();
return true;
}

Expand Down
7 changes: 1 addition & 6 deletions src/output/video/GLWidgetRenderer2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2014 Wang Bin <[email protected]>
Copyright (C) 2014-2015 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -56,11 +56,6 @@ GLWidgetRenderer2::GLWidgetRenderer2(QWidget *parent, const QGLWidget* shareWidg
setAutoFillBackground(false);
}

void GLWidgetRenderer2::onUpdate()
{
update();
}

void GLWidgetRenderer2::initializeGL()
{
// already current
Expand Down
4 changes: 2 additions & 2 deletions src/output/video/GraphicsItemRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool GraphicsItemRenderer::receiveFrame(const VideoFrame& frame)
{
prepareFrame(frame);
}
scene()->update(sceneBoundingRect());
scene()->update(sceneBoundingRect()); //TODO: thread?
//update(); //does not cause an immediate paint. my not redraw.
return true;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ bool GraphicsItemRenderer::onSetOrientation(int value)
{
Q_UNUSED(value);
d_func().setupAspectRatio();
update();
update(); //TODO: thread?
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/output/video/OpenGLRendererBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool OpenGLRendererBase::receiveFrame(const VideoFrame& frame)

d.glv.setCurrentFrame(frame);

onUpdate(); //can not call updateGL() directly because no event and paintGL() will in video thread
updateUi(); //can not call updateGL() directly because no event and paintGL() will in video thread
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions src/output/video/OpenGLWidgetRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ OpenGLWidgetRenderer::OpenGLWidgetRenderer(QWidget *parent, Qt::WindowFlags f):
{
setAcceptDrops(true);
setFocusPolicy(Qt::StrongFocus);
connect(this, SIGNAL(frameReady()), SLOT(update()));
}

void OpenGLWidgetRenderer::onUpdate()
void OpenGLWidgetRenderer::updateUi()
{
update();
Q_EMIT frameReady();
}

void OpenGLWidgetRenderer::initializeGL()
Expand Down
8 changes: 1 addition & 7 deletions src/output/video/OpenGLWindowRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ VideoRendererId OpenGLWindowRenderer::id() const
{
return VideoRendererId_OpenGLWindow;
}

void OpenGLWindowRenderer::onUpdate()
{
// MUST call update() on gui(main) thread that the window belongs to because update() will finally call startTimer
updateUi();
}

// MUST call update() on gui(main) thread that the window belongs to because update() will finally call startTimer
void OpenGLWindowRenderer::initializeGL()
{
onInitializeGL();
Expand Down
1 change: 1 addition & 0 deletions src/output/video/VideoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ VideoRendererId VideoRendererId_OpenGLWindow = mkid::id32base36_6<'Q', 'O', 'G',
VideoRenderer::VideoRenderer()
:AVOutput(*new VideoRendererPrivate)
{
// can not do 'if (widget()) connect to update()' because widget() is virtual
}

VideoRenderer::VideoRenderer(VideoRendererPrivate &d)
Expand Down
5 changes: 3 additions & 2 deletions src/output/video/WidgetRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ WidgetRenderer::WidgetRenderer(WidgetRendererPrivate &d, QWidget *parent, Qt::Wi
} else {
qWarning("FilterContext not available!");
}
connect(this, SIGNAL(imageReady()), SLOT(update()));
connect(this, SIGNAL(frameReady()), SLOT(update()));
}

bool WidgetRenderer::receiveFrame(const VideoFrame &frame)
Expand All @@ -87,7 +87,8 @@ bool WidgetRenderer::receiveFrame(const VideoFrame &frame)
* 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
*/
emit imageReady();
Q_EMIT frameReady();
Q_EMIT imageReady();
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/output/video/XVRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bool XVRenderer::receiveFrame(const VideoFrame& frame)
if (!frame.isValid()) {
d.update_background = true;
d.video_frame = VideoFrame(); // fill background
update();
updateUi();
return true;
}
if (!d.ensureImage(frame.width(), frame.height(), frame.format().pixelFormat()))
Expand Down
2 changes: 0 additions & 2 deletions widgets/QtAVWidgets/GLWidgetRenderer2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class Q_AVWIDGETS_EXPORT GLWidgetRenderer2 : public QGLWidget, public OpenGLRend
DPTR_DECLARE_PRIVATE(GLWidgetRenderer2)
public:
GLWidgetRenderer2(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
virtual void onUpdate();

virtual VideoRendererId id() const;
virtual QWidget* widget() { return this; }
protected:
Expand Down
6 changes: 4 additions & 2 deletions widgets/QtAVWidgets/OpenGLWidgetRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ namespace QtAV {
class OpenGLWidgetRendererPrivate;
class Q_AVWIDGETS_EXPORT OpenGLWidgetRenderer : public QOpenGLWidget, public OpenGLRendererBase
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(OpenGLWidgetRenderer)
public:
explicit OpenGLWidgetRenderer(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual void onUpdate() Q_DECL_OVERRIDE;

virtual VideoRendererId id() const Q_DECL_OVERRIDE;
virtual QWidget* widget() Q_DECL_OVERRIDE { return this; }
Q_SIGNALS:
void frameReady();
protected:
virtual void updateUi() Q_DECL_OVERRIDE;
virtual void initializeGL() Q_DECL_OVERRIDE;
virtual void paintGL() Q_DECL_OVERRIDE;
virtual void resizeGL(int w, int h) Q_DECL_OVERRIDE;
Expand Down
5 changes: 3 additions & 2 deletions widgets/QtAVWidgets/WidgetRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class Q_AVWIDGETS_EXPORT WidgetRenderer : public QWidget, public QPainterRendere
explicit WidgetRenderer(QWidget *parent = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const;
virtual QWidget* widget() { return this; }
signals:
void imageReady();
Q_SIGNALS:
void frameReady();
QTAVWIDGETS_DEPRECATED void imageReady(); // use frameReady() instead
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool needUpdateBackground() const;
Expand Down
6 changes: 5 additions & 1 deletion widgets/QtAVWidgets/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#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 QtAV {
namespace Widgets {
/*!
Expand Down
4 changes: 1 addition & 3 deletions widgets/X11Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ VideoFormat::PixelFormat pixelFormat(XImage* xi) {
//qDebug() << fmte->fmt;
fmte++;
}
qDebug("XImage format: bpp %d, endian: %d, R %X, G %X, B %X", xi->bits_per_pixel, xi->byte_order, xi->red_mask, xi->green_mask, xi->blue_mask);
qDebug() << "PixelFormat: " << fmte->fmt;
return fmte->fmt;
}

Expand Down Expand Up @@ -378,7 +376,7 @@ bool X11Renderer::receiveFrame(const VideoFrame& frame)
VideoFrame::copyPlane(dst, d.ximage->bytes_per_line, (const quint8*)d.video_frame.constBits(0), d.video_frame.bytesPerLine(0), d.ximage->bytes_per_line, d.ximage->height);
}
}
update();
updateUi();
return true;
}

Expand Down

0 comments on commit 5294c21

Please sign in to comment.