USB audio: use new(std::nothrow) for allocations

* Use new(std::nothrow) for allocations;
* Input buffer index counter restored;
* Improve unsupported UI controls debug info tracing;
* Some cleanup.
This commit is contained in:
Siarzhuk Zharski
2013-08-18 14:49:51 +02:00
parent 743d75946f
commit 14f92002e1
7 changed files with 81 additions and 96 deletions
@@ -380,7 +380,7 @@ MixerUnit::MixerUnit(AudioControlInterface* interface,
mixerControlsSize = Mixer->length - 10 - Mixer->num_input_pins; mixerControlsSize = Mixer->length - 10 - Mixer->num_input_pins;
fStringIndex = *(mixerControlsData + mixerControlsSize); fStringIndex = *(mixerControlsData + mixerControlsSize);
#if 1 // TEST #if 0 // TEST
if (fOutChannelsNumber > 2) { if (fOutChannelsNumber > 2) {
// fOutChannelsNumber = 2; // fOutChannelsNumber = 2;
// fChannelsConfig = 0x03; // fChannelsConfig = 0x03;
@@ -397,7 +397,7 @@ MixerUnit::MixerUnit(AudioControlInterface* interface,
mixerControlsData[10] = 0x02; mixerControlsData[10] = 0x02;
mixerControlsData[11] = 0x01; mixerControlsData[11] = 0x01;
} }
#endif #endif
} else { } else {
usb_audio_output_channels_descriptor* OutChannels usb_audio_output_channels_descriptor* OutChannels
@@ -511,7 +511,7 @@ SelectorUnit::OutCluster()
{ {
if (fInterface == NULL) if (fInterface == NULL)
return NULL; return NULL;
for (int i = 0; i < fInputPins.Count(); i++) { for (int i = 0; i < fInputPins.Count(); i++) {
_AudioControl* control = fInterface->Find(fInputPins[i]); _AudioControl* control = fInterface->Find(fInputPins[i]);
if (control == NULL) if (control == NULL)
@@ -724,7 +724,7 @@ ProcessingUnit::ProcessingUnit(AudioControlInterface* interface,
TRACE(UAC, "Number of input pins:%d\n", Processing->num_input_pins); TRACE(UAC, "Number of input pins:%d\n", Processing->num_input_pins);
for (size_t i = 0; i < Processing->num_input_pins; i++) { for (size_t i = 0; i < Processing->num_input_pins; i++) {
fInputPins.PushBack(Processing->input_pins[i]); fInputPins.PushBack(Processing->input_pins[i]);
TRACE(UAC, "Input pin #%d:%d\n", i, fInputPins[i]); TRACE(UAC, "Input pin #%d:%d\n", i, fInputPins[i]);
} }
@@ -959,46 +959,46 @@ AudioControlInterface::Init(size_t interface, usb_interface_info* Interface)
InitACHeader(interface, Header); InitACHeader(interface, Header);
break; break;
case USB_AUDIO_AC_INPUT_TERMINAL: case USB_AUDIO_AC_INPUT_TERMINAL:
control = new InputTerminal(this, Header); control = new(std::nothrow) InputTerminal(this, Header);
break; break;
case USB_AUDIO_AC_OUTPUT_TERMINAL: case USB_AUDIO_AC_OUTPUT_TERMINAL:
control = new OutputTerminal(this, Header); control = new(std::nothrow) OutputTerminal(this, Header);
break; break;
case USB_AUDIO_AC_MIXER_UNIT: case USB_AUDIO_AC_MIXER_UNIT:
control = new MixerUnit(this, Header); control = new(std::nothrow) MixerUnit(this, Header);
break; break;
case USB_AUDIO_AC_SELECTOR_UNIT: case USB_AUDIO_AC_SELECTOR_UNIT:
control = new SelectorUnit(this, Header); control = new(std::nothrow) SelectorUnit(this, Header);
break; break;
case USB_AUDIO_AC_FEATURE_UNIT: case USB_AUDIO_AC_FEATURE_UNIT:
control = new FeatureUnit(this, Header); control = new(std::nothrow) FeatureUnit(this, Header);
break; break;
case USB_AUDIO_AC_PROCESSING_UNIT: case USB_AUDIO_AC_PROCESSING_UNIT:
if (SpecReleaseNumber() < 200) if (SpecReleaseNumber() < 200)
control = new ProcessingUnit(this, Header); control = new(std::nothrow) ProcessingUnit(this, Header);
else else
control = new EffectUnit(this, Header); control = new(std::nothrow) EffectUnit(this, Header);
break; break;
case USB_AUDIO_AC_EXTENSION_UNIT: case USB_AUDIO_AC_EXTENSION_UNIT:
if (SpecReleaseNumber() < 200) if (SpecReleaseNumber() < 200)
control = new ExtensionUnit(this, Header); control = new(std::nothrow) ExtensionUnit(this, Header);
else else
control = new ProcessingUnit(this, Header); control = new(std::nothrow) ProcessingUnit(this, Header);
break; break;
case USB_AUDIO_AC_EXTENSION_UNIT_R2: case USB_AUDIO_AC_EXTENSION_UNIT_R2:
control = new ExtensionUnit(this, Header); control = new(std::nothrow) ExtensionUnit(this, Header);
break; break;
case USB_AUDIO_AC_CLOCK_SOURCE_R2: case USB_AUDIO_AC_CLOCK_SOURCE_R2:
control = new ClockSource(this, Header); control = new(std::nothrow) ClockSource(this, Header);
break; break;
case USB_AUDIO_AC_CLOCK_SELECTOR_R2: case USB_AUDIO_AC_CLOCK_SELECTOR_R2:
control = new ClockSelector(this, Header); control = new(std::nothrow) ClockSelector(this, Header);
break; break;
case USB_AUDIO_AC_CLOCK_MULTIPLIER_R2: case USB_AUDIO_AC_CLOCK_MULTIPLIER_R2:
control = new ClockMultiplier(this, Header); control = new(std::nothrow) ClockMultiplier(this, Header);
break; break;
case USB_AUDIO_AC_SAMPLE_RATE_CONVERTER_R2: case USB_AUDIO_AC_SAMPLE_RATE_CONVERTER_R2:
control = new SampleRateConverter(this, Header); control = new(std::nothrow) SampleRateConverter(this, Header);
break; break;
} }
@@ -1551,7 +1551,7 @@ AudioControlInterface::_CollectMixerUnitControls(
else else
count++; count++;
} }
// take care about surround bus // take care about surround bus
if (inLeft == inRight) if (inLeft == inRight)
break; break;
@@ -1628,16 +1628,16 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
{ 15, 17, "Top Back" }, { 15, 17, "Top Back" },
{ 16, 16, "Top Back Center" } { 16, 16, "Top Back Center" }
}; };
Vector<_MixPageCollector*> mixControls; Vector<_MixPageCollector*> mixControls;
_MixPageCollector* genericPage = new _MixPageCollector("Mixer"); _MixPageCollector* genericPage = new(std::nothrow) _MixPageCollector("Mixer");
mixControls.PushBack(genericPage); mixControls.PushBack(genericPage);
// page for extended in (>2) and out (>2) mixer controls // page for extended in (>2) and out (>2) mixer controls
size_t controlsOnExMixerPage = 0; size_t controlsOnExMixerPage = 0;
_MixPageCollector* exMixerPage = new _MixPageCollector("Mixer"); _MixPageCollector* exMixerPage = new(std::nothrow) _MixPageCollector("Mixer");
AudioChannelCluster* outCluster = mixer->OutCluster(); AudioChannelCluster* outCluster = mixer->OutCluster();
int inOffset = 0; int inOffset = 0;
@@ -1659,7 +1659,7 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
&& inChannel < inCluster->ChannelsCount(); in++) { && inChannel < inCluster->ChannelsCount(); in++) {
if ((inCluster->ChannelsConfig() & (1 << in)) == 0) if ((inCluster->ChannelsConfig() & (1 << in)) == 0)
continue; continue;
for (size_t out = 0, outChannel = 0; out < kChannels for (size_t out = 0, outChannel = 0; out < kChannels
&& outChannel < outCluster->ChannelsCount(); out++) { && outChannel < outCluster->ChannelsCount(); out++) {
if ((outCluster->ChannelsConfig() & (1 << out)) == 0) if ((outCluster->ChannelsConfig() & (1 << out)) == 0)
@@ -1677,7 +1677,7 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
(inOffset + inChannel) * outCluster->ChannelsCount() (inOffset + inChannel) * outCluster->ChannelsCount()
+ outChannel, mixer->ID(), fInterface); + outChannel, mixer->ID(), fInterface);
} }
outChannel++; outChannel++;
} }
@@ -1693,7 +1693,7 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
controlIds[in][out], in, out); controlIds[in][out], in, out);
// second step - distribute controls on // second step - distribute controls on
// mixer pages in logical groups // mixer pages in logical groups
uint32 exChannelsMask = ~(B_CHANNEL_LEFT | B_CHANNEL_RIGHT); uint32 exChannelsMask = ~(B_CHANNEL_LEFT | B_CHANNEL_RIGHT);
bool inIsEx = (inCluster->ChannelsConfig() & exChannelsMask) != 0; bool inIsEx = (inCluster->ChannelsConfig() & exChannelsMask) != 0;
bool outIsEx = (outCluster->ChannelsConfig() & exChannelsMask) != 0; bool outIsEx = (outCluster->ChannelsConfig() & exChannelsMask) != 0;
@@ -1707,8 +1707,8 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
control->Name(), channelPairs[i].name, control->Name(), channelPairs[i].name,
*mixControls[0]); *mixControls[0]);
continue; // go next input cluster continue; // go next input cluster
} }
if (!outIsEx) { if (!outIsEx) {
// special case - extended (>2 channels) input cluster // special case - extended (>2 channels) input cluster
// connected to 2-channels output - add into generic "Mixer" page // connected to 2-channels output - add into generic "Mixer" page
@@ -1729,9 +1729,9 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
if (in == out) if (in == out)
strlcpy(outName, channelPairs[out].name, sizeof(outName)); strlcpy(outName, channelPairs[out].name, sizeof(outName));
else else
snprintf(outName, sizeof(outName), "%s to %s", snprintf(outName, sizeof(outName), "%s to %s",
channelPairs[in].name, channelPairs[out].name); channelPairs[in].name, channelPairs[out].name);
controlsOnExMixerPage += _CollectMixerUnitControls(controlIds, controlsOnExMixerPage += _CollectMixerUnitControls(controlIds,
channelPairs[in].inLeft, channelPairs[out].inLeft, channelPairs[in].inLeft, channelPairs[out].inLeft,
channelPairs[in].inRight, channelPairs[out].inRight, channelPairs[in].inRight, channelPairs[out].inRight,
@@ -1740,7 +1740,7 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
if (controlsOnExMixerPage >= 6) { if (controlsOnExMixerPage >= 6) {
mixControls.PushBack(exMixerPage); mixControls.PushBack(exMixerPage);
exMixerPage = new _MixPageCollector("Mixer"); exMixerPage = new(std::nothrow) _MixPageCollector("Mixer");
controlsOnExMixerPage = 0; controlsOnExMixerPage = 0;
} }
} }
@@ -1750,7 +1750,7 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
mixControls.PushBack(exMixerPage); mixControls.PushBack(exMixerPage);
else else
delete exMixerPage; delete exMixerPage;
// final step - fill multiaudio controls info with // final step - fill multiaudio controls info with
// already structured pages/controls info arrays // already structured pages/controls info arrays
for (Vector<_MixPageCollector*>::Iterator I = mixControls.Begin(); for (Vector<_MixPageCollector*>::Iterator I = mixControls.Begin();
@@ -1808,7 +1808,7 @@ AudioControlInterface::ListMixControls(multi_mix_control_info* Info)
} }
// separate input and output Feature units // separate input and output Feature units
// and collect mixer units that can be controlled // and collect mixer units that can be controlled
AudioControlsMap InputControlsMap; AudioControlsMap InputControlsMap;
AudioControlsMap OutputControlsMap; AudioControlsMap OutputControlsMap;
AudioControlsMap MixerControlsMap; AudioControlsMap MixerControlsMap;
@@ -1872,20 +1872,20 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info)
ID_FROM_CTLID(Info->values[i].id)); ID_FROM_CTLID(Info->values[i].id));
continue; continue;
} }
switch (control->SubType()) { switch (control->SubType()) {
case USB_AUDIO_AC_FEATURE_UNIT: case USB_AUDIO_AC_FEATURE_UNIT:
switch(CS_FROM_CTLID(Info->values[i].id)) { switch(CS_FROM_CTLID(Info->values[i].id)) {
case USB_AUDIO_VOLUME_CONTROL: case USB_AUDIO_VOLUME_CONTROL:
length = 2; length = 2;
break; break;
//case 0: // Selector Unit
case USB_AUDIO_MUTE_CONTROL: case USB_AUDIO_MUTE_CONTROL:
case USB_AUDIO_AUTOMATIC_GAIN_CONTROL: case USB_AUDIO_AUTOMATIC_GAIN_CONTROL:
length = 1; length = 1;
break; break;
default: default:
TRACE(ERR, "Unsupported control type %#02x ignored.\n", TRACE(ERR, "Unsupported control id:%08x of type %#02x "
"ignored.\n", ID_FROM_CTLID(Info->values[i].id),
CS_FROM_CTLID(Info->values[i].id)); CS_FROM_CTLID(Info->values[i].id));
continue; continue;
} }
@@ -1897,8 +1897,8 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info)
length = 2; length = 2;
break; break;
default: default:
TRACE(ERR, "Control type %d is not suported\n", TRACE(ERR, "Control id:%08x of type %d is not supported\n",
control->SubType()); ID_FROM_CTLID(Info->values[i].id), control->SubType());
continue; continue;
} }
@@ -1977,7 +1977,7 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info)
ID_FROM_CTLID(Info->values[i].id)); ID_FROM_CTLID(Info->values[i].id));
continue; continue;
} }
switch (control->SubType()) { switch (control->SubType()) {
case USB_AUDIO_AC_FEATURE_UNIT: case USB_AUDIO_AC_FEATURE_UNIT:
switch(CS_FROM_CTLID(Info->values[i].id)) { switch(CS_FROM_CTLID(Info->values[i].id)) {
@@ -2009,7 +2009,8 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info)
Info->values[i].enable); Info->values[i].enable);
break; break;
default: default:
TRACE(ERR, "Unsupported control type %#02x ignored.\n", TRACE(ERR, "Unsupported control id:%08x of type %#02x "
"ignored.\n", ID_FROM_CTLID(Info->values[i].id),
CS_FROM_CTLID(Info->values[i].id)); CS_FROM_CTLID(Info->values[i].id));
continue; continue;
} }
@@ -2032,8 +2033,8 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info)
Info->values[i].gain); Info->values[i].gain);
break; break;
default: default:
TRACE(ERR, "Control type %d is not suported\n", TRACE(ERR, "Control id:%08x of type %d is not supported\n",
control->SubType()); Info->values[i].id, control->SubType());
continue; continue;
} }
@@ -29,7 +29,7 @@ public:
uint8 ChannelsCount() { return fOutChannelsNumber; } uint8 ChannelsCount() { return fOutChannelsNumber; }
uint32 ChannelsConfig() { return fChannelsConfig; } uint32 ChannelsConfig() { return fChannelsConfig; }
bool HasChannel(uint32 location); bool HasChannel(uint32 location);
protected: protected:
@@ -104,7 +104,7 @@ public:
InputTerminal(AudioControlInterface* interface, InputTerminal(AudioControlInterface* interface,
usb_audiocontrol_header_descriptor* Header); usb_audiocontrol_header_descriptor* Header);
virtual ~InputTerminal(); virtual ~InputTerminal();
virtual const char* Name(); virtual const char* Name();
protected: protected:
@@ -128,7 +128,7 @@ public:
MixerUnit(AudioControlInterface* interface, MixerUnit(AudioControlInterface* interface,
usb_audiocontrol_header_descriptor* Header); usb_audiocontrol_header_descriptor* Header);
virtual ~MixerUnit(); virtual ~MixerUnit();
virtual const char* Name() { return "Mixer"; } virtual const char* Name() { return "Mixer"; }
bool HasProgrammableControls(); bool HasProgrammableControls();
bool IsControlProgrammable(int inChannel, int outChannel); bool IsControlProgrammable(int inChannel, int outChannel);
@@ -48,7 +48,7 @@ ASInterfaceDescriptor::ASInterfaceDescriptor(
fDelay(0), fDelay(0),
fFormatTag(0) fFormatTag(0)
{ {
// TODO: what aboput rev 2??????? // TODO: what aboput rev 2???????
fTerminalLink = Descriptor->terminal_link; fTerminalLink = Descriptor->terminal_link;
fDelay = Descriptor->r1.delay; fDelay = Descriptor->r1.delay;
fFormatTag = Descriptor->r1.format_tag; fFormatTag = Descriptor->r1.format_tag;
@@ -119,18 +119,13 @@ _ASFormatDescriptor::GetSamFreq(const usb_audio_sampling_freq& freq)
return freq.bytes[0] | freq.bytes[1] << 8 | freq.bytes[2] << 16; return freq.bytes[0] | freq.bytes[1] << 8 | freq.bytes[2] << 16;
} }
// TODO: beautify!!!
usb_audio_sampling_freq usb_audio_sampling_freq
_ASFormatDescriptor::GetSamFreq(uint32 samplingRate) _ASFormatDescriptor::GetSamFreq(uint32 samplingRate)
{ {
usb_audio_sampling_freq freq; usb_audio_sampling_freq freq;
for (size_t i = 0; i < 3; i++) for (size_t i = 0; i < 3; i++)
freq.bytes[i] = 0xFF & samplingRate >> 8 * i; freq.bytes[i] = 0xFF & samplingRate >> 8 * i;
// return freq.bytes[0] | freq.bytes[1] << 8 | freq.bytes[2] << 16;
/* data[0] = 0xFF & samplingRate;
data[1] = 0xFF & samplingRate >> 8;
data[2] = 0xFF & samplingRate >> 16; */
return freq; return freq;
} }
@@ -244,10 +239,10 @@ AudioStreamAlternate::SetSamplingRate(uint32 newRate)
TRACE(ERR, "Format not set for active alternate\n"); TRACE(ERR, "Format not set for active alternate\n");
return B_NO_INIT; return B_NO_INIT;
} }
Vector<uint32>& frequencies = format->fSampleFrequencies; Vector<uint32>& frequencies = format->fSampleFrequencies;
bool continuous = format->fSampleFrequencyType == 0; bool continuous = format->fSampleFrequencyType == 0;
if (newRate == 0) { // by default select max available if (newRate == 0) { // by default select max available
fSamplingRate = 0; fSamplingRate = 0;
if (continuous) if (continuous)
@@ -305,7 +300,7 @@ AudioStreamAlternate::GetSamplingRateIds()
TRACE(ERR, "Format not set for active alternate\n"); TRACE(ERR, "Format not set for active alternate\n");
return 0; return 0;
} }
uint32 rates = 0; uint32 rates = 0;
Vector<uint32>& frequencies = format->fSampleFrequencies; Vector<uint32>& frequencies = format->fSampleFrequencies;
if (format->fSampleFrequencyType == 0) { // continuous frequencies if (format->fSampleFrequencyType == 0) { // continuous frequencies
@@ -366,7 +361,7 @@ AudioStreamAlternate::GetFormatId()
Interface()->fFormatTag); Interface()->fFormatTag);
break; break;
} }
return formats; return formats;
} }
@@ -425,14 +420,15 @@ AudioStreamingInterface::AudioStreamingInterface(
switch(Header->descriptor_subtype) { switch(Header->descriptor_subtype) {
case USB_AUDIO_AS_GENERAL: case USB_AUDIO_AS_GENERAL:
if (ASInterface == 0) if (ASInterface == 0)
ASInterface = new ASInterfaceDescriptor( ASInterface = new(std::nothrow)
ASInterfaceDescriptor(
(usb_audio_streaming_interface_descriptor*)Header); (usb_audio_streaming_interface_descriptor*)Header);
else else
TRACE(ERR, "Duplicate AStream interface ignored.\n"); TRACE(ERR, "Duplicate AStream interface ignored.\n");
break; break;
case USB_AUDIO_AS_FORMAT_TYPE: case USB_AUDIO_AS_FORMAT_TYPE:
if (ASFormat == 0) if (ASFormat == 0)
ASFormat = new TypeIFormatDescriptor( ASFormat = new(std::nothrow) TypeIFormatDescriptor(
(usb_audio_format_descriptor*) Header); (usb_audio_format_descriptor*) Header);
else else
TRACE(ERR, "Duplicate AStream format ignored.\n"); TRACE(ERR, "Duplicate AStream format ignored.\n");
@@ -449,7 +445,7 @@ AudioStreamingInterface::AudioStreamingInterface(
if (ASEndpoint == 0) { if (ASEndpoint == 0) {
usb_endpoint_descriptor* Endpoint usb_endpoint_descriptor* Endpoint
= Interface->endpoint[0].descr; = Interface->endpoint[0].descr;
ASEndpoint = new ASEndpointDescriptor(Endpoint, ASEndpoint = new(std::nothrow) ASEndpointDescriptor(Endpoint,
(usb_audio_streaming_endpoint_descriptor*)Header); (usb_audio_streaming_endpoint_descriptor*)Header);
} else } else
TRACE(ERR, "Duplicate AStream endpoint ignored.\n"); TRACE(ERR, "Duplicate AStream endpoint ignored.\n");
@@ -460,7 +456,7 @@ AudioStreamingInterface::AudioStreamingInterface(
"unknown descriptor type %#04x.\n", Header->descriptor_type); "unknown descriptor type %#04x.\n", Header->descriptor_type);
} }
fAlternates.Add(new AudioStreamAlternate(alt, ASInterface, fAlternates.Add(new(std::nothrow) AudioStreamAlternate(alt, ASInterface,
ASEndpoint, ASFormat)); ASEndpoint, ASFormat));
} }
} }
@@ -312,7 +312,7 @@ Device::_MultiGetDescription(multi_description* multiDescription)
for (int i = 0; i < fStreams.Count(); i++) { for (int i = 0; i < fStreams.Count(); i++) {
uint8 id = fStreams[i]->TerminalLink(); uint8 id = fStreams[i]->TerminalLink();
_AudioControl* control = fAudioControl.Find(id); _AudioControl* control = fAudioControl.Find(id);
//if (control->SubType() == USB_AUDIO_AC_OUTPUT_TERMINAL) { // if (control->SubType() == USB_AUDIO_AC_OUTPUT_TERMINAL) {
// if (control->SubType() == USB_AUDIO_AC_INPUT_TERMINAL) { // if (control->SubType() == USB_AUDIO_AC_INPUT_TERMINAL) {
// USBTerminals.PushFront(control); // USBTerminals.PushFront(control);
// fStreams[i]->GetFormatsAndRates(Description); // fStreams[i]->GetFormatsAndRates(Description);
@@ -320,7 +320,7 @@ Device::_MultiGetDescription(multi_description* multiDescription)
// if (control->SubType() == IDSInputTerminal) { // if (control->SubType() == IDSInputTerminal) {
USBTerminals.PushBack(control); USBTerminals.PushBack(control);
fStreams[i]->GetFormatsAndRates(&Description); fStreams[i]->GetFormatsAndRates(&Description);
//} // }
} }
Vector<multi_channel_info> Channels; Vector<multi_channel_info> Channels;
@@ -619,7 +619,8 @@ Device::_SetupEndpoints()
break; break;
case USB_AUDIO_INTERFACE_AUDIOSTREAMING_SUBCLASS: case USB_AUDIO_INTERFACE_AUDIOSTREAMING_SUBCLASS:
{ {
Stream* stream = new Stream(this, i, &config->interface[i]); Stream* stream = new(std::nothrow) Stream(this, i,
&config->interface[i]);
if (B_OK == stream->Init()) { if (B_OK == stream->Init()) {
// put the stream in the correct order: // put the stream in the correct order:
// first output that input ones. // first output that input ones.
@@ -46,7 +46,7 @@ usb_audio_device_added(usb_device device, void** cookie)
} }
// no such device yet, create a new one // no such device yet, create a new one
Device* audioDevice = new Device(device); Device* audioDevice = new(std::nothrow) Device(device);
if (audioDevice == 0) if (audioDevice == 0)
return ENODEV; return ENODEV;
@@ -116,8 +116,8 @@ Stream::_ChooseAlternate()
fIsInput = (endpoint->fEndpointAddress & USB_ENDPOINT_ADDR_DIR_IN) fIsInput = (endpoint->fEndpointAddress & USB_ENDPOINT_ADDR_DIR_IN)
== USB_ENDPOINT_ADDR_DIR_IN; == USB_ENDPOINT_ADDR_DIR_IN;
// if (fIsInput) if (fIsInput)
// fCurrentBuffer = -1; fCurrentBuffer = -1;
TRACE(INF, "Alternate %d EP:%x selected for %s!\n", TRACE(INF, "Alternate %d EP:%x selected for %s!\n",
fActiveAlternate, endpoint->fEndpointAddress, fActiveAlternate, endpoint->fEndpointAddress,
@@ -131,7 +131,6 @@ status_t
Stream::Init() Stream::Init()
{ {
fStatus = _ChooseAlternate(); fStatus = _ChooseAlternate();
//if (fStatus != B_OK)
return fStatus; return fStatus;
} }
@@ -156,10 +155,10 @@ Stream::_SetupBuffers()
// allocate buffer for worst (maximal size) case // allocate buffer for worst (maximal size) case
TypeIFormatDescriptor* format = static_cast<TypeIFormatDescriptor*>( TypeIFormatDescriptor* format = static_cast<TypeIFormatDescriptor*>(
fAlternates[fActiveAlternate]->Format()); fAlternates[fActiveAlternate]->Format());
uint32 samplingRate = fAlternates[fActiveAlternate]->GetSamplingRate(); uint32 samplingRate = fAlternates[fActiveAlternate]->GetSamplingRate();
uint32 sampleSize = format->fNumChannels * format->fSubframeSize; uint32 sampleSize = format->fNumChannels * format->fSubframeSize;
// data size pro 1 ms USB 1 frame or 1/8 ms USB 2 microframe // data size pro 1 ms USB 1 frame or 1/8 ms USB 2 microframe
fPacketSize = samplingRate * sampleSize fPacketSize = samplingRate * sampleSize
/ (fDevice->fUSBVersion < 0x0200 ? 1000 : 8000); / (fDevice->fUSBVersion < 0x0200 ? 1000 : 8000);
@@ -178,7 +177,7 @@ Stream::_SetupBuffers()
: DRIVER_NAME "_playback_area", (void**)&fDescriptors, : DRIVER_NAME "_playback_area", (void**)&fDescriptors,
B_ANY_KERNEL_ADDRESS, fAreaSize, B_CONTIGUOUS, B_ANY_KERNEL_ADDRESS, fAreaSize, B_CONTIGUOUS,
B_READ_AREA | B_WRITE_AREA); B_READ_AREA | B_WRITE_AREA);
if (fArea < 0) { if (fArea < 0) {
TRACE(ERR, "Error of creating %#x - " TRACE(ERR, "Error of creating %#x - "
"bytes size buffer area:%#010x\n", fAreaSize, fArea); "bytes size buffer area:%#010x\n", fAreaSize, fArea);
@@ -186,9 +185,6 @@ Stream::_SetupBuffers()
return fStatus; return fStatus;
} }
// physical_entry PhysEntry;
// get_memory_map(fDescriptors, fAreaSize, &PhysEntry, 1);
TRACE(INF, "Created area id:%d at addr:%#010x size:%#010lx\n", TRACE(INF, "Created area id:%d at addr:%#010x size:%#010lx\n",
fArea, fDescriptors, fAreaSize); fArea, fDescriptors, fAreaSize);
} }
@@ -196,7 +192,7 @@ Stream::_SetupBuffers()
// descriptors count // descriptors count
fDescriptorsCount = fAreaSize fDescriptorsCount = fAreaSize
/ (sizeof(usb_iso_packet_descriptor) + fPacketSize); / (sizeof(usb_iso_packet_descriptor) + fPacketSize);
// we need same size sub-buffers. round it // we need same size sub-buffers. round it
fDescriptorsCount /= kSamplesBufferCount; fDescriptorsCount /= kSamplesBufferCount;
fDescriptorsCount *= kSamplesBufferCount; fDescriptorsCount *= kSamplesBufferCount;
@@ -258,11 +254,8 @@ Stream::Start()
{ {
status_t result = B_BUSY; status_t result = B_BUSY;
if (!fIsRunning) { if (!fIsRunning) {
//if (!fIsInput) { // TODO: recording for (size_t i = 0; i < kSamplesBufferCount; i++)
for (size_t i = 0; i < kSamplesBufferCount; i++) result = _QueueNextTransfer(i, true);
result = _QueueNextTransfer(i, true);
//} else
// result = B_OK;
fIsRunning = result == B_OK; fIsRunning = result == B_OK;
} }
return result; return result;
@@ -321,10 +314,10 @@ Stream::_TransferCallback(void* cookie, int32 status, void* data,
if (status == B_CANCELED || stream->fDevice->fRemoved) { if (status == B_CANCELED || stream->fDevice->fRemoved) {
atomic_add(&stream->fInsideNotify, -1); atomic_add(&stream->fInsideNotify, -1);
TRACE(ERR, "Cancelled: c:%p st:%#010x, data:%#010x, len:%d\n", TRACE(ERR, "Cancelled: c:%p st:%#010x, data:%#010x, len:%d\n",
cookie, status, data, actualLength); cookie, status, data, actualLength);
return; return;
} }
stream->fCurrentBuffer = (stream->fCurrentBuffer + 1) % kSamplesBufferCount; stream->fCurrentBuffer = (stream->fCurrentBuffer + 1) % kSamplesBufferCount;
stream->_DumpDescriptors(); stream->_DumpDescriptors();
@@ -337,7 +330,7 @@ Stream::_TransferCallback(void* cookie, int32 status, void* data,
release_sem_etc(stream->fDevice->fBuffersReadySem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(stream->fDevice->fBuffersReadySem, 1, B_DO_NOT_RESCHEDULE);
TRACE(DTA, "st:%#010x, data:%#010x, len:%d\n", status, data, actualLength); TRACE(DTA, "st:%#010x, data:%#010x, len:%d\n", status, data, actualLength);
atomic_add(&stream->fInsideNotify, -1); atomic_add(&stream->fInsideNotify, -1);
} }
@@ -429,20 +422,17 @@ Stream::SetGlobalFormat(multi_format_info* Format)
if (status != B_OK) if (status != B_OK)
return status; return status;
// set endpoint speed // set endpoint speed
uint32 samplingRate = fAlternates[fActiveAlternate]->GetSamplingRate(); uint32 samplingRate = fAlternates[fActiveAlternate]->GetSamplingRate();
size_t actualLength = 0; size_t actualLength = 0;
usb_audio_sampling_freq freq = _ASFormatDescriptor::GetSamFreq(samplingRate); usb_audio_sampling_freq freq = _ASFormatDescriptor::GetSamFreq(samplingRate);
/* data[0] = 0xFF & samplingRate;
data[1] = 0xFF & samplingRate >> 8;
data[2] = 0xFF & samplingRate >> 16; */
uint8 address = fAlternates[fActiveAlternate]->Endpoint()->fEndpointAddress; uint8 address = fAlternates[fActiveAlternate]->Endpoint()->fEndpointAddress;
status = gUSBModule->send_request(fDevice->fDevice, status = gUSBModule->send_request(fDevice->fDevice,
USB_REQTYPE_CLASS | USB_REQTYPE_ENDPOINT_OUT, USB_REQTYPE_CLASS | USB_REQTYPE_ENDPOINT_OUT,
USB_AUDIO_SET_CUR, USB_AUDIO_SAMPLING_FREQ_CONTROL << 8, USB_AUDIO_SET_CUR, USB_AUDIO_SAMPLING_FREQ_CONTROL << 8,
address, sizeof(freq), &freq, &actualLength); address, sizeof(freq), &freq, &actualLength);
TRACE(ERR, "set_speed %02x%02x%02x for ep %#x %d: %x\n", TRACE(ERR, "set_speed %02x%02x%02x for ep %#x %d: %x\n",
freq.bytes[0], freq.bytes[1], freq.bytes[2], freq.bytes[0], freq.bytes[1], freq.bytes[2],
address, actualLength, status); address, actualLength, status);
@@ -527,11 +517,8 @@ Stream::GetBuffers(multi_buffer_list* List)
bool bool
Stream::ExchangeBuffer(multi_buffer_info* Info) Stream::ExchangeBuffer(multi_buffer_info* Info)
{ {
if (fProcessedBuffers <= 0) //{ if (fProcessedBuffers <= 0)
// looks like somebody else has processed buffers but this stream
// release_sem_etc(fDevice->fBuffersReadySem, 1, B_DO_NOT_RESCHEDULE);
return false; return false;
// }
if (fIsInput) { if (fIsInput) {
Info->recorded_real_time = system_time();// TODO fRealTime; Info->recorded_real_time = system_time();// TODO fRealTime;
@@ -15,9 +15,9 @@
## 0x40 - USB audio control parsing ## 0x40 - USB audio control parsing
## default value: 0x01 ## default value: 0x01
#trace 0x7F #trace 0x7F
## logfile [full path to private log file] ## logfile [full path to private log file]
## default path value: /var/log/usb_asix.log ## default path value: /var/log/usb_asix.log
## if disabled - all output goes to syslog ## if disabled - all output goes to syslog