diff --git a/src/org/freedesktop/gstreamer/Bin.java b/src/org/freedesktop/gstreamer/Bin.java index 86d2b7c..1dbf50c 100644 --- a/src/org/freedesktop/gstreamer/Bin.java +++ b/src/org/freedesktop/gstreamer/Bin.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2018 Neil C Smith * Copyright (c) 2016 Christophe Lafolet * Copyright (c) 2009 Levente Farkas * Copyright (C) 2007 Wayne Meissner @@ -88,24 +89,26 @@ public Bin(String name) { this(initializer(GSTBIN_API.ptr_gst_bin_new(name), false)); } - /** - * Creates a bin from a text bin description. - * - * This function allows creation of a bin based on the syntax used in the - * gst-launch utillity. - * - * @param binDecription the command line describing the bin - * @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads - * @return The new Bin. - */ - public static Bin launch(String binDecription, boolean ghostUnlinkedPads) { - Pointer[] err = { null }; - Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDecription, ghostUnlinkedPads, err); - if (bin == null) { - throw new GstException(new GError(new GErrorStruct(err[0]))); - } - return bin; - } + /** + * Creates a bin from a text bin description. + * + * This function allows creation of a bin based on the syntax used in the + * gst-launch utillity. + * + * @param binDecription the command line describing the bin + * @param ghostUnlinkedPads whether to create ghost pads for the bin from + * any unlinked pads + * @return The new Bin. + */ + @Deprecated + public static Bin launch(String binDecription, boolean ghostUnlinkedPads) { + Pointer[] err = {null}; + Bin bin = GSTPARSE_API.gst_parse_bin_from_description(binDecription, ghostUnlinkedPads, err); + if (bin == null) { + throw new GstException(new GError(new GErrorStruct(err[0]))); + } + return bin; + } /** * Adds an Element to this Bin. diff --git a/src/org/freedesktop/gstreamer/Gst.java b/src/org/freedesktop/gstreamer/Gst.java index 703ae2e..7036af3 100644 --- a/src/org/freedesktop/gstreamer/Gst.java +++ b/src/org/freedesktop/gstreamer/Gst.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Neil C Smith + * Copyright (c) 2018 Neil C Smith * Copyright (c) 2007 Wayne Meissner * * This file is part of gstreamer-java. @@ -213,14 +213,16 @@ public static void quit() { * to play the pipeline. * * @param pipelineDescription the command line describing the pipeline + * @param errors a list that any errors will be added to * @return a new element on success. - * If more than one toplevel element is specified by - * the pipeline_description , all elements are put into a GstPipeline, - * which than is returned. + * If more than one top-level element is specified by + * the pipeline_description , all elements are put into a Pipeline, + * which then is returned. + * @throws GstException if the pipeline / element could not be created */ - public static Pipeline parseLaunch(String pipelineDescription, List errors) { + public static Element parseLaunch(String pipelineDescription, List errors) { Pointer[] err = { null }; - Pipeline pipeline = GSTPARSE_API.gst_parse_launch(pipelineDescription, err); + Element pipeline = GSTPARSE_API.gst_parse_launch(pipelineDescription, err); if (pipeline == null) { throw new GstException(new GError(new GErrorStruct(err[0]))); } @@ -235,8 +237,24 @@ public static Pipeline parseLaunch(String pipelineDescription, List erro } return pipeline; - } - public static Pipeline parseLaunch(String pipelineDescription) { + } + + /** + * Create a new pipeline based on command line syntax. + * + * Please note that you might get a return value that is not NULL even + * though the error is set. + * In this case there was a recoverable parsing error and you can try + * to play the pipeline. + * + * @param pipelineDescription the command line describing the pipeline + * @return a new element on success. + * If more than one top-level element is specified by + * the pipeline_description , all elements are put into a Pipeline, + * which then is returned. + * @throws GstException if the pipeline / element could not be created + */ + public static Element parseLaunch(String pipelineDescription) { return parseLaunch(pipelineDescription, null); } @@ -247,11 +265,13 @@ public static Pipeline parseLaunch(String pipelineDescription) { * An error does not mean that the pipeline could not be constructed. * * @param pipelineDescription An array of strings containing the command line describing the pipeline. + * @param errors a list that any errors will be added to * @return a new element on success. + * @throws GstException if the pipeline / element could not be created */ - public static Pipeline parseLaunch(String[] pipelineDescription, List errors) { + public static Element parseLaunch(String[] pipelineDescription, List errors) { Pointer[] err = { null }; - Pipeline pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDescription, err); + Element pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDescription, err); if (pipeline == null) { throw new GstException(new GError(new GErrorStruct(err[0]))); } @@ -267,7 +287,18 @@ public static Pipeline parseLaunch(String[] pipelineDescription, List er return pipeline; } - public static Pipeline parseLaunch(String[] pipelineDescription) { + + /** + * Create a new element based on command line syntax. + * + * error will contain an error message if an erroneous pipeline is specified. + * An error does not mean that the pipeline could not be constructed. + * + * @param pipelineDescription An array of strings containing the command line describing the pipeline. + * @return a new element on success. + * @throws GstException if the pipeline / element could not be created + */ + public static Element parseLaunch(String[] pipelineDescription) { return parseLaunch(pipelineDescription, null); } @@ -279,7 +310,9 @@ public static Pipeline parseLaunch(String[] pipelineDescription) { * * @param binDescription the command line describing the bin * @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads + * @param errors list that any errors will be added to * @return The new Bin. + * @throws GstException if the bin could not be created */ public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads, List errors) { @@ -301,6 +334,18 @@ public static Bin parseBinFromDescription(String binDescription, boolean ghostUn return bin; } + + /** + * Creates a bin from a text bin description. + * + * This function allows creation of a bin based on the syntax used in the + * gst-launch utillity. + * + * @param binDescription the command line describing the bin + * @param ghostUnlinkedPads whether to create ghost pads for the bin from any unlinked pads + * @return The new Bin. + * @throws GstException if the bin could not be created + */ public static Bin parseBinFromDescription(String binDescription, boolean ghostUnlinkedPads) { return parseBinFromDescription(binDescription, ghostUnlinkedPads, null); } diff --git a/src/org/freedesktop/gstreamer/Pipeline.java b/src/org/freedesktop/gstreamer/Pipeline.java index c16760c..4544848 100644 --- a/src/org/freedesktop/gstreamer/Pipeline.java +++ b/src/org/freedesktop/gstreamer/Pipeline.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2015 Neil C Smith - * Copyright (c) 2007,2008 Wayne Meissner - * Copyright (C) 1999,2000 Erik Walthinsen - * 2004,2005 Wim Taymans + * Copyright (c) 2018 Neil C Smith + * Copyright (c) 2008 Wayne Meissner + * Copyright (C) 2000 Erik Walthinsen + * 2005 Wim Taymans * * This file is part of gstreamer-java. * @@ -131,9 +131,10 @@ private static Initializer initializer(String name) { * @param pipelineDecription the command line describing the pipeline * @return The new Pipeline. */ + @Deprecated public static Pipeline launch(String pipelineDecription) { Pointer[] err = { null }; - Pipeline pipeline = GSTPARSE_API.gst_parse_launch(pipelineDecription, err); + Pipeline pipeline = (Pipeline) GSTPARSE_API.gst_parse_launch(pipelineDecription, err); if (pipeline == null) { throw new GstException(new GError(new GErrorStruct(err[0]))); } @@ -156,9 +157,10 @@ public static Pipeline launch(String pipelineDecription) { * @param pipelineDecription An array of strings containing the command line describing the pipeline. * @return The new Pipeline. */ + @Deprecated public static Pipeline launch(String... pipelineDecription) { Pointer[] err = { null }; - Pipeline pipeline = GSTPARSE_API.gst_parse_launchv(pipelineDecription, err); + Pipeline pipeline = (Pipeline) GSTPARSE_API.gst_parse_launchv(pipelineDecription, err); if (pipeline == null) { throw new GstException(new GError(new GErrorStruct(err[0]))); } diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstParseAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstParseAPI.java index 8e9955c..9fb297e 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstParseAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstParseAPI.java @@ -24,6 +24,7 @@ import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn; import com.sun.jna.Pointer; +import org.freedesktop.gstreamer.Element; /** * gstparse functions @@ -31,9 +32,9 @@ public interface GstParseAPI extends com.sun.jna.Library { GstParseAPI GSTPARSE_API = GstNative.load(GstParseAPI.class); - @CallerOwnsReturn Pipeline gst_parse_launch(String pipeline_description, Pointer[] error); - @CallerOwnsReturn Pipeline gst_parse_launchv(String[] pipeline_description, Pointer[] error); - @CallerOwnsReturn Pipeline gst_parse_launch(String pipeline_description, GstAPI.GErrorStruct[] error); - @CallerOwnsReturn Pipeline gst_parse_launchv(String[] pipeline_description, GstAPI.GErrorStruct[] error); + @CallerOwnsReturn Element gst_parse_launch(String pipeline_description, Pointer[] error); + @CallerOwnsReturn Element gst_parse_launchv(String[] pipeline_description, Pointer[] error); + @CallerOwnsReturn Element gst_parse_launch(String pipeline_description, GstAPI.GErrorStruct[] error); + @CallerOwnsReturn Element gst_parse_launchv(String[] pipeline_description, GstAPI.GErrorStruct[] error); @CallerOwnsReturn Bin gst_parse_bin_from_description(String bin_description, boolean ghost_unlinked_pads,Pointer[] error); } diff --git a/test/org/freedesktop/gstreamer/BinTest.java b/test/org/freedesktop/gstreamer/BinTest.java index 8ae8a4b..4c72ed5 100644 --- a/test/org/freedesktop/gstreamer/BinTest.java +++ b/test/org/freedesktop/gstreamer/BinTest.java @@ -19,6 +19,7 @@ package org.freedesktop.gstreamer; +import java.util.ArrayList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -242,58 +243,80 @@ public void iterateSorted() { } @Test - public void testLaunch() { - Bin bin = Bin.launch("fakesrc ! fakesink", false); + public void testParseBin() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors); assertNotNull("Bin not created", bin); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchElementCount() { - Bin bin = Bin.launch("fakesrc ! fakesink", false); + public void testParseBinElementCount() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors); assertEquals("Number of elements in pipeline incorrect", 2, bin.getElements().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchSrcElement() { - Bin bin = Bin.launch("fakesrc ! fakesink", false); + public void testParseBinSrcElement() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors); assertEquals("First element not a fakesrc", "fakesrc", bin.getSources().get(0).getFactory().getName()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchSinkElement() { - Bin bin = Bin.launch("fakesrc ! fakesink", false); + public void testParseBinSinkElement() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", false, errors); assertEquals("First element not a fakesink", "fakesink", bin.getSinks().get(0).getFactory().getName()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchDisabledGhostPadsForSource() { - Bin bin = Bin.launch("fakesrc", false); + public void testParseBinDisabledGhostPadsForSource() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc", false, errors); assertEquals("Number of src pads incorrect", 0, bin.getSrcPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchDisabledGhostPadsForSink() { - Bin bin = Bin.launch("fakesink", false); + public void testParseBinDisabledGhostPadsForSink() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesink", false, errors); assertEquals("Number of sink pads incorrect", 0, bin.getSinkPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchEnabledGhostPadsForSource() { - Bin bin = Bin.launch("fakesrc", true); + public void testParseBinEnabledGhostPadsForSource() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc", true, errors); assertEquals("Number of src pads incorrect", 1, bin.getSrcPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchEnabledGhostPadsForSink() { - Bin bin = Bin.launch("fakesink", true); + public void testParseBinEnabledGhostPadsForSink() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesink", true, errors); assertEquals("Number of sink pads incorrect", 1, bin.getSinkPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchEnabledGhostPadsForSourceWithNoUsablePads() { - Bin bin = Bin.launch("fakesrc ! fakesink", true); + public void testParseBinEnabledGhostPadsForSourceWithNoUsablePads() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", true, errors); assertEquals("Number of src pads incorrect", 0, bin.getSrcPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchEnabledGhostPadsForSinkWithNoUsablePads() { - Bin bin = Bin.launch("fakesrc ! fakesink", true); + public void testParseBinEnabledGhostPadsForSinkWithNoUsablePads() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", true, errors); assertEquals("Number of sink pads incorrect", 0, bin.getSinkPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } @Test - public void testLaunchEnabledGhostPadsWithNoUsablePads() { - Bin bin = Bin.launch("fakesrc ! fakesink", true); + public void testParseBinEnabledGhostPadsWithNoUsablePads() { + ArrayList errors = new ArrayList(); + Bin bin = Gst.parseBinFromDescription("fakesrc ! fakesink", true, errors); assertEquals("Number of pads incorrect", 0, bin.getPads().size()); + assertEquals("parseBinFromDescription with error!", errors.size(), 0); } } diff --git a/test/org/freedesktop/gstreamer/PipelineTest.java b/test/org/freedesktop/gstreamer/PipelineTest.java index 266192c..c19f462 100644 --- a/test/org/freedesktop/gstreamer/PipelineTest.java +++ b/test/org/freedesktop/gstreamer/PipelineTest.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2018 Neil C Smith * Copyright (c) 2007 Wayne Meissner * * This file is part of gstreamer-java. @@ -25,6 +26,7 @@ import static org.junit.Assert.assertTrue; import java.lang.ref.WeakReference; +import java.util.ArrayList; import org.freedesktop.gstreamer.lowlevel.GObjectAPI.GObjectStruct; import org.junit.After; @@ -114,50 +116,75 @@ public void testBusGC() throws Exception { @Test - public void testLaunch() { - Pipeline pipeline = Pipeline.launch("fakesrc ! fakesink"); + public void testParseLaunch() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch("fakesrc ! fakesink", errors); assertNotNull("Pipeline not created", pipeline); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testLaunchElementCount() { - Pipeline pipeline = Pipeline.launch("fakesrc ! fakesink"); + public void testParseLaunchSingleElement() { + ArrayList errors = new ArrayList(); + Element element = Gst.parseLaunch("fakesink", errors); + assertNotNull("Element not created", element); + assertFalse("Single element returned in Pipeline", element instanceof Pipeline); + assertEquals("parseLaunch with error!", errors.size(), 0); + } + + @Test + public void testParseLaunchElementCount() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch("fakesrc ! fakesink", errors); assertEquals("Number of elements in pipeline incorrect", 2, pipeline.getElements().size()); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testLaunchSrcElement() { - Pipeline pipeline = Pipeline.launch("fakesrc ! fakesink"); + public void testParseLaunchSrcElement() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch("fakesrc ! fakesink", errors); assertEquals("First element not a fakesrc", "fakesrc", pipeline.getSources().get(0).getFactory().getName()); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testLaunchSinkElement() { - Pipeline pipeline = Pipeline.launch("fakesrc ! fakesink"); + public void testParseLaunchSinkElement() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch("fakesrc ! fakesink", errors); assertEquals("First element not a fakesink", "fakesink", pipeline.getSinks().get(0).getFactory().getName()); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testVarargLaunch() { - Pipeline pipeline = Pipeline.launch("fakesrc", "fakesink"); + public void testParseLaunchStringArr() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch(new String[] {"fakesrc", "fakesink"}, errors); assertNotNull("Pipeline not created", pipeline); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testVarargLaunchElementCount() { - Pipeline pipeline = Pipeline.launch("fakesrc", "fakesink"); + public void testParseLaunchStringArrElementCount() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch(new String[] {"fakesrc", "fakesink"}, errors); assertEquals("Number of elements in pipeline incorrect", 2, pipeline.getElements().size()); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testVarargLaunchSrcElement() { - Pipeline pipeline = Pipeline.launch("fakesrc", "fakesink"); + public void testParseLaunchStringArrSrcElement() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch(new String[] {"fakesrc", "fakesink"}, errors); assertEquals("First element not a fakesrc", "fakesrc", pipeline.getSources().get(0).getFactory().getName()); + assertEquals("parseLaunch with error!", errors.size(), 0); } @Test - public void testVarargLaunchSinkElement() { - Pipeline pipeline = Pipeline.launch("fakesrc", "fakesink"); + public void testParseLaunchStringArrSinkElement() { + ArrayList errors = new ArrayList(); + Pipeline pipeline = (Pipeline) Gst.parseLaunch(new String[] {"fakesrc", "fakesink"}, errors); assertEquals("First element not a fakesink", "fakesink", pipeline.getSinks().get(0).getFactory().getName()); + assertEquals("parseLaunch with error!", errors.size(), 0); } }