Merge pull request #1360 from nickgzzjr/master

Only apply filter if filter is set
This commit is contained in:
Hampton Maxwell 2018-12-12 22:23:06 -08:00 committed by GitHub
commit e5bada9fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1268,39 +1268,29 @@ static int const RCTVideoUnset = -1;
}
- (void)setFilter:(NSString *)filterName {
_filterName = filterName;
AVAsset *asset = _playerItem.asset;
if (asset != nil) {
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];
}
}];
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
@ -1463,4 +1453,4 @@ static int const RCTVideoUnset = -1;
return array[0];
}
@end
@end