Skip to content

Commit 10775ac

Browse files
Merge pull request #43 from matthiasblaesing/centralize_native_bindings
Centralize native bindings
2 parents df7574f + d9d744d commit 10775ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+577
-830
lines changed

src/org/freedesktop/gstreamer/Bin.java

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
*/
2121

2222
package org.freedesktop.gstreamer;
23+
2324
import java.util.List;
2425

26+
import com.sun.jna.Pointer;
27+
2528
import org.freedesktop.gstreamer.lowlevel.GstAPI.GErrorStruct;
2629
import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback;
27-
import org.freedesktop.gstreamer.lowlevel.GstBinAPI;
28-
import org.freedesktop.gstreamer.lowlevel.GstNative;
29-
import org.freedesktop.gstreamer.lowlevel.GstParseAPI;
3030
import org.freedesktop.gstreamer.lowlevel.GstTypes;
31-
import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn;
3231

33-
import com.sun.jna.Pointer;
32+
import static org.freedesktop.gstreamer.lowlevel.GstBinAPI.GSTBIN_API;
33+
import static org.freedesktop.gstreamer.lowlevel.GstParseAPI.GSTPARSE_API;
3434

3535
/**
3636
* Base class and element that can contain other elements.
@@ -61,11 +61,6 @@
6161
public class Bin extends Element {
6262
public static final String GST_NAME = "bin";
6363
public static final String GTYPE_NAME = "GstBin";
64-
65-
private static interface API extends GstBinAPI, GstParseAPI {
66-
@CallerOwnsReturn Pointer ptr_gst_pipeline_new(String name);
67-
}
68-
private static final API gst = GstNative.load(API.class);
6964

7065
public static final int DEBUG_GRAPH_SHOW_MEDIA_TYPE = (1<<0);
7166
public static final int DEBUG_GRAPH_SHOW_CAPS_DETAILS = (1<<1);
@@ -81,15 +76,15 @@ public Bin(Initializer init) {
8176
* Creates a new Bin with a unique name.
8277
*/
8378
public Bin() {
84-
this(initializer(gst.ptr_gst_bin_new(null), false));
79+
this(initializer(GSTBIN_API.ptr_gst_bin_new(null), false));
8580
}
8681

8782
/**
8883
* Creates a new Bin with the given name.
8984
* @param name The Name to assign to the new Bin
9085
*/
9186
public Bin(String name) {
92-
this(initializer(gst.ptr_gst_bin_new(name), false));
87+
this(initializer(GSTBIN_API.ptr_gst_bin_new(name), false));
9388
}
9489

