status_t AVFormatReader::AllocateCookie(int32 streamIndex, void** _cookie) { TRACE("AVFormatReader::AllocateCookie(%ld)\n", streamIndex); BAutolock _(fSourceLock); if (fStreams == NULL) return B_NO_INIT; if (streamIndex < 0 || streamIndex >= fStreams[0]->CountStreams()) return B_BAD_INDEX; if (_cookie == NULL) return B_BAD_VALUE; Stream* cookie = fStreams[streamIndex]; if (cookie == NULL) { // Allocate the cookie BPositionIO* source = dynamic_cast<BPositionIO*>(Source()); if (source == NULL) { TRACE(" not a BPositionIO, but we need it to be one.\n"); return B_NOT_SUPPORTED; } cookie = new(std::nothrow) Stream(source, &fSourceLock); if (cookie == NULL) { ERROR("AVFormatReader::Sniff() - failed to allocate " "Stream\n"); return B_NO_MEMORY; } status_t ret = cookie->Open(); if (ret != B_OK) { TRACE(" stream failed to open: %s\n", strerror(ret)); delete cookie; return ret; } } status_t ret = cookie->Init(streamIndex); if (ret != B_OK) { TRACE(" stream failed to initialize: %s\n", strerror(ret)); // NOTE: Never delete the first stream! if (streamIndex != 0) delete cookie; return ret; } fStreams[streamIndex] = cookie; *_cookie = cookie; return B_OK; }
status_t Device::_SetupEndpoints() { const usb_configuration_info *config = gUSBModule->get_nth_configuration(fDevice, 0); if (config == NULL) { TRACE_ALWAYS("Error of getting USB device configuration.\n"); return B_ERROR; } if (config->interface_count <= 0) { TRACE_ALWAYS("Error:no interfaces found in USB device configuration\n"); return B_ERROR; } for (size_t i = 0; i < config->interface_count; i++) { usb_interface_info *Interface = config->interface[i].active; if (Interface->descr->interface_class != UAS_AUDIO) { continue; } switch (Interface->descr->interface_subclass) { case UAS_AUDIOCONTROL: fAudioControl.Init(i, Interface); break; case UAS_AUDIOSTREAMING: { Stream *stream = new Stream(this, i, &config->interface[i]); if (B_OK == stream->Init()) { // put the stream in the correct order: // first output that input ones. if (stream->IsInput()) { fStreams.PushBack(stream); } else { fStreams.PushFront(stream); } } else { delete stream; } } break; default: TRACE_ALWAYS("Ignore interface of unsupported subclass %#x.\n", Interface->descr->interface_subclass); break; } } if (fAudioControl.InitCheck() == B_OK && fStreams.Count() > 0) { TRACE("Found device %#06x:%#06x\n", fVendorID, fProductID); gUSBModule->set_configuration(fDevice, config); for (int i = 0; i < fStreams.Count(); i++) { fStreams[i]->OnSetConfiguration(fDevice, config); } return B_OK; } return B_NO_INIT; }