Unreviewed build fix: internal builds can't find AVVideoPerformanceMetrics.
[WebKit-https.git] / Source / WebCore / PAL / pal / spi / mac / AVFoundationSPI.h
1 /*
2  * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #import <objc/runtime.h>
29 #import <wtf/SoftLinking.h>
30
31 #if USE(APPLE_INTERNAL_SDK)
32
33 #import <AVFoundation/AVAssetCache_Private.h>
34 #import <AVFoundation/AVOutputContext_Private.h>
35 #import <AVFoundation/AVPlayerItem_Private.h>
36 #import <AVFoundation/AVPlayerLayer_Private.h>
37 #import <AVFoundation/AVPlayer_Private.h>
38
39 #if PLATFORM(IOS) && HAVE(AVKIT)
40 #import <AVKit/AVPlayerViewController_WebKitOnly.h>
41 #endif
42
43 #if !PLATFORM(IOS)
44 #import <AVFoundation/AVStreamDataParser.h>
45 #endif
46
47 #if PLATFORM(IOS)
48 #import <AVFoundation/AVAudioSession_Private.h>
49 #endif
50
51 #else
52
53 #import <AVFoundation/AVPlayer.h>
54 #import <AVFoundation/AVPlayerItem.h>
55 #import <AVFoundation/AVPlayerLayer.h>
56
57 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000)
58 NS_ASSUME_NONNULL_BEGIN
59 @interface AVPlayerItem ()
60 @property (nonatomic, readonly) NSTimeInterval seekableTimeRangesLastModifiedTime NS_AVAILABLE(10_13, 11_0);
61 @property (nonatomic, readonly) NSTimeInterval liveUpdateInterval;
62 @end
63 NS_ASSUME_NONNULL_END
64 #endif // (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000)
65
66 #if ENABLE(WIRELESS_PLAYBACK_TARGET) || PLATFORM(IOS)
67
68 NS_ASSUME_NONNULL_BEGIN
69
70 @class AVOutputContext;
71 @class AVOutputDevice;
72 @interface AVOutputContext : NSObject <NSSecureCoding>
73 @property (nonatomic, readonly) NSString *deviceName;
74 + (instancetype)outputContext;
75 + (nullable AVOutputContext *)sharedAudioPresentationOutputContext;
76 @property (readonly) BOOL supportsMultipleOutputDevices;
77 @property (readonly) NSArray<AVOutputDevice *> *outputDevices;
78 @end
79
80 #if !PLATFORM(IOS)
81 @interface AVPlayer (AVPlayerExternalPlaybackSupportPrivate)
82 @property (nonatomic, retain) AVOutputContext *outputContext;
83 @end
84 #else
85 typedef NS_ENUM(NSInteger, AVPlayerExternalPlaybackType) {
86     AVPlayerExternalPlaybackTypeNone,
87     AVPlayerExternalPlaybackTypeAirPlay,
88     AVPlayerExternalPlaybackTypeTVOut,
89 };
90
91 @interface AVPlayer (AVPlayerExternalPlaybackSupportPrivate)
92 @property (nonatomic, readonly) AVPlayerExternalPlaybackType externalPlaybackType;
93 @end
94 #endif
95
96 NS_ASSUME_NONNULL_END
97
98 #endif // ENABLE(WIRELESS_PLAYBACK_TARGET) || PLATFORM(IOS)
99
100 #import <AVFoundation/AVAssetCache.h>
101 NS_ASSUME_NONNULL_BEGIN
102 @interface AVAssetCache ()
103 + (AVAssetCache *)assetCacheWithURL:(NSURL *)URL;
104 - (id)initWithURL:(NSURL *)URL;
105 - (NSArray *)allKeys;
106 - (NSDate *)lastModifiedDateOfEntryForKey:(NSString *)key;
107 - (void)removeEntryForKey:(NSString *)key;
108 @property (nonatomic, readonly, copy) NSURL *URL;
109 @end
110 NS_ASSUME_NONNULL_END
111
112 #if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
113 @interface AVPlayer (AVPlayerVideoSleepPrevention)
114 @property (nonatomic, getter=_preventsSleepDuringVideoPlayback, setter=_setPreventsSleepDuringVideoPlayback:) BOOL preventsSleepDuringVideoPlayback;
115 @end
116
117 #endif // PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
118
119 #if !PLATFORM(IOS)
120
121 #pragma mark -
122 #pragma mark AVStreamDataParser
123
124 @protocol AVStreamDataParserOutputHandling <NSObject>
125 @end
126
127 typedef int32_t CMPersistentTrackID;
128
129 NS_ASSUME_NONNULL_BEGIN
130 typedef NS_ENUM(NSUInteger, AVStreamDataParserOutputMediaDataFlags) {
131     AVStreamDataParserOutputMediaDataReserved = 1 << 0
132 };
133
134 typedef NS_ENUM(NSUInteger, AVStreamDataParserStreamDataFlags) {
135     AVStreamDataParserStreamDataDiscontinuity = 1 << 0,
136 };
137
138 @interface AVStreamDataParser : NSObject
139 - (void)setDelegate:(nullable id<AVStreamDataParserOutputHandling>)delegate;
140 - (void)appendStreamData:(NSData *)data;
141 - (void)appendStreamData:(NSData *)data withFlags:(AVStreamDataParserStreamDataFlags)flags;
142 - (void)setShouldProvideMediaData:(BOOL)shouldProvideMediaData forTrackID:(CMPersistentTrackID)trackID;
143 - (BOOL)shouldProvideMediaDataForTrackID:(CMPersistentTrackID)trackID;
144 - (void)providePendingMediaData;
145 - (void)processContentKeyResponseData:(NSData *)contentKeyResponseData forTrackID:(CMPersistentTrackID)trackID;
146 - (void)processContentKeyResponseError:(NSError *)error forTrackID:(CMPersistentTrackID)trackID;
147 - (void)renewExpiringContentKeyResponseDataForTrackID:(CMPersistentTrackID)trackID;
148 - (NSData *)streamingContentKeyRequestDataForApp:(NSData *)appIdentifier contentIdentifier:(NSData *)contentIdentifier trackID:(CMPersistentTrackID)trackID options:(NSDictionary *)options error:(NSError **)outError;
149 @end
150
151 NS_ASSUME_NONNULL_END
152
153 #if HAVE(AVCONTENTKEYSESSION)
154 #import <AVFoundation/AVContentKeySession.h>
155 @interface AVStreamDataParser () <AVContentKeyRecipient>
156 @end
157 #endif
158
159 #endif // !PLATFORM(IOS)
160
161 #endif // USE(APPLE_INTERNAL_SDK)
162
163 #if PLATFORM(MAC) && !USE(APPLE_INTERNAL_SDK)
164 NS_ASSUME_NONNULL_BEGIN
165 @interface AVStreamDataParser (AVStreamDataParserPrivate)
166 + (NSString *)outputMIMECodecParameterForInputMIMECodecParameter:(NSString *)inputMIMECodecParameter;
167 @end
168 NS_ASSUME_NONNULL_END
169 #endif
170
171 #if PLATFORM(IOS) && (!HAVE(AVKIT) || !USE(APPLE_INTERNAL_SDK))
172 #import <AVFoundation/AVPlayerLayer.h>
173 @interface AVPlayerLayer (AVPlayerLayerPictureInPictureModeSupportPrivate)
174 - (void)setPIPModeEnabled:(BOOL)flag;
175 @end
176 #endif // !HAVE(AVKIT)
177
178 #if !USE(APPLE_INTERNAL_SDK) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101404) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 120200)
179 @class AVVideoPerformanceMetrics;
180 NS_ASSUME_NONNULL_BEGIN
181 @interface AVPlayerLayer (AVPlayerLayerVideoPerformanceMetrics)
182 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
183 @end
184 NS_ASSUME_NONNULL_END
185 #endif
186
187 // FIXME: Wrap in a #if USE(APPLE_INTERNAL_SDK) once these SPI land
188 #import <AVFoundation/AVAsset.h>
189 #import <AVFoundation/AVAssetResourceLoader.h>
190
191 NS_ASSUME_NONNULL_BEGIN
192
193 @interface AVAssetResourceLoader (AVAssetResourceLoaderPrivate)
194 @property (nonatomic, readonly) id<NSURLSessionDataDelegate> URLSessionDataDelegate;
195 @property (nonatomic, readonly) NSOperationQueue *URLSessionDataDelegateQueue;
196 @property (nonatomic, nullable, retain) NSURLSession *URLSession;
197 @end
198
199 @interface AVAsset (AVAssetFragmentsPrivate)
200 @property (nonatomic, readonly) CMTime overallDurationHint;
201 @end
202
203 NS_ASSUME_NONNULL_END
204
205 #import <CoreMedia/CMSampleBuffer.h>
206 #import <CoreMedia/CMSync.h>
207
208 #if __has_include(<AVFoundation/AVSampleBufferRenderSynchronizer.h>)
209 #import <AVFoundation/AVSampleBufferRenderSynchronizer.h>
210
211 NS_ASSUME_NONNULL_BEGIN
212 @interface AVSampleBufferRenderSynchronizer (AVSampleBufferRenderSynchronizerPrivate)
213 - (void)removeRenderer:(id)renderer atTime:(CMTime)time withCompletionHandler:(void (^)(BOOL didRemoveRenderer))completionHandler;
214 @end
215 NS_ASSUME_NONNULL_END
216
217 #else
218
219 NS_ASSUME_NONNULL_BEGIN
220
221 @interface AVSampleBufferRenderSynchronizer : NSObject
222 - (CMTimebaseRef)timebase;
223 - (float)rate;
224 - (void)setRate:(float)rate;
225 - (void)setRate:(float)rate time:(CMTime)time;
226 - (NSArray *)renderers;
227 - (void)addRenderer:(id)renderer;
228 - (void)removeRenderer:(id)renderer atTime:(CMTime)time withCompletionHandler:(void (^)(BOOL didRemoveRenderer))completionHandler;
229 - (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_t)queue usingBlock:(void (^)(CMTime time))block;
230 - (id)addBoundaryTimeObserverForTimes:(NSArray *)times queue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
231 - (void)removeTimeObserver:(id)observer;
232 @end
233
234 NS_ASSUME_NONNULL_END
235
236 #endif // __has_include(<AVFoundation/AVSampleBufferRenderSynchronizer.h>)
237
238 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 110000)) && __has_include(<AVFoundation/AVQueuedSampleBufferRendering.h>)
239 #import <AVFoundation/AVQueuedSampleBufferRendering.h>
240 @class AVVideoPerformanceMetrics;
241 NS_ASSUME_NONNULL_BEGIN
242 @interface AVSampleBufferDisplayLayer (VideoPerformanceMetrics)
243 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
244 @end
245 NS_ASSUME_NONNULL_END
246 #elif __has_include(<AVFoundation/AVSampleBufferDisplayLayer_Private.h>)
247 #import <AVFoundation/AVSampleBufferDisplayLayer_Private.h>
248 #elif __has_include(<AVFoundation/AVSampleBufferDisplayLayer.h>)
249 #import <AVFoundation/AVSampleBufferDisplayLayer.h>
250 NS_ASSUME_NONNULL_BEGIN
251 @interface AVSampleBufferDisplayLayer (VideoPerformanceMetrics)
252 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
253 @end
254 NS_ASSUME_NONNULL_END
255 #else
256
257 NS_ASSUME_NONNULL_BEGIN
258
259 #pragma mark -
260 #pragma mark AVSampleBufferDisplayLayer
261
262 @interface AVSampleBufferDisplayLayer : CALayer
263 - (NSInteger)status;
264 - (NSError*)error;
265 - (void)enqueueSampleBuffer:(CMSampleBufferRef)sampleBuffer;
266 - (void)flush;
267 - (void)flushAndRemoveImage;
268 - (BOOL)isReadyForMoreMediaData;
269 - (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
270 - (void)stopRequestingMediaData;
271 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
272 @end
273 NS_ASSUME_NONNULL_END
274 #endif // __has_include(<AVFoundation/AVSampleBufferDisplayLayer.h>)
275
276 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 110000)) && __has_include(<AVFoundation/AVQueuedSampleBufferRendering.h>)
277 // Nothing to do, AVfoundation/AVQueuedSampleBufferRendering.h was imported above.
278 #elif __has_include(<AVFoundation/AVSampleBufferAudioRenderer.h>)
279 #import <AVFoundation/AVSampleBufferAudioRenderer.h>
280 #else
281
282 NS_ASSUME_NONNULL_BEGIN
283
284 @interface AVSampleBufferAudioRenderer : NSObject
285 - (NSInteger)status;
286 - (NSError*)error;
287 - (void)enqueueSampleBuffer:(CMSampleBufferRef)sampleBuffer;
288 - (void)flush;
289 - (BOOL)isReadyForMoreMediaData;
290 - (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
291 - (void)stopRequestingMediaData;
292 - (void)setVolume:(float)volume;
293 - (void)setMuted:(BOOL)muted;
294 @property (nonatomic, copy) NSString *audioTimePitchAlgorithm;
295 @end
296
297 NS_ASSUME_NONNULL_END
298
299 #endif // __has_include(<AVFoundation/AVSampleBufferAudioRenderer.h>)
300
301 #if !USE(APPLE_INTERNAL_SDK) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300)
302 @interface AVVideoPerformanceMetrics : NSObject
303 @property (nonatomic, readonly) unsigned long totalNumberOfVideoFrames;
304 @property (nonatomic, readonly) unsigned long numberOfDroppedVideoFrames;
305 @property (nonatomic, readonly) unsigned long numberOfCorruptedVideoFrames;
306 @property (nonatomic, readonly) unsigned long numberOfDisplayCompositedVideoFrames;
307 @property (nonatomic, readonly) double totalFrameDelay;
308 @end
309 #else
310 @interface AVVideoPerformanceMetrics (AVVideoPerformanceMetricsDisplayCompositedVideoFrames)
311 @property (nonatomic, readonly) unsigned long numberOfDisplayCompositedVideoFrames;
312 @end
313 #endif
314
315 #if !USE(APPLE_INTERNAL_SDK) && PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR) && !PLATFORM(IOSMAC)
316 #import <AVFoundation/AVAudioSession.h>
317
318 NS_ASSUME_NONNULL_BEGIN
319
320 @interface AVAudioSession (AVAudioSessionPrivate)
321 @property (readonly) NSString* routingContextUID;
322 @end
323
324 NS_ASSUME_NONNULL_END
325 #endif
326