1
/*  This file is part of the KDE project
2
    Copyright (C) 2006-2007 Matthias Kretz <kretz@kde.org>
3
4
    This library is free software; you can redistribute it and/or
5
    modify it under the terms of the GNU Lesser General Public
6
    License as published by the Free Software Foundation; either
7
    version 2.1 of the License, or (at your option) version 3, or any
8
    later version accepted by the membership of KDE e.V. (or its
9
    successor approved by the membership of KDE e.V.), Nokia Corporation 
10
    (or its successors, if any) and the KDE Free Qt Foundation, which shall
11
    act as a proxy defined in Section 6 of version 3 of the license.
12
13
    This library is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
    Lesser General Public License for more details.
17
18
    You should have received a copy of the GNU Lesser General Public 
19
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
21
*/
22
23
#ifndef PHONON_BACKENDINTERFACE_H
24
#define PHONON_BACKENDINTERFACE_H
25
26
#include "phonon_export.h"
27
#include "objectdescription.h"
28
29
#include <QtCore/QtGlobal>
30
#include <QtCore/QSet>
31
32
QT_BEGIN_HEADER
33
QT_BEGIN_NAMESPACE
34
35
class QVariant;
36
37
namespace Phonon
38
{
39
40
/** \class BackendInterface backendinterface.h Phonon/BackendInterface
41
 * \short Main Backend class interface
42
 *
43
 * This interface defines the main factory of the backend. The createObject function creates all the
44
 * objects needed by the frontend.
45
 *
46
 * The objectDescriptionIndexes and objectDescriptionProperties functions return information about
47
 * available devices, effects and codecs.
48
 *
49
 * An implementation could look like this:
50
 * \code
51
 * QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const QList<QVariant> &args)
52
 * {
53
 *     switch (c) {
54
 *     case MediaObjectClass:
55
 *         return new MediaObject(parent);
56
 *     case VolumeFaderEffectClass:
57
 *         return new VolumeFaderEffect(parent);
58
 *     case AudioOutputClass:
59
 *         return new AudioOutput(parent);
60
 *     case AudioDataOutputClass:
61
 *         return new AudioDataOutput(parent);
62
 *     case VisualizationClass:
63
 *         return new Visualization(parent);
64
 *     case VideoDataOutputClass:
65
 *         return new VideoDataOutput(parent);
66
 *     case EffectClass:
67
 *         return new Effect(args[0].toInt(), parent);
68
 *     case VideoWidgetClass:
69
 *         return new VideoWidget(qobject_cast<QWidget *>(parent));
70
 *     }
71
 *     return 0;
72
 * }
73
 *
74
 * QSet<int> Backend::objectDescriptionIndexes(ObjectDescriptionType type) const
75
 * {
76
 *     QSet<int> set;
77
 *     switch(type)
78
 *     {
79
 *     case Phonon::AudioOutputDeviceType:
80
 *         // use AudioDeviceEnumerator to list ALSA and OSS devices
81
 *         set << 10000 << 10001;
82
 *         break;
83
 *     case Phonon::AudioCaptureDeviceType:
84
 *         set << 20000 << 20001;
85
 *         break;
86
 *     case Phonon::VideoOutputDeviceType:
87
 *         break;
88
 *     case Phonon::VideoCaptureDeviceType:
89
 *         set << 30000 << 30001;
90
 *         break;
91
 *     case Phonon::VisualizationType:
92
 *     case Phonon::AudioCodecType:
93
 *     case Phonon::VideoCodecType:
94
 *     case Phonon::ContainerFormatType:
95
 *         break;
96
 *     case Phonon::EffectType:
97
 *         set << 0x7F000001;
98
 *         break;
99
 *     }
100
 *     return set;
101
 * }
102
 *
103
 * QHash<QByteArray, QVariant> Backend::objectDescriptionProperties(ObjectDescriptionType type, int index) const
104
 * {
105
 *     QHash<QByteArray, QVariant> ret;
106
 *     switch (type) {
107
 *     case Phonon::AudioOutputDeviceType:
108
 *         switch (index) {
109
 *         case 10000:
110
 *             ret.insert("name", QLatin1String("internal Soundcard"));
111
 *             break;
112
 *         case 10001:
113
 *             ret.insert("name", QLatin1String("USB Headset"));
114
 *             ret.insert("icon", KIcon("usb-headset"));
115
 *             ret.insert("available", false);
116
 *             break;
117
 *         }
118
 *         break;
119
 *     case Phonon::AudioCaptureDeviceType:
120
 *         switch (index) {
121
 *         case 20000:
122
 *             ret.insert("name", QLatin1String("Soundcard"));
123
 *             ret.insert("description", QLatin1String("first description"));
124
 *             break;
125
 *         case 20001:
126
 *             ret.insert("name", QLatin1String("DV"));
127
 *             ret.insert("description", QLatin1String("second description"));
128
 *             break;
129
 *         }
130
 *         break;
131
 *     case Phonon::VideoOutputDeviceType:
132
 *         break;
133
 *     case Phonon::VideoCaptureDeviceType:
134
 *         switch (index) {
135
 *         case 30000:
136
 *             ret.insert("name", QLatin1String("USB Webcam"));
137
 *             ret.insert("description", QLatin1String("first description"));
138
 *             break;
139
 *         case 30001:
140
 *             ret.insert("name", QLatin1String("DV"));
141
 *             ret.insert("description", QLatin1String("second description"));
142
 *             break;
143
 *         }
144
 *         break;
145
 *     case Phonon::VisualizationType:
146
 *         break;
147
 *     case Phonon::AudioCodecType:
148
 *         break;
149
 *     case Phonon::VideoCodecType:
150
 *         break;
151
 *     case Phonon::ContainerFormatType:
152
 *         break;
153
 *     case Phonon::EffectType:
154
 *         switch (index) {
155
 *         case 0x7F000001:
156
 *             ret.insert("name", QLatin1String("Delay"));
157
 *             ret.insert("description", QLatin1String("Simple delay effect with time, feedback and level controls."));
158
 *             break;
159
 *         }
160
 *         break;
161
 *     }
162
 *     return ret;
163
 * }
164
 * \endcode
165
 *
166
 * \author Matthias Kretz <kretz@kde.org>
167
 */
168
class BackendInterface
169
{
170
    public:
171
        /**
172
         * \internal
173
         *
174
         * Silence gcc's warning.
175
         */
176
        virtual ~BackendInterface() {}
177
178
        /**
179
         * Classes that the createObject function has to handle.
180
         */
181
        enum Class {
182
            /**
183
             * Request to return a %MediaObject object.
184
             */
185
            MediaObjectClass,
186
            /**
187
             * Request to return a %VolumeFaderEffect object.
188
             */
189
            VolumeFaderEffectClass,
190
            /**
191
             * Request to return a %AudioOutput object.
192
             */
193
            AudioOutputClass,
194
            /**
195
             * Request to return a %AudioDataOutput object.
196
             */
197
            AudioDataOutputClass,
198
            /**
199
             * Request to return a %Visualization object.
200
             */
201
            VisualizationClass,
202
            /**
203
             * Request to return a %VideoDataOutput object.
204
             */
205
            VideoDataOutputClass,
206
            /**
207
             * Request to return a %Effect object.
208
             *
209
             * Takes an additional int that specifies the effect Id.
210
             */
211
            EffectClass,
212
            /**
213
             * Request to return a %VideoWidget object.
214
             */
215
            VideoWidgetClass
216
        };
217
218
        /**
219
         * Returns a new instance of the requested class.
220
         *
221
         * \param c The requested class.
222
         * \param parent The parent object.
223
         * \param args Additional arguments (documented in \ref Class).
224
         */
225
        virtual QObject *createObject(Class c, QObject *parent, const QList<QVariant> &args = QList<QVariant>()) = 0;
226
227
        /**
228
         * Returns the unique identifiers for the devices/effects/codecs of the given \p type.
229
         *
230
         * \param type see \ref ObjectDescriptionType
231
         */
232
        virtual QList<int> objectDescriptionIndexes(ObjectDescriptionType type) const = 0;
233
234
        /**
235
         * Given a unique identifier that was returned from objectDescriptionIndexes this function
236
         * returns a hash mapping property names to values.
237
         *
238
         * The property "name" must always be present. All other properties are optional.
239
         *
240
         * List of possible properties:
241
         * \li \c \b name: The name of the device/effect/codec/...
242
         * \li \c \b description: A text explaining what this device/effect/codec/... is/can do
243
         * \li \c \b icon: An icon name (using the freedesktop naming scheme) or a QIcon for this
244
         * device/effect/codec/...
245
         * \li \c \b available: A bool telling whether the device is present or unplugged.
246
         *
247
         * \param type see \ref ObjectDescriptionType
248
         * \param index The unique identifier that is returned from objectDescriptionIndexes
249
         */
250
        virtual QHash<QByteArray, QVariant> objectDescriptionProperties(ObjectDescriptionType type, int index) const = 0;
251
252
        /**
253
         * When this function is called the nodes given in the parameter list should not lose any
254
         * signal data when connections are changed.
255
         */
256
        virtual bool startConnectionChange(QSet<QObject *>) = 0;
257
258
        /**
259
         * Defines a signal connection between the two given nodes.
260
         */
261
        virtual bool connectNodes(QObject *, QObject *) = 0;
262
263
        /**
264
         * Cuts a signal connection between the two given nodes.
265
         */
266
        virtual bool disconnectNodes(QObject *, QObject *) = 0;
267
268
        /**
269
         * When this function is called the nodes given in the parameter list may lose
270
         * signal data when a port is not connected.
271
         */
272
        virtual bool endConnectionChange(QSet<QObject *>) = 0;
273
274
        /**
275
         * gets all available mime types
276
         */
277
        virtual QStringList availableMimeTypes() const = 0;
278
279
};
280
} // namespace Phonon
281
282
Q_DECLARE_INTERFACE(Phonon::BackendInterface, "BackendInterface3.phonon.kde.org")
283
284
QT_END_NAMESPACE
285
QT_END_HEADER
286
287
#endif // PHONON_BACKENDINTERFACE_H