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 /*
   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 #import "OSXMediaPlayer.h"
  27 #import "com_sun_media_jfxmediaimpl_platform_osx_OSXMediaPlayer.h"
  28 #import <Utils/JObjectPeers.h>
  29 #import <Utils/JavaUtils.h>
  30 #import <CoreAudio/CoreAudio.h>
  31 #import <jni/Logger.h>
  32 
  33 #import "QTKMediaPlayer.h"
  34 
  35 #import <objc/runtime.h>
  36 
  37 #define USE_WEAK_REFS 0
  38 
  39 // Don't access directly, use the OSXMediaPlayer static methods to ensure thread safe access
  40 static JObjectPeers *gMediaPlayerPeers = nil;

  41 
  42 @implementation OSXMediaPlayer
  43 
  44 + (void) initialize
  45 {
  46     gMediaPlayerPeers = [[JObjectPeers alloc] init];
  47 }
  48 
  49 + (OSXMediaPlayer*) peerForPlayer:(jobject)javaPlayer andEnv:(JNIEnv*)javaEnv
  50 {
  51     return [gMediaPlayerPeers peerForJObject:javaPlayer javaEnv:javaEnv];
  52 }
  53 
  54 + (void) setPeer:(OSXMediaPlayer*)player forJavaPlayer:(jobject)javaPlayer andEnv:(JNIEnv*)javaEnv
  55 {
  56     [gMediaPlayerPeers setPeer:player forJObject:javaPlayer javaEnv:javaEnv];
  57 }
  58 
  59 + (void) removePlayerPeers:(OSXMediaPlayer*)player
  60 {
  61     [gMediaPlayerPeers removePeer:player];
  62 }
  63 










  64 - (id) init
  65 {
  66     if ((self = [super init]) != nil) {
  67     }
  68     return self;
  69 }
  70 
  71 - (id) initWithURL:(NSURL *)source javaPlayer:(jobject)jp andEnv:(JNIEnv*)env eventHandler:(CJavaPlayerEventDispatcher*)hdlr
  72 {





  73     if ((self = [super init]) != nil) {
  74         movieURL = [source retain];
  75         
  76         env->GetJavaVM(&javaPlayerVM);
  77 #if USE_WEAK_REFS
  78         javaPlayer = env->NewWeakGlobalRef(jp);
  79 #else
  80         javaPlayer = env->NewGlobalRef(jp);
  81 #endif
  82         // set up the peer association
  83         [OSXMediaPlayer setPeer:self forJavaPlayer:javaPlayer andEnv:env];
  84         
  85         eventHandler = hdlr;
  86         
  87         // create the movie object
  88         player = [[QTKMediaPlayer alloc] initWithURL:movieURL eventHandler:eventHandler];
  89     }
  90     return self;
  91 }
  92 
  93 - (void) dealloc
  94 {
  95     [self dispose]; // just in case
  96     [movieURL release];
  97     [super dealloc];
  98 }
  99 
 100 - (void) dispose
 101 {
 102     @synchronized(self) {
 103         [player dispose];
 104         [player release];
 105         player = nil;
 106     
 107         if (eventHandler) {
 108             eventHandler->Dispose();


   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 #import "OSXMediaPlayer.h"
  27 #import "com_sun_media_jfxmediaimpl_platform_osx_OSXMediaPlayer.h"
  28 #import <Utils/JObjectPeers.h>
  29 #import <Utils/JavaUtils.h>
  30 #import <CoreAudio/CoreAudio.h>
  31 #import <jni/Logger.h>
  32 


  33 #import <objc/runtime.h>
  34 
  35 #define USE_WEAK_REFS 0
  36 
  37 // Don't access directly, use the OSXMediaPlayer static methods to ensure thread safe access
  38 static JObjectPeers *gMediaPlayerPeers = nil;
  39 static id gMediaPlayerClass = nil;
  40 
  41 @implementation OSXMediaPlayer
  42 
  43 + (void) initialize
  44 {
  45     gMediaPlayerPeers = [[JObjectPeers alloc] init];
  46 }
  47 
  48 + (OSXMediaPlayer*) peerForPlayer:(jobject)javaPlayer andEnv:(JNIEnv*)javaEnv
  49 {
  50     return [gMediaPlayerPeers peerForJObject:javaPlayer javaEnv:javaEnv];
  51 }
  52 
  53 + (void) setPeer:(OSXMediaPlayer*)player forJavaPlayer:(jobject)javaPlayer andEnv:(JNIEnv*)javaEnv
  54 {
  55     [gMediaPlayerPeers setPeer:player forJObject:javaPlayer javaEnv:javaEnv];
  56 }
  57 
  58 + (void) removePlayerPeers:(OSXMediaPlayer*)player
  59 {
  60     [gMediaPlayerPeers removePeer:player];
  61 }
  62 
  63 + (void) initPlayerPlatform
  64 {
  65     // Determine if we can use QTKMediaPlayer or not, without directly linking and pulling
  66     // in unwanted dependencies
  67     id klass = objc_getClass("QTKMediaPlayer");
  68     if (klass) {
  69         gMediaPlayerClass = klass;
  70     }
  71 }
  72 
  73 - (id) init
  74 {
  75     if ((self = [super init]) != nil) {
  76     }
  77     return self;
  78 }
  79 
  80 - (id) initWithURL:(NSURL *)source javaPlayer:(jobject)jp andEnv:(JNIEnv*)env eventHandler:(CJavaPlayerEventDispatcher*)hdlr
  81 {
  82     if (!gMediaPlayerClass) {
  83         // No player class available, abort
  84         return nil;
  85     }
  86 
  87     if ((self = [super init]) != nil) {
  88         movieURL = [source retain];
  89         
  90         env->GetJavaVM(&javaPlayerVM);
  91 #if USE_WEAK_REFS
  92         javaPlayer = env->NewWeakGlobalRef(jp);
  93 #else
  94         javaPlayer = env->NewGlobalRef(jp);
  95 #endif
  96         // set up the peer association
  97         [OSXMediaPlayer setPeer:self forJavaPlayer:javaPlayer andEnv:env];
  98         
  99         eventHandler = hdlr;
 100         
 101         // create the movie object
 102         player = [[gMediaPlayerClass alloc] initWithURL:movieURL eventHandler:eventHandler];
 103     }
 104     return self;
 105 }
 106 
 107 - (void) dealloc
 108 {
 109     [self dispose]; // just in case
 110     [movieURL release];
 111     [super dealloc];
 112 }
 113 
 114 - (void) dispose
 115 {
 116     @synchronized(self) {
 117         [player dispose];
 118         [player release];
 119         player = nil;
 120     
 121         if (eventHandler) {
 122             eventHandler->Dispose();