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:
@@ -380,7 +380,7 @@ MixerUnit::MixerUnit(AudioControlInterface* interface,
|
||||
mixerControlsSize = Mixer->length - 10 - Mixer->num_input_pins;
|
||||
fStringIndex = *(mixerControlsData + mixerControlsSize);
|
||||
|
||||
#if 1 // TEST
|
||||
#if 0 // TEST
|
||||
if (fOutChannelsNumber > 2) {
|
||||
// fOutChannelsNumber = 2;
|
||||
// fChannelsConfig = 0x03;
|
||||
@@ -959,46 +959,46 @@ AudioControlInterface::Init(size_t interface, usb_interface_info* Interface)
|
||||
InitACHeader(interface, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_INPUT_TERMINAL:
|
||||
control = new InputTerminal(this, Header);
|
||||
control = new(std::nothrow) InputTerminal(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_OUTPUT_TERMINAL:
|
||||
control = new OutputTerminal(this, Header);
|
||||
control = new(std::nothrow) OutputTerminal(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_MIXER_UNIT:
|
||||
control = new MixerUnit(this, Header);
|
||||
control = new(std::nothrow) MixerUnit(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_SELECTOR_UNIT:
|
||||
control = new SelectorUnit(this, Header);
|
||||
control = new(std::nothrow) SelectorUnit(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_FEATURE_UNIT:
|
||||
control = new FeatureUnit(this, Header);
|
||||
control = new(std::nothrow) FeatureUnit(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_PROCESSING_UNIT:
|
||||
if (SpecReleaseNumber() < 200)
|
||||
control = new ProcessingUnit(this, Header);
|
||||
control = new(std::nothrow) ProcessingUnit(this, Header);
|
||||
else
|
||||
control = new EffectUnit(this, Header);
|
||||
control = new(std::nothrow) EffectUnit(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_EXTENSION_UNIT:
|
||||
if (SpecReleaseNumber() < 200)
|
||||
control = new ExtensionUnit(this, Header);
|
||||
control = new(std::nothrow) ExtensionUnit(this, Header);
|
||||
else
|
||||
control = new ProcessingUnit(this, Header);
|
||||
control = new(std::nothrow) ProcessingUnit(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_EXTENSION_UNIT_R2:
|
||||
control = new ExtensionUnit(this, Header);
|
||||
control = new(std::nothrow) ExtensionUnit(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_CLOCK_SOURCE_R2:
|
||||
control = new ClockSource(this, Header);
|
||||
control = new(std::nothrow) ClockSource(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_CLOCK_SELECTOR_R2:
|
||||
control = new ClockSelector(this, Header);
|
||||
control = new(std::nothrow) ClockSelector(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_CLOCK_MULTIPLIER_R2:
|
||||
control = new ClockMultiplier(this, Header);
|
||||
control = new(std::nothrow) ClockMultiplier(this, Header);
|
||||
break;
|
||||
case USB_AUDIO_AC_SAMPLE_RATE_CONVERTER_R2:
|
||||
control = new SampleRateConverter(this, Header);
|
||||
control = new(std::nothrow) SampleRateConverter(this, Header);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1631,12 +1631,12 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
|
||||
|
||||
Vector<_MixPageCollector*> mixControls;
|
||||
|
||||
_MixPageCollector* genericPage = new _MixPageCollector("Mixer");
|
||||
_MixPageCollector* genericPage = new(std::nothrow) _MixPageCollector("Mixer");
|
||||
mixControls.PushBack(genericPage);
|
||||
|
||||
// page for extended in (>2) and out (>2) mixer controls
|
||||
size_t controlsOnExMixerPage = 0;
|
||||
_MixPageCollector* exMixerPage = new _MixPageCollector("Mixer");
|
||||
_MixPageCollector* exMixerPage = new(std::nothrow) _MixPageCollector("Mixer");
|
||||
|
||||
AudioChannelCluster* outCluster = mixer->OutCluster();
|
||||
|
||||
@@ -1740,7 +1740,7 @@ AudioControlInterface::_ListMixControlsForMixerUnit(int32& index,
|
||||
|
||||
if (controlsOnExMixerPage >= 6) {
|
||||
mixControls.PushBack(exMixerPage);
|
||||
exMixerPage = new _MixPageCollector("Mixer");
|
||||
exMixerPage = new(std::nothrow) _MixPageCollector("Mixer");
|
||||
controlsOnExMixerPage = 0;
|
||||
}
|
||||
}
|
||||
@@ -1879,13 +1879,13 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info)
|
||||
case USB_AUDIO_VOLUME_CONTROL:
|
||||
length = 2;
|
||||
break;
|
||||
//case 0: // Selector Unit
|
||||
case USB_AUDIO_MUTE_CONTROL:
|
||||
case USB_AUDIO_AUTOMATIC_GAIN_CONTROL:
|
||||
length = 1;
|
||||
break;
|
||||
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));
|
||||
continue;
|
||||
}
|
||||
@@ -1897,8 +1897,8 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info)
|
||||
length = 2;
|
||||
break;
|
||||
default:
|
||||
TRACE(ERR, "Control type %d is not suported\n",
|
||||
control->SubType());
|
||||
TRACE(ERR, "Control id:%08x of type %d is not supported\n",
|
||||
ID_FROM_CTLID(Info->values[i].id), control->SubType());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2009,7 +2009,8 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info)
|
||||
Info->values[i].enable);
|
||||
break;
|
||||
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));
|
||||
continue;
|
||||
}
|
||||
@@ -2032,8 +2033,8 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info)
|
||||
Info->values[i].gain);
|
||||
break;
|
||||
default:
|
||||
TRACE(ERR, "Control type %d is not suported\n",
|
||||
control->SubType());
|
||||
TRACE(ERR, "Control id:%08x of type %d is not supported\n",
|
||||
Info->values[i].id, control->SubType());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,18 +119,13 @@ _ASFormatDescriptor::GetSamFreq(const usb_audio_sampling_freq& freq)
|
||||
return freq.bytes[0] | freq.bytes[1] << 8 | freq.bytes[2] << 16;
|
||||
}
|
||||
|
||||
// TODO: beautify!!!
|
||||
|
||||
usb_audio_sampling_freq
|
||||
_ASFormatDescriptor::GetSamFreq(uint32 samplingRate)
|
||||
{
|
||||
usb_audio_sampling_freq freq;
|
||||
for (size_t i = 0; i < 3; 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;
|
||||
}
|
||||
|
||||
@@ -425,14 +420,15 @@ AudioStreamingInterface::AudioStreamingInterface(
|
||||
switch(Header->descriptor_subtype) {
|
||||
case USB_AUDIO_AS_GENERAL:
|
||||
if (ASInterface == 0)
|
||||
ASInterface = new ASInterfaceDescriptor(
|
||||
ASInterface = new(std::nothrow)
|
||||
ASInterfaceDescriptor(
|
||||
(usb_audio_streaming_interface_descriptor*)Header);
|
||||
else
|
||||
TRACE(ERR, "Duplicate AStream interface ignored.\n");
|
||||
break;
|
||||
case USB_AUDIO_AS_FORMAT_TYPE:
|
||||
if (ASFormat == 0)
|
||||
ASFormat = new TypeIFormatDescriptor(
|
||||
ASFormat = new(std::nothrow) TypeIFormatDescriptor(
|
||||
(usb_audio_format_descriptor*) Header);
|
||||
else
|
||||
TRACE(ERR, "Duplicate AStream format ignored.\n");
|
||||
@@ -449,7 +445,7 @@ AudioStreamingInterface::AudioStreamingInterface(
|
||||
if (ASEndpoint == 0) {
|
||||
usb_endpoint_descriptor* Endpoint
|
||||
= Interface->endpoint[0].descr;
|
||||
ASEndpoint = new ASEndpointDescriptor(Endpoint,
|
||||
ASEndpoint = new(std::nothrow) ASEndpointDescriptor(Endpoint,
|
||||
(usb_audio_streaming_endpoint_descriptor*)Header);
|
||||
} else
|
||||
TRACE(ERR, "Duplicate AStream endpoint ignored.\n");
|
||||
@@ -460,7 +456,7 @@ AudioStreamingInterface::AudioStreamingInterface(
|
||||
"unknown descriptor type %#04x.\n", Header->descriptor_type);
|
||||
}
|
||||
|
||||
fAlternates.Add(new AudioStreamAlternate(alt, ASInterface,
|
||||
fAlternates.Add(new(std::nothrow) AudioStreamAlternate(alt, ASInterface,
|
||||
ASEndpoint, ASFormat));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ Device::_MultiGetDescription(multi_description* multiDescription)
|
||||
for (int i = 0; i < fStreams.Count(); i++) {
|
||||
uint8 id = fStreams[i]->TerminalLink();
|
||||
_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) {
|
||||
// USBTerminals.PushFront(control);
|
||||
// fStreams[i]->GetFormatsAndRates(Description);
|
||||
@@ -320,7 +320,7 @@ Device::_MultiGetDescription(multi_description* multiDescription)
|
||||
// if (control->SubType() == IDSInputTerminal) {
|
||||
USBTerminals.PushBack(control);
|
||||
fStreams[i]->GetFormatsAndRates(&Description);
|
||||
//}
|
||||
// }
|
||||
}
|
||||
|
||||
Vector<multi_channel_info> Channels;
|
||||
@@ -619,7 +619,8 @@ Device::_SetupEndpoints()
|
||||
break;
|
||||
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()) {
|
||||
// put the stream in the correct order:
|
||||
// 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
|
||||
Device* audioDevice = new Device(device);
|
||||
Device* audioDevice = new(std::nothrow) Device(device);
|
||||
if (audioDevice == 0)
|
||||
return ENODEV;
|
||||
|
||||
|
||||
@@ -116,8 +116,8 @@ Stream::_ChooseAlternate()
|
||||
fIsInput = (endpoint->fEndpointAddress & USB_ENDPOINT_ADDR_DIR_IN)
|
||||
== USB_ENDPOINT_ADDR_DIR_IN;
|
||||
|
||||
// if (fIsInput)
|
||||
// fCurrentBuffer = -1;
|
||||
if (fIsInput)
|
||||
fCurrentBuffer = -1;
|
||||
|
||||
TRACE(INF, "Alternate %d EP:%x selected for %s!\n",
|
||||
fActiveAlternate, endpoint->fEndpointAddress,
|
||||
@@ -131,7 +131,6 @@ status_t
|
||||
Stream::Init()
|
||||
{
|
||||
fStatus = _ChooseAlternate();
|
||||
//if (fStatus != B_OK)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
@@ -186,9 +185,6 @@ Stream::_SetupBuffers()
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
// physical_entry PhysEntry;
|
||||
// get_memory_map(fDescriptors, fAreaSize, &PhysEntry, 1);
|
||||
|
||||
TRACE(INF, "Created area id:%d at addr:%#010x size:%#010lx\n",
|
||||
fArea, fDescriptors, fAreaSize);
|
||||
}
|
||||
@@ -258,11 +254,8 @@ Stream::Start()
|
||||
{
|
||||
status_t result = B_BUSY;
|
||||
if (!fIsRunning) {
|
||||
//if (!fIsInput) { // TODO: recording
|
||||
for (size_t i = 0; i < kSamplesBufferCount; i++)
|
||||
result = _QueueNextTransfer(i, true);
|
||||
//} else
|
||||
// result = B_OK;
|
||||
fIsRunning = result == B_OK;
|
||||
}
|
||||
return result;
|
||||
@@ -433,9 +426,6 @@ Stream::SetGlobalFormat(multi_format_info* Format)
|
||||
uint32 samplingRate = fAlternates[fActiveAlternate]->GetSamplingRate();
|
||||
size_t actualLength = 0;
|
||||
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;
|
||||
|
||||
status = gUSBModule->send_request(fDevice->fDevice,
|
||||
@@ -527,11 +517,8 @@ Stream::GetBuffers(multi_buffer_list* List)
|
||||
bool
|
||||
Stream::ExchangeBuffer(multi_buffer_info* Info)
|
||||
{
|
||||
if (fProcessedBuffers <= 0) //{
|
||||
// looks like somebody else has processed buffers but this stream
|
||||
// release_sem_etc(fDevice->fBuffersReadySem, 1, B_DO_NOT_RESCHEDULE);
|
||||
if (fProcessedBuffers <= 0)
|
||||
return false;
|
||||
// }
|
||||
|
||||
if (fIsInput) {
|
||||
Info->recorded_real_time = system_time();// TODO fRealTime;
|
||||
|
||||
Reference in New Issue
Block a user