File indexing completed on 2025-02-09 05:31:47
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004-2007 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 0023 #ifndef PHONON_FACTORY_P_H 0024 #define PHONON_FACTORY_P_H 0025 0026 #include "phonon_export.h" 0027 0028 #include <QObject> 0029 #include <QFileInfo> 0030 #include <QPluginLoader> 0031 #include <QStringList> 0032 0033 class QUrl; 0034 class QIcon; 0035 0036 namespace Phonon 0037 { 0038 class PlatformPlugin; 0039 class MediaNodePrivate; 0040 class AbstractMediaStream; 0041 0042 /** 0043 * \internal 0044 */ 0045 struct Q_DECL_HIDDEN BackendDescriptor { 0046 explicit BackendDescriptor(const QString &path = QString()) 0047 : isValid(false) 0048 { 0049 QFileInfo info(path); 0050 if (!info.exists()) { 0051 return; 0052 } 0053 0054 QPluginLoader loader(path); 0055 0056 iid = loader.metaData().value(QLatin1String("IID")).toString(); 0057 0058 const QJsonObject metaData = loader.metaData().value(QLatin1String("MetaData")).toObject(); 0059 name = metaData.value(QLatin1String("Name")).toString(); 0060 icon = metaData.value(QLatin1String("Icon")).toString(); 0061 version = metaData.value(QLatin1String("Version")).toString(); 0062 website = metaData.value(QLatin1String("Website")).toString(); 0063 initialPreference = metaData.value(QLatin1String("InitialPreference")).toInt(); 0064 0065 pluginPath = path; 0066 pluginName = info.baseName(); 0067 0068 if (name.isEmpty()) { 0069 name = pluginName; 0070 } 0071 0072 if (iid.isEmpty()) { 0073 return; // Not valid. 0074 } 0075 0076 isValid = true; 0077 } 0078 0079 bool isValid; 0080 0081 QString iid; 0082 0083 QString name; 0084 QString icon; 0085 QString version; 0086 QString website; 0087 int initialPreference; // Initial preference declared by the backend; larger is better 0088 int weight = -1; // Weight assigned by user configuration 0089 0090 QString pluginPath; 0091 QString pluginName; // basename of the file. "legacy" name used for PHONON_BACKEND 0092 0093 /** Implemented for sorting */ 0094 bool operator <(const BackendDescriptor &rhs) const 0095 { 0096 if (weight >= 0) { 0097 // If we have a weight the preference doesn't matter. 0098 // User configured weight always wins against initial preference. 0099 return (weight < rhs.weight); 0100 } 0101 0102 return this->initialPreference < rhs.initialPreference; 0103 } 0104 }; 0105 0106 /** 0107 * \internal 0108 * \brief Factory to access the preferred Backend. 0109 * 0110 * This class is used internally to get the backend's implementation. 0111 * It keeps track of the objects that were created. When a 0112 * request for a backend change comes, it asks all frontend objects to delete 0113 * their backend objects and then checks whether they were all deleted. Only 0114 * then the old backend is unloaded and the new backend is loaded. 0115 * 0116 * \author Matthias Kretz <kretz@kde.org> 0117 */ 0118 namespace Factory 0119 { 0120 /** 0121 * Emits signals for Phonon::Factory. 0122 */ 0123 class Sender : public QObject 0124 { 0125 Q_OBJECT 0126 Q_SIGNALS: 0127 /** 0128 * Emitted after the backend has successfully been changed. 0129 */ 0130 void backendChanged(); 0131 0132 /** 0133 * \copydoc BackendCapabilities::Notifier::availableAudioOutputDevicesChanged 0134 */ 0135 void availableAudioOutputDevicesChanged(); 0136 0137 /** 0138 * \copydoc BackendCapabilities::Notifier::availableAudioCaptureDevicesChanged 0139 */ 0140 void availableAudioCaptureDevicesChanged(); 0141 0142 /** 0143 * \copydoc BackendCapabilities::Notifier::availableVideoCaptureDevicesChanged 0144 */ 0145 void availableVideoCaptureDevicesChanged(); 0146 }; 0147 0148 PHONON_EXPORT QList<BackendDescriptor> findBackends(); 0149 0150 /** 0151 * Returns a pointer to the object emitting the signals. 0152 * 0153 * \see Sender::backendChanged() 0154 */ 0155 PHONON_EXPORT Sender *sender(); 0156 0157 /** 0158 * Create a new backend object for a MediaObject. 0159 * 0160 * \return a pointer to the MediaObject the backend provides. 0161 */ 0162 QObject *createMediaObject(QObject *parent = nullptr); 0163 /** 0164 * Create a new backend object for a Effect. 0165 * 0166 * \return a pointer to the Effect the backend provides. 0167 */ 0168 #ifndef QT_NO_PHONON_EFFECT 0169 QObject *createEffect(int effectId, QObject *parent = nullptr); 0170 #endif //QT_NO_PHONON_EFFECT 0171 /** 0172 * Create a new backend object for a VolumeFaderEffect. 0173 * 0174 * \return a pointer to the VolumeFaderEffect the backend provides. 0175 */ 0176 #ifndef QT_NO_PHONON_VOLUMEFADEREFFECT 0177 QObject *createVolumeFaderEffect(QObject *parent = nullptr); 0178 #endif //QT_NO_PHONON_VOLUMEFADEREFFECT 0179 /** 0180 * Create a new backend object for a AudioOutput. 0181 * 0182 * \return a pointer to the AudioOutput the backend provides. 0183 */ 0184 QObject *createAudioOutput(QObject *parent = nullptr); 0185 /** 0186 * Create a new backend object for a VideoWidget. 0187 * 0188 * \return a pointer to the VideoWidget the backend provides. 0189 */ 0190 #ifndef QT_NO_PHONON_VIDEO 0191 QObject *createVideoWidget(QObject *parent = nullptr); 0192 QObject *createVideoGraphicsObject(QObject *parent = nullptr); 0193 #endif //QT_NO_PHONON_VIDEO 0194 0195 /** 0196 * Create a new backend object for a AudioDataOutput. 0197 * 0198 * \return a pointer to the AudioDataOutput the backend provides. 0199 */ 0200 PHONON_EXPORT QObject *createAudioDataOutput(QObject *parent = nullptr); 0201 0202 /** 0203 * \return a pointer to the backend interface. 0204 */ 0205 PHONON_EXPORT QObject *backend(bool createWhenNull = true); 0206 0207 /** 0208 * Unique identifier for the Backend. Can be used in configuration files 0209 * for example. 0210 */ 0211 QString identifier(); 0212 0213 /** 0214 * Get the name of the Backend. It's the name from the .desktop file. 0215 */ 0216 PHONON_EXPORT QString backendName(); 0217 0218 /** 0219 * Get the comment of the Backend. It's the comment from the .desktop file. 0220 */ 0221 QString backendComment(); 0222 0223 /** 0224 * Get the version of the Backend. It's the version from the .desktop file. 0225 * 0226 * The version is especially interesting if there are several versions 0227 * available for binary incompatible versions of the backend's media 0228 * framework. 0229 */ 0230 QString backendVersion(); 0231 0232 /** 0233 * Get the icon (name) of the Backend. It's the icon from the .desktop file. 0234 */ 0235 QString backendIcon(); 0236 0237 /** 0238 * Get the website of the Backend. It's the website from the .desktop file. 0239 */ 0240 QString backendWebsite(); 0241 0242 /** 0243 * registers the backend object 0244 */ 0245 PHONON_EXPORT QObject *registerQObject(QObject *o); 0246 0247 bool isMimeTypeAvailable(const QString &mimeType); 0248 0249 PHONON_EXPORT void registerFrontendObject(MediaNodePrivate *); 0250 PHONON_EXPORT void deregisterFrontendObject(MediaNodePrivate *); 0251 0252 PHONON_EXPORT void setBackend(QObject *); 0253 //PHONON_EXPORT void createBackend(const QString &library, const QString &version = QString()); 0254 0255 PHONON_EXPORT PlatformPlugin *platformPlugin(); 0256 0257 //X It is probably better if we can get away with internal handling of 0258 //X freeing the soundcard device when it's not needed anymore and 0259 //X providing an IPC method to stop all MediaObjects -> free all 0260 //X devices 0261 //X /** 0262 //X * \internal 0263 //X * This is called when the application needs to free the soundcard 0264 //X * device(s). 0265 //X */ 0266 //X void freeSoundcardDevices(); 0267 } // namespace Factory 0268 } // namespace Phonon 0269 0270 0271 #endif // PHONON_FACTORY_P_H 0272 // vim: sw=4 ts=4