Add support for reporting "display composited video frames" through the VideoPlayback...
[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 !USE(APPLE_INTERNAL_SDK) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300)
164 @interface AVVideoPerformanceMetrics : NSObject
165 @property (nonatomic, readonly) unsigned long totalNumberOfVideoFrames;
166 @property (nonatomic, readonly) unsigned long numberOfDroppedVideoFrames;
167 @property (nonatomic, readonly) unsigned long numberOfCorruptedVideoFrames;
168 @property (nonatomic, readonly) unsigned long numberOfDisplayCompositedVideoFrames;
169 @property (nonatomic, readonly) double totalFrameDelay;
170 @end
171 #endif
172
173 #if PLATFORM(MAC) && !USE(APPLE_INTERNAL_SDK)
174 NS_ASSUME_NONNULL_BEGIN
175 @interface AVStreamDataParser (AVStreamDataParserPrivate)
176 + (NSString *)outputMIMECodecParameterForInputMIMECodecParameter:(NSString *)inputMIMECodecParameter;
177 @end
178 NS_ASSUME_NONNULL_END
179 #endif
180
181 #if PLATFORM(IOS) && (!HAVE(AVKIT) || !USE(APPLE_INTERNAL_SDK))
182 #import <AVFoundation/AVPlayerLayer.h>
183 @interface AVPlayerLayer (AVPlayerLayerPictureInPictureModeSupportPrivate)
184 - (void)setPIPModeEnabled:(BOOL)flag;
185 @end
186 #endif // !HAVE(AVKIT)
187
188 #if !USE(APPLE_INTERNAL_SDK) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101404) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 120200)
189 @class AVVideoPerformanceMetrics;
190 NS_ASSUME_NONNULL_BEGIN
191 @interface AVPlayerLayer (AVPlayerLayerVideoPerformanceMetrics)
192 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
193 @end
194 NS_ASSUME_NONNULL_END
195 #endif
196
197 // FIXME: Wrap in a #if USE(APPLE_INTERNAL_SDK) once these SPI land
198 #import <AVFoundation/AVAsset.h>
199 #import <AVFoundation/AVAssetResourceLoader.h>
200
201 NS_ASSUME_NONNULL_BEGIN
202
203 @interface AVAssetResourceLoader (AVAssetResourceLoaderPrivate)
204 @property (nonatomic, readonly) id<NSURLSessionDataDelegate> URLSessionDataDelegate;
205 @property (nonatomic, readonly) NSOperationQueue *URLSessionDataDelegateQueue;
206 @property (nonatomic, nullable, retain) NSURLSession *URLSession;
207 @end
208
209 @interface AVAsset (AVAssetFragmentsPrivate)
210 @property (nonatomic, readonly) CMTime overallDurationHint;
211 @end
212
213 NS_ASSUME_NONNULL_END
214
215 #import <CoreMedia/CMSampleBuffer.h>
216 #import <CoreMedia/CMSync.h>
217
218 #if __has_include(<AVFoundation/AVSampleBufferRenderSynchronizer.h>)
219 #import <AVFoundation/AVSampleBufferRenderSynchronizer.h>
220
221 NS_ASSUME_NONNULL_BEGIN
222 @interface AVSampleBufferRenderSynchronizer (AVSampleBufferRenderSynchronizerPrivate)
223 - (void)removeRenderer:(id)renderer atTime:(CMTime)time withCompletionHandler:(void (^)(BOOL didRemoveRenderer))completionHandler;
224 @end
225 NS_ASSUME_NONNULL_END
226
227 #else
228
229 NS_ASSUME_NONNULL_BEGIN
230
231 @interface AVSampleBufferRenderSynchronizer : NSObject
232 - (CMTimebaseRef)timebase;
233 - (float)rate;
234 - (void)setRate:(float)rate;
235 - (void)setRate:(float)rate time:(CMTime)time;
236 - (NSArray *)renderers;
237 - (void)addRenderer:(id)renderer;
238 - (void)removeRenderer:(id)renderer atTime:(CMTime)time withCompletionHandler:(void (^)(BOOL didRemoveRenderer))completionHandler;
239 - (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_t)queue usingBlock:(void (^)(CMTime time))block;
240 - (id)addBoundaryTimeObserverForTimes:(NSArray *)times queue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
241 - (void)removeTimeObserver:(id)observer;
242 @end
243
244 NS_ASSUME_NONNULL_END
245
246 #endif // __has_include(<AVFoundation/AVSampleBufferRenderSynchronizer.h>)
247
248 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 110000)) && __has_include(<AVFoundation/AVQueuedSampleBufferRendering.h>)
249 #import <AVFoundation/AVQueuedSampleBufferRendering.h>
250 @class AVVideoPerformanceMetrics;
251 NS_ASSUME_NONNULL_BEGIN
252 @interface AVSampleBufferDisplayLayer (VideoPerformanceMetrics)
253 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
254 @end
255 NS_ASSUME_NONNULL_END
256 #elif __has_include(<AVFoundation/AVSampleBufferDisplayLayer_Private.h>)
257 #import <AVFoundation/AVSampleBufferDisplayLayer_Private.h>
258 #elif __has_include(<AVFoundation/AVSampleBufferDisplayLayer.h>)
259 #import <AVFoundation/AVSampleBufferDisplayLayer.h>
260 NS_ASSUME_NONNULL_BEGIN
261 @interface AVSampleBufferDisplayLayer (VideoPerformanceMetrics)
262 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
263 @end
264 NS_ASSUME_NONNULL_END
265 #else
266
267 NS_ASSUME_NONNULL_BEGIN
268
269 #pragma mark -
270 #pragma mark AVSampleBufferDisplayLayer
271
272 @interface AVSampleBufferDisplayLayer : CALayer
273 - (NSInteger)status;
274 - (NSError*)error;
275 - (void)enqueueSampleBuffer:(CMSampleBufferRef)sampleBuffer;
276 - (void)flush;
277 - (void)flushAndRemoveImage;
278 - (BOOL)isReadyForMoreMediaData;
279 - (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
280 - (void)stopRequestingMediaData;
281 - (AVVideoPerformanceMetrics *)videoPerformanceMetrics;
282 @end
283 NS_ASSUME_NONNULL_END
284 #endif // __has_include(<AVFoundation/AVSampleBufferDisplayLayer.h>)
285
286 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 110000)) && __has_include(<AVFoundation/AVQueuedSampleBufferRendering.h>)
287 // Nothing to do, AVfoundation/AVQueuedSampleBufferRendering.h was imported above.
288 #elif __has_include(<AVFoundation/AVSampleBufferAudioRenderer.h>)
289 #import <AVFoundation/AVSampleBufferAudioRenderer.h>
290 #else
291
292 NS_ASSUME_NONNULL_BEGIN
293
294 @interface AVSampleBufferAudioRenderer : NSObject
295 - (NSInteger)status;
296 - (NSError*)error;
297 - (void)enqueueSampleBuffer:(CMSampleBufferRef)sampleBuffer;
298 - (void)flush;
299 - (BOOL)isReadyForMoreMediaData;
300 - (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
301 - (void)stopRequestingMediaData;
302 - (void)setVolume:(float)volume;
303 - (void)setMuted:(BOOL)muted;
304 @property (nonatomic, copy) NSString *audioTimePitchAlgorithm;
305 @end
306
307 NS_ASSUME_NONNULL_END
308
309 #endif // __has_include(<AVFoundation/AVSampleBufferAudioRenderer.h>)
310
311 #if !USE(APPLE_INTERNAL_SDK) && PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR) && !PLATFORM(IOSMAC)
312 #import <AVFoundation/AVAudioSession.h>
313
314 NS_ASSUME_NONNULL_BEGIN
315
316 @interface AVAudioSession (AVAudioSessionPrivate)
317 @property (readonly) NSString* routingContextUID;
318 @end
319
320 NS_ASSUME_NONNULL_END
321 #endif
322