38 ** $QT_END_LICENSE$ |
38 ** $QT_END_LICENSE$ |
39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include <QtCore/qstring.h> |
42 #include <QtCore/qstring.h> |
|
43 #include <QtCore/qfile.h> |
43 #include <QtCore/qdebug.h> |
44 #include <QtCore/qdebug.h> |
44 #include <QtCore/QFile> |
45 #include <QtCore/qdir.h> |
45 |
46 |
46 #include "v4lserviceplugin.h" |
47 #include "v4lserviceplugin.h" |
47 #include "v4lcameraservice.h" |
|
48 #include "v4lradioservice.h" |
48 #include "v4lradioservice.h" |
49 |
49 |
50 #include <qmediaserviceprovider.h> |
50 #include <qmediaserviceprovider.h> |
51 |
51 |
52 |
52 |
53 QStringList V4LServicePlugin::keys() const |
53 QStringList V4LServicePlugin::keys() const |
54 { |
54 { |
55 return QStringList() << |
55 return QStringList() << |
56 QLatin1String(Q_MEDIASERVICE_RADIO) << |
56 QLatin1String(Q_MEDIASERVICE_RADIO); |
57 QLatin1String(Q_MEDIASERVICE_CAMERA); |
|
58 } |
57 } |
59 |
58 |
60 QMediaService* V4LServicePlugin::create(QString const& key) |
59 QMediaService* V4LServicePlugin::create(QString const& key) |
61 { |
60 { |
62 if (key == QLatin1String(Q_MEDIASERVICE_RADIO)) |
61 if (key == QLatin1String(Q_MEDIASERVICE_RADIO)) |
63 return new V4LRadioService; |
62 return new V4LRadioService; |
64 |
63 |
65 if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) |
|
66 return new V4LCameraService; |
|
67 |
|
68 //qDebug() << "unsupported key:" << key; |
|
69 return 0; |
64 return 0; |
70 } |
65 } |
71 |
66 |
72 void V4LServicePlugin::release(QMediaService *service) |
67 void V4LServicePlugin::release(QMediaService *service) |
73 { |
68 { |
74 delete service; |
69 delete service; |
75 } |
70 } |
76 |
71 |
77 QList<QByteArray> V4LServicePlugin::devices(const QByteArray &service) const |
72 QList<QByteArray> V4LServicePlugin::devices(const QByteArray &service) const |
78 { |
73 { |
79 if (service == Q_MEDIASERVICE_CAMERA) { |
|
80 if (m_cameraDevices.isEmpty()) |
|
81 updateDevices(); |
|
82 |
|
83 return m_cameraDevices; |
|
84 } |
|
85 |
|
86 return QList<QByteArray>(); |
74 return QList<QByteArray>(); |
87 } |
75 } |
88 |
76 |
89 QString V4LServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) |
77 QString V4LServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) |
90 { |
78 { |
91 if (service == Q_MEDIASERVICE_CAMERA) { |
|
92 if (m_cameraDevices.isEmpty()) |
|
93 updateDevices(); |
|
94 |
|
95 for (int i=0; i<m_cameraDevices.count(); i++) |
|
96 if (m_cameraDevices[i] == device) |
|
97 return m_cameraDescriptions[i]; |
|
98 } |
|
99 |
|
100 return QString(); |
79 return QString(); |
101 } |
|
102 |
|
103 void V4LServicePlugin::updateDevices() const |
|
104 { |
|
105 m_cameraDevices.clear(); |
|
106 m_cameraDescriptions.clear(); |
|
107 |
|
108 QString name; |
|
109 QFile video0("/sys/class/video4linux/video0/name"); |
|
110 if (video0.exists()) { |
|
111 m_cameraDevices.append("v4l:/dev/video0"); |
|
112 char str[31]; |
|
113 memset(str,0,31); |
|
114 video0.open(QIODevice::ReadOnly); |
|
115 video0.read(str,30); |
|
116 name = QString(str); |
|
117 m_cameraDescriptions.append(name.simplified()); |
|
118 video0.close(); |
|
119 } |
|
120 |
|
121 QFile video1("/sys/class/video4linux/video1/name"); |
|
122 if (video0.exists()) { |
|
123 m_cameraDevices.append("v4l:/dev/video1"); |
|
124 char str[31]; |
|
125 memset(str,0,31); |
|
126 video1.open(QIODevice::ReadOnly); |
|
127 video1.read(str,30); |
|
128 name = QString(str); |
|
129 m_cameraDescriptions.append(name.simplified()); |
|
130 video1.close(); |
|
131 } |
|
132 } |
80 } |
133 |
81 |
134 |
82 |
135 Q_EXPORT_PLUGIN2(v4lengine, V4LServicePlugin); |
83 Q_EXPORT_PLUGIN2(v4lengine, V4LServicePlugin); |
136 |
84 |