Android: allow to map video buffers.

Since we internally use a fbo, use QOpenGLFramebufferObject::toImage()
to grab the pixel data and enable the use of map() on frames retrieved
using QAbstractVideoFilter.

Change-Id: If96e992e12e26091524913bb24926fa21d9d58cc
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Yoann Lopes
2015-08-31 16:50:53 +02:00
parent edc415be47
commit 29ce8886b3

View File

@@ -73,29 +73,60 @@ public:
: QAbstractVideoBuffer(GLTextureHandle) : QAbstractVideoBuffer(GLTextureHandle)
, m_control(control) , m_control(control)
, m_textureUpdated(false) , m_textureUpdated(false)
, m_mapMode(NotMapped)
{ {
} }
virtual ~AndroidTextureVideoBuffer() {} virtual ~AndroidTextureVideoBuffer() {}
MapMode mapMode() const { return NotMapped; } MapMode mapMode() const { return m_mapMode; }
uchar *map(MapMode, int*, int*) { return 0; }
void unmap() {} uchar *map(MapMode mode, int *numBytes, int *bytesPerLine)
{
if (m_mapMode == NotMapped && mode == ReadOnly) {
updateFrame();
m_mapMode = mode;
m_image = m_control->m_fbo->toImage();
if (numBytes)
*numBytes = m_image.byteCount();
if (bytesPerLine)
*bytesPerLine = m_image.bytesPerLine();
return m_image.bits();
} else {
return 0;
}
}
void unmap()
{
m_image = QImage();
m_mapMode = NotMapped;
}
QVariant handle() const QVariant handle() const
{
AndroidTextureVideoBuffer *that = const_cast<AndroidTextureVideoBuffer*>(this);
that->updateFrame();
return m_control->m_fbo->texture();
}
private:
void updateFrame()
{ {
if (!m_textureUpdated) { if (!m_textureUpdated) {
// update the video texture (called from the render thread) // update the video texture (called from the render thread)
m_control->renderFrameToFbo(); m_control->renderFrameToFbo();
m_textureUpdated = true; m_textureUpdated = true;
} }
return m_control->m_fbo->texture();
} }
private: QAndroidVideoRendererControl *m_control;
mutable QAndroidVideoRendererControl *m_control; bool m_textureUpdated;
mutable bool m_textureUpdated; MapMode m_mapMode;
QImage m_image;
}; };
QAndroidVideoRendererControl::QAndroidVideoRendererControl(QObject *parent) QAndroidVideoRendererControl::QAndroidVideoRendererControl(QObject *parent)