modules/media/src/main/native/jfxmedia/platform/osx/OSXMediaPlayer.mm

Print this page
rev 7591 : RT-38074: [macosx] Separate QTKit platform code from core media code so it can be removed for MAS
Reviewed-by:

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -22,24 +22,24 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 #import "OSXMediaPlayer.h"
+#import "OSXPlayerProtocol.h"
 #import "com_sun_media_jfxmediaimpl_platform_osx_OSXMediaPlayer.h"
 #import <Utils/JObjectPeers.h>
 #import <Utils/JavaUtils.h>
 #import <CoreAudio/CoreAudio.h>
 #import <jni/Logger.h>
 
-#import "QTKMediaPlayer.h"
-
 #import <objc/runtime.h>
 
 #define USE_WEAK_REFS 0
 
 // Don't access directly, use the OSXMediaPlayer static methods to ensure thread safe access
 static JObjectPeers *gMediaPlayerPeers = nil;
+static Class gMediaPlayerClass = nil;
 
 @implementation OSXMediaPlayer
 
 + (void) initialize
 {

@@ -59,19 +59,37 @@
 + (void) removePlayerPeers:(OSXMediaPlayer*)player
 {
     [gMediaPlayerPeers removePeer:player];
 }
 
++ (void) initPlayerPlatform
+{
+    // Determine if we can use QTKMediaPlayer or not, without directly linking and pulling
+    // in unwanted dependencies
+    Class klass = objc_getClass("QTKMediaPlayer");
+    if (klass) {
+        // And make sure it conforms to the OSXPlayerProtocol
+        if ([klass conformsToProtocol:@protocol(OSXPlayerProtocol)]) {
+            gMediaPlayerClass = klass;
+        }
+    } // else we can't log yet, so fail silently
+}
+
 - (id) init
 {
     if ((self = [super init]) != nil) {
     }
     return self;
 }
 
 - (id) initWithURL:(NSURL *)source javaPlayer:(jobject)jp andEnv:(JNIEnv*)env eventHandler:(CJavaPlayerEventDispatcher*)hdlr
 {
+    if (!gMediaPlayerClass) {
+        // No player class available, abort
+        return nil;
+    }
+
     if ((self = [super init]) != nil) {
         movieURL = [source retain];
         
         env->GetJavaVM(&javaPlayerVM);
 #if USE_WEAK_REFS

@@ -82,16 +100,23 @@
         // set up the peer association
         [OSXMediaPlayer setPeer:self forJavaPlayer:javaPlayer andEnv:env];
         
         eventHandler = hdlr;
         
-        // create the movie object
-        player = [[QTKMediaPlayer alloc] initWithURL:movieURL eventHandler:eventHandler];
+        // create the player object
+        player = [[gMediaPlayerClass alloc] initWithURL:movieURL eventHandler:eventHandler];
     }
     return self;
 }
 
+- (id) initWithURL:(NSURL *)source eventHandler:(CJavaPlayerEventDispatcher*)hdlr
+{
+    // stub initWithURL message to satisfy the protocol requirements, this should
+    // never be called
+    return nil;
+}
+
 - (void) dealloc
 {
     [self dispose]; // just in case
     [movieURL release];
     [super dealloc];