From e60fc758b7d21d1fd64d5ff99cb50fc0fbcef823 Mon Sep 17 00:00:00 2001 From: daniel Date: Sun, 24 May 2020 21:04:56 +0200 Subject: [PATCH] added pipeline parsing with Gst.parseLaunch() --- src/processing/video/Capture.java | 50 +++++++++++-------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/processing/video/Capture.java b/src/processing/video/Capture.java index d5c398b..ef36090 100644 --- a/src/processing/video/Capture.java +++ b/src/processing/video/Capture.java @@ -432,44 +432,30 @@ public static String fpsToFramerate(float fps) { protected void initCustomPipeline(String pstr) { -// String[] parts = pstr.split("!"); -// int n = parts.length; - + String PIPELINE_END + = " ! videorate ! videoscale ! videoconvert ! appsink name=sink"; - int n = 1; - Element[] elements = new Element[n + 4]; + pipeline = (Pipeline) Gst.parseLaunch(pstr + PIPELINE_END); - Element el = Gst.parseLaunch(pstr); - elements[0] = el; - -// for (int i = 0; i < n; i++) { -// String el = parts[i].trim(); -// elements[i] = ElementFactory.make(el, null); -// } - - pipeline = new Pipeline(); + String caps = ", width=" + width + ", height=" + height; + if (frameRate != 0.0) { + caps += ", framerate=" + fpsToFramerate(frameRate); + } - Element videoscale = ElementFactory.make("videoscale", null); - Element videoconvert = ElementFactory.make("videoconvert", null); - Element capsfilter = ElementFactory.make("capsfilter", null); + rgbSink = (AppSink) pipeline.getElementByName("sink"); + rgbSink.set("emit-signals", true); + newSampleListener = new NewSampleListener(); + newPrerollListener = new NewPrerollListener(); + rgbSink.connect(newSampleListener); + rgbSink.connect(newPrerollListener); - String frameRateString; - if (frameRate != 0.0) { - frameRateString = ", framerate=" + fpsToFramerate(frameRate); + useBufferSink = Video.useGLBufferSink && parent.g.isGL(); + if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { + if (useBufferSink) rgbSink.setCaps(Caps.fromString("video/x-raw, format=RGBx" + caps)); + else rgbSink.setCaps(Caps.fromString("video/x-raw, format=BGRx" + caps)); } else { - frameRateString = ""; + rgbSink.setCaps(Caps.fromString("video/x-raw, format=xRGB" + caps)); } - capsfilter.set("caps", Caps.fromString("video/x-raw, width=" + width + ", height=" + height + frameRateString)); - - initSink(); - - elements[n + 0] = videoscale; - elements[n + 1] = videoconvert; - elements[n + 2] = capsfilter; - elements[n + 3] = rgbSink; - - pipeline.addMany(elements); - Pipeline.linkMany(elements); makeBusConnections(pipeline.getBus()); }