Skip to content

Commit bc197c6

Browse files
Final tidy up for first v1 beta (#145)
* Update Bin debug to dot file flags to use enum / NativeFlags. * Hide metadata methods in DeviceProvider exposing lowlevel API. * Move GSource and GMainContext into org.freedesktop.gstreamer.glib * API tidy up - remove some remaining lowlevel-exposing, little used or deprecated code.
1 parent 55ed120 commit bc197c6

16 files changed

+205
-268
lines changed

src/org/freedesktop/gstreamer/Bin.java

+70-29
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import static org.freedesktop.gstreamer.lowlevel.GstBinAPI.GSTBIN_API;
2626

2727
import com.sun.jna.Pointer;
28+
import java.util.EnumSet;
2829
import java.util.List;
30+
import org.freedesktop.gstreamer.glib.NativeFlags;
2931
import org.freedesktop.gstreamer.glib.Natives;
3032
import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback;
3133

@@ -67,17 +69,6 @@ public class Bin extends Element {
6769
public static final String GST_NAME = "bin";
6870
public static final String GTYPE_NAME = "GstBin";
6971

70-
@Deprecated
71-
public static final int DEBUG_GRAPH_SHOW_MEDIA_TYPE = (1 << 0);
72-
@Deprecated
73-
public static final int DEBUG_GRAPH_SHOW_CAPS_DETAILS = (1 << 1);
74-
@Deprecated
75-
public static final int DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS = (1 << 2);
76-
@Deprecated
77-
public static final int DEBUG_GRAPH_SHOW_STATES = (1 << 3);
78-
@Deprecated
79-
public static final int DEBUG_GRAPH_SHOW_ALL = ((1 << 4) - 1);
80-
8172
protected Bin(Initializer init) {
8273
super(init);
8374
}
@@ -237,37 +228,44 @@ public Element getElementByNameRecurseUp(String name) {
237228
// public <T extends Element> T getElementByInterface(Class<T> iface) {
238229
// return iface.cast(GSTBIN_API.gst_bin_get_by_interface(this, GstTypes.typeFor(iface)));
239230
// }
240-
241231
/**
242-
* Calls {@link #debugToDotFile(int, String, boolean)} without timestamping
232+
* To aid debugging applications one can use this method to write out the
233+
* whole network of gstreamer elements that form the pipeline into a dot
234+
* file. This file can be processed with graphviz to get an image. e.g. dot
235+
* -Tpng -oimage.png graph_lowlevel.dot
236+
* <p>
237+
* The function is only active if gstreamer is configured with
238+
* "--gst-enable-gst-debug" and the environment variable
239+
* GST_DEBUG_DUMP_DOT_DIR is set to a basepath (e.g. /tmp).
240+
*
241+
* @param details to show in the graph
242+
* @param fileName output base filename (e.g. "myplayer")
243243
*/
244-
@Deprecated
245-
public void debugToDotFile(int details, String fileName) {
246-
debugToDotFile(details, fileName, false);
244+
public void debugToDotFile(EnumSet<DebugGraphDetails> details, String fileName) {
245+
GSTBIN_API.gst_debug_bin_to_dot_file(
246+
this, NativeFlags.toInt(details), fileName);
247247
}
248248

249249
/**
250250
* To aid debugging applications one can use this method to write out the
251-
* whole network of gstreamer elements that form the pipeline into an dot
251+
* whole network of gstreamer elements that form the pipeline into a dot
252252
* file. This file can be processed with graphviz to get an image. e.g. dot
253253
* -Tpng -oimage.png graph_lowlevel.dot
254-
*
254+
* <p>
255255
* The function is only active if gstreamer is configured with
256256
* "--gst-enable-gst-debug" and the environment variable
257257
* GST_DEBUG_DUMP_DOT_DIR is set to a basepath (e.g. /tmp).
258-
*
259-
* @param details to show in the graph, e.g. DEBUG_GRAPH_SHOW_ALL
258+
* <p>
259+
* Unlike {@link #debugToDotFile(java.util.EnumSet, java.lang.String)} this
260+
* method adds the current timestamp to the filename, so that it can be
261+
* used to take multiple snapshots.
262+
*
263+
* @param details to show in the graph
260264
* @param fileName output base filename (e.g. "myplayer")
261-
* @param timestampFileName if true it adds the current timestamp to the
262-
* filename, so that it can be used to take multiple snapshots.
263265
*/
264-
@Deprecated
265-
public void debugToDotFile(int details, String fileName, boolean timestampFileName) {
266-
if (timestampFileName) {
267-
GSTBIN_API.gst_debug_bin_to_dot_file_with_ts(this, details, fileName);
268-
} else {
269-
GSTBIN_API.gst_debug_bin_to_dot_file(this, details, fileName);
270-
}
266+
public void debugToDotFileWithTS(EnumSet<DebugGraphDetails> details, String fileName) {
267+
GSTBIN_API.gst_debug_bin_to_dot_file_with_ts(
268+
this, NativeFlags.toInt(details), fileName);
271269
}
272270

273271
/**
@@ -490,4 +488,47 @@ public void callback(Bin bin) {
490488
public void disconnect(DO_LATENCY listener) {
491489
disconnect(DO_LATENCY.class, listener);
492490
}
491+
492+
/**
493+
* Available details for pipeline graphs produced by
494+
* {@link #debugToDotFile(int, java.lang.String, boolean)}
495+
*/
496+
public static enum DebugGraphDetails implements NativeFlags<DebugGraphDetails> {
497+
498+
/**
499+
* Show caps-name on edges.
500+
*/
501+
SHOW_MEDIA_TYPE(1 << 0),
502+
/**
503+
* Show caps-details on edges.
504+
*/
505+
SHOW_CAPS_DETAILS(1 << 1),
506+
/**
507+
* Show modified parameters on elements.
508+
*/
509+
SHOW_NON_DEFAULT_PARAMS(1 << 2),
510+
/**
511+
* Show element states.
512+
*/
513+
SHOW_STATES(1 << 3);
514+
515+
/**
516+
* A convenience EnumSet with all values.
517+
*/
518+
public final static EnumSet<DebugGraphDetails> SHOW_ALL
519+
= EnumSet.allOf(DebugGraphDetails.class);
520+
521+
private final int value;
522+
523+
private DebugGraphDetails(int value) {
524+
this.value = value;
525+
}
526+
527+
@Override
528+
public int intValue() {
529+
return value;
530+
}
531+
532+
}
533+
493534
}

src/org/freedesktop/gstreamer/DateTime.java

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import static org.freedesktop.gstreamer.lowlevel.GstDateTimeAPI.GSTDATETIME_API;
2121

22-
import org.freedesktop.gstreamer.lowlevel.GType;
2322
import org.freedesktop.gstreamer.glib.NativeObject;
2423

2524
import com.sun.jna.Pointer;
@@ -30,7 +29,6 @@
3029
public class DateTime extends NativeObject {
3130

3231
public static final String GTYPE_NAME = "GstDateTime";
33-
public static final GType GTYPE = GSTDATETIME_API.gst_date_time_get_type();
3432

3533
public static DateTime createInstanceLocalEpoch(long secs) {
3634
return new DateTime(GSTDATETIME_API.gst_date_time_new_from_unix_epoch_local_time(secs), false, true);

src/org/freedesktop/gstreamer/ElementFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static Pointer makeRawElement(String factoryName, String name) {
311311
}
312312

313313
private static Element elementFor(Pointer ptr, String factoryName) {
314-
return Natives.objectFor(ptr, Element.class, false);
314+
return Natives.objectFor(ptr, Element.class, false, true);
315315
}
316316

317317
/**

src/org/freedesktop/gstreamer/Gst.java

+21-53
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Collections;
3030
import java.util.List;
3131
import java.util.concurrent.CountDownLatch;
32-
import java.util.concurrent.ExecutorService;
3332
import java.util.concurrent.Executors;
3433
import java.util.concurrent.ScheduledExecutorService;
3534
import java.util.concurrent.ThreadFactory;
@@ -38,7 +37,6 @@
3837
import java.util.logging.Logger;
3938

4039
import org.freedesktop.gstreamer.glib.MainContextExecutorService;
41-
import org.freedesktop.gstreamer.lowlevel.GMainContext;
4240
import org.freedesktop.gstreamer.lowlevel.GstAPI.GErrorStruct;
4341
import org.freedesktop.gstreamer.lowlevel.GstTypes;
4442
import org.freedesktop.gstreamer.glib.NativeObject;
@@ -56,14 +54,15 @@
5654
import java.util.stream.Stream;
5755
import org.freedesktop.gstreamer.elements.Elements;
5856
import org.freedesktop.gstreamer.glib.GLib;
57+
import org.freedesktop.gstreamer.glib.GMainContext;
5958
import static org.freedesktop.gstreamer.lowlevel.GstParseAPI.GSTPARSE_API;
6059
import static org.freedesktop.gstreamer.glib.Natives.registration;
60+
import static org.freedesktop.gstreamer.lowlevel.GlibAPI.GLIB_API;
6161
import org.freedesktop.gstreamer.webrtc.WebRTC;
6262

6363
/**
6464
* Media library supporting arbitrary formats and filter graphs.
6565
*/
66-
@SuppressWarnings("deprecation")
6766
public final class Gst {
6867

6968
private final static Logger LOG = Logger.getLogger(Gst.class.getName());
@@ -79,7 +78,7 @@ public final class Gst {
7978
// set minorVersion to a value guaranteed to be >= anything else unless set in init()
8079
private static int minorVersion = Integer.MAX_VALUE;
8180

82-
public static class NativeArgs {
81+
private static class NativeArgs {
8382

8483
public IntByReference argcRef;
8584
public PointerByReference argvRef;
@@ -126,9 +125,6 @@ String[] toStringArray() {
126125
}
127126
}
128127

129-
/**
130-
* Creates a new instance of Gst
131-
*/
132128
private Gst() {
133129
}
134130

@@ -195,27 +191,6 @@ public static synchronized final boolean isInitialized() {
195191
* @return an executor that can be used for background tasks.
196192
*/
197193
public static ScheduledExecutorService getExecutor() {
198-
return getScheduledExecutorService();
199-
}
200-
201-
/**
202-
* Gets the common {@code ExecutorService} used to execute background tasks.
203-
*
204-
* @return an executor that can be used for background tasks.
205-
*/
206-
@Deprecated
207-
public static ExecutorService getExecutorService() {
208-
return getScheduledExecutorService();
209-
}
210-
211-
/**
212-
* Gets the common {@code ScheduledExecutorService} used to execute
213-
* background tasks and schedule timeouts.
214-
*
215-
* @return an executor that can be used for background tasks.
216-
*/
217-
@Deprecated
218-
public static ScheduledExecutorService getScheduledExecutorService() {
219194
return executorService;
220195
}
221196

@@ -244,15 +219,15 @@ public static Element parseLaunch(String pipelineDescription, List<GError> error
244219
Pointer[] err = {null};
245220
Element pipeline = GSTPARSE_API.gst_parse_launch(pipelineDescription, err);
246221
if (pipeline == null) {
247-
throw new GstException(new GError(new GErrorStruct(err[0])));
222+
throw new GstException(extractError(err[0]));
248223
}
249224

250225
// check for error
251226
if (err[0] != null) {
252227
if (errors != null) {
253-
errors.add(new GError(new GErrorStruct(err[0])));
228+
errors.add(extractError(err[0]));
254229
} else {
255-
LOG.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
230+
LOG.log(Level.WARNING, extractError(err[0]).getMessage());
256231
}
257232
}
258233

@@ -293,15 +268,15 @@ public static Element parseLaunch(String[] pipelineDescription, List<GError> err
293268
Pointer[] err = {null};
294269
Element pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDescription, err);
295270
if (pipeline == null) {
296-
throw new GstException(new GError(new GErrorStruct(err[0])));
271+
throw new GstException(extractError(err[0]));
297272
}
298273

299274
// check for error
300275
if (err[0] != null) {
301276
if (errors != null) {
302-
errors.add(new GError(new GErrorStruct(err[0])));
277+
errors.add(extractError(err[0]));
303278
} else {
304-
LOG.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
279+
LOG.log(Level.WARNING, extractError(err[0]).getMessage());
305280
}
306281
}
307282

@@ -343,15 +318,15 @@ public static Bin parseBinFromDescription(String binDescription, boolean ghostUn
343318
Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDescription, ghostUnlinkedPads, err);
344319

345320
if (bin == null) {
346-
throw new GstException(new GError(new GErrorStruct(err[0])));
321+
throw new GstException(extractError(err[0]));
347322
}
348323

349324
// check for error
350325
if (err[0] != null) {
351326
if (errors != null) {
352-
errors.add(new GError(new GErrorStruct(err[0])));
327+
errors.add(extractError(err[0]));
353328
} else {
354-
LOG.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
329+
LOG.log(Level.WARNING, extractError(err[0]).getMessage());
355330
}
356331
}
357332

@@ -373,6 +348,14 @@ public static Bin parseBinFromDescription(String binDescription, boolean ghostUn
373348
public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads) {
374349
return parseBinFromDescription(binDescription, ghostUnlinkedPads, null);
375350
}
351+
352+
private static GError extractError(Pointer errorPtr) {
353+
GErrorStruct struct = new GErrorStruct(errorPtr);
354+
struct.read();
355+
GError err = new GError(struct.getCode(), struct.getMessage());
356+
GLIB_API.g_error_free(struct);
357+
return err;
358+
}
376359

377360
/**
378361
* Waits for the gstreamer system to shutdown via a call to {@link #quit}.
@@ -403,21 +386,6 @@ public static void invokeLater(final Runnable task) {
403386
getExecutor().execute(task);
404387
}
405388

406-
/**
407-
* Executes a task on the gstreamer background
408-
* {@link java.util.concurrent.Executor}, waiting until the task completes
409-
* before returning.
410-
*
411-
* @param task the task to execute.
412-
*/
413-
@Deprecated
414-
public static void invokeAndWait(Runnable task) {
415-
try {
416-
getExecutorService().submit(task).get();
417-
} catch (Exception ex) {
418-
throw new RuntimeException(ex.getCause());
419-
}
420-
}
421389

422390
/**
423391
* Gets the current main context used (if any).
@@ -528,7 +496,7 @@ public static synchronized final String[] init(Version requestedVersion,
528496
Pointer[] error = {null};
529497
if (!GST_API.gst_init_check(argv.argcRef, argv.argvRef, error)) {
530498
INIT_COUNT.decrementAndGet();
531-
throw new GstException(new GError(new GErrorStruct(error[0])));
499+
throw new GstException(extractError(error[0]));
532500
}
533501

534502
LOG.fine("after gst_init, argc=" + argv.argcRef.getValue());

src/org/freedesktop/gstreamer/TagList.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
public class TagList extends MiniObject {
5353

5454
public static final String GTYPE_NAME = "GstTagList";
55-
55+
5656
/**
5757
* Creates a new instance of TagList
5858
*
@@ -281,18 +281,17 @@ public Object get(TagList tl, String tag, int index) {
281281
return ret;
282282
}
283283
});
284-
put(GDate.GTYPE, new TagGetter() {
284+
put(GType.valueOf(GDate.GTYPE_NAME), new TagGetter() {
285285
public Object get(TagList tl, String tag, int index) {
286286
PointerByReference value = new PointerByReference();
287287
GSTTAGLIST_API.gst_tag_list_get_date_index(tl, tag, index, value);
288288
if (value.getValue() == null) {
289289
return null;
290290
}
291-
// return new GDate(value.getValue(), false, true);
292-
return Natives.objectFor(value.getValue(), GDate.class);
291+
return Natives.objectFor(value.getValue(), GDate.class, false, true);
293292
}
294293
});
295-
put(DateTime.GTYPE, new TagGetter() {
294+
put(GType.valueOf(DateTime.GTYPE_NAME), new TagGetter() {
296295
public Object get(TagList tl, String tag, int index) {
297296
PointerByReference value = new PointerByReference();
298297
GSTTAGLIST_API.gst_tag_list_get_date_time_index(tl, tag, index, value);

0 commit comments

Comments
 (0)