/** * Initialize webcam device. */ private synchronized void init() { if (!initialized.compareAndSet(false, true)) { return; } LOG.debug("GStreamer webcam device initialization"); pipe = new Pipeline(getName()); source = ElementFactory.make(GStreamerDriver.getSourceBySystem(), "source"); if (Platform.isWindows()) { source.set("device-index", deviceIndex); } else if (Platform.isLinux()) { source.set("device", videoFile.getAbsolutePath()); } else if (Platform.isMacOSX()) { throw new IllegalStateException("not yet implemented"); } sink = new RGBDataSink(getName(), this); sink.setPassDirectBuffer(true); sink.getSinkElement().setMaximumLateness(LATENESS, TimeUnit.MILLISECONDS); sink.getSinkElement().setQOSEnabled(true); filter = ElementFactory.make("capsfilter", "capsfilter"); jpegdec = ElementFactory.make("jpegdec", "jpegdec"); pipelineReady(); resolutions = parseResolutions(source.getPads().get(0)); pipelineStop(); }
/** * Remove a listener for the <code>preroll-handoff</code> signal. * * @param listener The listener that was previously added. */ public void disconnect(PREROLL_HANDOFF listener) { disconnect(PREROLL_HANDOFF.class, listener); } }
public BufferDataSink(String name, Pipeline pipeline, Listener listener) { super(initializer(gst.ptr_gst_bin_new(name))); this.listener = listener; Element element = pipeline.getElementByName(name); if (element != null) { // TODO: Fix. This doesn't work as it should. getElementByName() returns a // BaseSink which cannot be casted to FakeSink. sink = (BaseSink) element; sink.set("signal-handoffs", true); sink.set("sync", true); sink.set("preroll-queue-len", 1); sink.connect((BaseSink.HANDOFF) new SinkNewBufferListener()); sink.connect((BaseSink.PREROLL_HANDOFF) new SinkNewBufferListener()); } else { sink = null; throw new RuntimeException("Element with name " + name + " not found in the pipeline"); } }
public void setQOSEnabled(boolean qos) { gst().gst_base_sink_set_qos_enabled(this, qos); } public boolean isQOSEnabled() {
/** * Dispose this Widget */ public void widgetDisposed(DisposeEvent arg0) { if (sinkListener != null) autosink.disconnect(sinkListener); removeDisposeListener(this); if (x11Events) watcherRunning = false; if (videosink != null && !videosink.getState().equals(State.NULL)) throw new IllegalStateException("Wrong state on dispose: " + videosink.getState() + " -> " + videosink.getName()); }
/** * Set the final sink's properties (or cache it until it'll be created). * * @param property * @param data */ public void set(String property, Object data) { properties.put(property, data); if (videosink != null) videosink.set(property, data); }
/** * Add a listener for the <code>preroll-handoff</code> signal. * * @param listener The listener to be called when a {@link Buffer} is ready. */ public void connect(final PREROLL_HANDOFF listener) { connect(PREROLL_HANDOFF.class, listener, new PrerollHandoffCallback(listener)); } /**
public ByteDataSink(String name, Pipeline pipeline, Listener listener) { super(initializer(gst.ptr_gst_bin_new(name))); this.listener = listener; Element element = pipeline.getElementByName(name); if (element != null) { // TODO: Fix. This doesn't work as it should. getElementByName() returns a // BaseSink which cannot be casted to FakeSink. sink = (BaseSink) element; sink.set("signal-handoffs", true); sink.set("sync", true); sink.set("preroll-queue-len", 1); sink.connect((BaseSink.HANDOFF) new DataHandoffListener()); sink.connect((BaseSink.PREROLL_HANDOFF) new DataHandoffListener()); } else { sink = null; throw new RuntimeException("Element with name " + name + " not found in the pipeline"); } }
public void enableAsync(boolean enabled) { gst().gst_base_sink_set_async_enabled(this, enabled); } public boolean isAsync() {
public void elementAdded(Bin bin, Element element) { if (element instanceof BaseSink) { videosink = (BaseSink)element; for (Map.Entry<String, Object> e : properties.entrySet()) videosink.set(e.getKey(), e.getValue()); // according to gstreamer docs: // http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-gstxoverlay.html // the overlay should have to be set from bus's SyncHandler, // but we use autosink and in element-added the pipe already // created so the windows must be prepared so we simple call // the setOverlay and not the comment code bellow // Bus bus = videosink.getBus(); // oldSyncHandler = bus.getSyncHandler(); // bus.setSyncHandler(VideoComponent.this); // for prepare-xwindow-id setOverlay(); autosink.disconnect(this); // from element-added sinkListener = null; // no longer needed } } };
/** * Add a listener for the <code>handoff</code> signal on this sink * * @param listener The listener to be called when a {@link Buffer} is ready. */ public void connect(final HANDOFF listener) { connect(HANDOFF.class, listener, new HandoffCallback(listener)); } /**
/** * Initialize webcam device. */ private synchronized void init() { if (!initialized.compareAndSet(false, true)) { return; } LOG.debug("GStreamer webcam device initialization"); pipe = new Pipeline(getName()); source = ElementFactory.make(GStreamerDriver.getSourceBySystem(), "source"); if (Platform.isWindows()) { source.set("device-index", deviceIndex); } else if (Platform.isLinux()) { source.set("device", videoFile.getAbsolutePath()); } else if (Platform.isMacOSX()) { throw new IllegalStateException("not yet implemented"); } sink = new RGBDataSink(getName(), this); sink.setPassDirectBuffer(true); sink.getSinkElement().setMaximumLateness(LATENESS, TimeUnit.MILLISECONDS); sink.getSinkElement().setQOSEnabled(true); filter = ElementFactory.make("capsfilter", "capsfilter"); jpegdec = ElementFactory.make("jpegdec", "jpegdec"); pipelineReady(); resolutions = parseResolutions(source.getPads().get(0)); pipelineStop(); }
public RGBDataSink(String name, Pipeline pipeline, Listener listener) { super(initializer(gst.ptr_gst_bin_new(name))); this.listener = listener; Element element = pipeline.getElementByName(name); if (element != null) { // TODO: Fix. This doesn't work as it should. getElementByName() returns a // BaseSink which cannot be casted to FakeSink. videosink = (BaseSink) element; videosink.set("signal-handoffs", true); videosink.set("sync", true); videosink.set("preroll-queue-len", 1); videosink.connect((BaseSink.HANDOFF) new VideoHandoffListener()); videosink.connect((BaseSink.PREROLL_HANDOFF) new VideoHandoffListener()); } else { videosink = null; throw new RuntimeException("Element with name " + name + " not found in the pipeline"); } }
public void enableLastBuffer(boolean enable) { gst().gst_base_sink_set_last_buffer_enabled(this, enable); } public boolean isLastBufferEnabled() {
videosink.set("handle-events", !x11Events); overlay.handleEvent(!x11Events); watcherRunning = true;
/** * Remove a listener for the <code>handoff</code> signal * * @param listener The listener that was previously added. */ public void disconnect(HANDOFF listener) { disconnect(HANDOFF.class, listener); }
videosink.setPassDirectBuffer(true); videosink.getSinkElement().setMaximumLateness(20, TimeUnit.MILLISECONDS); videosink.getSinkElement().setQOSEnabled(true);
private void initSink(String name, String mask) { sink = (FakeSink) ElementFactory.make("fakesink", name); sink.set("signal-handoffs", true); sink.set("sync", true); sink.set("preroll-queue-len", 1); sink.connect((BaseSink.HANDOFF) new SinkNewBufferListener()); sink.connect((BaseSink.PREROLL_HANDOFF) new SinkNewBufferListener()); // // Convert the input into 32bit RGB so it can be fed directly to a BufferedImage // Element conv = ElementFactory.make("ffmpegcolorspace", "ColorConverter"); Element videofilter = ElementFactory.make("capsfilter", "ColorFilter"); StringBuilder caps = new StringBuilder("video/x-raw-rgb, bpp=32, depth=24, endianness=(int)4321, "); caps.append(mask); videofilter.setCaps(new Caps(caps.toString())); addMany(conv, videofilter, sink); Element.linkMany(conv, videofilter, sink); // // Link the ghost pads on the bin to the sink pad on the convertor // addPad(new GhostPad("sink", conv.getStaticPad("sink"))); }
public void setBlocksize(int blocksize) { gst().gst_base_sink_set_blocksize(this, blocksize); } public int getBlocksize() {
/** * Creates a new instance of RGBDataSink with the given name. * * @param name The name used to identify this pipeline. */ public ByteDataSink(String name, Listener listener) { super(initializer(gst.ptr_gst_bin_new(name))); this.listener = listener; sink = (FakeSink) ElementFactory.make("fakesink", name); sink.set("signal-handoffs", true); sink.set("sync", true); sink.set("preroll-queue-len", 1); sink.connect((BaseSink.HANDOFF) new DataHandoffListener()); sink.connect((BaseSink.PREROLL_HANDOFF) new DataHandoffListener()); // // Adding identity element // Element conv = ElementFactory.make("identity", "Data"); addMany(conv, sink); Element.linkMany(conv, sink); // // Link the ghost pads on the bin to the sink pad on the convertor // addPad(new GhostPad("sink", conv.getStaticPad("sink"))); }