diff --git a/src/processing/video/Capture.java b/src/processing/video/Capture.java index c86dc7c..f7ec37c 100644 --- a/src/processing/video/Capture.java +++ b/src/processing/video/Capture.java @@ -432,49 +432,37 @@ 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"; + pipeline = (Pipeline) Gst.parseLaunch(pstr + PIPELINE_END); - int n = 1; - Element[] elements = new Element[n + 4]; - - 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(); - - Element videoscale = ElementFactory.make("videoscale", null); - Element videoconvert = ElementFactory.make("videoconvert", null); - Element capsfilter = ElementFactory.make("capsfilter", null); - - String frameRateString; + String caps = ", width=" + width + ", height=" + height; if (frameRate != 0.0) { - frameRateString = ", framerate=" + fpsToFramerate(frameRate); - } else { - frameRateString = ""; + caps += ", framerate=" + fpsToFramerate(frameRate); } - 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; + rgbSink = (AppSink) pipeline.getElementByName("sink"); + rgbSink.set("emit-signals", true); + newSampleListener = new NewSampleListener(); + newPrerollListener = new NewPrerollListener(); + rgbSink.connect(newSampleListener); + rgbSink.connect(newPrerollListener); - pipeline.addMany(elements); - Element.linkMany(elements); + 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 { + rgbSink.setCaps(Caps.fromString("video/x-raw, format=xRGB" + caps)); + } makeBusConnections(pipeline.getBus()); } - + protected void initDevicePipeline() { Element srcElement = null; if (device == null) {