summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiane Trout <diane@ghic.org>2014-06-09 23:01:57 -0700
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2014-06-14 15:11:12 +0200
commit1fb631350cab5fe30749dae93b4b32e7c86cb3ea (patch)
tree869803801147c0395e5cc8d53afcba009ca553b2 /src
parent2a9664aff4980380afb93720795d326dfc76785f (diff)
Implement QGst::Allocator and a unit test for it
Diffstat (limited to 'src')
-rw-r--r--src/QGst/Allocator1
-rw-r--r--src/QGst/CMakeLists.txt2
-rw-r--r--src/QGst/allocator.cpp135
-rw-r--r--src/QGst/allocator.h83
-rw-r--r--src/QGst/global.h3
-rw-r--r--src/QGst/memory.cpp5
-rw-r--r--src/QGst/memory.h4
7 files changed, 229 insertions, 4 deletions
diff --git a/src/QGst/Allocator b/src/QGst/Allocator
new file mode 100644
index 0000000..30c4efa
--- /dev/null
+++ b/src/QGst/Allocator
@@ -0,0 +1 @@
+#include "allocator.h"
diff --git a/src/QGst/CMakeLists.txt b/src/QGst/CMakeLists.txt
index 98f6877..b780fb8 100644
--- a/src/QGst/CMakeLists.txt
+++ b/src/QGst/CMakeLists.txt
@@ -24,6 +24,7 @@ set(QtGStreamer_SRCS
colorbalance.cpp
query.cpp
clock.cpp
+ allocator.cpp
memory.cpp
buffer.cpp
event.cpp
@@ -86,6 +87,7 @@ set(QtGStreamer_INSTALLED_HEADERS
clock.h Clock
buffer.h Buffer
sample.h Sample
+ allocator.h Allocator
memory.h Memory
event.h Event
clocktime.h ClockTime
diff --git a/src/QGst/allocator.cpp b/src/QGst/allocator.cpp
new file mode 100644
index 0000000..05f01ae
--- /dev/null
+++ b/src/QGst/allocator.cpp
@@ -0,0 +1,135 @@
+/*
+ Copyright (C) 2014 Diane Trout <diane@ghic.org>
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "allocator.h"
+#include <gst/gstobject.h>
+#include <gst/gstminiobject.h>
+#include <gst/gstallocator.h>
+
+namespace QGst {
+
+struct AllocationParamsPrivate : GstAllocationParams
+{
+};
+
+AllocationParams::AllocationParams()
+ : d_ptr(new AllocationParamsPrivate)
+{
+ Q_D(AllocationParams);
+ gst_allocation_params_init(d);
+}
+
+AllocationParams::AllocationParams(AllocationParams &other)
+ : d_ptr(static_cast<AllocationParamsPrivate *>(gst_allocation_params_copy(other.d_ptr)))
+{
+}
+
+AllocationParams::~AllocationParams()
+{
+ gst_allocation_params_free(d_ptr);
+}
+
+MemoryFlags AllocationParams::flags() const
+{
+ Q_D(const AllocationParams);
+ return static_cast<QGst::MemoryFlags>(static_cast<unsigned int>(d->flags));
+}
+
+void AllocationParams::setFlags(MemoryFlags flags)
+{
+ Q_D(AllocationParams);
+ d->flags = static_cast<GstMemoryFlags>(static_cast<unsigned int>(flags));
+}
+
+size_t AllocationParams::align() const
+{
+ Q_D(const AllocationParams);
+ return d->align;
+}
+
+void AllocationParams::setAlign(size_t align)
+{
+ Q_D(AllocationParams);
+ d->align = align;
+}
+
+size_t AllocationParams::prefix() const
+{
+ Q_D(const AllocationParams);
+ return d->prefix;
+}
+
+void AllocationParams::setPrefix(size_t align)
+{
+ Q_D(AllocationParams);
+ d->prefix = align;
+}
+
+size_t AllocationParams::padding() const
+{
+ Q_D(const AllocationParams);
+ return d->padding;
+}
+
+void AllocationParams::setPadding(size_t padding)
+{
+ Q_D(AllocationParams);
+ d->padding = padding;
+}
+
+Allocator::Allocator(GstAllocator *g_alloc)
+{
+ m_object = static_cast<void *>(g_alloc);
+}
+
+Allocator::operator GstAllocator *()
+{
+ return static_cast<GstAllocator *>(m_object);
+}
+
+Allocator::operator GstAllocator *() const
+{
+ return static_cast<GstAllocator *>(m_object);
+}
+
+
+AllocatorPtr Allocator::find(const char *name)
+{
+ return AllocatorPtr(new Allocator(gst_allocator_find(name)));
+}
+
+void Allocator::registerAllocator(const char *name)
+{
+ gst_allocator_register(name, object<GstAllocator>());
+}
+
+void Allocator::setDefault()
+{
+ gst_allocator_set_default(object<GstAllocator>());
+}
+
+MemoryPtr Allocator::alloc(size_t size, AllocationParams &params)
+{
+ return MemoryPtr::wrap(gst_allocator_alloc(object<GstAllocator>(), size, params.d_ptr));
+}
+
+void Allocator::free(MemoryPtr memory)
+{
+ gst_allocator_free(object<GstAllocator>(), memory);
+}
+
+} /* QGst */
diff --git a/src/QGst/allocator.h b/src/QGst/allocator.h
new file mode 100644
index 0000000..b87acdd
--- /dev/null
+++ b/src/QGst/allocator.h
@@ -0,0 +1,83 @@
+/*
+ Copyright (C) 2014 Diane Trout <diane@ghic.org>
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef QGST_ALLOCATOR_H
+#define QGST_ALLOCATOR_H
+
+#include "global.h"
+#include "object.h"
+#include "enums.h"
+#include "memory.h"
+#include <qglobal.h>
+
+namespace QGst {
+
+class AllocationParamsPrivate;
+class QTGSTREAMER_EXPORT AllocationParams
+{
+public:
+ AllocationParams();
+ AllocationParams(AllocationParams &other);
+ ~AllocationParams();
+
+ MemoryFlags flags() const;
+ void setFlags(MemoryFlags flags);
+ size_t align() const;
+ void setAlign(size_t align);
+ size_t prefix() const;
+ void setPrefix(size_t align);
+ size_t padding() const;
+ void setPadding(size_t padding);
+
+protected:
+ AllocationParamsPrivate * const d_ptr;
+
+private:
+ Q_DECLARE_PRIVATE(AllocationParams)
+ friend Allocator;
+};
+
+
+class QTGSTREAMER_EXPORT Allocator : public Object
+{
+ QGST_WRAPPER(Allocator)
+public:
+ explicit Allocator(GstAllocator *g_alloc);
+
+ operator GstAllocator *();
+ operator GstAllocator *() const;
+
+ // search for an already registered allocator.
+ static AllocatorPtr find(const char *name);
+ // this corresponds to gst_allocator_register.
+ void registerAllocator(const char *name);
+ // sets this allocator to be the default allocator
+ void setDefault();
+
+ // using this allocator create a chunk of memory
+ MemoryPtr alloc(size_t size, AllocationParams &params);
+ // release memory allocated with alloc
+ void free(MemoryPtr memory);
+// MemoryPtr newWrapped(MemoryFlags flags, void *data, size_t maxsize, size_t offset, size_t size, void *user_data, GDestroyNotify);
+
+ friend Memory;
+};
+
+} /* QGst */
+
+QGST_REGISTER_TYPE(QGst::Allocator)
+#endif /* QGST_ALLOCATOR_H */
diff --git a/src/QGst/global.h b/src/QGst/global.h
index 07f9815..26f01ce 100644
--- a/src/QGst/global.h
+++ b/src/QGst/global.h
@@ -120,6 +120,7 @@ QGST_WRAPPER_REFPOINTER_DECLARATION(FormatsQuery)
QGST_WRAPPER_REFPOINTER_DECLARATION(BufferingQuery)
QGST_WRAPPER_REFPOINTER_DECLARATION(UriQuery)
QGST_WRAPPER_DECLARATION(Buffer)
+QGST_WRAPPER_DECLARATION(Allocator)
QGST_WRAPPER_DECLARATION(Memory)
QGST_WRAPPER_DECLARATION(BufferList)
QGST_WRAPPER_DECLARATION(Event)
@@ -145,6 +146,8 @@ namespace QGst {
class Structure;
class SharedStructure;
typedef QSharedPointer<SharedStructure> StructurePtr;
+ class AllocationParams;
+ typedef QSharedPointer<AllocationParams> AllocationParamsPtr;
class MapInfo;
class Segment;
}
diff --git a/src/QGst/memory.cpp b/src/QGst/memory.cpp
index 8b33d4f..361b842 100644
--- a/src/QGst/memory.cpp
+++ b/src/QGst/memory.cpp
@@ -14,6 +14,7 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "allocator.h"
#include "memory.h"
#include "buffer.h"
@@ -62,13 +63,13 @@ MemoryPtr Memory::create(size_t size)
return MemoryPtr::wrap(gst_allocator_alloc(NULL, size, NULL));
}
-MemoryPtr Memory::create(MemoryFlags flags, void *allocator, MemoryPtr parent,
+MemoryPtr Memory::create(MemoryFlags flags, AllocatorPtr allocator, MemoryPtr parent,
size_t maxsize, size_t align, size_t offset, size_t size)
{
MemoryPtr mem;
gst_memory_init(mem, static_cast<GstMemoryFlags>(static_cast<int>(flags)),
- static_cast<GstAllocator *>(allocator), parent, maxsize, align, offset, size);
+ allocator->object<GstAllocator>(), parent, maxsize, align, offset, size);
return mem;
}
diff --git a/src/QGst/memory.h b/src/QGst/memory.h
index 7ff0e50..aa3bd1d 100644
--- a/src/QGst/memory.h
+++ b/src/QGst/memory.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013 Diane Trout <diane@ghic.org>
+ Copyright (C) 2014 Diane Trout <diane@ghic.org>
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
@@ -53,7 +53,7 @@ class QTGSTREAMER_EXPORT Memory : public MiniObject
QGST_WRAPPER(Memory)
public:
static MemoryPtr create(size_t size);
- static MemoryPtr create(MemoryFlags flags, void *allocator, MemoryPtr parent,
+ static MemoryPtr create(MemoryFlags flags, AllocatorPtr allocator, MemoryPtr parent,
size_t maxsize, size_t align, size_t offset, size_t size);
size_t getSizes(size_t &offset, size_t &maxsize);