22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- #import " FLTVideoPlayerPlugin .h"
6- #import " FLTVideoPlayerPlugin_Test .h"
5+ #import " FVPVideoPlayerPlugin .h"
6+ #import " FVPVideoPlayerPlugin_Test .h"
77
88#import < AVFoundation/AVFoundation.h>
99#import < GLKit/GLKit.h>
1515#error Code Requires ARC.
1616#endif
1717
18- @interface FLTFrameUpdater : NSObject
18+ @interface FVPFrameUpdater : NSObject
1919@property (nonatomic ) int64_t textureId;
2020@property (nonatomic , weak , readonly ) NSObject <FlutterTextureRegistry> *registry;
2121- (void )onDisplayLink : (CADisplayLink *)link ;
2222@end
2323
24- @implementation FLTFrameUpdater
25- - (FLTFrameUpdater *)initWithRegistry : (NSObject <FlutterTextureRegistry> *)registry {
24+ @implementation FVPFrameUpdater
25+ - (FVPFrameUpdater *)initWithRegistry : (NSObject <FlutterTextureRegistry> *)registry {
2626 NSAssert (self, @" super init cannot be nil" );
2727 if (self == nil ) return nil ;
2828 _registry = registry;
@@ -44,7 +44,7 @@ - (AVPlayer *)playerWithPlayerItem:(AVPlayerItem *)playerItem {
4444
4545@end
4646
47- @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
47+ @interface FVPVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
4848@property (readonly , nonatomic ) AVPlayer *player;
4949@property (readonly , nonatomic ) AVPlayerItemVideoOutput *videoOutput;
5050// This is to fix 2 bugs: 1. blank video for encrypted video streams on iOS 16
@@ -62,7 +62,7 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
6262@property (nonatomic ) BOOL isLooping;
6363@property (nonatomic , readonly ) BOOL isInitialized;
6464- (instancetype )initWithURL : (NSURL *)url
65- frameUpdater : (FLTFrameUpdater *)frameUpdater
65+ frameUpdater : (FVPFrameUpdater *)frameUpdater
6666 httpHeaders : (nonnull NSDictionary <NSString *, NSString *> *)headers
6767 playerFactory : (id <FVPPlayerFactory>)playerFactory ;
6868@end
@@ -74,9 +74,9 @@ - (instancetype)initWithURL:(NSURL *)url
7474static void *playbackLikelyToKeepUpContext = &playbackLikelyToKeepUpContext;
7575static void *rateContext = &rateContext;
7676
77- @implementation FLTVideoPlayer
77+ @implementation FVPVideoPlayer
7878- (instancetype )initWithAsset : (NSString *)asset
79- frameUpdater : (FLTFrameUpdater *)frameUpdater
79+ frameUpdater : (FVPFrameUpdater *)frameUpdater
8080 playerFactory : (id <FVPPlayerFactory>)playerFactory {
8181 NSString *path = [[NSBundle mainBundle ] pathForResource: asset ofType: nil ];
8282 return [self initWithURL: [NSURL fileURLWithPath: path]
@@ -134,7 +134,7 @@ - (void)itemDidPlayToEndTime:(NSNotification *)notification {
134134
135135const int64_t TIME_UNSET = -9223372036854775807 ;
136136
137- NS_INLINE int64_t FLTCMTimeToMillis (CMTime time) {
137+ NS_INLINE int64_t FVPCMTimeToMillis (CMTime time) {
138138 // When CMTIME_IS_INDEFINITE return a value that matches TIME_UNSET from ExoPlayer2 on Android.
139139 // Fixes https://github.com/flutter/flutter/issues/48670
140140 if (CMTIME_IS_INDEFINITE (time)) return TIME_UNSET;
@@ -195,7 +195,7 @@ - (AVMutableVideoComposition *)getVideoCompositionWithTransform:(CGAffineTransfo
195195 return videoComposition;
196196}
197197
198- - (void )createVideoOutputAndDisplayLink : (FLTFrameUpdater *)frameUpdater {
198+ - (void )createVideoOutputAndDisplayLink : (FVPFrameUpdater *)frameUpdater {
199199 NSDictionary *pixBuffAttributes = @{
200200 (id )kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA ),
201201 (id )kCVPixelBufferIOSurfacePropertiesKey : @{}
@@ -209,7 +209,7 @@ - (void)createVideoOutputAndDisplayLink:(FLTFrameUpdater *)frameUpdater {
209209}
210210
211211- (instancetype )initWithURL : (NSURL *)url
212- frameUpdater : (FLTFrameUpdater *)frameUpdater
212+ frameUpdater : (FVPFrameUpdater *)frameUpdater
213213 httpHeaders : (nonnull NSDictionary <NSString *, NSString *> *)headers
214214 playerFactory : (id <FVPPlayerFactory>)playerFactory {
215215 NSDictionary <NSString *, id > *options = nil ;
@@ -222,7 +222,7 @@ - (instancetype)initWithURL:(NSURL *)url
222222}
223223
224224- (instancetype )initWithPlayerItem : (AVPlayerItem *)item
225- frameUpdater : (FLTFrameUpdater *)frameUpdater
225+ frameUpdater : (FVPFrameUpdater *)frameUpdater
226226 playerFactory : (id <FVPPlayerFactory>)playerFactory {
227227 self = [super init ];
228228 NSAssert (self, @" super init cannot be nil" );
@@ -238,7 +238,7 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem *)item
238238 if ([videoTrack statusOfValueForKey: @" preferredTransform"
239239 error: nil ] == AVKeyValueStatusLoaded) {
240240 // Rotate the video by using a videoComposition and the preferredTransform
241- self->_preferredTransform = FLTGetStandardizedTransformForTrack (videoTrack);
241+ self->_preferredTransform = FVPGetStandardizedTransformForTrack (videoTrack);
242242 // Note:
243243 // https://developer.apple.com/documentation/avfoundation/avplayeritem/1388818-videocomposition
244244 // Video composition can only be used with file-based media and is not supported for
@@ -285,8 +285,8 @@ - (void)observeValueForKeyPath:(NSString *)path
285285 NSMutableArray <NSArray <NSNumber *> *> *values = [[NSMutableArray alloc ] init ];
286286 for (NSValue *rangeValue in [object loadedTimeRanges ]) {
287287 CMTimeRange range = [rangeValue CMTimeRangeValue ];
288- int64_t start = FLTCMTimeToMillis (range.start );
289- [values addObject: @[ @(start), @(start + FLTCMTimeToMillis (range.duration)) ]];
288+ int64_t start = FVPCMTimeToMillis (range.start );
289+ [values addObject: @[ @(start), @(start + FVPCMTimeToMillis (range.duration)) ]];
290290 }
291291 _eventSink (@{@" event" : @" bufferingUpdate" , @" values" : values});
292292 }
@@ -414,14 +414,14 @@ - (void)pause {
414414}
415415
416416- (int64_t )position {
417- return FLTCMTimeToMillis ([_player currentTime ]);
417+ return FVPCMTimeToMillis ([_player currentTime ]);
418418}
419419
420420- (int64_t )duration {
421421 // Note: https://openradar.appspot.com/radar?id=4968600712511488
422422 // `[AVPlayerItem duration]` can be `kCMTimeIndefinite`,
423423 // use `[[AVPlayerItem asset] duration]` instead.
424- return FLTCMTimeToMillis ([[[_player currentItem ] asset ] duration ]);
424+ return FVPCMTimeToMillis ([[[_player currentItem ] asset ] duration ]);
425425}
426426
427427- (void )seekTo : (int )location completionHandler : (void (^)(BOOL ))completionHandler {
@@ -507,8 +507,8 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments
507507- (void )disposeSansEventChannel {
508508 // This check prevents the crash caused by removing the KVO observers twice.
509509 // When performing a Hot Restart, the leftover players are disposed once directly
510- // by [FLTVideoPlayerPlugin initialize:] method and then disposed again by
511- // [FLTVideoPlayer onTextureUnregistered:] call leading to possible over-release.
510+ // by [FVPVideoPlayerPlugin initialize:] method and then disposed again by
511+ // [FVPVideoPlayer onTextureUnregistered:] call leading to possible over-release.
512512 if (_disposed) {
513513 return ;
514514 }
@@ -535,20 +535,20 @@ - (void)dispose {
535535
536536@end
537537
538- @interface FLTVideoPlayerPlugin () <FLTAVFoundationVideoPlayerApi >
538+ @interface FVPVideoPlayerPlugin () <FVPAVFoundationVideoPlayerApi >
539539@property (readonly , weak , nonatomic ) NSObject <FlutterTextureRegistry> *registry;
540540@property (readonly , weak , nonatomic ) NSObject <FlutterBinaryMessenger> *messenger;
541541@property (readonly , strong , nonatomic )
542- NSMutableDictionary <NSNumber *, FLTVideoPlayer *> *playersByTextureId;
542+ NSMutableDictionary <NSNumber *, FVPVideoPlayer *> *playersByTextureId;
543543@property (readonly , strong , nonatomic ) NSObject <FlutterPluginRegistrar> *registrar;
544544@property (nonatomic , strong ) id <FVPPlayerFactory> playerFactory;
545545@end
546546
547- @implementation FLTVideoPlayerPlugin
547+ @implementation FVPVideoPlayerPlugin
548548+ (void )registerWithRegistrar : (NSObject <FlutterPluginRegistrar> *)registrar {
549- FLTVideoPlayerPlugin *instance = [[FLTVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
549+ FVPVideoPlayerPlugin *instance = [[FVPVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
550550 [registrar publish: instance];
551- FLTAVFoundationVideoPlayerApiSetup (registrar.messenger , instance);
551+ FVPAVFoundationVideoPlayerApiSetup (registrar.messenger , instance);
552552}
553553
554554- (instancetype )initWithRegistrar : (NSObject <FlutterPluginRegistrar> *)registrar {
@@ -573,11 +573,11 @@ - (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar> *)registr
573573 // TODO(57151): This should be commented out when 57151's fix lands on stable.
574574 // This is the correct behavior we never did it in the past and the engine
575575 // doesn't currently support it.
576- // FLTAVFoundationVideoPlayerApiSetup (registrar.messenger, nil);
576+ // FVPAVFoundationVideoPlayerApiSetup (registrar.messenger, nil);
577577}
578578
579- - (FLTTextureMessage *)onPlayerSetup : (FLTVideoPlayer *)player
580- frameUpdater : (FLTFrameUpdater *)frameUpdater {
579+ - (FVPTextureMessage *)onPlayerSetup : (FVPVideoPlayer *)player
580+ frameUpdater : (FVPFrameUpdater *)frameUpdater {
581581 int64_t textureId = [self .registry registerTexture: player];
582582 frameUpdater.textureId = textureId;
583583 FlutterEventChannel *eventChannel = [FlutterEventChannel
@@ -587,7 +587,7 @@ - (FLTTextureMessage *)onPlayerSetup:(FLTVideoPlayer *)player
587587 [eventChannel setStreamHandler: player];
588588 player.eventChannel = eventChannel;
589589 self.playersByTextureId [@(textureId)] = player;
590- FLTTextureMessage *result = [FLTTextureMessage makeWithTextureId: @(textureId)];
590+ FVPTextureMessage *result = [FVPTextureMessage makeWithTextureId: @(textureId)];
591591 return result;
592592}
593593
@@ -596,16 +596,16 @@ - (void)initialize:(FlutterError *__autoreleasing *)error {
596596 [[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryPlayback error: nil ];
597597
598598 [self .playersByTextureId
599- enumerateKeysAndObjectsUsingBlock: ^(NSNumber *textureId, FLTVideoPlayer *player, BOOL *stop) {
599+ enumerateKeysAndObjectsUsingBlock: ^(NSNumber *textureId, FVPVideoPlayer *player, BOOL *stop) {
600600 [self .registry unregisterTexture: textureId.unsignedIntegerValue];
601601 [player dispose ];
602602 }];
603603 [self .playersByTextureId removeAllObjects ];
604604}
605605
606- - (FLTTextureMessage *)create : (FLTCreateMessage *)input error : (FlutterError **)error {
607- FLTFrameUpdater *frameUpdater = [[FLTFrameUpdater alloc ] initWithRegistry: _registry];
608- FLTVideoPlayer *player;
606+ - (FVPTextureMessage *)create : (FVPCreateMessage *)input error : (FlutterError **)error {
607+ FVPFrameUpdater *frameUpdater = [[FVPFrameUpdater alloc ] initWithRegistry: _registry];
608+ FVPVideoPlayer *player;
609609 if (input.asset ) {
610610 NSString *assetPath;
611611 if (input.packageName ) {
@@ -614,7 +614,7 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
614614 assetPath = [_registrar lookupKeyForAsset: input.asset];
615615 }
616616 @try {
617- player = [[FLTVideoPlayer alloc ] initWithAsset: assetPath
617+ player = [[FVPVideoPlayer alloc ] initWithAsset: assetPath
618618 frameUpdater: frameUpdater
619619 playerFactory: _playerFactory];
620620 return [self onPlayerSetup: player frameUpdater: frameUpdater];
@@ -623,7 +623,7 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
623623 return nil ;
624624 }
625625 } else if (input.uri ) {
626- player = [[FLTVideoPlayer alloc ] initWithURL: [NSURL URLWithString: input.uri]
626+ player = [[FVPVideoPlayer alloc ] initWithURL: [NSURL URLWithString: input.uri]
627627 frameUpdater: frameUpdater
628628 httpHeaders: input.httpHeaders
629629 playerFactory: _playerFactory];
@@ -634,8 +634,8 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
634634 }
635635}
636636
637- - (void )dispose : (FLTTextureMessage *)input error : (FlutterError **)error {
638- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
637+ - (void )dispose : (FVPTextureMessage *)input error : (FlutterError **)error {
638+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
639639 [self .registry unregisterTexture: input.textureId.intValue];
640640 [self .playersByTextureId removeObjectForKey: input.textureId];
641641 // If the Flutter contains https://github.com/flutter/engine/pull/12695,
@@ -656,36 +656,36 @@ - (void)dispose:(FLTTextureMessage *)input error:(FlutterError **)error {
656656 });
657657}
658658
659- - (void )setLooping : (FLTLoopingMessage *)input error : (FlutterError **)error {
660- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
659+ - (void )setLooping : (FVPLoopingMessage *)input error : (FlutterError **)error {
660+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
661661 player.isLooping = input.isLooping .boolValue ;
662662}
663663
664- - (void )setVolume : (FLTVolumeMessage *)input error : (FlutterError **)error {
665- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
664+ - (void )setVolume : (FVPVolumeMessage *)input error : (FlutterError **)error {
665+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
666666 [player setVolume: input.volume.doubleValue];
667667}
668668
669- - (void )setPlaybackSpeed : (FLTPlaybackSpeedMessage *)input error : (FlutterError **)error {
670- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
669+ - (void )setPlaybackSpeed : (FVPPlaybackSpeedMessage *)input error : (FlutterError **)error {
670+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
671671 [player setPlaybackSpeed: input.speed.doubleValue];
672672}
673673
674- - (void )play : (FLTTextureMessage *)input error : (FlutterError **)error {
675- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
674+ - (void )play : (FVPTextureMessage *)input error : (FlutterError **)error {
675+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
676676 [player play ];
677677}
678678
679- - (FLTPositionMessage *)position : (FLTTextureMessage *)input error : (FlutterError **)error {
680- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
681- FLTPositionMessage *result = [FLTPositionMessage makeWithTextureId: input.textureId
679+ - (FVPPositionMessage *)position : (FVPTextureMessage *)input error : (FlutterError **)error {
680+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
681+ FVPPositionMessage *result = [FVPPositionMessage makeWithTextureId: input.textureId
682682 position: @([player position ])];
683683 return result;
684684}
685685
686- - (void )seekTo : (FLTPositionMessage *)input
686+ - (void )seekTo : (FVPPositionMessage *)input
687687 completion : (void (^)(FlutterError *_Nullable))completion {
688- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
688+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
689689 [player seekTo: input.position.intValue
690690 completionHandler: ^(BOOL finished) {
691691 dispatch_async (dispatch_get_main_queue (), ^{
@@ -695,12 +695,12 @@ - (void)seekTo:(FLTPositionMessage *)input
695695 }];
696696}
697697
698- - (void )pause : (FLTTextureMessage *)input error : (FlutterError **)error {
699- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
698+ - (void )pause : (FVPTextureMessage *)input error : (FlutterError **)error {
699+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
700700 [player pause ];
701701}
702702
703- - (void )setMixWithOthers : (FLTMixWithOthersMessage *)input
703+ - (void )setMixWithOthers : (FVPMixWithOthersMessage *)input
704704 error : (FlutterError *_Nullable __autoreleasing *)error {
705705 if (input.mixWithOthers .boolValue ) {
706706 [[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryPlayback
0 commit comments