1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include <QtCore/qstring.h> |
41 | #include <QtCore/qdebug.h> |
42 | #include <QtCore/QDir> |
43 | #include <QtCore/QDebug> |
44 | |
45 | #include "qgstreamercaptureserviceplugin.h" |
46 | |
47 | //#define QT_SUPPORTEDMIMETYPES_DEBUG |
48 | |
49 | #include "qgstreamercaptureservice.h" |
50 | #include <private/qgstutils_p.h> |
51 | |
52 | QMediaService* QGstreamerCaptureServicePlugin::create(const QString &key) |
53 | { |
54 | QGstUtils::initializeGst(); |
55 | |
56 | if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)) |
57 | return new QGstreamerCaptureService(key); |
58 | |
59 | #if defined(USE_GSTREAMER_CAMERA) |
60 | if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) |
61 | return new QGstreamerCaptureService(key); |
62 | #endif |
63 | |
64 | qWarning() << "Gstreamer capture service plugin: unsupported key:" << key; |
65 | return 0; |
66 | } |
67 | |
68 | void QGstreamerCaptureServicePlugin::release(QMediaService *service) |
69 | { |
70 | delete service; |
71 | } |
72 | |
73 | #if defined(USE_GSTREAMER_CAMERA) |
74 | QMediaServiceProviderHint::Features QGstreamerCaptureServicePlugin::supportedFeatures( |
75 | const QByteArray &service) const |
76 | { |
77 | if (service == Q_MEDIASERVICE_CAMERA) |
78 | return QMediaServiceProviderHint::VideoSurface; |
79 | |
80 | return QMediaServiceProviderHint::Features(); |
81 | } |
82 | |
83 | QByteArray QGstreamerCaptureServicePlugin::defaultDevice(const QByteArray &service) const |
84 | { |
85 | return service == Q_MEDIASERVICE_CAMERA |
86 | ? QGstUtils::enumerateCameras().value(0).name.toUtf8() |
87 | : QByteArray(); |
88 | } |
89 | |
90 | QList<QByteArray> QGstreamerCaptureServicePlugin::devices(const QByteArray &service) const |
91 | { |
92 | return service == Q_MEDIASERVICE_CAMERA ? QGstUtils::cameraDevices() : QList<QByteArray>(); |
93 | } |
94 | |
95 | QString QGstreamerCaptureServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) |
96 | { |
97 | return service == Q_MEDIASERVICE_CAMERA ? QGstUtils::cameraDescription(device) : QString(); |
98 | } |
99 | |
100 | QVariant QGstreamerCaptureServicePlugin::deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property) |
101 | { |
102 | Q_UNUSED(service); |
103 | Q_UNUSED(device); |
104 | Q_UNUSED(property); |
105 | return QVariant(); |
106 | } |
107 | |
108 | #endif |
109 | |
110 | QMultimedia::SupportEstimate QGstreamerCaptureServicePlugin::hasSupport(const QString &mimeType, |
111 | const QStringList& codecs) const |
112 | { |
113 | if (m_supportedMimeTypeSet.isEmpty()) |
114 | updateSupportedMimeTypes(); |
115 | |
116 | return QGstUtils::hasSupport(mimeType, codecs, supportedMimeTypeSet: m_supportedMimeTypeSet); |
117 | } |
118 | |
119 | |
120 | static bool isEncoderOrMuxer(GstElementFactory *factory) |
121 | { |
122 | #if GST_CHECK_VERSION(0, 10, 31) |
123 | return gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_MUXER) |
124 | || gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_ENCODER); |
125 | #else |
126 | return (factory |
127 | && (qstrcmp(factory->details.klass, "Codec/Encoder/Audio" ) == 0 |
128 | || qstrcmp(factory->details.klass, "Codec/Encoder/Video" ) == 0 |
129 | || qstrcmp(factory->details.klass, "Codec/Muxer" ) == 0 )); |
130 | #endif |
131 | } |
132 | |
133 | void QGstreamerCaptureServicePlugin::updateSupportedMimeTypes() const |
134 | { |
135 | m_supportedMimeTypeSet = QGstUtils::supportedMimeTypes(isValidFactory: isEncoderOrMuxer); |
136 | } |
137 | |
138 | QStringList QGstreamerCaptureServicePlugin::supportedMimeTypes() const |
139 | { |
140 | return QStringList(); |
141 | } |
142 | |
143 | |