From 97ac68745b455fbc381bce09bb9e256e0e0c69e5 Mon Sep 17 00:00:00 2001 From: Nicolas Gonzalez Date: Sat, 1 Dec 2018 21:58:12 -0600 Subject: [PATCH 1/2] only apply filter if filter is set --- ios/Video/RCTVideo.m | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index a56b08a2aa..741ac6719e 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -1274,27 +1274,23 @@ - (void)setFilter:(NSString *)filterName { CIFilter *filter = [CIFilter filterWithName:filterName]; - _playerItem.videoComposition = [AVVideoComposition - videoCompositionWithAsset:asset - applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest *_Nonnull request) { + if (filter != nil) { - if (filter == nil) { + _playerItem.videoComposition = [AVVideoComposition + videoCompositionWithAsset:asset + applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest *_Nonnull request) { - [request finishWithImage:request.sourceImage context:nil]; + CIImage *image = request.sourceImage.imageByClampingToExtent; - } else { + [filter setValue:image forKey:kCIInputImageKey]; - CIImage *image = request.sourceImage.imageByClampingToExtent; + CIImage *output = [filter.outputImage imageByCroppingToRect:request.sourceImage.extent]; - [filter setValue:image forKey:kCIInputImageKey]; + [request finishWithImage:output context:nil]; - CIImage *output = [filter.outputImage imageByCroppingToRect:request.sourceImage.extent]; - [request finishWithImage:output context:nil]; - - } - - }]; + }]; + } } From a4a0c8ad17b4315c72f5bfb6ced44d7faedc2742 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Wed, 12 Dec 2018 22:21:19 -0800 Subject: [PATCH 2/2] Refactor setFilter code --- ios/Video/RCTVideo.m | 48 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 741ac6719e..5c2477950c 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -1265,35 +1265,29 @@ - (void)videoPlayerViewControllerDidDismiss:(AVPlayerViewController *)playerView } - (void)setFilter:(NSString *)filterName { - _filterName = filterName; - AVAsset *asset = _playerItem.asset; - - if (asset != nil) { - - CIFilter *filter = [CIFilter filterWithName:filterName]; - - if (filter != nil) { - - _playerItem.videoComposition = [AVVideoComposition - videoCompositionWithAsset:asset - applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest *_Nonnull request) { - - CIImage *image = request.sourceImage.imageByClampingToExtent; - - [filter setValue:image forKey:kCIInputImageKey]; - - CIImage *output = [filter.outputImage imageByCroppingToRect:request.sourceImage.extent]; - - [request finishWithImage:output context:nil]; - - - }]; - } - + + if (!asset) { + return; + } else if (!_playerItem.videoComposition && (filterName == nil || [filterName isEqualToString:@""])) { + return; // Setting up an empty filter has a cost so avoid whenever possible } - + // TODO: filters don't work for HLS, check & return + + CIFilter *filter = [CIFilter filterWithName:filterName]; + _playerItem.videoComposition = [AVVideoComposition + videoCompositionWithAsset:asset + applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest *_Nonnull request) { + if (filter == nil) { + [request finishWithImage:request.sourceImage context:nil]; + } else { + CIImage *image = request.sourceImage.imageByClampingToExtent; + [filter setValue:image forKey:kCIInputImageKey]; + CIImage *output = [filter.outputImage imageByCroppingToRect:request.sourceImage.extent]; + [request finishWithImage:output context:nil]; + } + }]; } #pragma mark - React View Management @@ -1456,4 +1450,4 @@ - (NSString *)cacheDirectoryPath { return array[0]; } -@end \ No newline at end of file +@end