Changeset 1204

Show
Ignore:
Timestamp:
03/09/2010 05:11:28 PM (2 years ago)
Author:
gbooker
Message:

Reduce memory usage by creating NSImages on demand instead of every single time. Also reduced 3 arrays to one and used type checking to see what data it currently has. This makes a difference with The Dark Knight which has 100 images, consuming 80MB. This is a lot for the ATV which only has a total of 256.

Location:
trunk/SapphireFrappliance/MetaDataImporting
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireFrappliance/MetaDataImporting/SapphirePosterChooser.h

    r1179 r1204  
    3232@interface SapphirePosterChooser : SapphireMediaMenuController <BRIconSourceProtocol, BRMenuListItemProvider, SapphireLayoutDelegate, SapphireChooser> { 
    3333        BOOL                                    displayed;              /*!< @brief YES if currently displayed, NO otherwise*/ 
    34         NSMutableArray                  *posters;               /*!< @brief The array of poster urls and after loaded, the NSImages*/ 
    35         NSMutableArray                  *posterLayers;  /*!< @brief The image layers of posters*/ 
    36         NSMutableArray                  *posterData;    /*!< @brief The data for the poster images*/ 
     34        NSMutableArray                  *posters;               /*!< @brief The array of poster urls, NSImages, NSData, or BlurredImages*/ 
    3735        NSString                                *fileName;              /*!< @brief The movie filename*/ 
    3836        NSString                                *movieTitle;    /*!< @brief The title of the movie*/ 
     
    7775 
    7876/*! 
    79  * @brief The list of posters to choose from 
    80  * 
    81  * @return The list of posters to choose from 
    82  */ 
    83 - (NSArray *)posters; 
    84  
    85 /*! 
    86  * @brief Loads the posters from disk 
    87  */ 
    88 - (void)loadPosters; 
    89  
    90 /*! 
    9177 * @brief Sets the filename to display 
    9278 * 
  • trunk/SapphireFrappliance/MetaDataImporting/SapphirePosterChooser.m

    r1198 r1204  
    4141@interface SapphirePosterChooser () 
    4242- (BRBlurryImageLayer *)getPosterLayerForData:(NSData *)thePosterData; 
    43 - (void)loadPoster:(int)index; 
    44 - (void)reloadPosterWithData:(NSData *)data atIndex:(int)intIndex; 
     43- (void)loadPosters; 
     44- (void)loadPosterWithURL:(int)index; 
     45- (void)reloadPosterWithDataAtIndex:(int)intIndex; 
    4546@end 
    4647 
     
    9394//    [posterMarch setIconSource: nil];  //This throws an exception 
    9495        [posters release]; 
    95         [posterLayers release]; 
    96         [posterData release]; 
    9796        [fileName release]; 
    9897        [movieTitle release]; 
     
    157156#pragma mark List of posters 
    158157 
     158- (void)freePosterMarch 
     159{ 
     160        [posterMarch release]; 
     161        posterMarch = nil; 
     162} 
     163 
    159164- (void)setPosters:(NSArray *)posterList 
    160165{ 
    161166        posters = [posterList mutableCopy]; 
    162167        if([posters count] > 5) 
    163         { 
    164                 [posterMarch release]; 
    165                 posterMarch = nil; 
     168                [self freePosterMarch]; 
     169        else 
     170        { 
     171                [posterMarch setIconSource: self]; 
    166172        } 
    167173        [self loadPosters]; 
    168     [posterMarch setIconSource: self]; 
    169174        [[self list] setDatasource:self]; 
    170175} 
     
    174179        posters = [posterList retain]; 
    175180 
    176         [posterMarch release]; 
    177         posterMarch = nil; 
    178  
    179         [[self list] setDatasource: self]; 
     181        [self freePosterMarch]; 
     182        [[self list] setDatasource:self]; 
    180183} 
    181184 
     
    188191{ 
    189192        int i, count = [posters count]; 
    190         posterLayers = [posters mutableCopy]; 
    191         posterData = [[NSMutableArray alloc] initWithCapacity:[posters count]]; 
    192         NSNull *nsnull = [NSNull null]; 
    193193        for(i=0; i<count; i++) 
    194                 [posterData addObject:nsnull]; 
    195         for(i=0; i<count; i++) 
    196                 [self loadPoster:i]; 
     194                [self loadPosterWithURL:i]; 
    197195        [posterMarch reload]; 
    198196        [SapphireFrontRowCompat renderScene:[self scene]]; 
     
    204202 * @param The index of the poster to load 
    205203 */ 
    206 - (void)loadPoster:(int)index; 
     204- (void)loadPosterWithURL:(int)index; 
    207205{ 
    208206        NSString *posterURL = [posters objectAtIndex:index]; 
    209         [posterLayers replaceObjectAtIndex:index withObject:[self getPosterLayerForData:nil]]; 
    210207        [[SapphireApplianceController urlLoader] loadDataURL:posterURL withTarget:self selector:@selector(gotPosterData:atIndex:) object:[NSNumber numberWithInt:index] withPriority:YES]; 
    211208} 
     
    213210- (void)gotPosterData:(NSData *)data atIndex:(NSNumber *)index; 
    214211{ 
    215         if(displayed) 
    216                 [self reloadPosterWithData:data atIndex:[index intValue]]; 
    217         else if(data != nil) 
    218                 [posterData replaceObjectAtIndex:[index intValue] withObject:data]; 
    219         else 
    220                 [posterData replaceObjectAtIndex:[index intValue] withObject:[NSData data]]; 
    221 } 
    222  
    223 - (void)reloadPosterWithData:(NSData *)data atIndex:(int)intIndex; 
    224 { 
    225         [posterLayers replaceObjectAtIndex:intIndex withObject:[self getPosterLayerForData:data]]; 
    226         NSImage *image = [[NSImage alloc] initWithData:data]; 
    227         if(image == nil) 
    228                 image = [errorNSImage retain]; 
    229         [posters replaceObjectAtIndex:intIndex withObject:image]; 
    230         [image release]; 
     212        if(data != nil) 
     213                [posters replaceObjectAtIndex:[index intValue] withObject:data]; 
     214        else 
     215                [posters replaceObjectAtIndex:[index intValue] withObject:[NSData data]]; 
     216        if(displayed && posterMarch) 
     217                [self reloadPosterWithDataAtIndex:[index intValue]]; 
     218} 
     219 
     220- (void)reloadPosterWithDataAtIndex:(int)intIndex; 
     221{ 
     222        NSData *data = [posters objectAtIndex:intIndex]; 
     223        [posters replaceObjectAtIndex:intIndex withObject:[self getPosterLayerForData:data]]; 
    231224        [posterMarch _updateIcons]; 
    232225        if([self getSelection] == intIndex) 
     
    367360- (long)iconCount 
    368361{ 
    369         return [posterLayers count]; 
     362        return [posters count]; 
    370363} 
    371364 
    372365- (NSDictionary *)iconInfoAtIndex:(long)index 
    373366{ 
    374         return [NSDictionary dictionaryWithObject:[posterLayers objectAtIndex:index] forKey:@"icon"]; 
     367        id poster = [posters objectAtIndex:index]; 
     368        if([poster isKindOfClass:[NSString class]] || [poster isKindOfClass:[NSData class]]) 
     369                poster = defaultImage; 
     370        return [NSDictionary dictionaryWithObject:poster forKey:@"icon"]; 
    375371} 
    376372 
    377373- (id)iconAtIndex:(long)index 
    378374{ 
    379     if ( index >= [posterLayers count] ) 
     375    if ( index >= [posters count] ) 
    380376        return nil; 
    381377         
    382     return [posterLayers objectAtIndex:index]; 
     378    return [posters objectAtIndex:index]; 
    383379} 
    384380 
     
    410406                id poster = [posters objectAtIndex:row]; 
    411407                 
    412                 if(![poster isKindOfClass:[NSString class]]) 
     408                if([poster isKindOfClass:[NSImage class]]) 
    413409                        [asset setImage:poster]; 
     410                else if([poster isKindOfClass:[NSData class]]) 
     411                { 
     412                        NSImage *image = [[NSImage alloc] initWithData:poster]; 
     413                        if(image) 
     414                        { 
     415                                [asset setImage:image]; 
     416                                [image release]; 
     417                        } 
     418                        else 
     419                                [asset setImage:errorNSImage]; 
     420                } 
    414421                else 
    415422                        [asset setImage:defaultNSImage]; 
     
    555562        [super wasPushed]; 
    556563        displayed = YES; 
    557         int i, count = [posterData count]; 
    558         for(i=0; i<count; i++) 
    559         { 
    560                 id obj = [posterData objectAtIndex:i]; 
    561                 if([obj isKindOfClass:[NSData class]]) 
    562                         [self reloadPosterWithData:obj atIndex:i]; 
     564        if(posterMarch) 
     565        { 
     566                int i, count = [posters count]; 
     567                for(i=0; i<count; i++) 
     568                { 
     569                        id obj = [posters objectAtIndex:i]; 
     570                        if([obj isKindOfClass:[NSData class]]) 
     571                                [self reloadPosterWithDataAtIndex:i]; 
     572                } 
    563573        } 
    564574}