Changeset 524

Show
Ignore:
Timestamp:
04/26/08 02:55:39 (9 months ago)
Author:
gbooker
Message:

Moved the AC3 support and resume support to a dedicated controller.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SapphireFrappliance/Sapphire.xcodeproj/project.pbxproj

    r513 r524  
    5555                F531A5BA0C2CB43400E46F62 /* SapphireMetaData.m in Sources */ = {isa = PBXBuildFile; fileRef = F531A5B90C2CB43400E46F62 /* SapphireMetaData.m */; }; 
    5656                F531A98F0C2DACBE00E46F62 /* SapphireApplianceController.m in Sources */ = {isa = PBXBuildFile; fileRef = F531A98E0C2DACBE00E46F62 /* SapphireApplianceController.m */; }; 
     57                F53420560DC2F17F00498822 /* SapphireVideoPlayerController.m in Sources */ = {isa = PBXBuildFile; fileRef = F53420550DC2F17F00498822 /* SapphireVideoPlayerController.m */; }; 
    5758                F541CBF50D9C2D19002F9278 /* SapphireRadioSetting.m in Sources */ = {isa = PBXBuildFile; fileRef = F541CBF40D9C2D19002F9278 /* SapphireRadioSetting.m */; }; 
    5859                F565A1FD0C5BE81F00AE7110 /* SapphireAudioPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = F565A1FC0C5BE81F00AE7110 /* SapphireAudioPlayer.m */; }; 
     
    7778                F5CE69660D4575DC003C4B2D /* SapphireAllFileDataImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = F5CE69650D4575DC003C4B2D /* SapphireAllFileDataImporter.m */; }; 
    7879                F5D0DEB60C331D76007652B2 /* SapphireTheme.m in Sources */ = {isa = PBXBuildFile; fileRef = F5D0DEB50C331D76007652B2 /* SapphireTheme.m */; }; 
     80                F5D909190DB520B900F12E12 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5D909180DB520B900F12E12 /* Security.framework */; }; 
    7981                F5DF246B0C8636DE005C7ECB /* SapphireMultipleImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DF246A0C8636DE005C7ECB /* SapphireMultipleImporter.m */; }; 
    8082                F5E849C70C3F008100913832 /* SapphireMetaDataScanner.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E849C60C3F008100913832 /* SapphireMetaDataScanner.m */; }; 
     
    262264                F531A98D0C2DACBE00E46F62 /* SapphireApplianceController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SapphireApplianceController.h; sourceTree = "<group>"; }; 
    263265                F531A98E0C2DACBE00E46F62 /* SapphireApplianceController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SapphireApplianceController.m; sourceTree = "<group>"; }; 
     266                F53420540DC2F17F00498822 /* SapphireVideoPlayerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SapphireVideoPlayerController.h; sourceTree = "<group>"; }; 
     267                F53420550DC2F17F00498822 /* SapphireVideoPlayerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SapphireVideoPlayerController.m; sourceTree = "<group>"; }; 
    264268                F541CBF30D9C2D19002F9278 /* SapphireRadioSetting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SapphireRadioSetting.h; sourceTree = "<group>"; }; 
    265269                F541CBF40D9C2D19002F9278 /* SapphireRadioSetting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SapphireRadioSetting.m; sourceTree = "<group>"; }; 
     
    297301                F5D0DEB40C331D76007652B2 /* SapphireTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SapphireTheme.h; sourceTree = "<group>"; }; 
    298302                F5D0DEB50C331D76007652B2 /* SapphireTheme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SapphireTheme.m; sourceTree = "<group>"; }; 
     303                F5D909180DB520B900F12E12 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; }; 
    299304                F5DF24690C8636DE005C7ECB /* SapphireMultipleImporter.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SapphireMultipleImporter.h; sourceTree = "<group>"; }; 
    300305                F5DF246A0C8636DE005C7ECB /* SapphireMultipleImporter.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SapphireMultipleImporter.m; sourceTree = "<group>"; }; 
     
    358363                                F56A19490C3170870022918E /* AppKit.framework in Frameworks */, 
    359364                                F56A1DF50C31CE190022918E /* QTKit.framework in Frameworks */, 
     365                                F5D909190DB520B900F12E12 /* Security.framework in Frameworks */, 
    360366                        ); 
    361367                        runOnlyForDeploymentPostprocessing = 0; 
     
    395401                        isa = PBXGroup; 
    396402                        children = ( 
     403                                F5D909180DB520B900F12E12 /* Security.framework */, 
    397404                                F5185B400D1344D700712020 /* ExceptionHandling.framework */, 
    398405                                F56A1DF40C31CE190022918E /* QTKit.framework */, 
     
    563570                                F51DCDB70C30AE010046F25E /* SapphireVideoPlayer.h */, 
    564571                                F51DCDB80C30AE010046F25E /* SapphireVideoPlayer.m */, 
     572                                F53420540DC2F17F00498822 /* SapphireVideoPlayerController.h */, 
     573                                F53420550DC2F17F00498822 /* SapphireVideoPlayerController.m */, 
    565574                        ); 
    566575                        name = Players; 
     
    833842                                F541CBF50D9C2D19002F9278 /* SapphireRadioSetting.m in Sources */, 
    834843                                F59B29D10D9E8C6E002D5DBD /* NSArray-Extensions.m in Sources */, 
     844                                F53420560DC2F17F00498822 /* SapphireVideoPlayerController.m in Sources */, 
    835845                        ); 
    836846                        runOnlyForDeploymentPostprocessing = 0; 
  • trunk/SapphireFrappliance/SapphireBrowser.h

    r461 r524  
    2323@class SapphireSettings, BRSegmentedSortControl, SapphirePredicate; 
    2424 
    25 #define SOUND_STATE_SOUND_ENABLED               1 
    26 #define SOUND_STATE_SOUND_PASSTHROUGH   2 
    27  
    2825/*! 
    2926 * @brief A subclass of SapphireMediaMenuController for browsing metadata 
     
    3734        SapphireDirectoryMetaData               *metaData;                      /*!< @brief The directory for the browser*/ 
    3835        SapphirePredicate                               *predicate;                     /*!< @brief Predicate to determine which files are matched*/ 
    39         SapphireFileMetaData                    *currentPlayFile;       /*!< @brief If we are the browser to actually play something, the file we are playing*/ 
    4036        int                                                             dirCount;                       /*!< @brief The number of directories in this directory*/ 
    4137        int                                                             fileCount;                      /*!< @brief The number of files in this directory*/ 
    4238        BOOL                                                    cancelScan;                     /*!< @brief Cancel the background importer for this directory*/ 
    43         int                                                             soundState;                     /*!< @brief Sound state before we played the current file*/ 
    4439} 
    4540 
  • trunk/SapphireFrappliance/SapphireBrowser.m

    r467 r524  
    3232#import "SapphireAudioMedia.h" 
    3333#import "SapphireApplianceController.h" 
     34#import "SapphireVideoPlayerController.h" 
    3435#import <SapphireCompatClasses/SapphireFrontRowCompat.h> 
    3536#import <SapphireCompatClasses/SapphireDVDLoadingController.h> 
    3637 
    37 #import <AudioUnit/AudioUnit.h> 
    3838#import <objc/objc-class.h> 
    39  
    40 #define PASSTHROUGH_KEY         (CFStringRef)@"attemptPassthrough" 
    41 #define A52_DOMIAN                      (CFStringRef)@"com.cod3r.a52codec" 
    4239 
    4340@interface SapphireBrowser (private) 
     
    235232    // the user pressed Menu, but we've not been revealed yet 
    236233     
    237         /*Check to see if the user stopped playing something*/ 
    238         id controller = [[self stack] peekController]; 
    239         float elapsed = 0.0; 
    240         float duration = 0.0000001; //prevent a div by 0 
    241         if([controller isKindOfClass:[BRVideoPlayerController class]]) 
    242         { 
    243                 /*Check for 90% completion*/ 
    244                 BRVideoPlayer *player = [(BRVideoPlayerController *)controller player]; 
    245                 elapsed = [player elapsedPlaybackTime]; 
    246                 duration = [player trackDuration]; 
    247         } 
    248         else if([controller isKindOfClass:[BRMusicNowPlayingController class]]) 
    249         { 
    250                 BRMusicPlayer *player = [(BRMusicNowPlayingController *)controller player]; 
    251                 elapsed = [player elapsedPlaybackTime]; 
    252                 duration = [player trackDuration]; 
    253                 [player stop]; 
    254         } 
    255         if(elapsed / duration > 0.9f) 
    256                 /*Mark as watched and reload info*/ 
    257                 [currentPlayFile setWatched:YES]; 
    258          
    259         /*Get the resume time to save*/ 
    260         if(elapsed < duration - 2) 
    261                 [currentPlayFile setResumeTime:elapsed]; 
    262         else 
    263                 [currentPlayFile setResumeTime:0]; 
    264         [currentPlayFile writeMetaData]; 
    265  
    266         /*cleanup*/ 
    267         [currentPlayFile release]; 
    268         currentPlayFile = nil; 
    269234        /*Reload our display*/ 
    270235        [self setNewPredicate:[SapphireApplianceController predicate]]; 
     
    285250                /*Resume importing now that we are up again*/ 
    286251                [metaData resumeImport]; 
    287         //Turn off the AC3 Passthrough hack 
    288         CFPreferencesSetAppValue(PASSTHROUGH_KEY, (CFNumberRef)[NSNumber numberWithInt:((soundState & SOUND_STATE_SOUND_PASSTHROUGH)? 1 : 0)], A52_DOMIAN); 
    289         CFPreferencesAppSynchronize(A52_DOMIAN); 
    290         if(soundState & SOUND_STATE_SOUND_ENABLED) 
    291                 [(RUIPreferences *)[RUIPreferences sharedFrontRowPreferences] setBool:YES forKey:@"PlayFrontRowSounds"]; 
    292252} 
    293253 
     
    303263- (id<BRMenuItemLayer>) itemForRow: (long) row 
    304264{ 
    305 /* 
    306     // build a BRTextMenuItemLayer or a BRAdornedMenuItemLayer, etc. here 
    307     // return that object, it will be used to display the list item. 
    308     return ( nil ); 
    309 */ 
    310265        NSString * displayName=nil ; 
    311266        FileClass fileCls=0 ; 
     
    447402} 
    448403 
    449 BOOL findCorrectDescriptionForStream(AudioStreamID streamID, int sampleRate) 
    450 { 
    451         OSStatus err; 
    452         UInt32 propertySize = 0; 
    453         err = AudioStreamGetPropertyInfo(streamID, 0, kAudioStreamPropertyPhysicalFormats, &propertySize, NULL); 
    454          
    455         if(err != noErr || propertySize == 0) 
    456                 return NO; 
    457          
    458         AudioStreamBasicDescription *descs = malloc(propertySize); 
    459         if(descs == NULL) 
    460                 return NO; 
    461          
    462         int formatCount = propertySize / sizeof(AudioStreamBasicDescription); 
    463         err = AudioStreamGetProperty(streamID, 0, kAudioStreamPropertyPhysicalFormats, &propertySize, descs); 
    464          
    465         if(err != noErr) 
    466         { 
    467                 free(descs); 
    468                 return NO; 
    469         } 
    470          
    471         int i; 
    472         BOOL ret = NO; 
    473         for(i=0; i<formatCount; i++) 
    474         { 
    475                 if (descs[i].mBitsPerChannel == 16 && descs[i].mFormatID == kAudioFormatLinearPCM) 
    476                 { 
    477                         if(descs[i].mSampleRate == sampleRate) 
    478                         { 
    479                                 err = AudioStreamSetProperty(streamID, NULL, 0, kAudioStreamPropertyPhysicalFormat, sizeof(AudioStreamBasicDescription), descs + i); 
    480                                 if(err != noErr) 
    481                                         continue; 
    482                                 ret = YES; 
    483                                 break; 
    484                         } 
    485                 } 
    486         } 
    487         free(descs); 
    488         return ret; 
    489 } 
    490  
    491 BOOL setupDevice(AudioDeviceID devID, int sampleRate) 
    492 { 
    493         OSStatus err; 
    494         UInt32 propertySize = 0; 
    495         err = AudioDeviceGetPropertyInfo(devID, 0, FALSE, kAudioDevicePropertyStreams, &propertySize, NULL); 
    496          
    497         if(err != noErr || propertySize == 0) 
    498                 return NO; 
    499          
    500         AudioStreamID *streams = malloc(propertySize); 
    501         if(streams == NULL) 
    502                 return NO; 
    503          
    504         int streamCount = propertySize / sizeof(AudioStreamID); 
    505         err = AudioDeviceGetProperty(devID, 0, FALSE, kAudioDevicePropertyStreams, &propertySize, streams); 
    506         if(err != noErr) 
    507         { 
    508                 free(streams); 
    509                 return NO; 
    510         } 
    511          
    512         int i; 
    513         BOOL ret = NO; 
    514         for(i=0; i<streamCount; i++) 
    515         { 
    516                 if(findCorrectDescriptionForStream(streams[i], sampleRate)) 
    517                 { 
    518                         ret = YES; 
    519                         break; 
    520                 } 
    521         } 
    522         free(streams); 
    523         return ret; 
    524 } 
    525  
    526 BOOL setupAudioOutput(int sampleRate) 
    527 { 
    528         OSErr err; 
    529         UInt32 propertySize = 0; 
    530          
    531         err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propertySize, NULL); 
    532         if(err != noErr || propertySize == 0) 
    533                 return NO; 
    534          
    535         AudioDeviceID *devs = malloc(propertySize); 
    536         if(devs == NULL) 
    537                 return NO; 
    538          
    539         err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propertySize, devs); 
    540         if(err != noErr) 
    541         { 
    542                 free(devs); 
    543                 return NO; 
    544         } 
    545          
    546         int i, devCount = propertySize/sizeof(AudioDeviceID); 
    547         BOOL ret = NO; 
    548         for(i=0; i<devCount; i++) 
    549         { 
    550                 if(setupDevice(devs[i], sampleRate)) 
    551                 { 
    552                         err = AudioHardwareSetProperty(kAudioHardwarePropertyDefaultOutputDevice, sizeof(AudioDeviceID), devs + i); 
    553                         if(err != noErr) 
    554                                 continue; 
    555                         ret = YES; 
    556                         break; 
    557                 } 
    558         } 
    559         free(devs); 
    560         return ret; 
    561 } 
    562  
    563404- (void)setNewPredicate:(SapphirePredicate *)newPredicate 
    564405{ 
     
    596437        { 
    597438                /*Play the file*/ 
    598                 currentPlayFile = [[metaData metaDataForFile:name] retain]; 
     439                SapphireFileMetaData *currentPlayFile = [[metaData metaDataForFile:name] retain]; 
    599440                 
    600441                NSString *path = [currentPlayFile path]; 
     
    691532                        [download autorelease]; 
    692533                } 
    693                  
    694                 /*AC3 passthrough*/ 
    695                 BOOL useAC3Passthrough = NO; 
    696                 if([currentPlayFile updateMetaData]) 
    697                         [currentPlayFile writeMetaData]; 
    698                 if([settings useAC3Passthrough]) 
    699                 { 
    700                         Float64 sampleRate = [currentPlayFile sampleRate]; 
    701                         UInt32 type = [currentPlayFile audioFormatID]; 
    702                          
    703                         if((type == 'ac-3' || type == 0x6D732000) && setupAudioOutput((int)sampleRate)) 
    704                                 useAC3Passthrough = YES; 
    705                 } 
    706                  
    707                 Boolean temp; 
    708                 BOOL passthrough = CFPreferencesGetAppBooleanValue(PASSTHROUGH_KEY, A52_DOMIAN, &temp); 
    709                 BOOL soundsWereEnabled = NO; 
    710                 if(useAC3Passthrough) 
    711                 { 
    712                         RUIPreferences *prefs = [RUIPreferences sharedFrontRowPreferences]; 
    713                         soundsWereEnabled = [prefs boolForKey:@"PlayFrontRowSounds"]; 
    714                         if(soundsWereEnabled) 
    715                                 [prefs setBool:NO forKey:@"PlayFrontRowSounds"]; 
    716                         CFPreferencesSetAppValue(PASSTHROUGH_KEY, (CFNumberRef)[NSNumber numberWithInt:1], A52_DOMIAN); 
    717                 } 
    718                 else 
    719                         CFPreferencesSetAppValue(PASSTHROUGH_KEY, (CFNumberRef)[NSNumber numberWithInt:0], A52_DOMIAN); 
    720                 soundState = (passthrough ? SOUND_STATE_SOUND_PASSTHROUGH : 0) | (soundsWereEnabled ? SOUND_STATE_SOUND_ENABLED : 0); 
    721                 CFPreferencesAppSynchronize(A52_DOMIAN); 
    722534                 
    723535                if ([currentPlayFile fileContainerType] == FILE_CONTAINER_TYPE_VIDEO_TS) 
     
    743555                         
    744556                        /*and go*/ 
    745                         BRVideoPlayerController *controller = [BRVideoPlayerController alloc]; 
    746                         if([controller respondsToSelector:@selector(initWithScene:)]) 
    747                                 controller = [controller initWithScene:[self scene]]; 
    748                         else 
    749                                 controller = [controller init]; 
     557                        SapphireVideoPlayerController *controller = [[SapphireVideoPlayerController alloc] initWithScene:[self scene]]; 
     558                        [controller setPlayFile:currentPlayFile]; 
    750559                        [controller setAllowsResume:YES]; 
    751560                        [controller setVideoPlayer:player];