1 /*  smplayer, GUI front-end for mplayer.
2     Copyright (C) 2006-2021 Ricardo Villalba <ricardo@smplayer.info>
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 #ifndef DEVICEINFO_H
20 #define DEVICEINFO_H
21 
22 #include <QString>
23 #include <QVariant>
24 #include <QList>
25 
26 #ifdef Q_OS_WIN
27 #define USE_DSOUND_DEVICES 1
28 #define USE_MPV_WASAPI_DEVICES 1
29 #else
30 #define USE_ALSA_DEVICES 0
31 #define USE_MPV_ALSA_DEVICES 0
32 #define USE_PULSEAUDIO_DEVICES 1
33 #define USE_XV_ADAPTORS 1
34 #endif
35 
36 #if defined(USE_MPV_ALSA_DEVICES) || defined(USE_MPV_WASAPI_DEVICES)
37 #define MPV_AUDIO_DEVICES 1
38 #endif
39 
40 #ifndef Q_OS_WIN
41 #define CACHE_DEVICE_INFO
42 #endif
43 
44 class QSettings;
45 
46 class DeviceData {
47 
48 public:
DeviceData()49 	DeviceData() {};
DeviceData(QVariant ID,QString desc)50 	DeviceData(QVariant ID, QString desc) { _id = ID; _desc = desc; };
~DeviceData()51 	~DeviceData() {};
52 
setID(QVariant ID)53 	void setID(QVariant ID) { _id = ID; };
setDesc(QString desc)54 	void setDesc(QString desc) { _desc = desc; };
55 
ID()56 	QVariant ID() const { return _id; };
desc()57 	QString desc() const { return _desc; };
58 
59 private:
60 	QVariant _id;
61 	QString _desc;
62 };
63 
64 
65 typedef QList<DeviceData> DeviceList;
66 
67 
68 class DeviceInfo {
69 
70 public:
71 #ifdef Q_OS_WIN
72 	static DeviceList dsoundDevices();
73 	static DeviceList displayDevices();
74 #else
75 	#if USE_PULSEAUDIO_DEVICES
76 	static DeviceList paDevices();
77 	#endif
78 	#if USE_ALSA_DEVICES
79 	static DeviceList alsaDevices();
80 	#endif
81 	#if USE_XV_ADAPTORS
82 	static DeviceList xvAdaptors();
83 	#endif
84 #endif
85 
86 #if MPV_AUDIO_DEVICES
setMpvBin(const QString & bin)87 	static void setMpvBin(const QString & bin) { mpv_bin = bin; };
88 
89 	#if USE_MPV_ALSA_DEVICES
90 	static DeviceList mpvAlsaDevices();
91 	#endif
92 
93 	#if USE_MPV_WASAPI_DEVICES
94 	static DeviceList mpvWasapiDevices();
95 	#endif
96 
97 	static DeviceList mpvAudioDevices(const QString & mpv_bin, const QString & filter);
98 	static DeviceList mpvAudioDevices(const QString & filter);
99 #endif
100 
101 	static QString printableName(const QString & driver_name, const DeviceData & device);
102 	static QString internalName(const QString & driver_name, const DeviceData & device);
103 
104 	static QString printableName(const QString & driver_name, const QString & id, const QString & desc);
105 	static QString internalName(const QString & driver_name, const QString & id, const QString & desc);
106 	static QStringList extractDevice(const QString & internal_name);
107 
108 protected:
109 #ifdef CACHE_DEVICE_INFO
110 	static void saveList(QSettings * set, const QString & section_name, const DeviceList & list);
111 	static DeviceList loadList(QSettings * set, const QString & section_name);
112 #endif
113 
114 #ifdef Q_OS_WIN
115 	enum DeviceType { Sound = 0, Display = 1 };
116 
117 	static DeviceList retrieveDevices(DeviceType type);
118 #endif
119 
120 #if MPV_AUDIO_DEVICES
121 	static QString mpv_bin;
122 #endif
123 };
124 
125 #endif
126 
127