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

Print this page
rev 7587 : RT-38074: [macosx] Separate QTKit platform code from core media code so it can be removed for MAS
Reviewed-by:
   1 /*
   2  * Copyright (c) 2010, 2013, 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.media.jfxmedia.Media;
  29 import com.sun.media.jfxmedia.MediaPlayer;
  30 import com.sun.media.jfxmedia.locator.Locator;
  31 import com.sun.media.jfxmedia.logging.Logger;
  32 import com.sun.media.jfxmediaimpl.HostUtils;
  33 import com.sun.media.jfxmediaimpl.platform.Platform;


  34 
  35 /**
  36  * Mac OS X Platform implementation.
  37  */
  38 public final class OSXPlatform extends Platform {
  39     /**
  40      * The MIME types of all supported media.
  41      */
  42     private static final String[] CONTENT_TYPES = {
  43         "video/mp4",
  44         "audio/x-m4a",
  45         "video/x-m4v",
  46         "application/vnd.apple.mpegurl",
  47         "audio/mpegurl"
  48     };
  49 
  50     private static final class OSXPlatformInitializer {
  51         private static final OSXPlatform globalInstance = new OSXPlatform();























  52     }
  53 
  54     public static Platform getPlatformInstance() {
  55         return OSXPlatformInitializer.globalInstance;
  56     }
  57 
  58     private OSXPlatform() {
  59     }
  60 
  61     @Override
  62     public void preloadPlatform() {}
  63 
  64     /**
  65      * @return false if the platform cannot be loaded
  66      */
  67     @Override
  68     public boolean loadPlatform() {
  69         if (!HostUtils.isMacOSX()) {
  70             return false;
  71         }
  72 

  73         try {
  74             osxPlatformInit();
  75         } catch (UnsatisfiedLinkError ule) {
  76             if (Logger.canLog(Logger.DEBUG)) {
  77                 Logger.logMsg(Logger.DEBUG, "Unable to load OSX platform.");
  78             }
  79 //            MediaUtils.nativeError(OSXPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL);
  80             return false;
  81         }
  82         return true;
  83     }
  84 
  85     @Override
  86     public String[] getSupportedContentTypes() {
  87         String[] contentTypesCopy = new String[CONTENT_TYPES.length];
  88         System.arraycopy(CONTENT_TYPES, 0, contentTypesCopy, 0, CONTENT_TYPES.length);
  89         return contentTypesCopy;
  90     }
  91 
  92     @Override
  93     public Media createMedia(Locator source) {
  94         return new OSXMedia(source);
  95     }
  96 
  97     @Override
   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.
  40  */
  41 public final class OSXPlatform extends Platform {
  42     /**
  43      * The MIME types of all supported media.
  44      */
  45     private static final String[] CONTENT_TYPES = {
  46         "video/mp4",
  47         "audio/x-m4a",
  48         "video/x-m4v",
  49         "application/vnd.apple.mpegurl",
  50         "audio/mpegurl"
  51     };
  52 
  53     private static final class OSXPlatformInitializer {
  54         private static final OSXPlatform globalInstance;
  55         static {
  56             // Platform is only available if we can load it's native lib
  57             // Do this early so we can report the correct content types
  58             boolean isLoaded = false;
  59             try {
  60                 isLoaded = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
  61                     try {
  62                         NativeLibLoader.loadLibrary("jfxmedia_qtkit");
  63                     } catch (UnsatisfiedLinkError ule) {
  64                         // non-fatal condition, keep quiet about it
  65                         return Boolean.FALSE;
  66                     }
  67                     return Boolean.TRUE;
  68                 });
  69             } catch (Exception e) {
  70                 // Ignore
  71             }
  72             if (isLoaded) {
  73                 globalInstance = new OSXPlatform();
  74             } else {
  75                 globalInstance = null;
  76             }
  77         }
  78     }
  79 
  80     public static Platform getPlatformInstance() {
  81         return OSXPlatformInitializer.globalInstance;
  82     }
  83 
  84     private OSXPlatform() {
  85     }
  86 



  87     /**
  88      * @return false if the platform cannot be loaded
  89      */
  90     @Override
  91     public boolean loadPlatform() {
  92         if (!HostUtils.isMacOSX()) {
  93             return false;
  94         }
  95 
  96         // ULE should not happen here, but just in case
  97         try {
  98             osxPlatformInit();
  99         } catch (UnsatisfiedLinkError ule) {
 100             if (Logger.canLog(Logger.DEBUG)) {
 101                 Logger.logMsg(Logger.DEBUG, "QTKit platform lib is not available.");
 102             }
 103 //                MediaUtils.nativeError(OSXPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL);
 104             return false;
 105         }
 106         return true;
 107     }
 108 
 109     @Override
 110     public String[] getSupportedContentTypes() {
 111         String[] contentTypesCopy = new String[CONTENT_TYPES.length];
 112         System.arraycopy(CONTENT_TYPES, 0, contentTypesCopy, 0, CONTENT_TYPES.length);
 113         return contentTypesCopy;
 114     }
 115 
 116     @Override
 117     public Media createMedia(Locator source) {
 118         return new OSXMedia(source);
 119     }
 120 
 121     @Override