1 /* 2 * Copyright (c) 2014, 2016, 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 <Foundation/Foundation.h> 27 #import <AVFoundation/AVFoundation.h> 28 #import <AVFoundation/AVPlayerItemOutput.h> 29 #import <CoreVideo/CoreVideo.h> 30 31 #import "OSXPlayerProtocol.h" 32 #import "jni/JavaPlayerEventDispatcher.h" 33 #import "AVFAudioSpectrumUnit.h" 34 #import "AVFAudioEqualizer.h" 35 36 @class AVFAudioProcessor; 37 38 @interface AVFMediaPlayer : NSObject<OSXPlayerProtocol,AVPlayerItemOutputPullDelegate> 39 { 40 CVDisplayLinkRef _displayLink; 41 CMVideoFormatDescriptionRef _videoFormat; 42 43 dispatch_queue_t playerQueue; 44 45 CJavaPlayerEventDispatcher *eventHandler; 46 47 int requestedState; // 0 - stop, 1 - play, 2 - pause 48 float requestedRate; 49 50 int previousWidth; 51 int previousHeight; 52 int previousPlayerState; // avoid repeated states 53 54 BOOL isDisposed; 55 NSMutableArray *keyPathsObserved; 56 NSMutableArray *playerObservers; // player item notification observers 57 } 58 59 @property (nonatomic,retain) NSURL *movieURL; 60 @property (nonatomic,retain) AVPlayer *player; 61 @property (nonatomic,retain) AVPlayerItemVideoOutput *playerOutput; 62 @property (nonatomic,retain) AVFAudioProcessor *audioProcessor; 63 @property (nonatomic,assign) uint64_t lastHostTime; 64 65 @property (nonatomic,assign) int64_t audioSyncDelay; 66 @property (nonatomic,assign) float balance; 67 68 69 @property (nonatomic,assign) BOOL movieReady; // set to YES the first time we get ready to play state 70 @property (nonatomic,assign) BOOL isLiveStream; // YES if the stream is indeterminate 71 72 // There's a bug in AVFoundation where when a HLS stream switches to a new 73 // sub-stream, the call to hasNewPixelBufferForItemTime will begin to return 74 // NO. So, we'll attempt to detect that case and when we encounter it we'll 75 // stop asking and always ask for a new frame instead. 76 // This *should* be fixed in a near-future version of AVFoundation, and it does 77 // not happen with non HLS sources, so we'll leave the current behavior as the 78 // default 79 @property (nonatomic,assign) BOOL buggyHLSSupport; 80 @property (nonatomic,assign) int hlsBugResetCount; 81 82 @property (nonatomic,readonly) CAudioEqualizer *audioEqualizer; 83 @property (nonatomic,readonly) CAudioSpectrum *audioSpectrum; 84 85 - (id) initWithURL:(NSURL *)source eventHandler:(CJavaPlayerEventDispatcher*)hdlr; 86 - (void) setPlayerState:(int)newState; 87 88 @end