29
29
import java .util .Collections ;
30
30
import java .util .List ;
31
31
import java .util .concurrent .CountDownLatch ;
32
- import java .util .concurrent .ExecutorService ;
33
32
import java .util .concurrent .Executors ;
34
33
import java .util .concurrent .ScheduledExecutorService ;
35
34
import java .util .concurrent .ThreadFactory ;
38
37
import java .util .logging .Logger ;
39
38
40
39
import org .freedesktop .gstreamer .glib .MainContextExecutorService ;
41
- import org .freedesktop .gstreamer .lowlevel .GMainContext ;
42
40
import org .freedesktop .gstreamer .lowlevel .GstAPI .GErrorStruct ;
43
41
import org .freedesktop .gstreamer .lowlevel .GstTypes ;
44
42
import org .freedesktop .gstreamer .glib .NativeObject ;
56
54
import java .util .stream .Stream ;
57
55
import org .freedesktop .gstreamer .elements .Elements ;
58
56
import org .freedesktop .gstreamer .glib .GLib ;
57
+ import org .freedesktop .gstreamer .glib .GMainContext ;
59
58
import static org .freedesktop .gstreamer .lowlevel .GstParseAPI .GSTPARSE_API ;
60
59
import static org .freedesktop .gstreamer .glib .Natives .registration ;
60
+ import static org .freedesktop .gstreamer .lowlevel .GlibAPI .GLIB_API ;
61
61
import org .freedesktop .gstreamer .webrtc .WebRTC ;
62
62
63
63
/**
64
64
* Media library supporting arbitrary formats and filter graphs.
65
65
*/
66
- @ SuppressWarnings ("deprecation" )
67
66
public final class Gst {
68
67
69
68
private final static Logger LOG = Logger .getLogger (Gst .class .getName ());
@@ -79,7 +78,7 @@ public final class Gst {
79
78
// set minorVersion to a value guaranteed to be >= anything else unless set in init()
80
79
private static int minorVersion = Integer .MAX_VALUE ;
81
80
82
- public static class NativeArgs {
81
+ private static class NativeArgs {
83
82
84
83
public IntByReference argcRef ;
85
84
public PointerByReference argvRef ;
@@ -126,9 +125,6 @@ String[] toStringArray() {
126
125
}
127
126
}
128
127
129
- /**
130
- * Creates a new instance of Gst
131
- */
132
128
private Gst () {
133
129
}
134
130
@@ -195,27 +191,6 @@ public static synchronized final boolean isInitialized() {
195
191
* @return an executor that can be used for background tasks.
196
192
*/
197
193
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 () {
219
194
return executorService ;
220
195
}
221
196
@@ -244,15 +219,15 @@ public static Element parseLaunch(String pipelineDescription, List<GError> error
244
219
Pointer [] err = {null };
245
220
Element pipeline = GSTPARSE_API .gst_parse_launch (pipelineDescription , err );
246
221
if (pipeline == null ) {
247
- throw new GstException (new GError ( new GErrorStruct ( err [0 ]) ));
222
+ throw new GstException (extractError ( err [0 ]));
248
223
}
249
224
250
225
// check for error
251
226
if (err [0 ] != null ) {
252
227
if (errors != null ) {
253
- errors .add (new GError ( new GErrorStruct ( err [0 ]) ));
228
+ errors .add (extractError ( err [0 ]));
254
229
} else {
255
- LOG .log (Level .WARNING , new GError ( new GErrorStruct ( err [0 ]) ).getMessage ());
230
+ LOG .log (Level .WARNING , extractError ( err [0 ]).getMessage ());
256
231
}
257
232
}
258
233
@@ -293,15 +268,15 @@ public static Element parseLaunch(String[] pipelineDescription, List<GError> err
293
268
Pointer [] err = {null };
294
269
Element pipeline = GSTPARSE_API .gst_parse_launchv (pipelineDescription , err );
295
270
if (pipeline == null ) {
296
- throw new GstException (new GError ( new GErrorStruct ( err [0 ]) ));
271
+ throw new GstException (extractError ( err [0 ]));
297
272
}
298
273
299
274
// check for error
300
275
if (err [0 ] != null ) {
301
276
if (errors != null ) {
302
- errors .add (new GError ( new GErrorStruct ( err [0 ]) ));
277
+ errors .add (extractError ( err [0 ]));
303
278
} else {
304
- LOG .log (Level .WARNING , new GError ( new GErrorStruct ( err [0 ]) ).getMessage ());
279
+ LOG .log (Level .WARNING , extractError ( err [0 ]).getMessage ());
305
280
}
306
281
}
307
282
@@ -343,15 +318,15 @@ public static Bin parseBinFromDescription(String binDescription, boolean ghostUn
343
318
Bin bin = GSTPARSE_API .gst_parse_bin_from_description (binDescription , ghostUnlinkedPads , err );
344
319
345
320
if (bin == null ) {
346
- throw new GstException (new GError ( new GErrorStruct ( err [0 ]) ));
321
+ throw new GstException (extractError ( err [0 ]));
347
322
}
348
323
349
324
// check for error
350
325
if (err [0 ] != null ) {
351
326
if (errors != null ) {
352
- errors .add (new GError ( new GErrorStruct ( err [0 ]) ));
327
+ errors .add (extractError ( err [0 ]));
353
328
} else {
354
- LOG .log (Level .WARNING , new GError ( new GErrorStruct ( err [0 ]) ).getMessage ());
329
+ LOG .log (Level .WARNING , extractError ( err [0 ]).getMessage ());
355
330
}
356
331
}
357
332
@@ -373,6 +348,14 @@ public static Bin parseBinFromDescription(String binDescription, boolean ghostUn
373
348
public static Bin parseBinFromDescription (String binDescription , boolean ghostUnlinkedPads ) {
374
349
return parseBinFromDescription (binDescription , ghostUnlinkedPads , null );
375
350
}
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
+ }
376
359
377
360
/**
378
361
* Waits for the gstreamer system to shutdown via a call to {@link #quit}.
@@ -403,21 +386,6 @@ public static void invokeLater(final Runnable task) {
403
386
getExecutor ().execute (task );
404
387
}
405
388
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
- }
421
389
422
390
/**
423
391
* Gets the current main context used (if any).
@@ -528,7 +496,7 @@ public static synchronized final String[] init(Version requestedVersion,
528
496
Pointer [] error = {null };
529
497
if (!GST_API .gst_init_check (argv .argcRef , argv .argvRef , error )) {
530
498
INIT_COUNT .decrementAndGet ();
531
- throw new GstException (new GError ( new GErrorStruct ( error [0 ]) ));
499
+ throw new GstException (extractError ( error [0 ]));
532
500
}
533
501
534
502
LOG .fine ("after gst_init, argc=" + argv .argcRef .getValue ());
0 commit comments