1/* This file is part of the KDE project.
2
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5 This library is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 2.1 or 3 of the License.
8
9 This library 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this library. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef Phonon_GSTREAMER_DEVICEMANAGER_H
19#define Phonon_GSTREAMER_DEVICEMANAGER_H
20
21#include <phonon/audiooutputinterface.h>
22
23#include <QtCore/QObject>
24#include <QtCore/QTimer>
25
26#include <gst/gstelement.h>
27
28namespace Phonon {
29namespace Gstreamer {
30
31class Backend;
32class DeviceManager;
33class AbstractRenderer;
34class VideoWidget;
35
36/** \brief Container for information about devices supported by Gstreamer
37 *
38 * It includes an unique device identifier, a name identifier, a
39 * description, a hardware identifier (may be a platform dependent device name),
40 * and other relevant info.
41 */
42class DeviceInfo
43{
44public:
45 enum Capability {
46 None = 0x0000,
47 AudioOutput = 0x0001,
48 AudioCapture = 0x0002, // TODO
49 VideoCapture = 0x0004
50 };
51public:
52 /**
53 * Constructs a device info object and sets it's device identifiers.
54 */
55 explicit DeviceInfo(DeviceManager *, const QByteArray &deviceId,
56 quint16 caps, bool isAdvanced = true);
57
58 int id() const;
59 const QString& name() const;
60 const QString& description() const;
61 bool isAdvanced() const;
62 void setAdvanced(bool advanced);
63 const DeviceAccessList& accessList() const;
64 void addAccess(const DeviceAccess &access);
65 quint16 capabilities() const;
66 void setCapabilities(quint16 cap);
67
68private:
69 void useGstElement(GstElement *element, const QByteArray &deviceId);
70
71 int m_id;
72 QString m_name; // the preferred name for the device
73 QString m_description; // describes how to access the device (factory name, gst id)
74 bool m_isAdvanced;
75 DeviceAccessList m_accessList;
76 quint16 m_capabilities;
77};
78
79/** \brief Keeps track of audio/video devices
80 *
81 * The device manager provides information about devices usable
82 * with Gstreamer.
83 *
84 * It also provides methods for creating specific objects depending on
85 * categories (audo sink, video renderer)
86 */
87class DeviceManager : public QObject {
88 Q_OBJECT
89public:
90 DeviceManager(Backend *parent);
91 virtual ~DeviceManager();
92 GstElement *createGNOMEAudioSink(Category category);
93 GstElement *createAudioSink(Category category = NoCategory);
94 AbstractRenderer *createVideoRenderer(VideoWidget *parent);
95 QList<int> deviceIds(ObjectDescriptionType type);
96 QHash<QByteArray, QVariant> deviceProperties(int id);
97 const DeviceInfo *device(int id) const;
98
99signals:
100 void deviceAdded(int);
101 void deviceRemoved(int);
102
103public slots:
104 void updateDeviceList();
105
106private:
107 static bool listContainsDevice(const QList<DeviceInfo> &list, int id);
108 bool canOpenDevice(GstElement *element) const;
109
110private:
111 Backend *m_backend;
112 QList<DeviceInfo> m_devices;
113 QTimer m_devicePollTimer;
114 QByteArray m_audioSink;
115 QByteArray m_videoSinkWidget;
116};
117}
118} // namespace Phonon::Gstreamer
119
120#endif // Phonon_GSTREAMER_DEVICEMANAGER_H
121