|
59 | 59 | import com.sun.jna.ptr.IntByReference; |
60 | 60 | import com.sun.jna.ptr.PointerByReference; |
61 | 61 | import java.util.Arrays; |
| 62 | +import java.util.logging.Level; |
| 63 | +import static org.freedesktop.gstreamer.lowlevel.GstParseAPI.GSTPARSE_API; |
62 | 64 |
|
63 | 65 | /** |
64 | 66 | * Media library supporting arbitrary formats and filter graphs. |
@@ -201,6 +203,109 @@ public static void quit() { |
201 | 203 | quit.countDown(); |
202 | 204 | } |
203 | 205 |
|
| 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 | + |
204 | 309 | /** |
205 | 310 | * Waits for the gstreamer system to shutdown via a call to {@link #quit}. |
206 | 311 | * <p> For most gui programs, this is of little use. However, it can be |
|
0 commit comments