Commit da93fe25 authored by Felix Paul Kühne's avatar Felix Paul Kühne

VLCMedia: added a new API to determine whether the media size is supposedly...

VLCMedia: added a new API to determine whether the media size is supposedly suitable for the current device or not
parent 64af03c6
...@@ -236,6 +236,11 @@ typedef enum VLCMediaState ...@@ -236,6 +236,11 @@ typedef enum VLCMediaState
*/ */
@property (readonly) VLCMediaState state; @property (readonly) VLCMediaState state;
/**
* returns a bool whether is the media is expected to play fluently on this
* device or not. It always returns YES on a Mac.*/
- (BOOL)isMediaSizeSuitableForDevice;
/** /**
* Tracks information NSDictionary Possible Keys * Tracks information NSDictionary Possible Keys
*/ */
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#import "VLCLibrary.h" #import "VLCLibrary.h"
#import "VLCLibVLCBridging.h" #import "VLCLibVLCBridging.h"
#import <vlc/libvlc.h> #import <vlc/libvlc.h>
#import <sys/sysctl.h> // for sysctlbyname
/* Meta Dictionary Keys */ /* Meta Dictionary Keys */
NSString * VLCMetaInformationTitle = @"title"; NSString * VLCMetaInformationTitle = @"title";
...@@ -453,6 +454,57 @@ NSString *VLCMediaTracksInformationTextEncoding = @"encoding"; // NSString ...@@ -453,6 +454,57 @@ NSString *VLCMediaTracksInformationTextEncoding = @"encoding"; // NSString
return array; return array;
} }
- (BOOL)isMediaSizeSuitableForDevice
{
#if TARGET_OS_IPHONE
// Trigger parsing if needed
[self parseIfNeeded];
NSUInteger biggestWidth = 0;
NSUInteger biggestHeight = 0;
libvlc_media_track_t **tracksInfo;
unsigned int count = libvlc_media_tracks_get(p_md, &tracksInfo);
for (NSUInteger i = 0; i < count; i++) {
switch (tracksInfo[i]->i_type) {
case libvlc_track_video:
if (tracksInfo[i]->video->i_width > biggestWidth)
biggestWidth = tracksInfo[i]->video->i_width;
if (tracksInfo[i]->video->i_height > biggestHeight)
biggestHeight = tracksInfo[i]->video->i_height;
break;
default:
break;
}
}
if (biggestHeight > 0 && biggestWidth > 0) {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *answer = malloc(size);
sysctlbyname("hw.machine", answer, &size, NULL, 0);
NSString *currentMachine = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
free(answer);
NSUInteger totalNumberOfPixels = biggestWidth * biggestHeight;
if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
// iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
return (totalNumberOfPixels < 600000); // between 480p and 720p
} else if ([currentMachine hasPrefix:@"iPhone4"] || [currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"] || [currentMachine hasPrefix:@"iPod5"]) {
// iPhone 4S, iPad 2 and 3, iPod 4 and 5
return (totalNumberOfPixels < 922000); // 720p
} else {
// iPhone 5, iPad 4
return (totalNumberOfPixels < 2074000); // 1080p
}
}
#endif
return YES;
}
@synthesize url; @synthesize url;
@synthesize subitems; @synthesize subitems;
@synthesize metaDictionary; @synthesize metaDictionary;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment