Skip to content

Commit

Permalink
Merge pull request #126 from vimeo/vim-2754
Browse files Browse the repository at this point in the history
Vim 2754
  • Loading branch information
alfiehanssen committed Aug 31, 2015
2 parents 387d670 + 773a6d6 commit da41043
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions VIMNetworking/Model/VIMVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ typedef NS_ENUM(NSUInteger, VIMVideoProcessingStatus) {

- (nullable VIMVideoFile *)hlsFileForScreenSize:(CGSize)size;
- (nullable VIMVideoFile *)mp4FileForScreenSize:(CGSize)size;
- (nullable VIMVideoFile *)fallbackFileForFile:(nonnull VIMVideoFile *)file screenSize:(CGSize)size;

@end
40 changes: 35 additions & 5 deletions VIMNetworking/Model/VIMVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,39 @@ - (VIMVideoFile *)mp4FileForScreenSize:(CGSize)size
return [self fileForPredicate:predicate screenSize:size];
}

- (nullable VIMVideoFile *)fallbackFileForFile:(VIMVideoFile *)file screenSize:(CGSize)size
{
if (!file)
{
return nil;
}

NSPredicate *predicate = nil;

if ([file.quality isEqualToString:VIMVideoFileQualityHLS])
{
// There will only ever be one HSL file so we choose !HLS [AH] 8/31/2015
predicate = [NSPredicate predicateWithFormat:@"SELF.quality != %@", VIMVideoFileQualityHLS];
}
else
{
if (!file.width ||
!file.height ||
[file.width isEqual:[NSNull null]] ||
[file.height isEqual:[NSNull null]] ||
[file.width isEqual:@(0)] ||
[file.height isEqual:@(0)])
{
return nil;
}

// And we want to exclude the file we're falling back from [AH] 8/31/2015
predicate = [NSPredicate predicateWithFormat:@"SELF.quality != %@ && SELF.width.integerValue < %i", VIMVideoFileQualityHLS, file.width.integerValue];
}

return [self fileForPredicate:predicate screenSize:size];
}

- (VIMVideoFile *)fileForPredicate:(NSPredicate *)predicate screenSize:(CGSize)size
{
if (CGSizeEqualToSize(size, CGSizeZero) || predicate == nil)
Expand All @@ -462,12 +495,8 @@ - (VIMVideoFile *)fileForPredicate:(NSPredicate *)predicate screenSize:(CGSize)s
// TODO: augment this to handle portrait videos [AH]
NSInteger targetScreenWidth = MAX(size.width, size.height);

// NSLog(@"SELECTING VIDEO FILE FOR SIZE: %@", NSStringFromCGSize(size));

for (VIMVideoFile *currentFile in sortedFiles)
{
// NSLog(@"option: (%@, %@)", currentFile.width, currentFile.height);

if ([currentFile isSupportedMimeType] && currentFile.link)
{
// We dont yet have a file, grab the largest one (based on sort order above)
Expand All @@ -479,6 +508,7 @@ - (VIMVideoFile *)fileForPredicate:(NSPredicate *)predicate screenSize:(CGSize)s
}

// We dont have the info with which to compare the files
// TODO: is this a problem? HLS files report width/height of 0,0 [AH] 8/31/2015
if ((file.width == nil || currentFile.width == nil ||
[file.width isEqual:[NSNull null]] || [currentFile.width isEqual:[NSNull null]] ||
[file.width isEqual:@(0)] || [currentFile.width isEqual:@(0)]))
Expand All @@ -493,7 +523,7 @@ - (VIMVideoFile *)fileForPredicate:(NSPredicate *)predicate screenSize:(CGSize)s
}
}

// NSLog(@"selected: (%@, %@)", file.width, file.height);
// NSLog(@"selected (%@, %@) for screensize (%@) out of %lu choices with format %@", file.width, file.height, NSStringFromCGSize(size), (unsigned long)[sortedFiles count], predicate.predicateFormat);

return file;
}
Expand Down

0 comments on commit da41043

Please sign in to comment.