Browse Source

UIDevice: generalize speed checker

Felix Paul Kühne 12 years ago
parent
commit
be7bf21027

+ 17 - 0
AspenProject/UIDevice+SpeedCategory.h

@@ -0,0 +1,17 @@
+//
+//  UIDevice+SpeedCategory.h
+//  VLC for iOS
+//
+//  Created by Felix Paul Kühne on 22.06.13.
+//  Copyright (c) 2013 VideoLAN. All rights reserved.
+//
+//  Refer to the COPYING file of the official project for license.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface UIDevice (SpeedCategory)
+
+- (int)speedCategory;
+
+@end

+ 42 - 0
AspenProject/UIDevice+SpeedCategory.m

@@ -0,0 +1,42 @@
+//
+//  UIDevice+SpeedCategory.m
+//  VLC for iOS
+//
+//  Created by Felix Paul Kühne on 22.06.13.
+//  Copyright (c) 2013 VideoLAN. All rights reserved.
+//
+//  Refer to the COPYING file of the official project for license.
+//
+
+#import "UIDevice+SpeedCategory.h"
+#import <sys/sysctl.h> // for sysctlbyname
+
+@implementation UIDevice (SpeedCategory)
+
+- (int)speedCategory
+{
+    size_t size;
+    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+
+    char *answer = malloc(size);
+    sysctlbyname("hw.machine", answer, &size, NULL, 0);
+
+    NSString *currentMachine = @(answer);
+    free(answer);
+
+    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
+        APLog(@"this is a cat one device");
+        return 1;
+    } 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
+        APLog(@"this is a cat two device");
+        return 2;
+    } else {
+        // iPhone 5, iPad 4
+        APLog(@"this is a cat three device");
+        return 3;
+    }
+}
+
+@end

+ 5 - 15
AspenProject/VLCMovieViewController.m

@@ -10,9 +10,9 @@
 
 #import "VLCMovieViewController.h"
 #import "VLCExternalDisplayController.h"
-#import <sys/sysctl.h> // for sysctlbyname
 #import <AVFoundation/AVFoundation.h>
 #import <CommonCrypto/CommonDigest.h>
+#import "UIDevice+SpeedCategory.h"
 
 #define INPUT_RATE_DEFAULT  1000.
 
@@ -279,26 +279,16 @@
 
     NSUInteger totalNumberOfPixels = [[[self.mediaItem videoTrack] valueForKey:@"width"] doubleValue] * [[[self.mediaItem videoTrack] valueForKey:@"height"] doubleValue];
 
-    size_t size;
-    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+    NSInteger speedCategory = [[UIDevice currentDevice] speedCategory];
 
-    char *answer = malloc(size);
-    sysctlbyname("hw.machine", answer, &size, NULL, 0);
-
-    NSString *currentMachine = @(answer);
-    free(answer);
-
-    if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
+    if (speedCategory == 1) {
         // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
-        APLog(@"this is a cat one device");
         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"]) {
+    } else if (speedCategory == 2) {
         // iPhone 4S, iPad 2 and 3, iPod 4 and 5
-        APLog(@"this is a cat two device");
         return (totalNumberOfPixels < 922000); // 720p
-    } else {
+    } else if (speedCategory == 3) {
         // iPhone 5, iPad 4
-        APLog(@"this is a cat three device");
         return (totalNumberOfPixels < 2074000); // 1080p
     }
 

+ 6 - 0
VLC for iOS.xcodeproj/project.pbxproj

@@ -188,6 +188,7 @@
 		7DBC3B451711FC6C00DCF688 /* VLCAboutViewController~iphone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7DBC3B431711FC6C00DCF688 /* VLCAboutViewController~iphone.xib */; };
 		7DC87AEE17412A1F009DC250 /* VLCLinearProgressIndicator.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DC87AED17412A1F009DC250 /* VLCLinearProgressIndicator.m */; };
 		7DC87AF217413EE3009DC250 /* VLCPlaylistGridView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7DC87AF117413EE3009DC250 /* VLCPlaylistGridView.xib */; };
+		7DDABBB71775A3C7003D8937 /* UIDevice+SpeedCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DDABBB61775A3C7003D8937 /* UIDevice+SpeedCategory.m */; };
 		7DDD0429172D98E5005A7B10 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DDD0428172D98E5005A7B10 /* CFNetwork.framework */; };
 		7DE18629175BA9A5006C0173 /* badgeUnread@2x~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DE1862B175BA9A5006C0173 /* badgeUnread@2x~ipad.png */; };
 		7DE1862C175BA9A9006C0173 /* badgeUnread@2x~iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = 7DE1862E175BA9A9006C0173 /* badgeUnread@2x~iphone.png */; };
@@ -551,6 +552,8 @@
 		7DC87AEF17413634009DC250 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
 		7DC87AF017413A17009DC250 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
 		7DC87AF117413EE3009DC250 /* VLCPlaylistGridView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCPlaylistGridView.xib; path = ../Resources/VLCPlaylistGridView.xib; sourceTree = "<group>"; };
+		7DDABBB51775A3A7003D8937 /* UIDevice+SpeedCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+SpeedCategory.h"; sourceTree = "<group>"; };
+		7DDABBB61775A3C7003D8937 /* UIDevice+SpeedCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+SpeedCategory.m"; sourceTree = "<group>"; };
 		7DDD0428172D98E5005A7B10 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
 		7DE1862A175BA9A5006C0173 /* en */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = en; path = "en.lproj/badgeUnread@2x~ipad.png"; sourceTree = "<group>"; };
 		7DE1862D175BA9A9006C0173 /* en */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = en; path = "en.lproj/badgeUnread@2x~iphone.png"; sourceTree = "<group>"; };
@@ -1344,6 +1347,8 @@
 			children = (
 				A7C3025C175A53D400AD4388 /* NSString+SupportedMedia.h */,
 				A7C3025D175A53D400AD4388 /* NSString+SupportedMedia.m */,
+				7DDABBB51775A3A7003D8937 /* UIDevice+SpeedCategory.h */,
+				7DDABBB61775A3C7003D8937 /* UIDevice+SpeedCategory.m */,
 			);
 			name = Extensions;
 			sourceTree = "<group>";
@@ -1662,6 +1667,7 @@
 				7A50619F176E3D410036E15D /* UINavigationController+Theme.m in Sources */,
 				7A5061A2176E41160036E15D /* UIBarButtonItem+Theme.m in Sources */,
 				A7990067176E9CF3009E8267 /* VLCMenuButton.m in Sources */,
+				7DDABBB71775A3C7003D8937 /* UIDevice+SpeedCategory.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};