5 // Created by Damiano Galassi on 23/01/08.
6 // This file is part of the HandBrake source code.
7 // Homepage: <http://handbrake.fr/>.
8 // It may be used under the terms of the GNU General Public License.
12 #import "DeviceController.h"
15 @implementation DeviceController
19 if (self = [super init])
21 devicesArray = [[NSMutableArray alloc] init];
22 appSupportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Instant HandBrake"];
23 [self loadBuiltInDevices];
31 [devicesArray release];
35 - (BOOL) loadBuiltInDevices
37 NSBundle *bundle = [NSBundle mainBundle];
38 NSArray *path = [bundle pathsForResourcesOfType:@"ihbdevice" inDirectory:@"Devices"];
43 NSEnumerator *dirEnum = [path objectEnumerator];
44 while (file = [dirEnum nextObject])
46 newDevice = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
47 [devicesArray addObject:newDevice];
50 if ( ![devicesArray count] )
59 NSFileManager *fileManager = [NSFileManager defaultManager];
62 NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:appSupportPath];
63 while (file = [dirEnum nextObject])
65 if ([[file pathExtension] isEqualToString: @"ihbdevice"])
67 newDevice = [NSKeyedUnarchiver unarchiveObjectWithFile:[appSupportPath stringByAppendingPathComponent:file]];
68 [devicesArray addObject:newDevice];
72 if ( ![devicesArray count] )
78 /* Use this to create a new device preset for now */
82 [devicesArray addObject:[[Device alloc] initWithDeviceName: @"iPod"]];
83 [devicesArray addObject:[[Device alloc] initWithDeviceName: @"PSP"]];
84 [devicesArray addObject:[[Device alloc] initWithDeviceName: @"AppleTV"]];
87 newPreset = [[Preset alloc] initWithMuxer: HB_MUX_IPOD
88 videoCodec: HB_VCODEC_X264
90 videoCodecOptions: @"bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subq=6:no-fast-pskip=1:level=30"
91 audioCodec: HB_ACODEC_FAAC
93 audioSampleRate: 48000
98 [[devicesArray objectAtIndex:0] addPreset:newPreset];
100 newPreset = [[Preset alloc] initWithMuxer: HB_MUX_MP4
101 videoCodec: HB_VCODEC_X264
103 videoCodecOptions: @""
104 audioCodec: HB_ACODEC_FAAC
106 audioSampleRate: 48000
111 [[devicesArray objectAtIndex:1] addPreset:newPreset];
113 newPreset = [[Preset alloc] initWithMuxer: HB_MUX_MP4
114 videoCodec: HB_VCODEC_X264
116 videoCodecOptions: @"bframes=3:ref=1:subq=5:me=umh:no-fast-pskip=1:trellis=1:cabac=0"
117 audioCodec: HB_ACODEC_FAAC
119 audioSampleRate: 48000
124 [[devicesArray objectAtIndex:2] addPreset:newPreset];
127 - (NSArray *) devicesList
129 NSArray *deviceList = [devicesArray copy];
130 [deviceList autorelease];
137 NSFileManager *fileManager = [NSFileManager defaultManager];
140 if( ![fileManager fileExistsAtPath:appSupportPath] )
141 [fileManager createDirectoryAtPath:appSupportPath attributes:nil];
143 NSEnumerator *enumerator;
145 enumerator = [devicesArray objectEnumerator];
147 while( object = [enumerator nextObject] )
149 NSString * saveLocation = [NSString stringWithFormat:@"%@/%@.ihbdevice", appSupportPath, [object name]];
150 if (![fileManager fileExistsAtPath:saveLocation])
152 noErr = [NSKeyedArchiver archiveRootObject:object
153 toFile:saveLocation];