Skip to content

Commit

Permalink
8238755: allow to create static lib for javafx.media on linux
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, almatvee
  • Loading branch information
Johan Vos committed Feb 25, 2020
1 parent c3ee1a3 commit ef2f9ce
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -71,6 +71,7 @@ public class PlatformUtil {
private static final boolean LINUX = os.startsWith("Linux") && !ANDROID;
private static final boolean SOLARIS = os.startsWith("SunOS");
private static final boolean IOS = os.startsWith("iOS");
private static final boolean STATIC_BUILD = "Substrate VM".equals(System.getProperty("java.vm.name"));

/**
* Utility method used to determine whether the version number as
Expand Down Expand Up @@ -177,6 +178,13 @@ public static boolean isIOS(){
return IOS;
}

/**
* Returns true if the current runtime is a statically linked image
*/
public static boolean isStaticBuild(){
return STATIC_BUILD;
}

private static void loadPropertiesFromFile(final File file) {
Properties p = new Properties();
try {
Expand Down
3 changes: 2 additions & 1 deletion modules/javafx.base/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,6 +49,7 @@
javafx.controls,
javafx.graphics,
javafx.fxml,
javafx.media,
javafx.swing;
exports com.sun.javafx.beans to
javafx.controls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ boolean needBuffer() {
boolean isSeekable() {
return (urlConnection instanceof HttpURLConnection) ||
(urlConnection instanceof JarURLConnection) ||
isJRT();
isJRT() || isResource();
}

boolean isRandomAccess() {
Expand Down Expand Up @@ -299,7 +299,7 @@ public long seek(long position) {
Locator.closeConnection(tmpURLConnection);
}
}
} else if ((urlConnection instanceof JarURLConnection) || isJRT()) {
} else if ((urlConnection instanceof JarURLConnection) || isJRT() || isResource()) {
try {
closeConnection();

Expand Down Expand Up @@ -342,6 +342,12 @@ private boolean isJRT() {
String scheme = uri.getScheme().toLowerCase();
return "jrt".equals(scheme);
}

private boolean isResource() {
String scheme = uri.getScheme().toLowerCase();
return "resource".equals(scheme);
}

}

// A "ConnectionHolder" that "reads" from a ByteBuffer, generally loaded from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
}

// FIXME: get cache settings from server, honor them
} else if (scheme.equals("file") || scheme.equals("jar") || scheme.equals("jrt")) {
} else if (scheme.equals("file") || scheme.equals("jar") || scheme.equals("jrt") || (scheme.equals("resource")) ) {
InputStream stream = getInputStream(uri);
stream.close();
isConnected = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,6 +25,7 @@

package com.sun.media.jfxmediaimpl.platform;

import com.sun.javafx.PlatformUtil;
import com.sun.media.jfxmedia.Media;
import com.sun.media.jfxmedia.MediaPlayer;
import com.sun.media.jfxmedia.MetadataParser;
Expand Down Expand Up @@ -199,6 +200,9 @@ public List<String> getSupportedProtocols() {
}
}
}
if (PlatformUtil.isStaticBuild()) {
outProtocols.add("resource");
}

return outProtocols;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public final class GSTPlatform extends Platform {
"file",
"http",
"https",
"jrt"
"jrt",
"resource"
};

private static GSTPlatform globalInstance = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@

#include "gst.h"

#ifdef GSTREAMER_LITE
#ifdef STATIC_BUILD
gboolean fxplugins_init (GstPlugin * plugin);
gboolean fxavplugins_init (GstPlugin * plugin);
#endif // STATIC_BUILD
#endif // GSTREAMER_LITE

#define GST_CAT_DEFAULT GST_CAT_GST_INIT

#define MAX_PATH_SPLIT 16
Expand Down Expand Up @@ -818,6 +825,16 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
"gstplugins-lite", "gstplugins-lite",
lite_plugins_init, VERSION, GST_LICENSE, PACKAGE,
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
#ifdef STATIC_BUILD
gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR,
"fxplugins", "fxplugin",
fxplugins_init, VERSION, GST_LICENSE, PACKAGE,
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR,
"fxavplugins", "fxavplugin",
fxavplugins_init, VERSION, GST_LICENSE, PACKAGE,
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
#endif // STATIC_BUILD
#endif // GSTREAMER_LITE

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@
#include <videodecoder.h>
#include <mpegtsdemuxer.h>

#ifdef STATIC_BUILD
gboolean fxavplugins_init (GstPlugin * plugin)
#else
static gboolean fxplugins_init (GstPlugin * plugin)
#endif
{
return audiodecoder_plugin_init(plugin) &&
videodecoder_plugin_init(plugin) &&
mpegts_demuxer_plugin_init(plugin);
}

#ifndef STATIC_BUILD
GstPluginDesc gst_plugin_desc =
{
GST_VERSION_MAJOR,
Expand All @@ -51,3 +56,4 @@ GstPluginDesc gst_plugin_desc =
"http://javafx.com/",
NULL
};
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
gboolean dshowwrapper_init(GstPlugin* aacdecoder);
#endif

#ifdef STATIC_BUILD
gboolean fxplugins_init (GstPlugin * plugin)
#else
static gboolean fxplugins_init (GstPlugin * plugin)
#endif
{
return java_source_plugin_init(plugin) &&
hls_progress_buffer_plugin_init(plugin) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ extern "C" {
/*
* Specify the require JNI version.
*/
#ifdef STATIC_BUILD
JNIEXPORT jint JNICALL JNI_OnLoad_jfxmedia(JavaVM *vm, void *reserved)
#else
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
#endif
{
g_pJVM = vm;
return JNI_VERSION_1_2;
Expand Down

0 comments on commit ef2f9ce

Please sign in to comment.