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

@@ -28,18 +28,17 @@
 #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 id gMediaPlayerClass = nil;
 
 @implementation OSXMediaPlayer
 
 + (void) initialize
 {

@@ -59,19 +58,34 @@
 + (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
+    id klass = objc_getClass("QTKMediaPlayer");
+    if (klass) {
+        gMediaPlayerClass = klass;
+    }
+}
+
 - (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

@@ -83,11 +97,11 @@
         [OSXMediaPlayer setPeer:self forJavaPlayer:javaPlayer andEnv:env];
         
         eventHandler = hdlr;
         
         // create the movie object
-        player = [[QTKMediaPlayer alloc] initWithURL:movieURL eventHandler:eventHandler];
+        player = [[gMediaPlayerClass alloc] initWithURL:movieURL eventHandler:eventHandler];
     }
     return self;
 }
 
 - (void) dealloc