Skip to content

Commit df7001a

Browse files
Add Version.of(major, minor) method for creating version for Gst.init(..)
1 parent ab4fc75 commit df7001a

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/org/freedesktop/gstreamer/Version.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 Neil C Smith
2+
* Copyright (c) 2021 Neil C Smith
33
* Copyright (c) 2008 Wayne Meissner
44
*
55
* This file is part of gstreamer-java.
@@ -22,8 +22,8 @@
2222
* Describes a GStreamer version.
2323
* <p>
2424
* Also upstream documentation at
25-
* <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/gstreamer-GstVersion.html"
26-
* >https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/gstreamer-GstVersion.html</a>
25+
* <a href="https://gstreamer.freedesktop.org/documentation/gstreamer/gst.html#gst_version"
26+
* >https://gstreamer.freedesktop.org/documentation/gstreamer/gst.html#gst_version</a>
2727
* <p>
2828
*/
2929
public class Version {
@@ -37,9 +37,9 @@ public class Version {
3737
private final int major, minor, micro, nano;
3838

3939
/**
40-
* Constructor for creating a Version with micro and nano set to zero - most
41-
* useful for requesting version in {@link Gst#init(org.freedesktop.gstreamer.Version)
42-
* }
40+
* Constructor for creating a Version with micro and nano set to zero. For
41+
* requesting version in {@link Gst#init(org.freedesktop.gstreamer.Version)}
42+
* prefer using {@link #of(int, int)}.
4343
* <p>
4444
* <b>The library only supports major version 1</b>
4545
*
@@ -130,4 +130,28 @@ public boolean checkSatisfies(Version required) {
130130
|| (major == required.major && minor == required.minor && micro >= required.micro);
131131
}
132132

133+
/**
134+
* Create a Version with specified major and minor version, and micro and
135+
* nano version set to zero. Useful for specifying a required version in
136+
* {@link Gst#init(org.freedesktop.gstreamer.Version)}.
137+
* <p>
138+
* <b>The library only supports major version 1</b>
139+
* <p>
140+
* Unlike the constructor this method will throw an exception if the version
141+
* is not greater or equal to {@link #BASELINE}, or the major version isn't
142+
* 1.
143+
*
144+
* @param major major version, currently must be 1
145+
* @param minor minor version, greater or equal to 8
146+
* @return requested version
147+
* @throws IllegalArgumentException if the requested version is invalid
148+
*/
149+
public static Version of(int major, int minor) {
150+
if (major == BASELINE.getMajor()
151+
&& minor >= BASELINE.getMinor()) {
152+
return new Version(major, minor);
153+
}
154+
throw new IllegalArgumentException("Invalid version");
155+
}
156+
133157
}

test/org/freedesktop/gstreamer/InitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public InitTest() {
3939
@Test
4040
public void testInit() {
4141
Version available = Gst.getVersion();
42-
Version notAvailable = new Version(available.getMajor(), available.getMinor() + 2);
42+
Version notAvailable = Version.of(available.getMajor(), available.getMinor() + 2);
4343
try {
4444
Gst.init(notAvailable);
4545
assertTrue("Version check exception not thrown!", false);

0 commit comments

Comments
 (0)