Skip to content

Update examples for gst1-java-core 1.4.0. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.2.0</version>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.freedesktop.gstreamer</groupId>
<artifactId>gst1-java-core</artifactId>
<version>1.1.0</version>
<version>1.4.0</version>
</dependency>
</dependencies>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2019 Neil C Smith.
* Copyright 2021 Neil C Smith.
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
Expand All @@ -14,6 +14,7 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;

import javax.swing.Box;
Expand All @@ -26,9 +27,11 @@
import org.freedesktop.gstreamer.Bus;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.ElementFactory;
import org.freedesktop.gstreamer.Format;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Structure;
import org.freedesktop.gstreamer.elements.PlayBin;
import org.freedesktop.gstreamer.event.SeekFlags;
import org.freedesktop.gstreamer.message.Message;
import org.freedesktop.gstreamer.message.MessageType;

Expand Down Expand Up @@ -80,24 +83,26 @@ public static void main(String[] args) {
playButton.addActionListener(e -> playbin.play());
JButton pauseButton = new JButton("Pause");
pauseButton.addActionListener(e -> playbin.pause());

// position slider
JSlider position = new JSlider(0, 1000);
position.addChangeListener(e -> {
if (position.getValueIsAdjusting()) {
long dur = playbin.queryDuration(TimeUnit.NANOSECONDS);
long pos = playbin.queryPosition(TimeUnit.NANOSECONDS);
long dur = playbin.queryDuration(Format.TIME);
long pos = playbin.queryPosition(Format.TIME);
if (dur > 0) {
double relPos = position.getValue() / 1000.0;
playbin.seek((long) (relPos * dur), TimeUnit.NANOSECONDS);
}
playbin.seekSimple(Format.TIME,
EnumSet.of(SeekFlags.FLUSH, SeekFlags.KEY_UNIT),
(long) (relPos * dur));
}
}
});
// sync slider position to video when not dragging
new Timer(50, e -> {
if (!position.getValueIsAdjusting()) {
long dur = playbin.queryDuration(TimeUnit.NANOSECONDS);
long pos = playbin.queryPosition(TimeUnit.NANOSECONDS);
long dur = playbin.queryDuration(Format.TIME);
long pos = playbin.queryPosition(Format.TIME);
if (dur > 0) {
double relPos = (double) pos / dur;
position.setValue((int) (relPos * 1000));
Expand Down Expand Up @@ -129,9 +134,9 @@ public static void main(String[] args) {

@Override
public void busMessage(Bus arg0, Message message) {
Structure struct = message.getStructure();
if (message.getType() == MessageType.ELEMENT
&& message.getSource().getName().startsWith("level")) {
Structure struct = message.getStructure();
// We can get either rms or peak
double[] levels = struct.getDoubles("peak");
// Calculate the time offset required to get the level
Expand All @@ -141,6 +146,7 @@ public void busMessage(Bus arg0, Message message) {
() -> EventQueue.invokeLater(() -> updateLevelDisplay(levels)),
timeDelay, TimeUnit.NANOSECONDS);
}
message.dispose();
}

private long getTimeOffset(Structure struct) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2019 Neil C Smith / Tim-Philipp Müller
* Copyright 2021 Neil C Smith / Tim-Philipp Müller
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
Expand Down Expand Up @@ -43,10 +43,13 @@ public static void main(String[] args) {
text.set("halignment", 4);
text.set("valignment", 3);

Element capsfilter = ElementFactory.make("capsfilter", "caps");
capsfilter.setAsString("caps", "video/x-raw, width=800, height=600");

Element sink = ElementFactory.make("autovideosink", "sink");

pipe.addMany(src, text, sink);
Pipeline.linkMany(src, text, sink);
pipe.addMany(src, text, capsfilter, sink);
Pipeline.linkMany(src, text, capsfilter, sink);


LFOControlSource csXPos = new LFOControlSource();
Expand Down