From fdb5c419c4fb7b1ae0268e496ccdd0ffa03b74ce Mon Sep 17 00:00:00 2001 From: Dmytro Poplavskiy Date: Mon, 14 May 2012 13:10:09 +1000 Subject: [PATCH] Gst backend: allow rendering other video buffers than allocated Moved checking the buffer type to the buffer pool instead of comparing the buffer type in QVideoSurfaceGstSink. Some gstreamer elements may push other buffer instance than provided by sink but with the same data pointer. Change-Id: Iab3bf4da2d5eeb5d2a9375aa609a89515b067ce3 Reviewed-by: Lev Zelenskiy Reviewed-by: Ling Hu --- src/gsttools/qgstxvimagebuffer.cpp | 3 +++ src/gsttools/qvideosurfacegstsink.cpp | 5 +++-- .../gsttools_headers/qgstbufferpoolinterface_p.h | 12 ++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gsttools/qgstxvimagebuffer.cpp b/src/gsttools/qgstxvimagebuffer.cpp index 423a0d39..40df2b44 100644 --- a/src/gsttools/qgstxvimagebuffer.cpp +++ b/src/gsttools/qgstxvimagebuffer.cpp @@ -177,6 +177,9 @@ QAbstractVideoBuffer::HandleType QGstXvImageBufferPool::handleType() const QAbstractVideoBuffer *QGstXvImageBufferPool::prepareVideoBuffer(GstBuffer *buffer, int bytesPerLine) { + if (!G_TYPE_CHECK_INSTANCE_TYPE(buffer, bufferType())) + return 0; + QGstXvImageBuffer *xvBuffer = reinterpret_cast(buffer); QVariant handle = QVariant::fromValue(xvBuffer->xvImage); return new QGstVideoBuffer(buffer, bytesPerLine, QAbstractVideoBuffer::XvShmImageHandle, handle); diff --git a/src/gsttools/qvideosurfacegstsink.cpp b/src/gsttools/qvideosurfacegstsink.cpp index 7f61a68e..afbc69c9 100644 --- a/src/gsttools/qvideosurfacegstsink.cpp +++ b/src/gsttools/qvideosurfacegstsink.cpp @@ -195,9 +195,10 @@ GstFlowReturn QVideoSurfaceGstDelegate::render(GstBuffer *buffer) QAbstractVideoBuffer *videoBuffer = 0; - if (m_pool && G_TYPE_CHECK_INSTANCE_TYPE(buffer, m_pool->bufferType())) + if (m_pool) videoBuffer = m_pool->prepareVideoBuffer(buffer, m_bytesPerLine); - else + + if (!videoBuffer) videoBuffer = new QGstVideoBuffer(buffer, m_bytesPerLine); m_frame = QVideoFrame( diff --git a/src/multimedia/gsttools_headers/qgstbufferpoolinterface_p.h b/src/multimedia/gsttools_headers/qgstbufferpoolinterface_p.h index 42c4fb55..929e7c68 100644 --- a/src/multimedia/gsttools_headers/qgstbufferpoolinterface_p.h +++ b/src/multimedia/gsttools_headers/qgstbufferpoolinterface_p.h @@ -73,16 +73,14 @@ public: virtual ~QGstBufferPoolInterface() {} virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const = 0; - - virtual GType bufferType() const = 0; virtual GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps) = 0; virtual void clear() = 0; virtual QAbstractVideoBuffer::HandleType handleType() const = 0; /*! - Build an QAbstractVideoBuffer instance from compatible (mathcing gst buffer type) - GstBuffer. + Build an QAbstractVideoBuffer instance from GstBuffer. + Returns NULL if GstBuffer is not compatible with this buffer pool. This method is called from gstreamer video sink thread. */ @@ -101,16 +99,14 @@ public: virtual ~QGstBufferPoolPlugin() {} virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const = 0; - - virtual GType bufferType() const = 0; virtual GstBuffer *takeBuffer(const QVideoSurfaceFormat &format, GstCaps *caps) = 0; virtual void clear() = 0; virtual QAbstractVideoBuffer::HandleType handleType() const = 0; /*! - Build an QAbstractVideoBuffer instance from compatible (mathcing gst buffer type) - GstBuffer. + Build an QAbstractVideoBuffer instance from compatible GstBuffer. + Returns NULL if GstBuffer is not compatible with this buffer pool. This method is called from gstreamer video sink thread. */