summaryrefslogtreecommitdiffstats
path: root/src/gsttools/qgstvideobuffer.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2014-11-20 17:54:18 +0100
committerAndrew den Exter <andrew.den.exter@qinetic.com.au>2014-11-27 23:30:05 +0100
commit108dda7a90bd0f0337358b0db47ae55acd16dea6 (patch)
treee74c44c004b257fb99fdc96063641c76ac0426cf /src/gsttools/qgstvideobuffer.cpp
parent7e3d69668e3f04110a651dee1850a1d0c885947b (diff)
GStreamer: port to 1.0.
0.10 is still used by default. To enable GStreamer 1.0, pass GST_VERSION=1.0 to qmake for qtmultimedia.pro. Contributions from: Andrew den Exter <andrew.den.exter@qinetic.com.au> Ilya Smelykh <ilya@videoexpertsgroup.com> Jim Hodapp <jim.hodapp@canonical.com> Sergio Schvezov <sergio.schvezov@canonical.com> Change-Id: I72a46d1170a8794a149bdb5e20767afcc5b7587c Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Diffstat (limited to 'src/gsttools/qgstvideobuffer.cpp')
-rw-r--r--src/gsttools/qgstvideobuffer.cpp70
1 files changed, 67 insertions, 3 deletions
diff --git a/src/gsttools/qgstvideobuffer.cpp b/src/gsttools/qgstvideobuffer.cpp
index 18702ec7..1ce07ca1 100644
--- a/src/gsttools/qgstvideobuffer.cpp
+++ b/src/gsttools/qgstvideobuffer.cpp
@@ -35,21 +35,35 @@
QT_BEGIN_NAMESPACE
+#if GST_CHECK_VERSION(1,0,0)
+QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info)
+ : QAbstractPlanarVideoBuffer(NoHandle)
+ , m_videoInfo(info)
+#else
QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine)
: QAbstractVideoBuffer(NoHandle)
- , m_buffer(buffer)
, m_bytesPerLine(bytesPerLine)
+#endif
+ , m_buffer(buffer)
, m_mode(NotMapped)
{
gst_buffer_ref(m_buffer);
}
+#if GST_CHECK_VERSION(1,0,0)
+QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, const GstVideoInfo &info,
+ QGstVideoBuffer::HandleType handleType,
+ const QVariant &handle)
+ : QAbstractPlanarVideoBuffer(handleType)
+ , m_videoInfo(info)
+#else
QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine,
QGstVideoBuffer::HandleType handleType,
const QVariant &handle)
: QAbstractVideoBuffer(handleType)
- , m_buffer(buffer)
, m_bytesPerLine(bytesPerLine)
+#endif
+ , m_buffer(buffer)
, m_mode(NotMapped)
, m_handle(handle)
{
@@ -58,6 +72,8 @@ QGstVideoBuffer::QGstVideoBuffer(GstBuffer *buffer, int bytesPerLine,
QGstVideoBuffer::~QGstVideoBuffer()
{
+ unmap();
+
gst_buffer_unref(m_buffer);
}
@@ -67,12 +83,49 @@ QAbstractVideoBuffer::MapMode QGstVideoBuffer::mapMode() const
return m_mode;
}
+#if GST_CHECK_VERSION(1,0,0)
+
+int QGstVideoBuffer::map(MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4])
+{
+ const GstMapFlags flags = GstMapFlags(((mode & ReadOnly) ? GST_MAP_READ : 0)
+ | ((mode & WriteOnly) ? GST_MAP_WRITE : 0));
+
+ if (mode == NotMapped || m_mode != NotMapped) {
+ return 0;
+ } else if (m_videoInfo.finfo->n_planes == 0) { // Encoded
+ if (gst_buffer_map(m_buffer, &m_frame.map[0], flags)) {
+ if (numBytes)
+ *numBytes = m_frame.map[0].size;
+ bytesPerLine[0] = -1;
+ data[0] = static_cast<uchar *>(m_frame.map[0].data);
+
+ m_mode = mode;
+
+ return 1;
+ }
+ } else if (gst_video_frame_map(&m_frame, &m_videoInfo, m_buffer, flags)) {
+ if (numBytes)
+ *numBytes = m_frame.info.size;
+
+ for (guint i = 0; i < m_frame.info.finfo->n_planes; ++i) {
+ bytesPerLine[i] = m_frame.info.stride[i];
+ data[i] = static_cast<uchar *>(m_frame.data[i]);
+ }
+
+ m_mode = mode;
+
+ return m_frame.info.finfo->n_planes;
+ }
+ return 0;
+}
+
+#else
+
uchar *QGstVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
{
if (mode != NotMapped && m_mode == NotMapped) {
if (numBytes)
*numBytes = m_buffer->size;
-
if (bytesPerLine)
*bytesPerLine = m_bytesPerLine;
@@ -83,8 +136,19 @@ uchar *QGstVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
return 0;
}
}
+
+#endif
+
void QGstVideoBuffer::unmap()
{
+#if GST_CHECK_VERSION(1,0,0)
+ if (m_mode != NotMapped) {
+ if (m_videoInfo.finfo->n_planes == 0)
+ gst_buffer_unmap(m_buffer, &m_frame.map[0]);
+ else
+ gst_video_frame_unmap(&m_frame);
+ }
+#endif
m_mode = NotMapped;
}