Skip to content

Commit

Permalink
[video_player_avfoundation] Split iOS native code into multiple files (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
FirentisTFW authored Dec 4, 2024
1 parent 264d920 commit d34f32d
Show file tree
Hide file tree
Showing 11 changed files with 844 additions and 676 deletions.
4 changes: 4 additions & 0 deletions packages/video_player/video_player_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.4

* Refactors native code structure.

## 2.6.3

* Fixes VideoPlayerController.initialize() future never resolving with invalid video file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "./include/video_player_avfoundation/FVPAVFactory.h"

#import <AVFoundation/AVFoundation.h>

@implementation FVPDefaultAVFactory
- (AVPlayer *)playerWithPlayerItem:(AVPlayerItem *)playerItem {
return [AVPlayer playerWithPlayerItem:playerItem];
}

- (AVPlayerItemVideoOutput *)videoOutputWithPixelBufferAttributes:
(NSDictionary<NSString *, id> *)attributes {
return [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:attributes];
}
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "./include/video_player_avfoundation/FVPFrameUpdater.h"

/// FVPFrameUpdater is responsible for notifying the Flutter texture registry
/// when a new video frame is available.
@interface FVPFrameUpdater ()
/// The Flutter texture registry used to notify about new frames.
@property(nonatomic, weak, readonly) NSObject<FlutterTextureRegistry> *registry;
@end

@implementation FVPFrameUpdater
- (FVPFrameUpdater *)initWithRegistry:(NSObject<FlutterTextureRegistry> *)registry {
NSAssert(self, @"super init cannot be nil");
if (self == nil) return nil;
_registry = registry;
_lastKnownAvailableTime = kCMTimeInvalid;
return self;
}

- (void)displayLinkFired {
// Only report a new frame if one is actually available.
CMTime outputItemTime = [self.videoOutput itemTimeForHostTime:CACurrentMediaTime()];
if ([self.videoOutput hasNewPixelBufferForItemTime:outputItemTime]) {
_lastKnownAvailableTime = outputItemTime;
[_registry textureFrameAvailable:_textureId];
}
}
@end
Loading

0 comments on commit d34f32d

Please sign in to comment.