summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2014-05-02 23:55:56 +0200
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2014-05-03 22:31:57 +0300
commit5a6fd670421656505223375b2065a7d024e21936 (patch)
tree285c2e88cd10bbb816a03fa7ae4ae2fd7970b980
parent30a51acdc9c611c02c8bafd5a0eb43ace29c40ac (diff)
QGst/memory: Wrap GstMapInfo properly
-rw-r--r--src/QGst/buffer.cpp6
-rw-r--r--src/QGst/buffer.h1
-rw-r--r--src/QGst/global.h3
-rw-r--r--src/QGst/memory.cpp36
-rw-r--r--src/QGst/memory.h22
-rw-r--r--tests/auto/memorytest.cpp10
6 files changed, 60 insertions, 18 deletions
diff --git a/src/QGst/buffer.cpp b/src/QGst/buffer.cpp
index 1bd3920..f770be0 100644
--- a/src/QGst/buffer.cpp
+++ b/src/QGst/buffer.cpp
@@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "buffer.h"
-#include "memory.h"
#include "caps.h"
#include <QtCore/QDebug>
#include <gst/gst.h>
@@ -92,7 +91,8 @@ MemoryPtr Buffer::peekMemory(uint index)
bool Buffer::map(MapInfo &info, MapFlags flags)
{
BufferPtr bptr(this);
- if (!gst_buffer_map(bptr, reinterpret_cast<GstMapInfo *>(&info), static_cast<GstMapFlags>(static_cast<int>(flags)))) {
+ if (!gst_buffer_map(bptr, static_cast<GstMapInfo *>(info.m_object),
+ static_cast<GstMapFlags>(static_cast<int>(flags)))) {
return false;
}
return true;
@@ -101,7 +101,7 @@ bool Buffer::map(MapInfo &info, MapFlags flags)
void Buffer::unmap(MapInfo &info)
{
BufferPtr bptr(this);
- gst_buffer_unmap(bptr, reinterpret_cast<GstMapInfo *>(&info));
+ gst_buffer_unmap(bptr, static_cast<GstMapInfo *>(info.m_object));
}
} //namespace QGst
diff --git a/src/QGst/buffer.h b/src/QGst/buffer.h
index 64d00b0..701371a 100644
--- a/src/QGst/buffer.h
+++ b/src/QGst/buffer.h
@@ -20,6 +20,7 @@
#include "miniobject.h"
#include "clocktime.h"
+#include "memory.h"
namespace QGst {
diff --git a/src/QGst/global.h b/src/QGst/global.h
index ba9a67b..6b8716f 100644
--- a/src/QGst/global.h
+++ b/src/QGst/global.h
@@ -121,9 +121,7 @@ QGST_WRAPPER_REFPOINTER_DECLARATION(BufferingQuery)
QGST_WRAPPER_REFPOINTER_DECLARATION(UriQuery)
QGST_WRAPPER_DECLARATION(Buffer)
QGST_WRAPPER_DECLARATION(Memory)
-QGST_WRAPPER_REFPOINTER_DECLARATION(MapInfo)
QGST_WRAPPER_DECLARATION(BufferList)
-QGST_WRAPPER_GSTCLASS_DECLARATION(BufferListIterator)
QGST_WRAPPER_DECLARATION(Event)
QGST_WRAPPER_REFPOINTER_DECLARATION(FlushStartEvent)
QGST_WRAPPER_REFPOINTER_DECLARATION(FlushStopEvent)
@@ -147,6 +145,7 @@ namespace QGst {
class Structure;
class SharedStructure;
typedef QSharedPointer<SharedStructure> StructurePtr;
+ class MapInfo;
}
QGST_WRAPPER_GSTCLASS_DECLARATION(URIHandler)
QGST_WRAPPER_REFPOINTER_DECLARATION(UriHandler)
diff --git a/src/QGst/memory.cpp b/src/QGst/memory.cpp
index 89b45b7..8b33d4f 100644
--- a/src/QGst/memory.cpp
+++ b/src/QGst/memory.cpp
@@ -25,6 +25,38 @@
namespace QGst {
+MapInfo::MapInfo()
+{
+ m_object = g_slice_new0(GstMapInfo);
+}
+
+MapInfo::~MapInfo()
+{
+ g_slice_free(GstMapInfo, m_object);
+}
+
+MapFlags MapInfo::flags() const
+{
+ return static_cast<MapFlag>(static_cast<GstMapInfo*>(m_object)->flags);
+}
+
+quint8 *MapInfo::data() const
+{
+ return static_cast<GstMapInfo*>(m_object)->data;
+}
+
+size_t MapInfo::size() const
+{
+ return static_cast<GstMapInfo*>(m_object)->size;
+}
+
+size_t MapInfo::maxSize() const
+{
+ return static_cast<GstMapInfo*>(m_object)->maxsize;
+}
+
+//-----------------------
+
MemoryPtr Memory::create(size_t size)
{
return MemoryPtr::wrap(gst_allocator_alloc(NULL, size, NULL));
@@ -47,13 +79,13 @@ size_t Memory::getSizes(size_t &offset, size_t &maxsize)
bool Memory::map(MapInfo &info, MapFlags flags)
{
- return gst_memory_map(object<GstMemory>(), reinterpret_cast<GstMapInfo *>(&info),
+ return gst_memory_map(object<GstMemory>(), static_cast<GstMapInfo*>(info.m_object),
static_cast<GstMapFlags>(static_cast<int>(flags)));
}
void Memory::unmap(MapInfo &info)
{
- gst_memory_unmap(object<GstMemory>(), reinterpret_cast<GstMapInfo *>(&info));
+ gst_memory_unmap(object<GstMemory>(), static_cast<GstMapInfo*>(info.m_object));
}
} // namespace QGst
diff --git a/src/QGst/memory.h b/src/QGst/memory.h
index 06e6d96..7ff0e50 100644
--- a/src/QGst/memory.h
+++ b/src/QGst/memory.h
@@ -22,13 +22,23 @@
namespace QGst {
-struct MapInfo
+class QTGSTREAMER_EXPORT MapInfo
{
- void *memory;
- MapFlags flags;
- quint8 *data;
- size_t size;
- size_t maxsize;
+public:
+ MapInfo();
+ virtual ~MapInfo();
+
+ MapFlags flags() const;
+ quint8 *data() const;
+ size_t size() const;
+ size_t maxSize() const;
+
+private:
+ friend class Buffer;
+ friend class Memory;
+ Q_DISABLE_COPY(MapInfo);
+
+ void *m_object;
};
/*! \headerfile memory.h <QGst/Memory>
diff --git a/tests/auto/memorytest.cpp b/tests/auto/memorytest.cpp
index b09427a..269d914 100644
--- a/tests/auto/memorytest.cpp
+++ b/tests/auto/memorytest.cpp
@@ -33,15 +33,15 @@ void MemoryTest::testMap()
size_t maxalloc;
size_t size = mem->getSizes(offset, maxalloc);
- QCOMPARE(size, static_cast<unsigned long>(100));
- QCOMPARE(offset, static_cast<unsigned long>(0));
+ QCOMPARE(size, static_cast<size_t>(100));
+ QCOMPARE(offset, static_cast<size_t>(0));
QVERIFY(maxalloc >= 100);
QGst::MapInfo info;
QVERIFY(mem->map(info, QGst::MapRead));
- QVERIFY(info.data != NULL);
- QVERIFY(info.size == 100);
- QVERIFY(info.maxsize == maxalloc);
+ QVERIFY(info.data() != NULL);
+ QCOMPARE(info.size(), static_cast<size_t>(100));
+ QCOMPARE(info.maxSize(), maxalloc);
mem->unmap(info);
}