# HG changeset patch # User ddehaven # Date 1406570727 25200 # Mon Jul 28 11:05:27 2014 -0700 # Node ID f1e520d45c7e358b1e980ca25b24184336058164 # Parent 4b8d06211312f5a7a2bbefd674647129df8d718f RT-38074: [macosx] Separate QTKit platform code from core media code so it can be removed for MAS Reviewed-by: diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -2877,6 +2877,11 @@ [ "fxplugins", "gstreamer-lite", "jfxmedia" ].each { name -> from ("modules/media/build/native/${t.name}/${mediaBuildType}/${library(name)}") } + if (t.name == "mac") { + // media platform dylibs, leave room for more + [ "jfxmedia_qtkit" ].each { name -> + from ("modules/media/build/native/${t.name}/${mediaBuildType}/${library(name)}") } + } if (t.name == "linux") from ("modules/media/build/native/${t.name}/${mediaBuildType}/${library("avplugin")}") else from ("modules/media/build/native/${t.name}/${mediaBuildType}/${library("glib-lite")}") } else { diff --git a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java --- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java +++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java @@ -33,6 +33,7 @@ import com.sun.media.jfxmediaimpl.platform.PlatformManager; import java.lang.ref.WeakReference; import java.security.AccessController; +import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.List; @@ -45,11 +46,6 @@ */ public class NativeMediaManager { /** - * The NativeMediaManager singleton. - */ - // If we create NativeMediaManager here we will not be able to catch exception from constructor. - private static NativeMediaManager theInstance = null; - /** * Whether the native layer has been initialized. */ private static boolean isNativeLayerInitialized = false; @@ -57,19 +53,28 @@ * The {@link MediaErrorListener}s. */ // FIXME: Change to WeakHashMap as it's more efficient - private List> errorListeners = - new ArrayList>(); - private static NativeMediaPlayerDisposer playerDisposer = new NativeMediaPlayerDisposer(); + private final List> errorListeners = + new ArrayList(); + private final static NativeMediaPlayerDisposer playerDisposer = + new NativeMediaPlayerDisposer(); /** * List of all un-disposed players. */ - private static Map allMediaPlayers = - new WeakHashMap(); + private final static Map allMediaPlayers = + new WeakHashMap(); // cached content types, so we don't have to poll and sort each time, this list // should never change once we're initialized private final List supportedContentTypes = - new ArrayList(); + new ArrayList(); + + /** + * The NativeMediaManager singleton. + */ + private static class NativeMediaManagerInitializer { + private static final NativeMediaManager globalInstance + = new NativeMediaManager(); + } /** * Get the default @@ -78,11 +83,8 @@ * @return the singleton * NativeMediaManager instance. */ - public static synchronized NativeMediaManager getDefaultInstance() { - if (theInstance == null) { - theInstance = new NativeMediaManager(); - } - return theInstance; + public static NativeMediaManager getDefaultInstance() { + return NativeMediaManagerInitializer.globalInstance; } //************************************************************************** @@ -91,43 +93,43 @@ /** * Create a NativeMediaManager. */ - protected NativeMediaManager() {} + protected NativeMediaManager() { + /* + * Load native libraries. This must be done early as platforms may need + * to attempt loading their own native libs that are dependent on these + * This is a slight performance hit, but necessary otherwise we could + * erroneously report content types for platforms that cannot be loaded + */ + try { + AccessController.doPrivileged((PrivilegedExceptionAction) () -> { + if (HostUtils.isWindows() || HostUtils.isMacOSX()) { + NativeLibLoader.loadLibrary("glib-lite"); + } + + if (!HostUtils.isLinux() && !HostUtils.isIOS()) { + NativeLibLoader.loadLibrary("gstreamer-lite"); + } + + NativeLibLoader.loadLibrary("jfxmedia"); + return null; + }); + } catch (PrivilegedActionException pae) { + MediaUtils.error(null, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL.code(), + "Unable to load one or more dependent libraries.", pae); + } + + // Get the Logger native side rolling before we load platforms + if (!Logger.initNative()) { + MediaUtils.error(null, MediaError.ERROR_MANAGER_LOGGER_INIT.code(), + "Unable to init logger", null); + } + } /** * Initialize the native layer if it has not been so already. */ synchronized static void initNativeLayer() { if (!isNativeLayerInitialized) { - // preload platforms - PlatformManager.getManager().preloadPlatforms(); - - // Load native libraries. - try { - AccessController.doPrivileged((PrivilegedExceptionAction) () -> { - if (HostUtils.isWindows() || HostUtils.isMacOSX()) { - NativeLibLoader.loadLibrary("glib-lite"); - } - - if (!HostUtils.isLinux() && !HostUtils.isIOS()) { - NativeLibLoader.loadLibrary("gstreamer-lite"); - } - - NativeLibLoader.loadLibrary("jfxmedia"); - return null; - }); - } catch (Exception e) { - MediaUtils.error(null, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL.code(), - "Unable to load one or more dependent libraries.", e); - return; // abort - } - - // Get the Logger native side rolling before we load platforms - if (!Logger.initNative()) { - MediaUtils.error(null, MediaError.ERROR_MANAGER_LOGGER_INIT.code(), - "Unable to init logger", null); - return; // abort - } - // load platforms PlatformManager.getManager().loadPlatforms(); diff --git a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/Platform.java b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/Platform.java --- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/Platform.java +++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/Platform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, 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 @@ -41,15 +41,6 @@ throw new UnsupportedOperationException("Invalid platform class."); } - /* - * Loading stages - * preloadPlatform gives the platform a chance to load or check dependencies - * before the main jfxmedia library is loaded. Then loadPlatform is called - * after jfxmedia library is loaded in case the platform has further - * dependencies. - */ - public void preloadPlatform() {} - /** * @return false if the platform cannot be loaded */ diff --git a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java --- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java +++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java @@ -81,6 +81,15 @@ Platform platty; + /* + * We don't want to fully initialize the platforms here for performance + * reasons but some platforms may be dependent on native resources that + * need to be loaded, those platforms need to be given a chance to load + * those resources (without initializing) and determine if the natives + * are available. + * + */ + // Now "universal" platform(s) if (isPlatformEnabled("JavaPlatform")) { platty = JavaPlatform.getPlatformInstance(); @@ -121,12 +130,6 @@ } } - public synchronized void preloadPlatforms() { - for (Platform platty : platforms) { - platty.preloadPlatform(); - } - } - public synchronized void loadPlatforms() { // Use an iterator so we can remove on failure Iterator iter = platforms.iterator(); @@ -147,6 +150,9 @@ if (!platforms.isEmpty()) { for (Platform platty : platforms) { + if (Logger.canLog(Logger.DEBUG)) { + Logger.logMsg(Logger.DEBUG, "Getting content types from platform: "+platty); + } String[] npt = platty.getSupportedContentTypes(); if (npt != null) { for (String type : npt) { diff --git a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/ios/IOSPlatform.java b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/ios/IOSPlatform.java --- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/ios/IOSPlatform.java +++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/ios/IOSPlatform.java @@ -65,9 +65,6 @@ private IOSPlatform() { } - @Override - public void preloadPlatform() {} - /** * @return false if the platform cannot be loaded */ diff --git a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/osx/OSXPlatform.java b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/osx/OSXPlatform.java --- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/osx/OSXPlatform.java +++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/osx/OSXPlatform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, 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 @@ -25,12 +25,15 @@ package com.sun.media.jfxmediaimpl.platform.osx; +import com.sun.glass.utils.NativeLibLoader; import com.sun.media.jfxmedia.Media; import com.sun.media.jfxmedia.MediaPlayer; import com.sun.media.jfxmedia.locator.Locator; import com.sun.media.jfxmedia.logging.Logger; import com.sun.media.jfxmediaimpl.HostUtils; import com.sun.media.jfxmediaimpl.platform.Platform; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Mac OS X Platform implementation. @@ -48,7 +51,30 @@ }; private static final class OSXPlatformInitializer { - private static final OSXPlatform globalInstance = new OSXPlatform(); + private static final OSXPlatform globalInstance; + static { + // Platform is only available if we can load it's native lib + // Do this early so we can report the correct content types + boolean isLoaded = false; + try { + isLoaded = AccessController.doPrivileged((PrivilegedAction) () -> { + try { + NativeLibLoader.loadLibrary("jfxmedia_qtkit"); + } catch (UnsatisfiedLinkError ule) { + // non-fatal condition, keep quiet about it + return Boolean.FALSE; + } + return Boolean.TRUE; + }); + } catch (Exception e) { + // Ignore + } + if (isLoaded) { + globalInstance = new OSXPlatform(); + } else { + globalInstance = null; + } + } } public static Platform getPlatformInstance() { @@ -58,9 +84,6 @@ private OSXPlatform() { } - @Override - public void preloadPlatform() {} - /** * @return false if the platform cannot be loaded */ @@ -70,13 +93,14 @@ return false; } + // ULE should not happen here, but just in case try { osxPlatformInit(); } catch (UnsatisfiedLinkError ule) { if (Logger.canLog(Logger.DEBUG)) { - Logger.logMsg(Logger.DEBUG, "Unable to load OSX platform."); + Logger.logMsg(Logger.DEBUG, "QTKit platform lib is not available."); } -// MediaUtils.nativeError(OSXPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL); +// MediaUtils.nativeError(OSXPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL); return false; } return true; diff --git a/modules/media/src/main/native/jfxmedia/Utils/JObjectPeers.h b/modules/media/src/main/native/jfxmedia/Utils/JObjectPeers.h --- a/modules/media/src/main/native/jfxmedia/Utils/JObjectPeers.h +++ b/modules/media/src/main/native/jfxmedia/Utils/JObjectPeers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, 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 @@ -24,7 +24,7 @@ */ #import -#import +#import // A place to store native peers to Java objects @interface JObjectPeers : NSObject diff --git a/modules/media/src/main/native/jfxmedia/Utils/JavaUtils.h b/modules/media/src/main/native/jfxmedia/Utils/JavaUtils.h --- a/modules/media/src/main/native/jfxmedia/Utils/JavaUtils.h +++ b/modules/media/src/main/native/jfxmedia/Utils/JavaUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, 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 @@ -24,7 +24,7 @@ */ #import -#import +#import #ifdef __cplusplus extern "C" { diff --git a/modules/media/src/main/native/jfxmedia/platform/osx/OSXMediaPlayer.h b/modules/media/src/main/native/jfxmedia/platform/osx/OSXMediaPlayer.h --- a/modules/media/src/main/native/jfxmedia/platform/osx/OSXMediaPlayer.h +++ b/modules/media/src/main/native/jfxmedia/platform/osx/OSXMediaPlayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, 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 @@ -27,7 +27,7 @@ #import #import #import "OSXPlayerProtocol.h" -#import +#import #import "JavaPlayerEventDispatcher.h" diff --git a/modules/media/src/main/native/jfxmedia/projects/mac/Makefile b/modules/media/src/main/native/jfxmedia/projects/mac/Makefile --- a/modules/media/src/main/native/jfxmedia/projects/mac/Makefile +++ b/modules/media/src/main/native/jfxmedia/projects/mac/Makefile @@ -1,7 +1,9 @@ # -# MacOs jfxmedia makefile +# Mac OS X jfxmedia makefile # +# OUTPUT_DIR, BUILD_TYPE and BASE_NAME are passed on the command line or from the +# parent make process BUILD_DIR = $(OUTPUT_DIR)/$(BUILD_TYPE) TARGET_DIRS = $(BUILD_DIR) @@ -19,26 +21,28 @@ Utils \ Utils/posix \ platform/gstreamer \ - platform/osx \ Projects/utils TARGET_NAME = lib$(BASE_NAME).dylib TARGET = $(BUILD_DIR)/$(TARGET_NAME) +QTMEDIA = $(BUILD_DIR)/lib$(TARGET_NAME)_qtkit.dylib + CFLAGS = -arch x86_64 \ - -fPIC \ - -Werror=implicit-function-declaration \ - -DTARGET_OS_MAC=1 \ - -D_GNU_SOURCE \ - -DGST_REMOVE_DEPRECATED \ - -DGST_DISABLE_GST_DEBUG \ - -DGST_DISABLE_LOADSAVE \ - -DGST_DISABLE_XML \ - -DHAVE_CONFIG_H \ - -DJFXMEDIA_JNI_EXPORTS \ - -DGSTREAMER_LITE \ - -msse2 \ - -mmacosx-version-min=10.7 + -pipe \ + -fPIC \ + -Werror=implicit-function-declaration \ + -DTARGET_OS_MAC=1 \ + -D_GNU_SOURCE \ + -DHAVE_CONFIG_H \ + -DGST_REMOVE_DEPRECATED \ + -DGST_DISABLE_GST_DEBUG \ + -DGST_DISABLE_LOADSAVE \ + -DGST_DISABLE_XML \ + -DGSTREAMER_LITE \ + -DJFXMEDIA_JNI_EXPORTS \ + -msse2 \ + -mmacosx-version-min=10.7 ifeq ($(BUILD_TYPE), release) CFLAGS += -Os @@ -47,25 +51,28 @@ endif BASE_INCLUDES = -I$(JAVA_HOME)/include \ - -I$(JAVA_HOME)/include/darwin \ - -I$(SRCBASE_DIR) \ - -I$(SRCBASE_DIR)/jni \ - -I$(GENERATED_HEADERS_DIR) + -I$(JAVA_HOME)/include/darwin \ + -I$(SRCBASE_DIR) \ + -I$(SRCBASE_DIR)/jni \ + -I$(GENERATED_HEADERS_DIR) INCLUDES = $(BASE_INCLUDES) \ -I$(GLIB_LITE_DIR)/ \ -I$(GLIB_LITE_DIR)/glib \ -I$(GLIB_LITE_DIR)/gmodule \ -I$(GLIB_LITE_DIR)/build/osx \ - -I$(GSTREAMER_LITE_DIR)/gstreamer \ + -I$(GSTREAMER_LITE_DIR)/gstreamer \ -I$(GSTREAMER_LITE_DIR)/gst-plugins-base/gst-libs \ - -I$(GSTREAMER_LITE_DIR)/gstreamer/libs + -I$(GSTREAMER_LITE_DIR)/gstreamer/libs -LDFLAGS = -mmacosx-version-min=10.7 -arch x86_64 \ - -L$(BUILD_DIR) -Wl,-install_name,@rpath/$(TARGET_NAME) \ - -lgstreamer-lite -lglib-lite -lobjc \ - -framework CoreVideo -framework CoreAudio -framework QTKit \ - -framework Cocoa -framework Carbon -framework CoreServices -framework JavaVM +LDFLAGS = -mmacosx-version-min=10.7 \ + -arch x86_64 \ + -L$(BUILD_DIR) \ + -Wl,-install_name,@rpath/$(TARGET_NAME) \ + -lobjc \ + -framework Cocoa \ + -lgstreamer-lite \ + -lglib-lite CPP_SOURCES = \ MediaManagement/Media.cpp \ @@ -106,36 +113,32 @@ C_SOURCES = Utils/ColorConverter.c -OBJCMM_SOURCES = \ - platform/osx/OSXPlatform.mm \ - platform/osx/OSXMediaPlayer.mm \ - platform/osx/QTKMediaPlayer.mm \ - platform/osx/CVVideoFrame.mm - OBJCM_SOURCES = \ Utils/JObjectPeers.m \ Utils/JavaUtils.m \ Utils/MTObjectProxy.m OBJ_DIRS = $(addprefix $(OBJBASE_DIR)/,$(DIRLIST)) + + OBJECTS = $(patsubst %.cpp,$(OBJBASE_DIR)/%.o,$(CPP_SOURCES)) \ $(patsubst %.c,$(OBJBASE_DIR)/%.o,$(C_SOURCES)) \ - $(patsubst %.mm,$(OBJBASE_DIR)/%.o,$(OBJCMM_SOURCES)) \ $(patsubst %.m,$(OBJBASE_DIR)/%.o,$(OBJCM_SOURCES)) .PHONY: default -default: $(TARGET) +default: $(TARGET) $(QTMEDIA) +$(QTMEDIA): $(TARGET) + $(MAKE) -f qtmedia.mk OUTPUT_DIR=$(OUTPUT_DIR) BUILD_TYPE=$(BUILD_TYPE) BASE_NAME=$(BASE_NAME) + +# jfxmedia objects $(OBJBASE_DIR)/%.o: $(SRCBASE_DIR)/%.cpp $(CC) $(CFLAGS) $(INCLUDES) -x c++ -c $< -o $@ $(OBJBASE_DIR)/%.o: $(SRCBASE_DIR)/%.c $(CC) $(CFLAGS) $(INCLUDES) -x c -c $< -o $@ -$(OBJBASE_DIR)/%.o: $(SRCBASE_DIR)/%.mm - $(CC) $(CFLAGS) $(INCLUDES) -x objective-c++ -c $< -o $@ - $(OBJBASE_DIR)/%.o: $(SRCBASE_DIR)/%.m $(CC) $(CFLAGS) $(INCLUDES) -x objective-c -c $< -o $@ @@ -149,4 +152,3 @@ $(TARGET): $(OBJECTS) $(LINK) -dynamiclib $(OBJECTS) $(LDFLAGS) -o $@ - diff --git a/modules/media/src/main/native/jfxmedia/projects/mac/qtmedia.mk b/modules/media/src/main/native/jfxmedia/projects/mac/qtmedia.mk new file mode 100644 --- /dev/null +++ b/modules/media/src/main/native/jfxmedia/projects/mac/qtmedia.mk @@ -0,0 +1,73 @@ +# Mac OS X jfxmedia QTKit platform objects +# !!! This module is deprecated and will be removed in a future release !!! + +# OUTPUT_DIR, BUILD_TYPE and BASE_NAME are passed on the command line or from the +# parent make process +BUILD_DIR = $(OUTPUT_DIR)/$(BUILD_TYPE) + +SRCBASE_DIR = ../.. +OBJBASE_DIR = $(BUILD_DIR)/obj/jfxmedia + +BASE_DIR = ../../.. + +DIRLIST = platform/osx + +TARGET_NAME = lib$(BASE_NAME)_qtkit.dylib +TARGET = $(BUILD_DIR)/$(TARGET_NAME) + +INCLUDES = -I$(JAVA_HOME)/include \ + -I$(JAVA_HOME)/include/darwin \ + -I$(SRCBASE_DIR) \ + -I$(SRCBASE_DIR)/jni \ + -I$(GENERATED_HEADERS_DIR) + +SOURCES = platform/osx/OSXPlatform.mm \ + platform/osx/OSXMediaPlayer.mm \ + platform/osx/QTKMediaPlayer.mm \ + platform/osx/CVVideoFrame.mm + +OBJ_DIRS = $(addprefix $(OBJBASE_DIR)/,$(DIRLIST)) + +OBJECTS = $(patsubst %.mm,$(OBJBASE_DIR)/%.o,$(SOURCES)) + +CFLAGS = -arch x86_64 \ + -pipe \ + -fPIC \ + -Werror=implicit-function-declaration \ + -DTARGET_OS_MAC=1 \ + -D_GNU_SOURCE \ + -DHAVE_CONFIG_H \ + -DJFXMEDIA_JNI_EXPORTS \ + -msse2 \ + -mmacosx-version-min=10.7 + +ifeq ($(BUILD_TYPE), release) + CFLAGS += -Os +else + CFLAGS += -O0 -g -Wall +endif + +LDFLAGS = -mmacosx-version-min=10.7 \ + -pipe \ + -arch x86_64 \ + -L$(BUILD_DIR) \ + -Wl,-install_name,@rpath/$(TARGET_NAME) \ + -lobjc \ + -framework Cocoa \ + -framework CoreVideo \ + -framework QTKit + +# must link against libjfxmedia.dylib +$(TARGET): $(OBJECTS) + $(LINK) -dynamiclib $(OBJECTS) -ljfxmedia $(LDFLAGS) -o $@ + +$(OBJECTS): | $(OBJ_DIRS) $(BUILD_DIR) + +$(OBJ_DIRS): + mkdir -p $(OBJ_DIRS) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +$(OBJBASE_DIR)/%.o: $(SRCBASE_DIR)/%.mm + $(CC) $(CFLAGS) $(INCLUDES) -x objective-c++ -c $< -o $@