Changeset 188 for smplayer/trunk/src/deviceinfo.cpp
- Timestamp:
- Jan 24, 2017, 12:41:54 PM (8 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 186
- Property svn:mergeinfo changed
-
smplayer/trunk/src/deviceinfo.cpp
r181 r188 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 6Ricardo Villalba <rvm@users.sourceforge.net>2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 22 22 #include <QFile> 23 23 #include <QSettings> 24 #include <QDebug> 24 25 25 26 #ifdef Q_OS_WIN 27 28 #define USE_DIRECTX 29 30 #ifdef USE_DIRECTX 31 #define DIRECTSOUND_VERSION 5 32 #include <dsound.h> 33 #include <ddraw.h> 34 35 QStringList dsound_device_list; 36 QStringList ddraw_device_list; 37 38 BOOL CALLBACK DirectSoundEnum(LPGUID guid, LPCSTR desc, LPCSTR module, LPVOID context) 39 { 40 Q_UNUSED(guid); 41 Q_UNUSED(module); 42 Q_UNUSED(context); 43 44 dsound_device_list << QString(desc); 45 return TRUE; 46 } 47 48 BOOL WINAPI DirectDrawEnum(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm) 49 { 50 Q_UNUSED(lpDriverName); 51 Q_UNUSED(lpContext); 52 Q_UNUSED(hm); 53 54 if (!lpGUID) { 55 ddraw_device_list << "Primary Display Adapter"; 56 } else { 57 ddraw_device_list << QString(lpDriverDescription); 58 } 59 return TRUE; 60 } 61 62 63 DeviceList DeviceInfo::retrieveDevices(DeviceType type) { 64 qDebug("DeviceInfo::retrieveDevices: %d", type); 65 66 DeviceList l; 67 68 dsound_device_list.clear(); 69 ddraw_device_list.clear(); 70 71 if (type == Sound) { 72 DirectSoundEnumerateA(DirectSoundEnum, NULL); 73 for (int n = 0; n < dsound_device_list.count(); n++) { 74 QString desc = dsound_device_list[n]; 75 qDebug() << "DeviceInfo::retrieveDevices: audio:" << n << desc; 76 l.append( DeviceData(n, desc) ); 77 } 78 } 79 else 80 if (type == Display) { 81 DirectDrawEnumerateExA(DirectDrawEnum, NULL, DDENUM_ATTACHEDSECONDARYDEVICES); 82 for (int n = 0; n < ddraw_device_list.count(); n++) { 83 QString desc = ddraw_device_list[n]; 84 qDebug() << "DeviceInfo::retrieveDevices: display:" << n << desc; 85 l.append( DeviceData(n, desc) ); 86 } 87 } 88 89 return l; 90 } 91 92 #else 26 93 27 94 DeviceList DeviceInfo::retrieveDevices(DeviceType type) { … … 71 138 return l; 72 139 } 140 #endif 73 141 74 142 DeviceList DeviceInfo::dsoundDevices() { … … 82 150 #else 83 151 152 // Linux 153 154 #if USE_PULSEAUDIO_DEVICES 155 DeviceList DeviceInfo::paDevices() { 156 qDebug("DeviceInfo::paDevices"); 157 158 static DeviceList l; 159 if (!l.isEmpty()) return l; 160 161 QRegExp rx_index("(.*)index: (\\d+)"); 162 QRegExp rx_name("(.*)name: (.*)"); 163 164 QProcess p; 165 p.setProcessChannelMode( QProcess::MergedChannels ); 166 QStringList env = QProcess::systemEnvironment(); 167 env << "LC_ALL=C"; 168 p.setEnvironment(env); 169 p.start("pacmd list-sinks"); 170 171 int index = -1; 172 QString name; 173 174 if (p.waitForFinished()) { 175 QByteArray line; 176 while (p.canReadLine()) { 177 line = p.readLine().trimmed(); 178 //qDebug() << "DeviceInfo::paDevices:" << line; 179 if (rx_index.indexIn(line) > -1 ) { 180 index = rx_index.cap(2).toInt(); 181 qDebug() << "DeviceInfo::paDevices: index:" << index; 182 } 183 if (rx_name.indexIn(line) > -1 ) { 184 name = rx_name.cap(2); 185 if (name.startsWith('<') && name.endsWith('>')) { name = name.mid(1); name.chop(1); } 186 qDebug() << "DeviceInfo::paDevices: name:" << name; 187 if (index != -1) { 188 l.append( DeviceData(index, name) ); 189 index = -1; 190 } 191 } 192 } 193 } 194 195 return l; 196 } 197 #endif // USE_PULSEAUDIO_DEVICES 198 199 #if USE_ALSA_DEVICES 84 200 DeviceList DeviceInfo::alsaDevices() { 85 201 qDebug("DeviceInfo::alsaDevices"); … … 127 243 return l; 128 244 } 129 245 #endif 246 247 #ifdef USE_XV_ADAPTORS 130 248 DeviceList DeviceInfo::xvAdaptors() { 131 249 qDebug("DeviceInfo::xvAdaptors"); … … 171 289 return l; 172 290 } 173 291 #endif 292 #endif 293 294 #if MPV_AUDIO_DEVICES 295 QString DeviceInfo::mpv_bin; 296 297 #if USE_MPV_ALSA_DEVICES 298 DeviceList DeviceInfo::mpvAlsaDevices() { 299 static DeviceList l; 300 if (!l.isEmpty()) return l; 301 l = mpvAudioDevices("alsa"); 302 return l; 303 } 304 #endif 305 306 #if USE_MPV_WASAPI_DEVICES 307 DeviceList DeviceInfo::mpvWasapiDevices() { 308 static DeviceList l; 309 if (!l.isEmpty()) return l; 310 l = mpvAudioDevices("wasapi"); 311 return l; 312 } 313 #endif 314 315 DeviceList DeviceInfo::mpvAudioDevices(const QString & filter) { 316 DeviceList l; 317 if (!mpv_bin.isEmpty()) l = mpvAudioDevices(mpv_bin, filter); 318 return l; 319 } 320 321 DeviceList DeviceInfo::mpvAudioDevices(const QString & mpv_bin, const QString & filter) { 322 qDebug("DeviceInfo::mpvAudioDevices"); 323 324 DeviceList l; 325 326 QRegExp rx("'" + filter + "\\/(.*)'\\s+\\((.*)\\)"); 327 328 QProcess p; 329 p.setProcessChannelMode( QProcess::MergedChannels ); 330 331 p.start(mpv_bin, QStringList() << "--audio-device=help"); 332 333 QString device; 334 QString name; 335 //int index = 0; 336 337 if (p.waitForFinished()) { 338 QString line; 339 while (p.canReadLine()) { 340 line = QString::fromUtf8(p.readLine().trimmed()); 341 qDebug() << "DeviceInfo::mpvAudioDevices:" << line; 342 343 if (rx.indexIn(line) > -1 ) { 344 device = rx.cap(1); 345 name = rx.cap(2); 346 qDebug() << "DeviceInfo::mpvAudioDevices: device:" << device << "name:" << name; 347 l.append( DeviceData(device, name) ); 348 //index++; 349 } 350 } 351 } 352 353 return l; 354 } 174 355 #endif 175 356 … … 201 382 } 202 383 #endif 384 385 QString DeviceInfo::printableName(const QString & driver_name, const DeviceData & device) { 386 return printableName(driver_name, device.ID().toString(), device.desc()); 387 } 388 389 QString DeviceInfo::internalName(const QString & driver_name, const DeviceData & device) { 390 return internalName(driver_name, device.ID().toString(), device.desc()); 391 } 392 393 QString DeviceInfo::printableName(const QString & driver_name, const QString & id, const QString & desc) { 394 Q_UNUSED(id); 395 return driver_name +" (" + /* id + " - " + */ desc + ")"; 396 } 397 398 QString DeviceInfo::internalName(const QString & driver_name, const QString & id, const QString & desc) { 399 return driver_name + ":::" + id + ":::" + desc; 400 } 401 402 QStringList DeviceInfo::extractDevice(const QString & internal_name) { 403 return internal_name.split(":::"); 404 }
Note:
See TracChangeset
for help on using the changeset viewer.