File indexing completed on 2024-04-21 04:43:15

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2006-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_BACKENDINTERFACE_H
0024 #define PHONON_BACKENDINTERFACE_H
0025 
0026 #include "phonon_export.h"
0027 #include "objectdescription.h"
0028 
0029 #include <QtGlobal>
0030 #include <QSet>
0031 
0032 
0033 class QVariant;
0034 
0035 namespace Phonon
0036 {
0037 
0038 /** \class BackendInterface backendinterface.h phonon/BackendInterface
0039  * \short Main Backend class interface
0040  *
0041  * This interface defines the main factory of the backend. The createObject function creates all the
0042  * objects needed by the frontend.
0043  *
0044  * The objectDescriptionIndexes and objectDescriptionProperties functions return information about
0045  * available devices, effects and codecs.
0046  *
0047  * An implementation could look like this:
0048  * \code
0049  * QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const QList<QVariant> &args)
0050  * {
0051  *     switch (c) {
0052  *     case MediaObjectClass:
0053  *         return new MediaObject(parent);
0054  *     case VolumeFaderEffectClass:
0055  *         return new VolumeFaderEffect(parent);
0056  *     case AudioOutputClass:
0057  *         return new AudioOutput(parent);
0058  *     case AudioDataOutputClass:
0059  *         return new AudioDataOutput(parent);
0060  *     case VisualizationClass:
0061  *         return new Visualization(parent);
0062  *     case VideoDataOutputClass:
0063  *         return new VideoDataOutput(parent);
0064  *     case EffectClass:
0065  *         return new Effect(args[0].toInt(), parent);
0066  *     case VideoWidgetClass:
0067  *         return new VideoWidget(qobject_cast<QWidget *>(parent));
0068  *     }
0069  *     return 0;
0070  * }
0071  *
0072  * QSet<int> Backend::objectDescriptionIndexes(ObjectDescriptionType type) const
0073  * {
0074  *     QSet<int> set;
0075  *     switch(type)
0076  *     {
0077  *     case Phonon::AudioOutputDeviceType:
0078  *         // use AudioDeviceEnumerator to list ALSA and OSS devices
0079  *         set << 10000 << 10001;
0080  *         break;
0081  *     case Phonon::AudioCaptureDeviceType:
0082  *         set << 20000 << 20001;
0083  *         break;
0084  *     case Phonon::VideoOutputDeviceType:
0085  *         break;
0086  *     case Phonon::VideoCaptureDeviceType:
0087  *         set << 30000 << 30001;
0088  *         break;
0089  *     case Phonon::VisualizationType:
0090  *     case Phonon::AudioCodecType:
0091  *     case Phonon::VideoCodecType:
0092  *     case Phonon::ContainerFormatType:
0093  *         break;
0094  *     case Phonon::EffectType:
0095  *         set << 0x7F000001;
0096  *         break;
0097  *     }
0098  *     return set;
0099  * }
0100  *
0101  * QHash<QByteArray, QVariant> Backend::objectDescriptionProperties(ObjectDescriptionType type, int index) const
0102  * {
0103  *     QHash<QByteArray, QVariant> ret;
0104  *     switch (type) {
0105  *     case Phonon::AudioOutputDeviceType:
0106  *         switch (index) {
0107  *         case 10000:
0108  *             ret.insert("name", QLatin1String("internal Soundcard"));
0109  *             break;
0110  *         case 10001:
0111  *             ret.insert("name", QLatin1String("USB Headset"));
0112  *             ret.insert("icon", KIcon("usb-headset"));
0113  *             ret.insert("available", false);
0114  *             break;
0115  *         }
0116  *         break;
0117  *     case Phonon::AudioCaptureDeviceType:
0118  *         switch (index) {
0119  *         case 20000:
0120  *             ret.insert("name", QLatin1String("Soundcard"));
0121  *             ret.insert("description", QLatin1String("first description"));
0122  *             break;
0123  *         case 20001:
0124  *             ret.insert("name", QLatin1String("DV"));
0125  *             ret.insert("description", QLatin1String("second description"));
0126  *             break;
0127  *         }
0128  *         break;
0129  *     case Phonon::VideoOutputDeviceType:
0130  *         break;
0131  *     case Phonon::VideoCaptureDeviceType:
0132  *         switch (index) {
0133  *         case 30000:
0134  *             ret.insert("name", QLatin1String("USB Webcam"));
0135  *             ret.insert("description", QLatin1String("first description"));
0136  *             break;
0137  *         case 30001:
0138  *             ret.insert("name", QLatin1String("DV"));
0139  *             ret.insert("description", QLatin1String("second description"));
0140  *             break;
0141  *         }
0142  *         break;
0143  *     case Phonon::VisualizationType:
0144  *         break;
0145  *     case Phonon::AudioCodecType:
0146  *         break;
0147  *     case Phonon::VideoCodecType:
0148  *         break;
0149  *     case Phonon::ContainerFormatType:
0150  *         break;
0151  *     case Phonon::EffectType:
0152  *         switch (index) {
0153  *         case 0x7F000001:
0154  *             ret.insert("name", QLatin1String("Delay"));
0155  *             ret.insert("description", QLatin1String("Simple delay effect with time, feedback and level controls."));
0156  *             break;
0157  *         }
0158  *         break;
0159  *     }
0160  *     return ret;
0161  * }
0162  * \endcode
0163  *
0164  * \author Matthias Kretz <kretz@kde.org>
0165  */
0166 class BackendInterface
0167 {
0168     public:
0169         /**
0170          * \internal
0171          *
0172          * Silence gcc's warning.
0173          */
0174         virtual ~BackendInterface() {}
0175 
0176         /**
0177          * Classes that the createObject function has to handle.
0178          */
0179         enum Class {
0180             /**
0181              * Request to return a %MediaObject object.
0182              */
0183             MediaObjectClass,
0184             /**
0185              * Request to return a %VolumeFaderEffect object.
0186              */
0187             VolumeFaderEffectClass,
0188             /**
0189              * Request to return a %AudioOutput object.
0190              */
0191             AudioOutputClass,
0192             /**
0193              * Request to return a %AudioDataOutput object.
0194              */
0195             AudioDataOutputClass,
0196             /**
0197              * Request to return a %Visualization object.
0198              */
0199             VisualizationClass,
0200             /**
0201              * Request to return a %VideoDataOutput object.
0202              */
0203             VideoDataOutputClass,
0204             /**
0205              * Request to return a %Effect object.
0206              *
0207              * Takes an additional int that specifies the effect Id.
0208              */
0209             EffectClass,
0210             /**
0211              * Request to return a %VideoWidget object.
0212              */
0213             VideoWidgetClass,
0214             VideoGraphicsObjectClass /* < No longer needs implementing; legacy */
0215         };
0216 
0217         /**
0218          * Returns a new instance of the requested class.
0219          *
0220          * \param c The requested class.
0221          * \param parent The parent object.
0222          * \param args Additional arguments (documented in \ref Class).
0223          */
0224         virtual QObject *createObject(Class c, QObject *parent, const QList<QVariant> &args = QList<QVariant>()) = 0;
0225 
0226         /**
0227          * Returns the unique identifiers for the devices/effects/codecs of the given \p type.
0228          *
0229          * \param type see \ref ObjectDescriptionType
0230          */
0231         virtual QList<int> objectDescriptionIndexes(ObjectDescriptionType type) const = 0;
0232 
0233         /**
0234          * Given a unique identifier that was returned from objectDescriptionIndexes this function
0235          * returns a hash mapping property names to values.
0236          *
0237          * The property "name" must always be present. All other properties are optional.
0238          *
0239          * List of possible properties:
0240          * \li \c \b name: The name of the device/effect/codec/...
0241          * \li \c \b description: A text explaining what this device/effect/codec/... is/can do
0242          * \li \c \b icon: An icon name (using the freedesktop naming scheme) or a QIcon for this
0243          * device/effect/codec/...
0244          * \li \c \b available: A bool telling whether the device is present or unplugged.
0245          *
0246          * \param type see \ref ObjectDescriptionType
0247          * \param index The unique identifier that is returned from objectDescriptionIndexes
0248          */
0249         virtual QHash<QByteArray, QVariant> objectDescriptionProperties(ObjectDescriptionType type, int index) const = 0;
0250 
0251         /**
0252          * When this function is called the nodes given in the parameter list should not lose any
0253          * signal data when connections are changed.
0254          */
0255         virtual bool startConnectionChange(QSet<QObject *>) = 0;
0256 
0257         /**
0258          * Defines a signal connection between the two given nodes.
0259          */
0260         virtual bool connectNodes(QObject *, QObject *) = 0;
0261 
0262         /**
0263          * Cuts a signal connection between the two given nodes.
0264          */
0265         virtual bool disconnectNodes(QObject *, QObject *) = 0;
0266 
0267         /**
0268          * When this function is called the nodes given in the parameter list may lose
0269          * signal data when a port is not connected.
0270          */
0271         virtual bool endConnectionChange(QSet<QObject *>) = 0;
0272 
0273         /**
0274          * gets all available mime types
0275          */
0276         virtual QStringList availableMimeTypes() const = 0;
0277 
0278 };
0279 } // namespace Phonon
0280 
0281 Q_DECLARE_INTERFACE(Phonon::BackendInterface, "BackendInterface3.phonon.kde.org")
0282 
0283 
0284 #endif // PHONON_BACKENDINTERFACE_H