1 /*
   2  * Copyright (c) 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 <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     // placeholders until audio processor is created
  59     float _volume;
  60     float _balance;
  61     int64_t _audioSyncDelay; // delay is time in milliseconds
  62 
  63     AVFAudioSpectrumUnit *_audioSpectrum;
  64     AVFAudioEqualizer *_audioEqualizer;
  65 }
  66 
  67 @property (nonatomic,retain) NSURL *movieURL;
  68 @property (nonatomic,retain) AVPlayer *player;
  69 @property (nonatomic,retain) AVPlayerItem *playerItem;
  70 @property (nonatomic,retain) AVPlayerItemVideoOutput *playerOutput;
  71 @property (nonatomic,retain) AVFAudioProcessor *audioProcessor;
  72 @property (nonatomic,assign) uint64_t lastHostTime;
  73 
  74 @property (nonatomic,assign) int64_t audioSyncDelay;
  75 @property (nonatomic,assign) float balance;
  76 
  77 
  78 @property (nonatomic,assign) BOOL movieReady;   // set to YES the first time we get ready to play state
  79 @property (nonatomic,assign) BOOL isLiveStream; // YES if the stream is indeterminate
  80 
  81 // There's a bug in AVFoundation where when a HLS stream switches to a new
  82 // sub-stream, the call to hasNewPixelBufferForItemTime will begin to return
  83 // NO. So, we'll attempt to detect that case and when we encounter it we'll
  84 // stop asking and always ask for a new frame instead.
  85 // This *should* be fixed in a near-future version of AVFoundation, and it does
  86 // not happen with non HLS sources, so we'll leave the current behavior as the
  87 // default
  88 @property (nonatomic,assign) BOOL buggyHLSSupport;
  89 @property (nonatomic,assign) int hlsBugResetCount;
  90 
  91 @property (nonatomic,readonly) CAudioEqualizer *audioEqualizer;
  92 @property (nonatomic,readonly) CAudioSpectrum *audioSpectrum;
  93 
  94 - (id) initWithURL:(NSURL *)source eventHandler:(CJavaPlayerEventDispatcher*)hdlr;
  95 - (void) setPlayerState:(int)newState;
  96 
  97 @end