Skip to content

Commit d34f32d

Browse files
authored
[video_player_avfoundation] Split iOS native code into multiple files (#8171)
This PR splits iOS native code into multiple files. Specifically, it extracts `FVPVideoPlayer` and `FVPFrameUpdater` from `FVPVideoPlayerPlugin.m` file, and puts them into separate files (.h and .m). This should make it easier to maintain the code and add new features in the future (e.g. support for platform views which is mentioned in [86613](flutter/flutter#86613). In order for the code to compile, I had to add some methods to the interface of `FVPVideoPlayer`. I also added doc comments for them. No tests were added as this PR does not introduce any new functionality. Related issues: - [86613](flutter/flutter#86613) This PR does not fix the issue, it only refactors some parts of the code, so that it is easier in the future to add support for platform views (the git diff will be cleaner when we modify the code to support it - only related changes would show up then). If you'd like me to create a new issue, specifically for splitting the native code into files, let me know.
1 parent 264d920 commit d34f32d

File tree

11 files changed

+844
-676
lines changed

11 files changed

+844
-676
lines changed

packages/video_player/video_player_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.6.4
2+
3+
* Refactors native code structure.
4+
15
## 2.6.3
26

37
* Fixes VideoPlayerController.initialize() future never resolving with invalid video file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "./include/video_player_avfoundation/FVPAVFactory.h"
6+
7+
#import <AVFoundation/AVFoundation.h>
8+
9+
@implementation FVPDefaultAVFactory
10+
- (AVPlayer *)playerWithPlayerItem:(AVPlayerItem *)playerItem {
11+
return [AVPlayer playerWithPlayerItem:playerItem];
12+
}
13+
14+
- (AVPlayerItemVideoOutput *)videoOutputWithPixelBufferAttributes:
15+
(NSDictionary<NSString *, id> *)attributes {
16+
return [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:attributes];
17+
}
18+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "./include/video_player_avfoundation/FVPFrameUpdater.h"
6+
7+
/// FVPFrameUpdater is responsible for notifying the Flutter texture registry
8+
/// when a new video frame is available.
9+
@interface FVPFrameUpdater ()
10+
/// The Flutter texture registry used to notify about new frames.
11+
@property(nonatomic, weak, readonly) NSObject<FlutterTextureRegistry> *registry;
12+
@end
13+
14+
@implementation FVPFrameUpdater
15+
- (FVPFrameUpdater *)initWithRegistry:(NSObject<FlutterTextureRegistry> *)registry {
16+
NSAssert(self, @"super init cannot be nil");
17+
if (self == nil) return nil;
18+
_registry = registry;
19+
_lastKnownAvailableTime = kCMTimeInvalid;
20+
return self;
21+
}
22+
23+
- (void)displayLinkFired {
24+
// Only report a new frame if one is actually available.
25+
CMTime outputItemTime = [self.videoOutput itemTimeForHostTime:CACurrentMediaTime()];
26+
if ([self.videoOutput hasNewPixelBufferForItemTime:outputItemTime]) {
27+
_lastKnownAvailableTime = outputItemTime;
28+
[_registry textureFrameAvailable:_textureId];
29+
}
30+
}
31+
@end

0 commit comments

Comments
 (0)