Skip to content

Commit bf13f52

Browse files
Update Gst.parseLaunch behaviour, deprecate replaced methods (#113)
* test Gst.parseBinFromDescription and Gst.parseLaunch * Update parse methods to support single elements. * Update parseLaunch tests to work with Element return; add single element test to check that a Pipeline class isn't returned. * Tidy up documentation.
1 parent bcc5c37 commit bf13f52

File tree

6 files changed

+178
-77
lines changed

6 files changed

+178
-77
lines changed

src/org/freedesktop/gstreamer/Bin.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2018 Neil C Smith
23
* Copyright (c) 2016 Christophe Lafolet
34
* Copyright (c) 2009 Levente Farkas
45
* Copyright (C) 2007 Wayne Meissner
@@ -88,24 +89,26 @@ public Bin(String name) {
8889
this(initializer(GSTBIN_API.ptr_gst_bin_new(name), false));
8990
}
9091

91-
/**
92-
* Creates a bin from a text bin description.
93-
*
94-
* This function allows creation of a bin based on the syntax used in the
95-
* gst-launch utillity.
96-
*
97-
* @param binDecription the command line describing the bin
98-
* @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads
99-
* @return The new Bin.
100-
*/
101-
public static Bin launch(String binDecription, boolean ghostUnlinkedPads) {
102-
Pointer[] err = { null };
103-
Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDecription, ghostUnlinkedPads, err);
104-
if (bin == null) {
105-
throw new GstException(new GError(new GErrorStruct(err[0])));
106-
}
107-
return bin;
108-
}
92+
/**
93+
* Creates a bin from a text bin description.
94+
*
95+
* This function allows creation of a bin based on the syntax used in the
96+
* gst-launch utillity.
97+
*
98+
* @param binDecription the command line describing the bin
99+
* @param ghostUnlinkedPads whether to create ghost pads for the bin from
100+
* any unlinked pads
101+
* @return The new Bin.
102+
*/
103+
@Deprecated
104+
public static Bin launch(String binDecription, boolean ghostUnlinkedPads) {
105+
Pointer[] err = {null};
106+
Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDecription, ghostUnlinkedPads, err);
107+
if (bin == null) {
108+
throw new GstException(new GError(new GErrorStruct(err[0])));
109+
}
110+
return bin;
111+
}
109112

