QtGStreamer 1.2.0
Loading...
Searching...
No Matches
allocator.cpp
1/*
2 Copyright (C) 2014 Diane Trout <diane@ghic.org>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "allocator.h"
19#include <gst/gst.h>
20
21namespace QGst {
22
23AllocationParams::AllocationParams()
24 : d(g_slice_new0(GstAllocationParams))
25{
26 gst_allocation_params_init(d);
27}
28
29AllocationParams::AllocationParams(const AllocationParams & other)
30 : d(gst_allocation_params_copy(other.d))
31{
32}
33
34AllocationParams::~AllocationParams()
35{
36 gst_allocation_params_free(d);
37}
38
39AllocationParams & AllocationParams::operator=(const AllocationParams & other)
40{
41 gst_allocation_params_free(d);
42 d = gst_allocation_params_copy(other.d);
43 return *this;
44}
45
46MemoryFlags AllocationParams::flags() const
47{
48 return static_cast<QGst::MemoryFlags>(static_cast<unsigned int>(d->flags));
49}
50
51void AllocationParams::setFlags(MemoryFlags flags)
52{
53 d->flags = static_cast<GstMemoryFlags>(static_cast<unsigned int>(flags));
54}
55
56size_t AllocationParams::align() const
57{
58 return d->align;
59}
60
61void AllocationParams::setAlign(size_t align)
62{
63 d->align = align;
64}
65
66size_t AllocationParams::prefix() const
67{
68 return d->prefix;
69}
70
71void AllocationParams::setPrefix(size_t align)
72{
73 d->prefix = align;
74}
75
76size_t AllocationParams::padding() const
77{
78 return d->padding;
79}
80
81void AllocationParams::setPadding(size_t padding)
82{
83 d->padding = padding;
84}
85
86AllocationParams::operator const GstAllocationParams*() const
87{
88 return d;
89}
90
91AllocationParams::operator GstAllocationParams*()
92{
93 return d;
94}
95
96//static
97AllocatorPtr Allocator::find(const char *name)
98{
99 return AllocatorPtr::wrap(gst_allocator_find(name), false);
100}
101
102//static
103AllocatorPtr Allocator::getDefault()
104{
105 return find(NULL);
106}
107
108//static
109AllocatorPtr Allocator::getSystemMemory()
110{
111 return find(GST_ALLOCATOR_SYSMEM);
112}
113
114MemoryPtr Allocator::alloc(size_t size, const AllocationParams & params)
115{
116 return MemoryPtr::wrap(gst_allocator_alloc(object<GstAllocator>(), size,
117 const_cast<GstAllocationParams *>(static_cast<const GstAllocationParams *>(params))), false);
118}
119
120void Allocator::free(MemoryPtr & memory)
121{
122 GstMemory *mem = memory;
123 gst_memory_ref(mem);
124 memory.clear();
125 gst_allocator_free(object<GstAllocator>(), mem);
126}
127
128} /* QGst */
Smart pointer class for working with wrapper classes that support reference counting.
Definition refpointer.h:91
Wrapper class for GstAllocationParams.
Definition allocator.h:31
Wrappers for GStreamer classes.