source: smplayer/vendor/current/src/deviceinfo.cpp@ 179

Last change on this file since 179 was 179, checked in by Silvan Scherrer, 9 years ago

smplayer: update vendor to version 16.8.0

File size: 5.4 KB
RevLine 
[90]1/* smplayer, GUI front-end for mplayer.
[175]2 Copyright (C) 2006-2016 Ricardo Villalba <[email protected]>
[90]3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "deviceinfo.h"
[175]20#include "paths.h"
[90]21#include <QProcess>
22#include <QFile>
[175]23#include <QSettings>
[90]24
25#ifdef Q_OS_WIN
26
27DeviceList DeviceInfo::retrieveDevices(DeviceType type) {
28 qDebug("DeviceInfo::retrieveDevices: %d", type);
[179]29
30 DeviceList l;
31
32 #ifdef CACHE_DEVICE_INFO
[175]33 QString inifile = Paths::configPath() + "/device_info.ini";
34 QSettings set(inifile, QSettings::IniFormat);
[179]35 QString section_name = "display-devices";
36 if (type == Sound) section_name = "dsound-devices";
37
[175]38 // Check if we already have the list stored in the INI file
[179]39 l = loadList(&set, section_name);
[175]40 if (l.count() > 0) return l;
[179]41 #endif
42
[90]43 QRegExp rx_device("^(\\d+): (.*)");
[179]44
[90]45 if (QFile::exists("dxlist.exe")) {
46 QProcess p;
47 p.setProcessChannelMode( QProcess::MergedChannels );
48 QStringList arg;
49 if (type == Sound) arg << "-s"; else arg << "-d";
50 p.start("dxlist", arg);
51
52 if (p.waitForFinished()) {
53 QByteArray line;
54 while (p.canReadLine()) {
55 line = p.readLine().trimmed();
56 qDebug("DeviceInfo::retrieveDevices: '%s'", line.constData());
57 if ( rx_device.indexIn(line) > -1 ) {
58 int id = rx_device.cap(1).toInt();
59 QString desc = rx_device.cap(2);
60 qDebug("DeviceInfo::retrieveDevices: found device: '%d' '%s'", id, desc.toUtf8().constData());
61 l.append( DeviceData(id, desc) );
62 }
63 }
64 }
65 }
[179]66
67 #ifdef CACHE_DEVICE_INFO
[175]68 saveList(&set, section_name, l);
[179]69 #endif
70
[90]71 return l;
72}
73
74DeviceList DeviceInfo::dsoundDevices() {
75 return retrieveDevices(Sound);
76}
77
78DeviceList DeviceInfo::displayDevices() {
79 return retrieveDevices(Display);
80}
81
82#else
83
84DeviceList DeviceInfo::alsaDevices() {
85 qDebug("DeviceInfo::alsaDevices");
86
[179]87 DeviceList l;
88
89 #ifdef CACHE_DEVICE_INFO
[175]90 QString inifile = Paths::configPath() + "/device_info.ini";
91 QSettings set(inifile, QSettings::IniFormat);
92
93 // Check if we already have the list stored in the INI file
[179]94 l = loadList(&set, "alsa-devices");
[175]95 if (l.count() > 0) return l;
[179]96 #endif
[175]97
[90]98 QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
99
100 QProcess p;
101 p.setProcessChannelMode( QProcess::MergedChannels );
102 p.setEnvironment( QStringList() << "LC_ALL=C" );
103 p.start("aplay", QStringList() << "-l");
104
105 if (p.waitForFinished()) {
106 QByteArray line;
107 while (p.canReadLine()) {
108 line = p.readLine();
109 qDebug("DeviceInfo::alsaDevices: '%s'", line.constData());
110 if ( rx_device.indexIn(line) > -1 ) {
111 QString id = rx_device.cap(1);
112 id.append(".");
113 id.append(rx_device.cap(3));
114 QString desc = rx_device.cap(2);
115 qDebug("DeviceInfo::alsaDevices: found device: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
116 l.append( DeviceData(id, desc) );
117 }
118 }
119 } else {
120 qDebug("DeviceInfo::alsaDevices: could not start aplay, error %d", p.error());
121 }
122
[179]123 #ifdef CACHE_DEVICE_INFO
124 saveList(&set, "alsa-devices", l);
125 #endif
[175]126
[90]127 return l;
128}
129
130DeviceList DeviceInfo::xvAdaptors() {
131 qDebug("DeviceInfo::xvAdaptors");
132
[179]133 DeviceList l;
134
135 #ifdef CACHE_DEVICE_INFO
[175]136 QString inifile = Paths::configPath() + "/device_info.ini";
137 QSettings set(inifile, QSettings::IniFormat);
138
139 // Check if we already have the list stored in the INI file
[179]140 l = loadList(&set, "xv-adaptors");
[175]141 if (l.count() > 0) return l;
[179]142 #endif
[175]143
[90]144 QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\"");
145
146 QProcess p;
147 p.setProcessChannelMode( QProcess::MergedChannels );
148 p.setEnvironment( QProcess::systemEnvironment() << "LC_ALL=C" );
149 p.start("xvinfo");
150
151 if (p.waitForFinished()) {
152 QByteArray line;
153 while (p.canReadLine()) {
154 line = p.readLine();
155 qDebug("DeviceInfo::xvAdaptors: '%s'", line.constData());
156 if ( rx_device.indexIn(line) > -1 ) {
157 QString id = rx_device.cap(1);
158 QString desc = rx_device.cap(2);
159 qDebug("DeviceInfo::xvAdaptors: found adaptor: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
160 l.append( DeviceData(id, desc) );
161 }
162 }
163 } else {
164 qDebug("DeviceInfo::xvAdaptors: could not start xvinfo, error %d", p.error());
165 }
166
[179]167 #ifdef CACHE_DEVICE_INFO
168 saveList(&set, "xv-adaptors", l);
169 #endif
[175]170
[90]171 return l;
172}
173
174#endif
[175]175
[179]176#ifdef CACHE_DEVICE_INFO
[175]177void DeviceInfo::saveList(QSettings * set, const QString & section_name, const DeviceList & list) {
178 set->beginWriteArray(section_name);
179 for (int i = 0; i < list.count(); ++i) {
180 set->setArrayIndex(i);
181 set->setValue("ID", list.at(i).ID());
[179]182 set->setValue("description", list.at(i).desc());
[175]183 }
184 set->endArray();
185}
186
187DeviceList DeviceInfo::loadList(QSettings * set, const QString & section_name) {
188 DeviceList l;
189
190 int count = set->beginReadArray(section_name);
191 for (int i = 0; i < count; ++i) {
192 set->setArrayIndex(i);
193 QVariant id = set->value("ID");
[179]194 QString desc = set->value("description", "").toString();
[175]195 l.append(DeviceData(id, desc));
196 }
197
198 set->endArray();
199
200 return l;
201}
[179]202#endif
Note: See TracBrowser for help on using the repository browser.