source: smplayer/trunk/src/deviceinfo.cpp@ 165

Last change on this file since 165 was 165, checked in by Silvan Scherrer, 11 years ago

SMPlayer: update trunk to latest 0.8.7

  • Property svn:eol-style set to LF
File size: 3.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net>
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"
20#include <QProcess>
21#include <QFile>
22
23#ifdef Q_OS_WIN
24
25DeviceList DeviceInfo::retrieveDevices(DeviceType type) {
26 qDebug("DeviceInfo::retrieveDevices: %d", type);
27
28 DeviceList l;
29 QRegExp rx_device("^(\\d+): (.*)");
30
31 if (QFile::exists("dxlist.exe")) {
32 QProcess p;
33 p.setProcessChannelMode( QProcess::MergedChannels );
34 QStringList arg;
35 if (type == Sound) arg << "-s"; else arg << "-d";
36 p.start("dxlist", arg);
37
38 if (p.waitForFinished()) {
39 QByteArray line;
40 while (p.canReadLine()) {
41 line = p.readLine().trimmed();
42 qDebug("DeviceInfo::retrieveDevices: '%s'", line.constData());
43 if ( rx_device.indexIn(line) > -1 ) {
44 int id = rx_device.cap(1).toInt();
45 QString desc = rx_device.cap(2);
46 qDebug("DeviceInfo::retrieveDevices: found device: '%d' '%s'", id, desc.toUtf8().constData());
47 l.append( DeviceData(id, desc) );
48 }
49 }
50 }
51 }
52
53 return l;
54}
55
56DeviceList DeviceInfo::dsoundDevices() {
57 return retrieveDevices(Sound);
58}
59
60DeviceList DeviceInfo::displayDevices() {
61 return retrieveDevices(Display);
62}
63
64#else
65
66DeviceList DeviceInfo::alsaDevices() {
67 qDebug("DeviceInfo::alsaDevices");
68
69 DeviceList l;
70 QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
71
72 QProcess p;
73 p.setProcessChannelMode( QProcess::MergedChannels );
74 p.setEnvironment( QStringList() << "LC_ALL=C" );
75 p.start("aplay", QStringList() << "-l");
76
77 if (p.waitForFinished()) {
78 QByteArray line;
79 while (p.canReadLine()) {
80 line = p.readLine();
81 qDebug("DeviceInfo::alsaDevices: '%s'", line.constData());
82 if ( rx_device.indexIn(line) > -1 ) {
83 QString id = rx_device.cap(1);
84 id.append(".");
85 id.append(rx_device.cap(3));
86 QString desc = rx_device.cap(2);
87 qDebug("DeviceInfo::alsaDevices: found device: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
88 l.append( DeviceData(id, desc) );
89 }
90 }
91 } else {
92 qDebug("DeviceInfo::alsaDevices: could not start aplay, error %d", p.error());
93 }
94
95 return l;
96}
97
98DeviceList DeviceInfo::xvAdaptors() {
99 qDebug("DeviceInfo::xvAdaptors");
100
101 DeviceList l;
102 QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\"");
103
104 QProcess p;
105 p.setProcessChannelMode( QProcess::MergedChannels );
106 p.setEnvironment( QProcess::systemEnvironment() << "LC_ALL=C" );
107 p.start("xvinfo");
108
109 if (p.waitForFinished()) {
110 QByteArray line;
111 while (p.canReadLine()) {
112 line = p.readLine();
113 qDebug("DeviceInfo::xvAdaptors: '%s'", line.constData());
114 if ( rx_device.indexIn(line) > -1 ) {
115 QString id = rx_device.cap(1);
116 QString desc = rx_device.cap(2);
117 qDebug("DeviceInfo::xvAdaptors: found adaptor: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
118 l.append( DeviceData(id, desc) );
119 }
120 }
121 } else {
122 qDebug("DeviceInfo::xvAdaptors: could not start xvinfo, error %d", p.error());
123 }
124
125 return l;
126}
127
128#endif
Note: See TracBrowser for help on using the repository browser.