9590
/**
@@ -104,7 +99,7 @@ public Bin(String name) {
10499
*/
105100
public static Bin launch(String binDecription, boolean ghostUnlinkedPads) {
106101
Pointer[] err = { null };
107-
Bin bin = gst.gst_parse_bin_from_description(binDecription, ghostUnlinkedPads, err);
102+
Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDecription, ghostUnlinkedPads, err);
108103
if (bin == null) {
109104
throw new GstException(new GError(new GErrorStruct(err[0])));
110105
}
@@ -125,7 +120,7 @@ public static Bin launch(String binDecription, boolean ghostUnlinkedPads) {
125120
* will not accept the element.
126121
*/
127122
public boolean add(Element element) {
128-
return gst.gst_bin_add(this, element);
123+
return GSTBIN_API.gst_bin_add(this, element);
129124
}
130125

131126
/**
@@ -135,7 +130,7 @@ public boolean add(Element element) {
135130
* @see Bin#add(Element)
136131
*/
137132
public void addMany(Element... elements) {
138-
gst.gst_bin_add_many(this, elements);
133+
GSTBIN_API.gst_bin_add_many(this, elements);
139134
}
140135

141136
/**
@@ -150,7 +145,7 @@ public void addMany(Element... elements) {
150145
* @return true if the element was successfully removed
151146
*/
152147
public boolean remove(Element element) {
153-
return gst.gst_bin_remove(this, element);
148+
return GSTBIN_API.gst_bin_remove(this, element);
154149
}
155150

156151
/**
@@ -159,7 +154,7 @@ public boolean remove(Element element) {
159154
* @param elements The list {@link Element} to remove
160155
*/
161156
public void removeMany(Element... elements) {
162-
gst.gst_bin_remove_many(this, elements);
157+
GSTBIN_API.gst_bin_remove_many(this, elements);
163158
}
164159

165160
private List<Element> elementList(Pointer iter) {
@@ -171,7 +166,7 @@ private List<Element> elementList(Pointer iter) {
171166
* @return The List of {@link Element}s.
172167
*/
173168
public List<Element> getElements() {
174-
return elementList(gst.gst_bin_iterate_elements(this));
169+
return elementList(GSTBIN_API.gst_bin_iterate_elements(this));
175170
}
176171
/**
177172
* Gets an a list of the elements in this bin in topologically
@@ -180,7 +175,7 @@ public List<Element> getElements() {
180175
* @return The List of {@link Element}s.
181176
*/
182177
public List<Element> getElementsSorted() {
183-
return elementList(gst.gst_bin_iterate_sorted(this));
178+
return elementList(GSTBIN_API.gst_bin_iterate_sorted(this));
184179
}
185180

186181
/**
@@ -192,23 +187,23 @@ public List<Element> getElementsSorted() {
192187
* @return The List of {@link Element}s.
193188
*/
194189
public List<Element> getElementsRecursive() {
195-
return elementList(gst.gst_bin_iterate_recurse(this));
190+
return elementList(GSTBIN_API.gst_bin_iterate_recurse(this));
196191
}
197192

198193
/**
199194
* Retrieve a list of the sink {@link Element}s contained in the Bin.
200195
* @return The List of sink {@link Element}s.
201196
*/
202197
public List<Element> getSinks() {
203-
return elementList(gst.gst_bin_iterate_sinks(this));
198+
return elementList(GSTBIN_API.gst_bin_iterate_sinks(this));
204199
}
205200

206201
/**
207202
* Retrieve a list of the source {@link Element}s contained in the Bin.
208203
* @return The List of source {@link Element}s.
209204
*/
210205
public List<Element> getSources() {
211-
return elementList(gst.gst_bin_iterate_sources(this));
206+
return elementList(GSTBIN_API.gst_bin_iterate_sources(this));
212207
}
213208

214209
/**
@@ -219,7 +214,7 @@ public List<Element> getSources() {
219214
* @return The {@link Element} if found, else null.
220215
*/
221216
public Element getElementByName(String name) {
222-
return gst.gst_bin_get_by_name(this, name);
217+
return GSTBIN_API.gst_bin_get_by_name(this, name);
223218
}
224219

225220
/**
@@ -229,7 +224,7 @@ public Element getElementByName(String name) {
229224
* @return The {@link Element} if found, else null.
230225
*/
231226
public Element getElementByNameRecurseUp(String name) {
232-
return gst.gst_bin_get_by_name_recurse_up(this, name);
227+
return GSTBIN_API.gst_bin_get_by_name_recurse_up(this, name);
233228
}
234229

235230
/**
@@ -239,7 +234,7 @@ public Element getElementByNameRecurseUp(String name) {
239234
* @return The {@link Element} that implements the interface.
240235
*/
241236
public <T extends Element> T getElementByInterface(Class<T> iface) {
242-
return iface.cast(gst.gst_bin_get_by_interface(this, GstTypes.typeFor(iface)));
237+
return iface.cast(GSTBIN_API.gst_bin_get_by_interface(this, GstTypes.typeFor(iface)));
243238
}
244239

245240
/**
@@ -266,9 +261,9 @@ public void debugToDotFile(int details, String fileName) {
266261
*/
267262
public void debugToDotFile(int details, String fileName, boolean timestampFileName) {
268263
if (timestampFileName)
269-
gst._gst_debug_bin_to_dot_file_with_ts(this, details, fileName);
264+
GSTBIN_API._gst_debug_bin_to_dot_file_with_ts(this, details, fileName);
270265
else
271-
gst.gst_debug_bin_to_dot_file(this, details, fileName);
266+
GSTBIN_API.gst_debug_bin_to_dot_file(this, details, fileName);
272267
}
273268

274269
/**

src/org/freedesktop/gstreamer/Buffer.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222

2323
package org.freedesktop.gstreamer;
2424

25+
import com.sun.jna.Pointer;
26+
import java.nio.ByteBuffer;
2527

2628
import org.freedesktop.gstreamer.lowlevel.GstBufferAPI;
2729
import org.freedesktop.gstreamer.lowlevel.GstBufferAPI.MapInfoStruct;
28-
import org.freedesktop.gstreamer.lowlevel.GstMiniObjectAPI;
29-
import org.freedesktop.gstreamer.lowlevel.GstNative;
30-
import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn;
3130

32-
import com.sun.jna.Pointer;
33-
import java.nio.ByteBuffer;
31+
import static org.freedesktop.gstreamer.lowlevel.GstBufferAPI.GSTBUFFER_API;
3432

3533
/**
3634
* Data-passing buffer type, supporting sub-buffers.
@@ -92,12 +90,6 @@
9290
public class Buffer extends MiniObject {
9391
public static final String GTYPE_NAME = "GstBuffer";
9492

95-
private static interface API extends GstBufferAPI, GstMiniObjectAPI {
96-
@CallerOwnsReturn Pointer ptr_gst_buffer_new();
97-
@CallerOwnsReturn Pointer ptr_gst_buffer_new_allocate(Pointer allocator, int size, Pointer params);
98-
}
99-
private static final API gst = GstNative.load(API.class);
100-
10193
private final MapInfoStruct mapInfo;
10294

10395
public Buffer(Initializer init) {
@@ -109,7 +101,7 @@ public Buffer(Initializer init) {
109101
* Creates a newly allocated buffer without any data.
110102
*/
111103
public Buffer() {
112-
this(initializer(gst.ptr_gst_buffer_new()));
104+
this(initializer(GSTBUFFER_API.ptr_gst_buffer_new()));
113105
}
114106

115107
/**
@@ -126,7 +118,7 @@ public Buffer(int size) {
126118
}
127119

128120
private static Pointer allocBuffer(int size) {
129-
Pointer ptr = gst.ptr_gst_buffer_new_allocate(null, size, null);
121+
Pointer ptr = GSTBUFFER_API.ptr_gst_buffer_new_allocate(null, size, null);
130122
if (ptr == null) {
131123
throw new OutOfMemoryError("Could not allocate Buffer of size "+ size);
132124
}
@@ -139,7 +131,7 @@ private static Pointer allocBuffer(int size) {
139131
// * @return the size of the buffer data in bytes.
140132
// */
141133
// public int getSize() {
142-
// return gst.gst_buffer_get_size(this).intValue();
134+
// return GstBufferAPI.GSTBUFFER_API.gst_buffer_get_size(this).intValue();
143135
// }
144136

145137
/**
@@ -149,7 +141,7 @@ private static Pointer allocBuffer(int size) {
149141
* @return A {@link java.nio.ByteBuffer} that can access this Buffer's data.
150142
*/
151143
public ByteBuffer map(boolean writeable) {
152-
boolean ok = gst.gst_buffer_map(this, mapInfo,
144+
boolean ok = GSTBUFFER_API.gst_buffer_map(this, mapInfo,
153145
writeable ? GstBufferAPI.GST_MAP_WRITE : GstBufferAPI.GST_MAP_READ);
154146
if (ok) {
155147
return mapInfo.data.getByteBuffer(0, mapInfo.size.intValue());
@@ -159,7 +151,7 @@ public ByteBuffer map(boolean writeable) {
159151
}
160152

161153
public void unmap() {
162-
gst.gst_buffer_unmap(this, mapInfo);
154+
GSTBUFFER_API.gst_buffer_unmap(this, mapInfo);
163155
}
164156

165157
}

0 commit comments

Comments
 (0)