Skip to content

Commit

Permalink
Merge pull request #154 from DanielAromi97/master
Browse files Browse the repository at this point in the history
added pipeline parsing with Gst.parseLaunch()
  • Loading branch information
codeanticode authored Oct 5, 2020
2 parents 4fb4bff + 3b960d0 commit 42b9910
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/processing/video/Capture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 42b9910

Please sign in to comment.