UdisksManager::UdisksManager(QObject *parent) : QObject(parent) { QDBusConnection system = QDBusConnection::systemBus(); if (!system.isConnected()) { emit error(tr("Cannot connect to Udisks daemon")); } system.connect("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceAdded", this, SLOT(onDeviceAdded(QDBusObjectPath))); system.connect("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceRemoved", this, SLOT(onDeviceRemoved(QDBusObjectPath))); system.connect("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", "DeviceChanged", this, SLOT(onDeviceChanged(QDBusObjectPath))); QDBusInterface devEnum("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", QDBusConnection::systemBus()); QDBusMessage enumRes = devEnum.call("EnumerateDevices"); // TODO/FIXME: error checking // if (enumRes.type() == QDBusMessage::ErrorMessage) // { // fprintf(stderr, "ERROR: Can't call EnumerateDevices\n"); // fprintf(stderr, " %s : %s\n", qPrintable(enumRes.errorName()), qPrintable(enumRes.errorMessage())); // } // // if (enumRes.type() != QDBusMessage::ReplyMessage || !enumRes.arguments().at(0).canConvert<QDBusArgument>()) // { // fprintf(stderr, "ERROR: Unexpected result type of EnumerateDevices call\n"); // } // const QDBusArgument enumArg = enumRes.arguments().at(0).value<QDBusArgument>(); // if (enumArg.currentType() != QDBusArgument::ArrayType) // { // fprintf(stderr, "ERROR: Unexpected argument type of EnumerateDevices call\n"); // } enumArg.beginArray(); while (!enumArg.atEnd()) { addDevice(qdbus_cast<QDBusObjectPath>(enumArg)); } enumArg.endArray(); }
void UDiskProvider::update() { QDBusInterface devEnum("org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks", QDBusConnection::systemBus()); QDBusMessage enumRes = devEnum.call("EnumerateDevices"); if (enumRes.type() != QDBusMessage::ReplyMessage || !enumRes.arguments().at(0).canConvert<QDBusArgument>()) { if (enumRes.type() == QDBusMessage::ErrorMessage) qWarning() << "ERROR: Can't call EnumerateDevices" << qPrintable(enumRes.errorName()) << qPrintable(enumRes.errorMessage()); else qWarning() << "ERROR: Unexpected result type of EnumerateDevices call"; return; } const QDBusArgument enumArg = enumRes.arguments().at(0).value<QDBusArgument>(); if (enumArg.currentType() != QDBusArgument::ArrayType) { qWarning() << "ERROR: Unexpected argument type of EnumerateDevices call"; return; } enumArg.beginArray(); while (!enumArg.atEnd()) { QDBusObjectPath path = qdbus_cast<QDBusObjectPath>(enumArg); if (mDevicesByPath.contains(path.path())) dbusDeviceChanged(path); else dbusDeviceAdded(path); } enumArg.endArray(); }
unsigned int findMatchingFormat(const std::vector<AudioStreamBasicDescription> &formatList, const AEAudioFormat &srcFormat) { unsigned int formatIdx = 0; float highestScore = 0; float currentScore = 0; AEDeviceEnumerationOSX devEnum((AudioDeviceID)0); // fprintf(stderr, "%s: Matching streamFormat for source: %s with samplerate: %d\n", __FUNCTION__, CAEUtil::DataFormatToStr(srcFormat.m_dataFormat), srcFormat.m_sampleRate); for (unsigned int i = 0; i < formatList.size(); i++) { AudioStreamBasicDescription desc = formatList[i]; std::string formatString; currentScore = devEnum.ScoreFormat(desc, srcFormat); // fprintf(stderr, "%s: Physical Format: %s idx: %d rated %f\n", __FUNCTION__, StreamDescriptionToString(desc, formatString), i, currentScore); if (currentScore > highestScore) { formatIdx = i; highestScore = currentScore; } } return formatIdx; }
QList<int> Backend::objectDescriptionIndexes(Phonon::ObjectDescriptionType type) const { QMutexLocker locker(&m_directShowMutex); QList<int> ret; switch(type) { case Phonon::AudioOutputDeviceType: { #ifdef Q_OS_WINCE ret << 0; // only one audio device with index 0 #else ComPointer<ICreateDevEnum> devEnum(CLSID_SystemDeviceEnum, IID_ICreateDevEnum); if (!devEnum) { return ret; //it is impossible to enumerate the devices } ComPointer<IEnumMoniker> enumMon; HRESULT hr = devEnum->CreateClassEnumerator(CLSID_AudioRendererCategory, enumMon.pparam(), 0); if (FAILED(hr)) { break; } AudioMoniker mon; //let's reorder the devices so that directshound appears first int nbds = 0; //number of directsound devices while (S_OK == enumMon->Next(1, mon.pparam(), 0)) { LPOLESTR str = 0; mon->GetDisplayName(0,0,&str); const QString name = QString::fromUtf16((const unsigned short*) str); ComPointer<IMalloc> alloc; ::CoGetMalloc(1, alloc.pparam()); alloc->Free(str); int insert_pos = 0; if (!m_audioOutputs.contains(mon)) { insert_pos = m_audioOutputs.count(); m_audioOutputs.append(mon); } else { insert_pos = m_audioOutputs.indexOf(mon); } if (name.contains(QLatin1String("DirectSound"))) { ret.insert(nbds++, insert_pos); } else { ret.append(insert_pos); } } #endif break; } #ifndef QT_NO_PHONON_EFFECT case Phonon::EffectType: { m_audioEffects.clear(); ComPointer<IEnumDMO> enumDMO; HRESULT hr = ::DMOEnum(DMOCATEGORY_AUDIO_EFFECT, DMO_ENUMF_INCLUDE_KEYED, 0, 0, 0, 0, enumDMO.pparam()); if (SUCCEEDED(hr)) { CLSID clsid; while (S_OK == enumDMO->Next(1, &clsid, 0, 0)) { ret += m_audioEffects.count(); m_audioEffects.append(clsid); } } break; } break; #endif //QT_NO_PHONON_EFFECT default: break; } return ret; }