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 <QtMultimedia/private/qtmultimediaglobal_p.h>
41#include "camerabincontainer.h"
42#include <QtCore/qregexp.h>
43#include <private/qgstutils_p.h>
44
45#include <QtCore/qdebug.h>
46
47QT_BEGIN_NAMESPACE
48
49CameraBinContainer::CameraBinContainer(QObject *parent)
50 :QMediaContainerControl(parent)
51#if QT_CONFIG(gstreamer_encodingprofiles)
52 , m_supportedContainers(QGstCodecsInfo::Muxer)
53#endif
54{
55}
56
57QStringList CameraBinContainer::supportedContainers() const
58{
59#if QT_CONFIG(gstreamer_encodingprofiles)
60 return m_supportedContainers.supportedCodecs();
61#else
62 return QStringList();
63#endif
64}
65
66QString CameraBinContainer::containerDescription(const QString &formatMimeType) const
67{
68#if QT_CONFIG(gstreamer_encodingprofiles)
69 return m_supportedContainers.codecDescription(codec: formatMimeType);
70#else
71 Q_UNUSED(formatMimeType)
72 return QString();
73#endif
74}
75
76QString CameraBinContainer::containerFormat() const
77{
78 return m_format;
79}
80
81void CameraBinContainer::setContainerFormat(const QString &format)
82{
83#if QT_CONFIG(gstreamer_encodingprofiles)
84 if (m_format != format) {
85 m_format = format;
86 m_actualFormat = format;
87 emit settingsChanged();
88 }
89#endif
90}
91
92QString CameraBinContainer::actualContainerFormat() const
93{
94 return m_actualFormat;
95}
96
97void CameraBinContainer::setActualContainerFormat(const QString &containerFormat)
98{
99#if QT_CONFIG(gstreamer_encodingprofiles)
100 m_actualFormat = containerFormat;
101#endif
102}
103
104void CameraBinContainer::resetActualContainerFormat()
105{
106 m_actualFormat = m_format;
107}
108
109#if QT_CONFIG(gstreamer_encodingprofiles)
110
111GstEncodingContainerProfile *CameraBinContainer::createProfile()
112{
113 GstCaps *caps = nullptr;
114
115 if (m_actualFormat.isEmpty()) {
116 return 0;
117 } else {
118 QString format = m_actualFormat;
119 const QStringList supportedFormats = m_supportedContainers.supportedCodecs();
120
121 //if format is not in the list of supported gstreamer mime types,
122 //try to find the mime type with matching extension
123 if (!supportedFormats.contains(str: format)) {
124 format.clear();
125 QString extension = QGstUtils::fileExtensionForMimeType(mimeType: m_actualFormat);
126 for (const QString &formatCandidate : supportedFormats) {
127 if (QGstUtils::fileExtensionForMimeType(mimeType: formatCandidate) == extension) {
128 format = formatCandidate;
129 break;
130 }
131 }
132 }
133
134 if (format.isEmpty())
135 return nullptr;
136
137 caps = gst_caps_from_string(string: format.toLatin1());
138 }
139
140 GstEncodingContainerProfile *profile = (GstEncodingContainerProfile *)gst_encoding_container_profile_new(
141 name: "camerabin2_profile",
142 description: (gchar *)"custom camera profile",
143 format: caps,
144 NULL); //preset
145
146 gst_caps_unref(caps);
147
148 return profile;
149}
150
151#endif
152
153QT_END_NAMESPACE
154

source code of qtmultimedia/src/plugins/gstreamer/camerabin/camerabincontainer.cpp