Debian Codegraph @

gstreamer/src/buffer.hg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2015 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gstreamermm/miniobject.h>
21 #include <gstreamermm/clock.h>
22 #include <gstreamermm/memory.h>
23
24 _DEFS(gstreamermm,gst)
25
26 namespace Gst
27 {
28
29 _WRAP_ENUM(BufferFlags, GstBufferFlags)
30 _WRAP_ENUM(BufferCopyFlags, GstBufferCopyFlags)
31
32 class Memory;
33
34 /**
35 * Data-passing buffer type.
36 * See also: Pad, MiniObject, Memory, Meta, BufferPool
37 *
38 * Buffers are the basic unit of data transfer in GStreamer. They contain the
39 * timing and offset along with other arbitrary metadata that is associated
40 * with the #GstMemory blocks that the buffer contains.
41 *
42 * Buffers are usually created with Gst::Buffer::create. After a buffer has been
43 * created one will typically allocate memory for it and add it to the buffer.
44 * The following example creates a buffer that can hold a given video frame
45 * with a given width, height and bits per plane.
46 *
47 * Buffers can contain a list of Gst::Memory objects. You can retrieve how many
48 * memory objects with n_memory() and you can get a pointer
49 * to memory with peek_memory()
50 *
51 * A buffer will usually have timestamps, and a duration, but neither of these
52 * are guaranteed (they may be set to #GST_CLOCK_TIME_NONE). Whenever a
53 * meaningful value can be given for these, they should be set. The timestamps
54 * and duration are measured in nanoseconds (they are Gst::ClockTime values).
55 *
56 * The buffer DTS refers to the timestamp when the buffer should be decoded and
57 * is usually monotonically increasing. The buffer PTS refers to the timestamp when
58 * the buffer content should be presented to the user and is not always
59 * monotonically increasing.
60 *
61 * A buffer can also have one or both of a start and an end offset. These are
62 * media-type specific. For video buffers, the start offset will generally be
63 * the frame number. For audio buffers, it will be the number of samples
64 * produced so far. For compressed data, it could be the byte offset in a
65 * source or destination file. Likewise, the end offset will be the offset of
66 * the end of the buffer. These can only be meaningfully interpreted if you
67 * know the media type of the buffer (the preceeding CAPS event). Either or both
68 * can be set to Gst::BUFFER_OFFSET_NONE.
69 *
70 * To efficiently create a smaller buffer out of an existing one, you can
71 * use copy_region(). This method tries to share the memory objects
72 * between the two buffers.
73 *
74 * If a plug-in wants to modify the buffer data or metadata in-place, it should
75 * first obtain a buffer that is safe to modify by using
76 * create_writable(). This function is optimized so that a copy will
77 * only be made when it is necessary.
78 *
79 * Several flags of the buffer can be set and unset with the
80 * GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
81 * GST_BUFFER_FLAG_IS_SET() to test if a certain Gst::BufferFlag is set.
82 *
83 * Buffers can be efficiently merged into a larger buffer with
84 * append(). Copying of memory will only be done when absolutely
85 * needed.
86 *
87 * Arbitrary extra metadata can be set on a buffer with add_meta().
88 * Metadata can be retrieved with get_meta(). See also Gst::Meta
89 *
90 * An element should either unref the buffer or push it out on a src pad
91 * using Gst::Pad::push() (see Gst::Pad).
92 */
93 class Buffer : public MiniObject
94 {
95 _CLASS_OPAQUE_REFCOUNTED(Buffer, GstBuffer, gst_buffer_new, gst_buffer_ref, gst_buffer_unref)
96 _IGNORE(gst_buffer_ref, gst_buffer_unref)
97
98 public:
99 _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> copy() const, gst_buffer_copy)
100
101 _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> copy_deep() const, gst_buffer_copy_deep)
102
103 _WRAP_METHOD(static void copy_into(const Glib::RefPtr<Gst::Buffer>& destination_buffer, const Glib::RefPtr<Gst::Buffer>& source_buffer, BufferCopyFlags flags, gsize offset, gsize size), gst_buffer_copy_into)
104
105 _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> copy_region(Gst::BufferCopyFlags flags, gsize offset, gsize size), gst_buffer_copy_region)
106
107 static Glib::RefPtr<Gst::Buffer> create(guint size);
108
109 /** Makes a writable buffer from the given buffer. If the source buffer is
110 * already writable, this will simply return the same buffer. A copy will
111 * otherwise be made.
112 * @return A buffer (possibly the same pointer) that is writable.
113 */
114 Glib::RefPtr<Gst::Buffer> create_writable();
115
116 _WRAP_METHOD(Glib::RefPtr<Gst::Memory> get_memory(guint idx) const, gst_buffer_get_memory)
117
118 _WRAP_METHOD(gsize get_size() const, gst_buffer_get_size)
119
120 _WRAP_METHOD(gsize get_sizes(gsize& offset, gsize& max_size) const, gst_buffer_get_sizes)
121
122 _WRAP_METHOD(gsize get_sizes_range(guint idx, gint length, gsize& offset, gsize& max_size) const, gst_buffer_get_sizes_range)
123
124 _WRAP_METHOD(bool resize_range(guint idx, gint length, gssize offset, gssize size), gst_buffer_resize_range)
125
126 _WRAP_METHOD(void resize(gssize offset, gssize size), gst_buffer_resize)
127
128 _WRAP_METHOD(void set_size(gssize size), gst_buffer_set_size)
129
130 _WRAP_METHOD(Glib::RefPtr<Gst::Memory> peek_memory(guint idx), gst_buffer_peek_memory, refreturn)
131
132 _WRAP_METHOD(guint n_memory() const, gst_buffer_n_memory)
133
134 _WRAP_METHOD(void insert_memory(gint idx, Glib::RefPtr<Gst::Memory>&& mem), gst_buffer_insert_memory)
135
136 _WRAP_METHOD(Glib::RefPtr<Gst::Memory> get_all_memory() const, gst_buffer_get_all_memory)
137
138 _WRAP_METHOD(gsize fill(gsize offset, gconstpointer src, gsize size), gst_buffer_fill)
139
140 _WRAP_METHOD(void replace_memory_range(guint idx, gint length, Glib::RefPtr<Gst::Memory>&& mem), gst_buffer_replace_memory_range)
141
142 _WRAP_METHOD(Glib::RefPtr<Gst::Memory> get_memory_range(guint idx, gint length), gst_buffer_get_memory_range)
143
144 _WRAP_METHOD(void remove_memory_range(guint idx, gint length), gst_buffer_remove_memory_range)
145
146 _WRAP_METHOD(bool find_memory(gsize offset, gsize size, guint& idx, guint& length, gsize& skip), gst_buffer_find_memory)
147
148 _WRAP_METHOD(void prepend_memory(Glib::RefPtr<Gst::Memory>&& mem), gst_buffer_prepend_memory)
149
150 _WRAP_METHOD(void append_memory(Glib::RefPtr<Gst::Memory>&& mem), gst_buffer_append_memory)
151
152 _WRAP_METHOD(void remove_memory(guint idx), gst_buffer_remove_memory)
153
154 _WRAP_METHOD(void remove_all_memory(), gst_buffer_remove_all_memory)
155
156 _WRAP_METHOD(gsize memset(gsize offset, guint8 val, gsize size), gst_buffer_memset)
157
158 _WRAP_METHOD(void replace_memory(guint idx, Glib::RefPtr<Gst::Memory>&& mem), gst_buffer_replace_memory)
159
160 _WRAP_METHOD(void replace_all_memory(Glib::RefPtr<Gst::Memory>&& mem), gst_buffer_replace_all_memory)
161
162 _WRAP_METHOD(gsize extract(gsize offset, gpointer dest, gsize size), gst_buffer_extract)
163
164 _WRAP_METHOD(void extract_dup(gsize offset, gsize size, gpointer& dest, gsize& dest_size), gst_buffer_extract_dup)
165
166 _WRAP_METHOD(int memcmp(gsize offset, gconstpointer mem, gsize size), gst_buffer_memcmp)
167
168 _WRAP_METHOD(bool is_all_memory_writable() const, gst_buffer_is_all_memory_writable)
169
170 _WRAP_METHOD(bool is_memory_range_writable(guint idx, gint length) const, gst_buffer_is_memory_range_writable)
171
172 _WRAP_METHOD(bool map(Gst::MapInfo& info, Gst::MapFlags flags), gst_buffer_map)
173
174 _WRAP_METHOD(bool map_range(guint idx, gint length, Gst::MapInfo& info, MapFlags flags), gst_buffer_map_range)
175
176 _WRAP_METHOD(void unmap(Gst::MapInfo& info), gst_buffer_unmap)
177
178 Glib::RefPtr<Gst::Buffer> append_region(Glib::RefPtr<Gst::Buffer>&& buf, gssize offset, gssize size);
179 _IGNORE(gst_buffer_append_region)
180
181 Glib::RefPtr<Gst::Buffer> append(Glib::RefPtr<Gst::Buffer>&& buf);
182 _IGNORE(gst_buffer_append)
183
184 _MEMBER_GET(pts, pts, ClockTime, GstClockTime)
185 _MEMBER_SET(pts, pts, ClockTime, GstClockTime)
186
187 _MEMBER_GET(dts, dts, ClockTime, GstClockTime)
188 _MEMBER_SET(dts, dts, ClockTime, GstClockTime)
189
190 /** Get duration of this buffer.
191 * @return he duration in nanoseconds (as a Gst::ClockTime) of the data in
192 * the buffer. Value will be Gst::CLOCK_TIME_NONE if the duration is unknown.
193 */
194 _MEMBER_GET(duration, duration, ClockTime, GstClockTime)
195 _MEMBER_SET(duration, duration, ClockTime, GstClockTime)
196 /** Get the offset of this buffer.
197 * @return The offset in the source file of the beginning of this buffer.
198 */
199 _MEMBER_GET(offset, offset, guint64, guint64)
200
201 /** Get the offset end of this buffer.
202 * @return The offset in the source file of the end of this buffer.
203 */
204 _MEMBER_GET(offset_end, offset_end, guint64, guint64)
205
206 /** Constant for no-offset return results.
207 */
208 static guint64 offset_none();
209 };
210
211 }//namespace Gst