Skip to content

Commit

Permalink
#112 doc. Change error return value to 255 of GetEndpointPollInterval…
Browse files Browse the repository at this point in the history
…. Fix another code line with always-failing pollinterval test. Determine input direction differently if format not supported.
  • Loading branch information
Wouter1 authored and wouter committed Apr 28, 2019
1 parent 43539c0 commit d8c570b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
24 changes: 13 additions & 11 deletions src/EMUUSBAudio/EMUUSBAudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,25 +1488,25 @@ IOReturn EMUUSBAudioEngine::performFormatChangeInternal (IOAudioStream *audioStr

if (audioStream == usbInputStream.audioStream || sampleRateChanged)
{
UInt8 newDirection = usbAudio->GetIsocEndpointDirection (usbInputStream.interfaceNumber, newAlternateSettingID);
if (FALSE == usbAudio->VerifySampleRateIsSupported(usbInputStream.interfaceNumber, newAlternateSettingID, sampleRate.whole)) {
// find an alternative if requested rate not supported.
UInt8 newDirection;
if (usbAudio->VerifySampleRateIsSupported(usbInputStream.interfaceNumber, newAlternateSettingID, sampleRate.whole)) {
newDirection = usbAudio->GetIsocEndpointDirection (usbInputStream.interfaceNumber, newAlternateSettingID);
ReturnIf (newDirection != usbInputStream.streamDirection, kIOReturnError);
} else {
// sample rate is not supported on input side. Find alternative.
// #112 it seems this code is for 0204 if someone switches to output 4 channels,
// in which case there is no 4 channels input. So let's just try 2 channels here
newDirection = usbInputStream.streamDirection;
newAlternateSettingID = usbAudio->FindAltInterfaceWithSettings (usbInputStream.interfaceNumber, 2, newFormat->fBitDepth, sampleRate.whole);
mPollInterval = (UInt32) (1 << ((UInt32) usbAudio->GetEndpointPollInterval(usbInputStream.interfaceNumber, newAlternateSettingID, newDirection) -1));
if ((1 != mPollInterval) && (8 != mPollInterval)) {
ReturnIf ( (1 != mPollInterval) && (8 != mPollInterval), kIOReturnError);
// disallow selection of endpoints with sub ms polling interval
//NB - assumes that sub ms device will not use a poll interval of 1 (every microframe)
newAlternateSettingID = 255;
}
debugIOLog ("%d channel %d bit @ %d Hz is not supported. Suggesting alternate setting %d", newFormat->fNumChannels,

debugIOLog ("direction %d, %d channel %d bit @ %d Hz is not supported. Suggesting alternate setting %d", newDirection, newFormat->fNumChannels,
newFormat->fBitDepth, sampleRate.whole, newAlternateSettingID);

ReturnIf (255 == newAlternateSettingID, kIOReturnError);
}

ReturnIf (newDirection != usbInputStream.streamDirection, kIOReturnError);
debugIOLog ("++about to set input : ourInterfaceNumber = %d & newAlternateSettingID = %d", usbInputStream.interfaceNumber, newAlternateSettingID);
beginConfigurationChange();

Expand Down Expand Up @@ -1538,7 +1538,9 @@ IOReturn EMUUSBAudioEngine::performFormatChangeInternal (IOAudioStream *audioStr
if (FALSE == usbAudio->VerifySampleRateIsSupported(mOutput.interfaceNumber, newAlternateSettingID, sampleRate.whole)) {
newAlternateSettingID = usbAudio->FindAltInterfaceWithSettings (mOutput.interfaceNumber, newFormat->fNumChannels, newFormat->fBitDepth, sampleRate.whole);
mPollInterval = (UInt32) (1 << ((UInt32) usbAudio->GetEndpointPollInterval(mOutput.interfaceNumber, newAlternateSettingID, newDirection) -1));
if ((1 != mPollInterval) || (8 != mPollInterval)) {// disallow selection of endpoints with sub ms polling interval NB - assumes that sub ms device will not use a poll interval of 1 (every microframe)
if ((1 != mPollInterval) && (8 != mPollInterval)) {
// disallow selection of endpoints with sub ms polling interval NB -
// assumes that sub ms device will not use a poll interval of 1 (every microframe)
newAlternateSettingID = 255;
}
debugIOLog ("%d channel %d bit @ %d Hz is not supported. Suggesting alternate setting %d", newFormat->fNumChannels,
Expand Down
7 changes: 4 additions & 3 deletions src/EMUUSBAudio/USBAudioObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ UInt8 EMUUSBAudioConfigObject::FindAltInterfaceWithSettings(UInt8 interfaceNum,
UInt8 potentialAltInterface = 1;
UInt8 theAltInterface = 255;

debugIOLogPC("Searching for alternative for interface %d, %d channels, rate %d", interfaceNum, numChannels, sampleRate);
// clumsy loop, straightforward write-out is lot smaller and readable. FIXME?
while(potentialAltInterface != 255) {
if((GetFormat(interfaceNum, potentialAltInterface) & 0x0FFF) != 0) { // Make sure it's not an undefined format
if((GetFormat(interfaceNum, potentialAltInterface) & 0x0FFF) != 0) { // Make sure it's a defined format
potentialAltInterface = FindNextAltInterfaceWithNumChannels(interfaceNum, potentialAltInterface, numChannels);
if(255 == potentialAltInterface) {
debugIOLogPC("Undefined format! No alternate setting ID for interface %d, %d channels", interfaceNum, numChannels);
Expand Down Expand Up @@ -316,14 +317,14 @@ UInt8 EMUUSBAudioConfigObject::GetEndpointPollInterval(UInt8 interfaceNum, UInt8
EMUUSBAudioStreamObject* stream = GetStreamObject(interfaceNum, altInterfaceNum);
if (!stream) {
IOLog("Bug? EMUUSBAudioConfigObject::GetEndpointPollInterval stream not opening");
return 1; // can we cancel the whole thing?
return 255;
}

UInt8 address = stream->GetIsocEndpointAddress(direction);
EMUUSBEndpointObject* endpoint = stream->GetEndpointByAddress(address);
if (!endpoint) {
IOLog("Bug? EMUUSBAudioConfigObject::GetEndpointPollInterval no endpoint");
return 1; // can we cancel the whole thing?
return 255;
}

pollInterval = endpoint->GetPollInt();
Expand Down
4 changes: 3 additions & 1 deletion src/EMUUSBAudio/USBAudioObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,9 @@ class EMUUSBAudioConfigObject : public OSObject {
UInt16 GetFormat (UInt8 interfaceNum, UInt8 altInterfaceNum);
UInt32 GetHighestSampleRate (UInt8 interfaceNum, UInt8 altInterfaceNum);
UInt32 GetEndpointMaxPacketSize(UInt8 interfaceNum, UInt8 altInterfaceNum, UInt8 address);
/*! get endpoint poll interval (bInterval), 1=every microframe, 2=every 2 microframes, 3=every 4 microframes, 4=every frame, etc */
/*! @return endpoint poll interval (bInterval), 1=every microframe, 2=every 2 microframes, 3=every 4 microframes, 4=8micro=1 full frame, etc.
Nomally the endpoint interval is computed as 1<<(pollinterval-1). If an error occurs, this returns 255.
*/
UInt8 GetEndpointPollInterval(UInt8 interfaceNum, UInt8 altInterfaceNum, UInt8 direction);

UInt8 GetIsocAssociatedEndpointAddress (UInt8 interfaceNum, UInt8 altInterfaceNum, UInt8 address);
Expand Down

0 comments on commit d8c570b

Please sign in to comment.