modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/osx/OSXPlatform.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.jfxmediaimpl.platform.osx;
  27 
  28 import com.sun.glass.utils.NativeLibLoader;
  29 import com.sun.media.jfxmedia.Media;
  30 import com.sun.media.jfxmedia.MediaPlayer;
  31 import com.sun.media.jfxmedia.locator.Locator;
  32 import com.sun.media.jfxmedia.logging.Logger;
  33 import com.sun.media.jfxmediaimpl.HostUtils;
  34 import com.sun.media.jfxmediaimpl.platform.Platform;
  35 import java.security.AccessController;
  36 import java.security.PrivilegedAction;

  37 
  38 /**
  39  * Mac OS X Platform implementation. This class implements both the QTKit based
  40  * platform and the AVFoundation based platforms.
  41  * 
  42  * NOTE: The QTKit based platform is deprecated and will be removed in a future
  43  * release.
  44  */
  45 public final class OSXPlatform extends Platform {
  46     /**
  47      * The MIME types of all supported media.
  48      */
  49     private static final String[] CONTENT_TYPES = {
  50         "audio/x-aiff",
  51         "audio/mp3",
  52         "audio/mpeg",
  53         "audio/x-m4a",
  54         "video/mp4",
  55         "video/x-m4v",
  56         "application/vnd.apple.mpegurl",
  57         "audio/mpegurl"
  58     };
  59 









  60     private static final class OSXPlatformInitializer {
  61         private static final OSXPlatform globalInstance;
  62         static {
  63             // Platform is only available if we can load it's native lib
  64             // Do this early so we can report the correct content types
  65             boolean isLoaded = false;
  66             try {
  67                 isLoaded = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
  68                     boolean avf = false;
  69                     boolean qtk = false;
  70                     // attempt to load the AVFoundation based player first
  71                     // AVFoundation will have precedence
  72                     try {
  73                         NativeLibLoader.loadLibrary("jfxmedia_avf");
  74                         avf = true;
  75                     } catch (UnsatisfiedLinkError ule) {}
  76                     try {
  77                         NativeLibLoader.loadLibrary("jfxmedia_qtkit");
  78                         qtk = true;
  79                     } catch (UnsatisfiedLinkError ule) {}


 104     @Override
 105     public boolean loadPlatform() {
 106         if (!HostUtils.isMacOSX()) {
 107             return false;
 108         }
 109 
 110         // ULE should not happen here, but just in case
 111         try {
 112             return osxPlatformInit();
 113         } catch (UnsatisfiedLinkError ule) {
 114             if (Logger.canLog(Logger.DEBUG)) {
 115                 Logger.logMsg(Logger.DEBUG, "Unable to load OSX platform.");
 116             }
 117 //            MediaUtils.nativeError(OSXPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL);
 118             return false;
 119         }
 120     }
 121 
 122     @Override
 123     public String[] getSupportedContentTypes() {
 124         String[] contentTypesCopy = new String[CONTENT_TYPES.length];
 125         System.arraycopy(CONTENT_TYPES, 0, contentTypesCopy, 0, CONTENT_TYPES.length);
 126         return contentTypesCopy;



 127     }
 128 
 129     @Override
 130     public Media createMedia(Locator source) {
 131         return new OSXMedia(source);
 132     }
 133 
 134     @Override
 135     public MediaPlayer createMediaPlayer(Locator source) {
 136         try {
 137             return new OSXMediaPlayer(source);
 138         } catch (Exception ex) {
 139             if (Logger.canLog(Logger.DEBUG)) {
 140                 Logger.logMsg(Logger.DEBUG, "OSXPlatform caught exception while creating media player: "+ex);
 141                 ex.printStackTrace();
 142             }
 143         }
 144         return null;
 145     }
 146 
   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.jfxmediaimpl.platform.osx;
  27 
  28 import com.sun.glass.utils.NativeLibLoader;
  29 import com.sun.media.jfxmedia.Media;
  30 import com.sun.media.jfxmedia.MediaPlayer;
  31 import com.sun.media.jfxmedia.locator.Locator;
  32 import com.sun.media.jfxmedia.logging.Logger;
  33 import com.sun.media.jfxmediaimpl.HostUtils;
  34 import com.sun.media.jfxmediaimpl.platform.Platform;
  35 import java.security.AccessController;
  36 import java.security.PrivilegedAction;
  37 import java.util.Arrays;
  38 
  39 /**
  40  * Mac OS X Platform implementation. This class implements both the QTKit based
  41  * platform and the AVFoundation based platforms.
  42  *
  43  * NOTE: The QTKit based platform is deprecated and will be removed in a future
  44  * release.
  45  */
  46 public final class OSXPlatform extends Platform {
  47     /**
  48      * The MIME types of all supported media.
  49      */
  50     private static final String[] CONTENT_TYPES = {
  51         "audio/x-aiff",
  52         "audio/mp3",
  53         "audio/mpeg",
  54         "audio/x-m4a",
  55         "video/mp4",
  56         "video/x-m4v",
  57         "application/vnd.apple.mpegurl",
  58         "audio/mpegurl"
  59     };
  60 
  61     /**
  62      * All supported protocols.
  63      */
  64     private static final String[] PROTOCOLS = {
  65         "file",
  66         "http",
  67         "https"
  68     };
  69 
  70     private static final class OSXPlatformInitializer {
  71         private static final OSXPlatform globalInstance;
  72         static {
  73             // Platform is only available if we can load it's native lib
  74             // Do this early so we can report the correct content types
  75             boolean isLoaded = false;
  76             try {
  77                 isLoaded = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
  78                     boolean avf = false;
  79                     boolean qtk = false;
  80                     // attempt to load the AVFoundation based player first
  81                     // AVFoundation will have precedence
  82                     try {
  83                         NativeLibLoader.loadLibrary("jfxmedia_avf");
  84                         avf = true;
  85                     } catch (UnsatisfiedLinkError ule) {}
  86                     try {
  87                         NativeLibLoader.loadLibrary("jfxmedia_qtkit");
  88                         qtk = true;
  89                     } catch (UnsatisfiedLinkError ule) {}


 114     @Override
 115     public boolean loadPlatform() {
 116         if (!HostUtils.isMacOSX()) {
 117             return false;
 118         }
 119 
 120         // ULE should not happen here, but just in case
 121         try {
 122             return osxPlatformInit();
 123         } catch (UnsatisfiedLinkError ule) {
 124             if (Logger.canLog(Logger.DEBUG)) {
 125                 Logger.logMsg(Logger.DEBUG, "Unable to load OSX platform.");
 126             }
 127 //            MediaUtils.nativeError(OSXPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL);
 128             return false;
 129         }
 130     }
 131 
 132     @Override
 133     public String[] getSupportedContentTypes() {
 134         return Arrays.copyOf(CONTENT_TYPES, CONTENT_TYPES.length);
 135     }
 136 
 137     @Override
 138     public String[] getSupportedProtocols() {
 139         return Arrays.copyOf(PROTOCOLS, PROTOCOLS.length);
 140     }
 141 
 142     @Override
 143     public Media createMedia(Locator source) {
 144         return new OSXMedia(source);
 145     }
 146 
 147     @Override
 148     public MediaPlayer createMediaPlayer(Locator source) {
 149         try {
 150             return new OSXMediaPlayer(source);
 151         } catch (Exception ex) {
 152             if (Logger.canLog(Logger.DEBUG)) {
 153                 Logger.logMsg(Logger.DEBUG, "OSXPlatform caught exception while creating media player: "+ex);
 154                 ex.printStackTrace();
 155             }
 156         }
 157         return null;
 158     }
 159