| 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(¤tMode); |
| | 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 | |
| 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]; |