Skip to content

Commit 90b1586

Browse files
i-n-g-oneilcsmith-net
authored andcommitted
Pipeline launch log error (#104)
* check and log error * update function documentation from official gstreamer 1.8 * add parseLaunch and parseBinFromDescription
1 parent 8bef024 commit 90b1586

File tree

2 files changed

+130
-6
lines changed

2 files changed

+130
-6
lines changed

src/org/freedesktop/gstreamer/Gst.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import com.sun.jna.ptr.IntByReference;
6060
import com.sun.jna.ptr.PointerByReference;
6161
import java.util.Arrays;
62+
import java.util.logging.Level;
63+
import static org.freedesktop.gstreamer.lowlevel.GstParseAPI.GSTPARSE_API;
6264

6365
/**
6466
* Media library supporting arbitrary formats and filter graphs.
@@ -201,6 +203,109 @@ public static void quit() {
201203
quit.countDown();
202204
}
203205

206+
207+
/**
208+
* Create a new pipeline based on command line syntax.
209+
*
210+
* Please note that you might get a return value that is not NULL even
211+
* though the error is set.
212+
* In this case there was a recoverable parsing error and you can try
213+
* to play the pipeline.
214+
*
215+
* @param pipelineDescription the command line describing the pipeline
216+
* @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.
220+
*/
221+
public static Pipeline parseLaunch(String pipelineDescription, List<GError> errors) {
222+
Pointer[] err = { null };
223+
Pipeline pipeline = GSTPARSE_API.gst_parse_launch(pipelineDescription, err);
224+
if (pipeline == null) {
225+
throw new GstException(new GError(new GErrorStruct(err[0])));
226+
}
227+
228+
// check for error
229+
if (err[0] != null) {
230+
if (errors != null) {
231+
errors.add(new GError(new GErrorStruct(err[0])));
232+
} else {
233+
logger.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
234+
}
235+
}
236+
237+
return pipeline;
238+
}
239+
public static Pipeline parseLaunch(String pipelineDescription) {
240+
return parseLaunch(pipelineDescription, null);
241+
}
242+
243+
/**
244+
* Create a new element based on command line syntax.
245+
*
246+
* error will contain an error message if an erroneous pipeline is specified.
247+
* An error does not mean that the pipeline could not be constructed.
248+
*
249+
* @param pipelineDescription An array of strings containing the command line describing the pipeline.
250+
* @return a new element on success.
251+
*/
252+
public static Pipeline parseLaunch(String[] pipelineDescription, List<GError> errors) {
253+
Pointer[] err = { null };
254+
Pipeline pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDescription, err);
255+
if (pipeline == null) {
256+
throw new GstException(new GError(new GErrorStruct(err[0])));
257+
}
258+
259+
// check for error
260+
if (err[0] != null) {
261+
if (errors != null) {
262+
errors.add(new GError(new GErrorStruct(err[0])));
263+
} else {
264+
logger.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
265+
}
266+
}
267+
268+
return pipeline;
269+
}
270+
public static Pipeline parseLaunch(String[] pipelineDescription) {
271+
return parseLaunch(pipelineDescription, null);
272+
}
273+
274+
/**
275+
* Creates a bin from a text bin description.
276+
*
277+
* This function allows creation of a bin based on the syntax used in the
278+
* gst-launch utillity.
279+
*
280+
* @param binDescription the command line describing the bin
281+
* @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads
282+
* @return The new Bin.
283+
*/
284+
public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads, List<GError> errors) {
285+
286+
Pointer[] err = { null };
287+
Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDescription, ghostUnlinkedPads, err);
288+
289+
if (bin == null) {
290+
throw new GstException(new GError(new GErrorStruct(err[0])));
291+
}
292+
293+
// check for error
294+
if (err[0] != null) {
295+
if (errors != null) {
296+
errors.add(new GError(new GErrorStruct(err[0])));
297+
} else {
298+
logger.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
299+
}
300+
}
301+
302+
return bin;
303+
}
304+
public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads) {
305+
return parseBinFromDescription(binDescription, ghostUnlinkedPads, null);
306+
}
307+
308+
204309
/**
205310
* Waits for the gstreamer system to shutdown via a call to {@link #quit}.
206311
* <p> For most gui programs, this is of little use. However, it can be

src/org/freedesktop/gstreamer/Pipeline.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.concurrent.TimeUnit;
2424

2525
import com.sun.jna.Pointer;
26+
import java.util.logging.Level;
27+
import java.util.logging.Logger;
2628

2729
import org.freedesktop.gstreamer.lowlevel.GstAPI.GErrorStruct;
2830

@@ -89,6 +91,8 @@ public class Pipeline extends Bin {
8991
public static final String GST_NAME = "pipeline";
9092
public static final String GTYPE_NAME = "GstPipeline";
9193

94+
private static Logger logger = Logger.getLogger(Pipeline.class.getName());
95+
9296
public Pipeline(Initializer init) {
9397
super(init);
9498
}
@@ -117,10 +121,12 @@ private static Initializer initializer(String name) {
117121
}
118122

119123
/**
120-
* Creates a pipeline from a text pipeline description.
124+
* Create a new pipeline based on command line syntax.
121125
*
122-
* This function allows creation of a pipeline based on the syntax used in the
123-
* gst-launch utillity.
126+
* Please note that you might get a return value that is not NULL even
127+
* though the error is set.
128+
* In this case there was a recoverable parsing error and you can try
129+
* to play the pipeline.
124130
*
125131
* @param pipelineDecription the command line describing the pipeline
126132
* @return The new Pipeline.
@@ -131,15 +137,21 @@ public static Pipeline launch(String pipelineDecription) {
131137
if (pipeline == null) {
132138
throw new GstException(new GError(new GErrorStruct(err[0])));
133139
}
140+
141+
// check for error
142+
if (err[0] != null) {
143+
logger.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
144+
}
145+
134146
pipeline.initBus();
135147
return pipeline;
136148
}
137149

138150
/**
139-
* Creates a pipeline from a text pipeline description.
151+
* Create a new element based on command line syntax.
140152
*
141-
* This function allows creation of a pipeline based on the syntax used in the
142-
* gst-launch utillity.
153+
* error will contain an error message if an erroneous pipeline is specified.
154+
* An error does not mean that the pipeline could not be constructed.
143155
*
144156
* @param pipelineDecription An array of strings containing the command line describing the pipeline.
145157
* @return The new Pipeline.
@@ -150,6 +162,13 @@ public static Pipeline launch(String... pipelineDecription) {
150162
if (pipeline == null) {
151163
throw new GstException(new GError(new GErrorStruct(err[0])));
152164
}
165+
166+
// check for error
167+
if (err[0] != null) {
168+
// log error!
169+
logger.log(Level.WARNING, new GError(new GErrorStruct(err[0])).getMessage());
170+
}
171+
153172
pipeline.initBus();
154173
return pipeline;
155174
}

0 commit comments

Comments
 (0)