110113
/**
111114
* Adds an Element to this Bin.

src/org/freedesktop/gstreamer/Gst.java

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 Neil C Smith
2+
* Copyright (c) 2018 Neil C Smith
33
* Copyright (c) 2007 Wayne Meissner
44
*
55
* This file is part of gstreamer-java.
@@ -213,14 +213,16 @@ public static void quit() {
213213
* to play the pipeline.
214214
*
215215
* @param pipelineDescription the command line describing the pipeline
216+
* @param errors a list that any errors will be added to
216217
* @return a new element on success.
217-
* If more than one toplevel element is specified by
218-
* the pipeline_description , all elements are put into a GstPipeline,
219-
* which than is returned.
218+
* If more than one top-level element is specified by
219+
* the pipeline_description , all elements are put into a Pipeline,
220+
* which then is returned.
221+
* @throws GstException if the pipeline / element could not be created
220222
*/
221-
public static Pipeline parseLaunch(String pipelineDescription, List<GError> errors) {
223+
public static Element parseLaunch(String pipelineDescription, List<GError> errors) {
222224
Pointer[] err = { null };
223-
Pipeline pipeline = GSTPARSE_API.gst_parse_launch(pipelineDescription, err);
225+
Element pipeline = GSTPARSE_API.gst_parse_launch(pipelineDescription, err);
224226
if (pipeline == null) {
225227
throw new GstException(new GError(new GErrorStruct(err[0])));
226228
}
@@ -235,8 +237,24 @@ public static Pipeline parseLaunch(String pipelineDescription, List<GError> erro
235237
}
236238

237239
return pipeline;
238-
}
239-
public static Pipeline parseLaunch(String pipelineDescription) {
240+
}
241+
242+
/**
243+
* Create a new pipeline based on command line syntax.
244+
*
245+
* Please note that you might get a return value that is not NULL even
246+
* though the error is set.
247+
* In this case there was a recoverable parsing error and you can try
248+
* to play the pipeline.
249+
*
250+
* @param pipelineDescription the command line describing the pipeline
251+
* @return a new element on success.
252+
* If more than one top-level element is specified by
253+
* the pipeline_description , all elements are put into a Pipeline,
254+
* which then is returned.
255+
* @throws GstException if the pipeline / element could not be created
256+
*/
257+
public static Element parseLaunch(String pipelineDescription) {
240258
return parseLaunch(pipelineDescription, null);
241259
}
242260

@@ -247,11 +265,13 @@ public static Pipeline parseLaunch(String pipelineDescription) {
247265
* An error does not mean that the pipeline could not be constructed.
248266
*
249267
* @param pipelineDescription An array of strings containing the command line describing the pipeline.
268+
* @param errors a list that any errors will be added to
250269
* @return a new element on success.
270+
* @throws GstException if the pipeline / element could not be created
251271
*/
252-
public static Pipeline parseLaunch(String[] pipelineDescription, List<GError> errors) {
272+
public static Element parseLaunch(String[] pipelineDescription, List<GError> errors) {
253273
Pointer[] err = { null };
254-
Pipeline pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDescription, err);
274+
Element pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDescription, err);
255275
if (pipeline == null) {
256276
throw new GstException(new GError(new GErrorStruct(err[0])));
257277
}
@@ -267,7 +287,18 @@ public static Pipeline parseLaunch(String[] pipelineDescription, List<GError> er
267287

268288
return pipeline;
269289
}
270-
public static Pipeline parseLaunch(String[] pipelineDescription) {
290+
291+
/**
292+
* Create a new element based on command line syntax.
293+
*
294+
* error will contain an error message if an erroneous pipeline is specified.
295+
* An error does not mean that the pipeline could not be constructed.
296+
*
297+
* @param pipelineDescription An array of strings containing the command line describing the pipeline.
298+
* @return a new element on success.
299+
* @throws GstException if the pipeline / element could not be created
300+
*/
301+
public static Element parseLaunch(String[] pipelineDescription) {
271302
return parseLaunch(pipelineDescription, null);
272303
}
273304

@@ -279,7 +310,9 @@ public static Pipeline parseLaunch(String[] pipelineDescription) {
279310
*
280311
* @param binDescription the command line describing the bin
281312
* @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads
313+
* @param errors list that any errors will be added to
282314
* @return The new Bin.
315+
* @throws GstException if the bin could not be created
283316
*/
284317
public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads, List<GError> errors) {
285318

@@ -301,6 +334,18 @@ public static Bin parseBinFromDescription(String binDescription, boolean ghostUn
301334

302335
return bin;
303336
}
337+
338+
/**
339+
* Creates a bin from a text bin description.
340+
*
341+
* This function allows creation of a bin based on the syntax used in the
342+
* gst-launch utillity.
343+
*
344+
* @param binDescription the command line describing the bin
345+
* @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads
346+
* @return The new Bin.
347+
* @throws GstException if the bin could not be created
348+
*/
304349
public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads) {
305350
return parseBinFromDescription(binDescription, ghostUnlinkedPads, null);
306351
}

src/org/freedesktop/gstreamer/Pipeline.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2015 Neil C Smith
3-
* Copyright (c) 2007,2008 Wayne Meissner
4-
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
5-
* 2004,2005 Wim Taymans <wim@fluendo.com>
2+
* Copyright (c) 2018 Neil C Smith
3+
* Copyright (c) 2008 Wayne Meissner
4+
* Copyright (C) 2000 Erik Walthinsen <omega@cse.ogi.edu>
5+
* 2005 Wim Taymans <wim@fluendo.com>
66
*
77
* This file is part of gstreamer-java.
88
*
@@ -131,9 +131,10 @@ private static Initializer initializer(String name) {
131131
* @param pipelineDecription the command line describing the pipeline
132132
* @return The new Pipeline.
133133
*/
134+
@Deprecated
134135
public static Pipeline launch(String pipelineDecription) {
135136
Pointer[] err = { null };
136-
Pipeline pipeline = GSTPARSE_API.gst_parse_launch(pipelineDecription, err);
137+
Pipeline pipeline = (Pipeline) GSTPARSE_API.gst_parse_launch(pipelineDecription, err);
137138
if (pipeline == null) {
138139
throw new GstException(new GError(new GErrorStruct(err[0])));
139140
}
@@ -156,9 +157,10 @@ public static Pipeline launch(String pipelineDecription) {
156157
* @param pipelineDecription An array of strings containing the command line describing the pipeline.
157158
* @return The new Pipeline.
158159
*/
160+
@Deprecated
159161
public static Pipeline launch(String... pipelineDecription) {
160162
Pointer[] err = { null };
161-
Pipeline pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDecription, err);
163+
Pipeline pipeline = (Pipeline) GSTPARSE_API.gst_parse_launchv(pipelineDecription, err);
162164
if (pipeline == null) {
163165
throw new GstException(new GError(new GErrorStruct(err[0])));
164166
}

src/org/freedesktop/gstreamer/lowlevel/GstParseAPI.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn;
2525

2626
import com.sun.jna.Pointer;
27+
import org.freedesktop.gstreamer.Element;
2728

2829
/**
2930
* gstparse functions
3031
*/
3132
public interface GstParseAPI extends com.sun.jna.Library {
3233
GstParseAPI GSTPARSE_API = GstNative.load(GstParseAPI.class);
3334

34-
@CallerOwnsReturn Pipeline gst_parse_launch(String pipeline_description, Pointer[] error);
35-
@CallerOwnsReturn Pipeline gst_parse_launchv(String[] pipeline_description, Pointer[] error);
36-
@CallerOwnsReturn Pipeline gst_parse_launch(String pipeline_description, GstAPI.GErrorStruct[] error);
37-
@CallerOwnsReturn Pipeline gst_parse_launchv(String[] pipeline_description, GstAPI.GErrorStruct[] error);
35+
@CallerOwnsReturn Element gst_parse_launch(String pipeline_description, Pointer[] error);
36+
@CallerOwnsReturn Element gst_parse_launchv(String[] pipeline_description, Pointer[] error);
37+
@CallerOwnsReturn Element gst_parse_launch(String pipeline_description, GstAPI.GErrorStruct[] error);
38+
@CallerOwnsReturn Element gst_parse_launchv(String[] pipeline_description, GstAPI.GErrorStruct[] error);
3839
@CallerOwnsReturn Bin gst_parse_bin_from_description(String bin_description, boolean ghost_unlinked_pads,Pointer[] error);
3940
}

test/org/freedesktop/gstreamer/BinTest.java

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.freedesktop.gstreamer;
2121

22+
import java.util.ArrayList;
2223
import static org.junit.Assert.assertEquals;
2324
import static org.junit.Assert.assertFalse;
2425
import static org.junit.Assert.assertNotNull;
@@ -242,58 +243,80 @@ public void iterateSorted() {
242243
}
243244

244245
@Test
245-
public void testLaunch() {
246-
Bin bin = Bin.launch("fakesrc ! fakesink", false);
246+
public void testParseBin() {
247+
ArrayList<GError> errors = new ArrayList<GError>();
248+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors);
247249
assertNotNull("Bin not created", bin);
250+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
248251
}
249252
@Test
250-
public void testLaunchElementCount() {
251-
Bin bin = Bin.launch("fakesrc ! fakesink", false);
253+
public void testParseBinElementCount() {
254+
ArrayList<GError> errors = new ArrayList<GError>();
255+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors);
252256
assertEquals("Number of elements in pipeline incorrect", 2, bin.getElements().size());
257+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
253258
}
254259
@Test
255-
public void testLaunchSrcElement() {
256-
Bin bin = Bin.launch("fakesrc ! fakesink", false);
260+
public void testParseBinSrcElement() {
261+
ArrayList<GError> errors = new ArrayList<GError>();
262+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors);
257263
assertEquals("First element not a fakesrc", "fakesrc", bin.getSources().get(0).getFactory().getName());
264+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
258265
}
259266
@Test
260-
public void testLaunchSinkElement() {
261-
Bin bin = Bin.launch("fakesrc ! fakesink", false);
267+
public void testParseBinSinkElement() {
268+
ArrayList<GError> errors = new ArrayList<GError>();
269+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors);
262270
assertEquals("First element not a fakesink", "fakesink", bin.getSinks().get(0).getFactory().getName());
271+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
263272
}
264273
@Test
265-
public void testLaunchDisabledGhostPadsForSource() {
266-
Bin bin = Bin.launch("fakesrc", false);
274+
public void testParseBinDisabledGhostPadsForSource() {
275+
ArrayList<GError> errors = new ArrayList<GError>();
276+
Bin bin = Gst.parseBinFromDescription("fakesrc", false, errors);
267277
assertEquals("Number of src pads incorrect", 0, bin.getSrcPads().size());
278+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
268279
}
269280
@Test
270-
public void testLaunchDisabledGhostPadsForSink() {
271-
Bin bin = Bin.launch("fakesink", false);
281+
public void testParseBinDisabledGhostPadsForSink() {
282+
ArrayList<GError> errors = new ArrayList<GError>();
283+
Bin bin = Gst.parseBinFromDescription("fakesink", false, errors);
272284
assertEquals("Number of sink pads incorrect", 0, bin.getSinkPads().size());
285+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
273286
}
274287
@Test
275-
public void testLaunchEnabledGhostPadsForSource() {
276-
Bin bin = Bin.launch("fakesrc", true);
288+
public void testParseBinEnabledGhostPadsForSource() {
289+
ArrayList<GError> errors = new ArrayList<GError>();
290+
Bin bin = Gst.parseBinFromDescription("fakesrc", true, errors);
277291
assertEquals("Number of src pads incorrect", 1, bin.getSrcPads().size());
292+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
278293
}
279294
@Test
280-
public void testLaunchEnabledGhostPadsForSink() {
281-
Bin bin = Bin.launch("fakesink", true);
295+
public void testParseBinEnabledGhostPadsForSink() {
296+
ArrayList<GError> errors = new ArrayList<GError>();
297+
Bin bin = Gst.parseBinFromDescription("fakesink", true, errors);
282298
assertEquals("Number of sink pads incorrect", 1, bin.getSinkPads().size());
299+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
283300
}
284301
@Test
285-
public void testLaunchEnabledGhostPadsForSourceWithNoUsablePads() {
286-
Bin bin = Bin.launch("fakesrc ! fakesink", true);
302+
public void testParseBinEnabledGhostPadsForSourceWithNoUsablePads() {
303+
ArrayList<GError> errors = new ArrayList<GError>();
304+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", true, errors);
287305
assertEquals("Number of src pads incorrect", 0, bin.getSrcPads().size());
306+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
288307
}
289308
@Test
290-
public void testLaunchEnabledGhostPadsForSinkWithNoUsablePads() {
291-
Bin bin = Bin.launch("fakesrc ! fakesink", true);
309+
public void testParseBinEnabledGhostPadsForSinkWithNoUsablePads() {
310+
ArrayList<GError> errors = new ArrayList<GError>();
311+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", true, errors);
292312
assertEquals("Number of sink pads incorrect", 0, bin.getSinkPads().size());
313+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
293314
}
294315
@Test
295-
public void testLaunchEnabledGhostPadsWithNoUsablePads() {
296-
Bin bin = Bin.launch("fakesrc ! fakesink", true);
316+
public void testParseBinEnabledGhostPadsWithNoUsablePads() {
317+
ArrayList<GError> errors = new ArrayList<GError>();
318+
Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", true, errors);
297319
assertEquals("Number of pads incorrect", 0, bin.getPads().size());
320+
assertEquals("parseBinFromDescription with error!", errors.size(), 0);
298321
}
299322
}

0 commit comments

Comments
 (0)