Skip to content

Commit ef2f9ce

Browse files
author
Johan Vos
committed
8238755: allow to create static lib for javafx.media on linux
Reviewed-by: kcr, almatvee
1 parent c3ee1a3 commit ef2f9ce

File tree

10 files changed

+58
-7
lines changed

10 files changed

+58
-7
lines changed

modules/javafx.base/src/main/java/com/sun/javafx/PlatformUtil.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -71,6 +71,7 @@ public class PlatformUtil {
7171
private static final boolean LINUX = os.startsWith("Linux") && !ANDROID;
7272
private static final boolean SOLARIS = os.startsWith("SunOS");
7373
private static final boolean IOS = os.startsWith("iOS");
74+
private static final boolean STATIC_BUILD = "Substrate VM".equals(System.getProperty("java.vm.name"));
7475

7576
/**
7677
* Utility method used to determine whether the version number as
@@ -177,6 +178,13 @@ public static boolean isIOS(){
177178
return IOS;
178179
}
179180

181+
/**
182+
* Returns true if the current runtime is a statically linked image
183+
*/
184+
public static boolean isStaticBuild(){
185+
return STATIC_BUILD;
186+
}
187+
180188
private static void loadPropertiesFromFile(final File file) {
181189
Properties p = new Properties();
182190
try {

modules/javafx.base/src/main/java/module-info.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,6 +49,7 @@
4949
javafx.controls,
5050
javafx.graphics,
5151
javafx.fxml,
52+
javafx.media,
5253
javafx.swing;
5354
exports com.sun.javafx.beans to
5455
javafx.controls,

modules/javafx.media/src/main/java/com/sun/media/jfxmedia/locator/ConnectionHolder.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ boolean needBuffer() {
258258
boolean isSeekable() {
259259
return (urlConnection instanceof HttpURLConnection) ||
260260
(urlConnection instanceof JarURLConnection) ||
261-
isJRT();
261+
isJRT() || isResource();
262262
}
263263

264264
boolean isRandomAccess() {
@@ -299,7 +299,7 @@ public long seek(long position) {
299299
Locator.closeConnection(tmpURLConnection);
300300
}
301301
}
302-
} else if ((urlConnection instanceof JarURLConnection) || isJRT()) {
302+
} else if ((urlConnection instanceof JarURLConnection) || isJRT() || isResource()) {
303303
try {
304304
closeConnection();
305305

@@ -342,6 +342,12 @@ private boolean isJRT() {
342342
String scheme = uri.getScheme().toLowerCase();
343343
return "jrt".equals(scheme);
344344
}
345+
346+
private boolean isResource() {
347+
String scheme = uri.getScheme().toLowerCase();
348+
return "resource".equals(scheme);
349+
}
350+
345351
}
346352

347353
// A "ConnectionHolder" that "reads" from a ByteBuffer, generally loaded from

modules/javafx.media/src/main/java/com/sun/media/jfxmedia/locator/Locator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
417417
}
418418

419419
// FIXME: get cache settings from server, honor them
420-
} else if (scheme.equals("file") || scheme.equals("jar") || scheme.equals("jrt")) {
420+
} else if (scheme.equals("file") || scheme.equals("jar") || scheme.equals("jrt") || (scheme.equals("resource")) ) {
421421
InputStream stream = getInputStream(uri);
422422
stream.close();
423423
isConnected = true;

modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626
package com.sun.media.jfxmediaimpl.platform;
2727

28+
import com.sun.javafx.PlatformUtil;
2829
import com.sun.media.jfxmedia.Media;
2930
import com.sun.media.jfxmedia.MediaPlayer;
3031
import com.sun.media.jfxmedia.MetadataParser;
@@ -199,6 +200,9 @@ public List<String> getSupportedProtocols() {
199200
}
200201
}
201202
}
203+
if (PlatformUtil.isStaticBuild()) {
204+
outProtocols.add("resource");
205+
}
202206

203207
return outProtocols;
204208
}

modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/platform/gstreamer/GSTPlatform.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public final class GSTPlatform extends Platform {
6262
"file",
6363
"http",
6464
"https",
65-
"jrt"
65+
"jrt",
66+
"resource"
6667
};
6768

6869
private static GSTPlatform globalInstance = null;

modules/javafx.media/src/main/native/gstreamer/gstreamer-lite/gstreamer/gst/gst.c

+17
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@
122122

123123
#include "gst.h"
124124

125+
#ifdef GSTREAMER_LITE
126+
#ifdef STATIC_BUILD
127+
gboolean fxplugins_init (GstPlugin * plugin);
128+
gboolean fxavplugins_init (GstPlugin * plugin);
129+
#endif // STATIC_BUILD
130+
#endif // GSTREAMER_LITE
131+
125132
#define GST_CAT_DEFAULT GST_CAT_GST_INIT
126133

127134
#define MAX_PATH_SPLIT 16
@@ -818,6 +825,16 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
818825
"gstplugins-lite", "gstplugins-lite",
819826
lite_plugins_init, VERSION, GST_LICENSE, PACKAGE,
820827
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
828+
#ifdef STATIC_BUILD
829+
gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR,
830+
"fxplugins", "fxplugin",
831+
fxplugins_init, VERSION, GST_LICENSE, PACKAGE,
832+
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
833+
gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR,
834+
"fxavplugins", "fxavplugin",
835+
fxavplugins_init, VERSION, GST_LICENSE, PACKAGE,
836+
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
837+
#endif // STATIC_BUILD
821838
#endif // GSTREAMER_LITE
822839

823840
/*

modules/javafx.media/src/main/native/gstreamer/plugins/av/fxavcodecplugin.c

+6
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
#include <videodecoder.h>
3131
#include <mpegtsdemuxer.h>
3232

33+
#ifdef STATIC_BUILD
34+
gboolean fxavplugins_init (GstPlugin * plugin)
35+
#else
3336
static gboolean fxplugins_init (GstPlugin * plugin)
37+
#endif
3438
{
3539
return audiodecoder_plugin_init(plugin) &&
3640
videodecoder_plugin_init(plugin) &&
3741
mpegts_demuxer_plugin_init(plugin);
3842
}
3943

44+
#ifndef STATIC_BUILD
4045
GstPluginDesc gst_plugin_desc =
4146
{
4247
GST_VERSION_MAJOR,
@@ -51,3 +56,4 @@ GstPluginDesc gst_plugin_desc =
5156
"http://javafx.com/",
5257
NULL
5358
};
59+
#endif

modules/javafx.media/src/main/native/gstreamer/plugins/fxplugins.c

+4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
gboolean dshowwrapper_init(GstPlugin* aacdecoder);
4040
#endif
4141

42+
#ifdef STATIC_BUILD
43+
gboolean fxplugins_init (GstPlugin * plugin)
44+
#else
4245
static gboolean fxplugins_init (GstPlugin * plugin)
46+
#endif
4347
{
4448
return java_source_plugin_init(plugin) &&
4549
hls_progress_buffer_plugin_init(plugin) &&

modules/javafx.media/src/main/native/jfxmedia/platform/gstreamer/GstPlatform.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ extern "C" {
5353
/*
5454
* Specify the require JNI version.
5555
*/
56+
#ifdef STATIC_BUILD
57+
JNIEXPORT jint JNICALL JNI_OnLoad_jfxmedia(JavaVM *vm, void *reserved)
58+
#else
5659
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
60+
#endif
5761
{
5862
g_pJVM = vm;
5963
return JNI_VERSION_1_2;

0 commit comments

Comments
 (0)