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

make device speed category a public API

parent b9a08fbb
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
@property (nonatomic, strong) NSURL *persistentStoreURL; @property (nonatomic, strong) NSURL *persistentStoreURL;
@property (nonatomic, strong) NSPersistentStoreCoordinator *persistentStoreCoordinator; @property (nonatomic, strong) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, copy) NSDictionary *additionalPersitentStoreOptions; @property (nonatomic, copy) NSDictionary *additionalPersitentStoreOptions;
@property (nonatomic, readonly) int deviceSpeedCategory;
+ (id)sharedMediaLibrary; + (id)sharedMediaLibrary;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#import "MLAlbum.h" #import "MLAlbum.h"
#import "MLFileParserQueue.h" #import "MLFileParserQueue.h"
#import "MLCrashPreventer.h" #import "MLCrashPreventer.h"
#import <sys/sysctl.h> // for sysctlbyname
@interface MLMediaLibrary () @interface MLMediaLibrary ()
{ {
...@@ -45,6 +46,7 @@ ...@@ -45,6 +46,7 @@
NSManagedObjectModel *_managedObjectModel; NSManagedObjectModel *_managedObjectModel;
BOOL _allowNetworkAccess; BOOL _allowNetworkAccess;
int _deviceSpeedCategory;
NSString *_thumbnailFolderPath; NSString *_thumbnailFolderPath;
NSString *_databaseFolderPath; NSString *_databaseFolderPath;
...@@ -128,6 +130,37 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -128,6 +130,37 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
[[self managedObjectContext] deleteObject:object]; [[self managedObjectContext] deleteObject:object];
} }
#pragma mark - helper
- (int)deviceSpeedCategory
{
if (_deviceSpeedCategory > 0)
return _deviceSpeedCategory;
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:@"iPhone4"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"]) {
// iPhone 3GS, iPhone 4, 3rd and 4th generation iPod touch, iPad 2, iPad mini (1st gen)
_deviceSpeedCategory = 1;
} else if ([currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod5"]) {
// iPod 5, iPad 3
_deviceSpeedCategory = 2;
} else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
// iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
_deviceSpeedCategory = 3;
} else
// iPhone 6, 2014 iPads
_deviceSpeedCategory = 4;
return _deviceSpeedCategory;
}
#pragma mark - #pragma mark -
#pragma mark Media Library #pragma mark Media Library
- (NSManagedObjectModel *)managedObjectModel - (NSManagedObjectModel *)managedObjectModel
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* MobileMediaLibraryKit * MobileMediaLibraryKit
***************************************************************************** *****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont * Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2010-2014 VLC authors and VideoLAN * Copyright (C) 2010-2015 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#import "MLThumbnailerQueue.h" #import "MLThumbnailerQueue.h"
#import "MLFile.h" #import "MLFile.h"
#import "MLCrashPreventer.h" #import "MLCrashPreventer.h"
#import <sys/sysctl.h> // for sysctlbyname #import "MLMediaLibrary.h"
@interface ThumbnailOperation : NSOperation <VLCMediaThumbnailerDelegate> @interface ThumbnailOperation : NSOperation <VLCMediaThumbnailerDelegate>
{ {
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
int speedCategory = [self _deviceSpeedCategory]; int speedCategory = [[MLMediaLibrary sharedMediaLibrary] deviceSpeedCategory];
APLog(@"running on a category %i device", speedCategory); APLog(@"running on a category %i device", speedCategory);
if (speedCategory < 2) if (speedCategory < 2)
_internalLibrary = [VLCLibrary sharedLibrary]; _internalLibrary = [VLCLibrary sharedLibrary];
...@@ -214,29 +214,4 @@ static inline NSString *hashFromFile(MLFile *file) ...@@ -214,29 +214,4 @@ static inline NSString *hashFromFile(MLFile *file)
[op setQueuePriority:NSOperationQueuePriorityNormal]; [op setQueuePriority:NSOperationQueuePriorityNormal];
} }
- (int)_deviceSpeedCategory
{
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:@"iPhone4"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"]) {
// iPhone 3GS, iPhone 4, 3rd and 4th generation iPod touch, iPad 2, iPad mini (1st gen)
return 1;
} else if ([currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod5"]) {
// iPod 5, iPad 3
return 2;
} else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
// iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
return 3;
} else
// iPhone 6, 2014 iPads
return 4;
}
@end @end
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