[iOS] AirPlay device name is sometimes wrong
[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 #else
48
49 #import <AVFoundation/AVPlayer.h>
50 #import <AVFoundation/AVPlayerItem.h>
51
52 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000)
53 NS_ASSUME_NONNULL_BEGIN
54 @interface AVPlayerItem ()
55 @property (nonatomic, readonly) NSTimeInterval seekableTimeRangesLastModifiedTime NS_AVAILABLE(10_13, 11_0);
56 @property (nonatomic, readonly) NSTimeInterval liveUpdateInterval;
57 @end
58 NS_ASSUME_NONNULL_END
59 #endif // (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000)
60
61 #if ENABLE(WIRELESS_PLAYBACK_TARGET) || PLATFORM(IOS)
62
63 NS_ASSUME_NONNULL_BEGIN
64
65 @class AVOutputContext;
66 @class AVOutputDevice;
67 @interface AVOutputContext : NSObject <NSSecureCoding>
68 @property (nonatomic, readonly) NSString *deviceName;
69 + (instancetype)outputContext;
70 + (nullable AVOutputContext *)sharedAudioPresentationOutputContext;
71 @property (readonly) BOOL supportsMultipleOutputDevices;
72 @property (readonly) NSArray<AVOutputDevice *> *outputDevices;
73 @end
74
75 #if !PLATFORM(IOS)
76 @interface AVPlayer (AVPlayerExternalPlaybackSupportPrivate)
77 @property (nonatomic, retain) AVOutputContext *outputContext;
78 @end
79 #else
80 typedef NS_ENUM(NSInteger, AVPlayerExternalPlaybackType) {
81     AVPlayerExternalPlaybackTypeNone,
82     AVPlayerExternalPlaybackTypeAirPlay,
83     AVPlayerExternalPlaybackTypeTVOut,
84 };
85
86 @interface AVPlayer (AVPlayerExternalPlaybackSupportPrivate)
87 @property (nonatomic, readonly) AVPlayerExternalPlaybackType externalPlaybackType;
88 @end
89 #endif
90
91 NS_ASSUME_NONNULL_END
92
93 #endif // ENABLE(WIRELESS_PLAYBACK_TARGET) || PLATFORM(IOS)
94
95 #import <AVFoundation/AVAssetCache.h>
96 NS_ASSUME_NONNULL_BEGIN
97 @interface AVAssetCache ()
98 + (AVAssetCache *)assetCacheWithURL:(NSURL *)URL;
99 - (id)initWithURL:(NSURL *)URL;
100 - (NSArray *)allKeys;
101 - (NSDate *)lastModifiedDateOfEntryForKey:(NSString *)key;
102 - (void)removeEntryForKey:(NSString *)key;
103 @property (nonatomic, readonly, copy) NSURL *URL;
104 @end
105 NS_ASSUME_NONNULL_END
106
107 #if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
108 @interface AVPlayer (AVPlayerVideoSleepPrevention)
109 @property (nonatomic, getter=_preventsSleepDuringVideoPlayback, setter=_setPreventsSleepDuringVideoPlayback:) BOOL preventsSleepDuringVideoPlayback;
110 @end
111
112 #endif // PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
113
114 #if !PLATFORM(IOS)
115
116 #pragma mark -
117 #pragma mark AVStreamDataParser
118
119 @protocol AVStreamDataParserOutputHandling <NSObject>
120 @end
121
122 typedef int32_t CMPersistentTrackID;
123
124 NS_ASSUME_NONNULL_BEGIN
125 typedef NS_ENUM(NSUInteger, AVStreamDataParserOutputMediaDataFlags) {
126     AVStreamDataParserOutputMediaDataReserved = 1 << 0
127 };
128
129 typedef NS_ENUM(NSUInteger, AVStreamDataParserStreamDataFlags) {
130     AVStreamDataParserStreamDataDiscontinuity = 1 << 0,
131 };
132
133 @interface AVStreamDataParser : NSObject
134 - (void)setDelegate:(nullable id<AVStreamDataParserOutputHandling>)delegate;
135 - (void)appendStreamData:(NSData *)data;
136 - (void)appendStreamData:(NSData *)data withFlags:(AVStreamDataParserStreamDataFlags)flags;
137 - (void)setShouldProvideMediaData:(BOOL)shouldProvideMediaData forTrackID:(CMPersistentTrackID)trackID;
138 - (BOOL)shouldProvideMediaDataForTrackID:(CMPersistentTrackID)trackID;
139 - (void)providePendingMediaData;
140 - (void)processContentKeyResponseData:(NSData *)contentKeyResponseData forTrackID:(CMPersistentTrackID)trackID;
141 - (void)processContentKeyResponseError:(NSError *)error forTrackID:(CMPersistentTrackID)trackID;
142 - (void)renewExpiringContentKeyResponseDataForTrackID:(CMPersistentTrackID)trackID;
143 - (NSData *)streamingContentKeyRequestDataForApp:(NSData *)appIdentifier contentIdentifier:(NSData *)contentIdentifier trackID:(CMPersistentTrackID)trackID options:(NSDictionary *)options error:(NSError **)outError;
144 @end
145
146 NS_ASSUME_NONNULL_END
147
148 #if HAVE(AVCONTENTKEYSESSION)
149 #import <AVFoundation/AVContentKeySession.h>
150 @interface AVStreamDataParser () <AVContentKeyRecipient>
151 @end
152 #endif
153
154 #endif // !PLATFORM(IOS)
155 #endif // USE(APPLE_INTERNAL_SDK)
156
157 #if PLATFORM(MAC) && !USE(APPLE_INTERNAL_SDK)
158 NS_ASSUME_NONNULL_BEGIN
159 @interface AVStreamDataParser (AVStreamDataParserPrivate)
160 + (NSString *)outputMIMECodecParameterForInputMIMECodecParameter:(NSString *)inputMIMECodecParameter;
161 @end
162 NS_ASSUME_NONNULL_END
163 #endif
164
165 #if PLATFORM(IOS) && (!HAVE(AVKIT) || !USE(APPLE_INTERNAL_SDK))
166 #import <AVFoundation/AVPlayerLayer.h>
167 @interface AVPlayerLayer (AVPlayerLayerPictureInPictureModeSupportPrivate)
168 - (void)setPIPModeEnabled:(BOOL)flag;
169 @end
170 #endif // !HAVE(AVKIT)
171
172
173 // FIXME: Wrap in a #if USE(APPLE_INTERNAL_SDK) once these SPI land
174 #import <AVFoundation/AVAsset.h>
175 #import <AVFoundation/AVAssetResourceLoader.h>
176
177 NS_ASSUME_NONNULL_BEGIN
178
179 @interface AVAssetResourceLoader (AVAssetResourceLoaderPrivate)
180 @property (nonatomic, readonly) id<NSURLSessionDataDelegate> URLSessionDataDelegate;
181 @property (nonatomic, readonly) NSOperationQueue *URLSessionDataDelegateQueue;
182 @property (nonatomic, nullable, retain) NSURLSession *URLSession;
183 @end
184
185 @interface AVAsset (AVAssetFragmentsPrivate)
186 @property (nonatomic, readonly) CMTime overallDurationHint;
187 @end
188
189 NS_ASSUME_NONNULL_END
190
191 #import <CoreMedia/CMSampleBuffer.h>
192 #import <CoreMedia/CMSync.h>
193
194 #if __has_include(<AVFoundation/AVSampleBufferRenderSynchronizer.h>)
195 #import <AVFoundation/AVSampleBufferRenderSynchronizer.h>
196
197 NS_ASSUME_NONNULL_BEGIN
198 @interface AVSampleBufferRenderSynchronizer (AVSampleBufferRenderSynchronizerPrivate)
199 - (void)removeRenderer:(id)renderer atTime:(CMTime)time withCompletionHandler:(void (^)(BOOL didRemoveRenderer))completionHandler;
200 @end
201 NS_ASSUME_NONNULL_END
202
203 #else
204
205 NS_ASSUME_NONNULL_BEGIN
206
207 @interface AVSampleBufferRenderSynchronizer : NSObject
208 - (CMTimebaseRef)timebase;
209 - (float)rate;
210 - (void)setRate:(float)rate;
211 - (void)setRate:(float)rate time:(CMTime)time;
212 - (NSArray *)renderers;
213 - (void)addRenderer:(id)renderer;
214 - (void)removeRenderer:(id)renderer atTime:(CMTime)time withCompletionHandler:(void (^)(BOOL didRemoveRenderer))completionHandler;
215 - (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_t)queue usingBlock:(void (^)(CMTime time))block;
216 - (id)addBoundaryTimeObserverForTimes:(NSArray *)times queue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
217 - (void)removeTimeObserver:(id)observer;
218 @end
219
220 NS_ASSUME_NONNULL_END
221
222 #endif // __has_include(<AVFoundation/AVSampleBufferRenderSynchronizer.h>)
223
224 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 110000)) && __has_include(<AVFoundation/AVQueuedSampleBufferRendering.h>)
225 #import <AVFoundation/AVQueuedSampleBufferRendering.h>
226 #elif __has_include(<AVFoundation/AVSampleBufferDisplayLayer.h>)
227 #import <AVFoundation/AVSampleBufferDisplayLayer.h>
228 #else
229
230 NS_ASSUME_NONNULL_BEGIN
231
232 #pragma mark -
233 #pragma mark AVSampleBufferDisplayLayer
234
235 @interface AVSampleBufferDisplayLayer : CALayer
236 - (NSInteger)status;
237 - (NSError*)error;
238 - (void)enqueueSampleBuffer:(CMSampleBufferRef)sampleBuffer;
239 - (void)flush;
240 - (void)flushAndRemoveImage;
241 - (BOOL)isReadyForMoreMediaData;
242 - (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
243 - (void)stopRequestingMediaData;
244 @end
245
246 NS_ASSUME_NONNULL_END
247
248 #endif // __has_include(<AVFoundation/AVSampleBufferDisplayLayer.h>)
249
250 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED < 110000)) && __has_include(<AVFoundation/AVQueuedSampleBufferRendering.h>)
251 // Nothing to do, AVfoundation/AVQueuedSampleBufferRendering.h was imported above.
252 #elif __has_include(<AVFoundation/AVSampleBufferAudioRenderer.h>)
253 #import <AVFoundation/AVSampleBufferAudioRenderer.h>
254 #else
255
256 NS_ASSUME_NONNULL_BEGIN
257
258 @interface AVSampleBufferAudioRenderer : NSObject
259 - (NSInteger)status;
260 - (NSError*)error;
261 - (void)enqueueSampleBuffer:(CMSampleBufferRef)sampleBuffer;
262 - (void)flush;
263 - (BOOL)isReadyForMoreMediaData;
264 - (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;
265 - (void)stopRequestingMediaData;
266 - (void)setVolume:(float)volume;
267 - (void)setMuted:(BOOL)muted;
268 @property (nonatomic, copy) NSString *audioTimePitchAlgorithm;
269 @end
270
271 NS_ASSUME_NONNULL_END
272
273 #endif // __has_include(<AVFoundation/AVSampleBufferAudioRenderer.h>)