Show
Ignore:
Timestamp:
08/07/10 18:43:54 (22 months ago)
Author:
gbooker
Message:

Detect and handle PCM audio in DVD playback. Also remove an unused static variable.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/CommonMediaPlayer/Media Players/DVD Framework/CMPDVDPlayer.m

    r1286 r1308  
    2626#import "CMPOverlayAction.h" 
    2727#import <AudioUnit/AudioUnit.h> 
     28#import <unistd.h> 
    2829 
    2930enum{ 
     
    716717} 
    717718 
    718 static BOOL pauseOnPlay = NO; 
     719- (void)setAudioMode 
     720{ 
     721        if(ignoreStopUntilPlay) 
     722                //Avoid excessive calls to this function resulting from what we do here 
     723                return; 
     724        BOOL useSPDIF = NO; 
     725        //See if we should go SPDIF (unknown formats default to SPDIF) 
     726        DVDAudioFormat format = kDVDAudioUnknownFormat; 
     727        UInt32 bitsPerSample, samplesPerSecond, channels; 
     728        DVDGetAudioStreamFormat(&format, &bitsPerSample, &samplesPerSecond, &channels); 
     729        switch (format) { 
     730                case kDVDAudioAC3Format: 
     731                case kDVDAudioUnknownFormat: 
     732                case kDVDAudioDTSFormat: 
     733                        useSPDIF = YES; 
     734                        break; 
     735                default: 
     736                        break; 
     737        } 
     738        OSStatus SPDIFresult = noErr; 
     739        if(useSPDIF) 
     740        { 
     741                //See if we can go SPDIF 
     742                DVDAudioMode audioMode = 0; 
     743                SPDIFresult = DVDGetAudioOutputModeCapabilities(&audioMode); 
     744                //NSLog(@"SPDIF get is %d with mode %d", SPDIFresult, audioMode); 
     745                if(!(audioMode & kDVDAudioModeSPDIF)) 
     746                        useSPDIF = NO; 
     747        } 
     748        //See what mode we are in 
     749        DVDAudioMode currentMode = kDVDAudioModeUninitialized; 
     750        DVDGetAudioOutputMode(&currentMode); 
     751        BOOL change = (currentMode == kDVDAudioModeSPDIF) ^ useSPDIF; 
     752        Boolean playing = NO; 
     753        DVDIsPlaying(&playing); 
     754        if(change) 
     755        { 
     756                //Something needs to change.  The changes cannot be made while playback is in progress, so stop, change, then play. 
     757                Boolean paused = NO; 
     758                DVDIsPaused(&paused); 
     759                if(playing) 
     760                { 
     761                        ignoreStopUntilPlay = YES;  //We don't want to trigger leaving playback. 
     762                        DVDStop(); 
     763                        sleep(1);  //Allow playback to stop before we fiddle with it. 
     764                } 
     765                if(useSPDIF) 
     766                { 
     767                        //Engage the SPDIF interface 
     768                        SPDIFresult = DVDSetAudioOutputMode(kDVDAudioModeSPDIF); 
     769                        //NSLog(@"Set to SPDIF with result %d", SPDIFresult); 
     770                        SPDIFresult = DVDSetSPDIFDataOutDevice(0); 
     771                        //NSLog(@"Set SPDIF device with result %d", SPDIFresult); 
     772                } 
     773                else 
     774                        //Disengage the SPDIF interface 
     775                        SPDIFresult = DVDSetAudioOutputMode(kDVDAudioModeProLogic); 
     776                if(playing) 
     777                { 
     778                        //If we were playing, resume. 
     779                        sleep(1);  //Allow changes above to take effect. 
     780                        DVDPlay(); 
     781                        if(paused) 
     782                                //Pause doesn't work here unless we actually play first. 
     783                                DVDPause(); 
     784                } 
     785        } 
     786} 
     787 
    719788- (void)initiatePlaybackWithResume:(BOOL *)resume; 
    720789{ 
    721         DVDAudioMode audioMode = 0; 
    722         //See if we can go SPDIF 
    723         OSStatus SPDIFresult = DVDGetAudioOutputModeCapabilities(&audioMode); 
    724         //NSLog(@"SPDIF get is %d with mode %d", SPDIFresult, audioMode); 
    725         if(audioMode & kDVDAudioModeSPDIF) 
    726         { 
    727                 //Engage the SPDIF interface 
    728                 SPDIFresult = DVDSetAudioOutputMode(kDVDAudioModeSPDIF); 
    729                 //NSLog(@"Set to SPDIF with result %d", SPDIFresult); 
    730                 SPDIFresult = DVDSetSPDIFDataOutDevice(0); 
    731                 //NSLog(@"Set SPDIF device with result %d", SPDIFresult); 
    732         }        
    733          
     790        ignoreStopUntilPlay = NO; 
     791        [self setAudioMode]; 
    734792        DVDGetNumTitles(&titleCount); 
    735793        BOOL doingResume = titleCount == 1 && resumeTime != 0; 
     
    738796        if(doingResume) 
    739797        { 
    740                 pauseOnPlay = YES; 
    741798                DVDSetTime(kDVDTimeCodeElapsedSeconds, resumeTime, 0); 
    742799                DVDPause(); 
     
    838895//              case kDVDEventAngle: 
    839896//                      //Angle has changed 
    840 //              case kDVDEventAudioStream: 
    841 //                      //Audio stream has changed 
     897                case kDVDEventAudioStream: 
     898                        //Audio stream has changed 
     899                        [player performSelectorOnMainThread:@selector(setAudioMode) withObject:nil waitUntilDone:NO]; 
     900                        break; 
    842901//              case kDVDEventSubpictureStream: 
    843902//                      //Subtitle has changed 
     
    918977        else 
    919978                titleDuration = -1; 
     979        [self performSelectorOnMainThread:@selector(setAudioMode) withObject:nil waitUntilDone:NO]; 
    920980} 
    921981