1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QGSTREAMERIMAGECAPTURECONTROL_H
5#define QGSTREAMERIMAGECAPTURECONTROL_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/private/qplatformimagecapture_p.h>
19#include <QtMultimedia/private/qmultimediautils_p.h>
20
21#include <QtCore/qmutex.h>
22#include <QtCore/qqueue.h>
23#include <QtConcurrent/QtConcurrentRun>
24
25#include <common/qgst_p.h>
26#include <common/qgstreamerbufferprobe_p.h>
27#include <mediacapture/qgstreamermediacapturesession_p.h>
28#include <gst/video/video.h>
29
30QT_BEGIN_NAMESPACE
31
32class QGstreamerImageCapture : public QPlatformImageCapture, private QGstreamerBufferProbe
33{
34 Q_OBJECT
35
36public:
37 static QMaybe<QPlatformImageCapture *> create(QImageCapture *parent);
38 virtual ~QGstreamerImageCapture();
39
40 bool isReadyForCapture() const override;
41 int capture(const QString &fileName) override;
42 int captureToBuffer() override;
43
44 QImageEncoderSettings imageSettings() const override;
45 void setImageSettings(const QImageEncoderSettings &settings) override;
46
47 bool probeBuffer(GstBuffer *buffer) override;
48
49 void setCaptureSession(QPlatformMediaCaptureSession *session);
50
51 QGstElement gstElement() const { return bin; }
52
53 void setMetaData(const QMediaMetaData &m) override;
54
55public Q_SLOTS:
56 void cameraActiveChanged(bool active);
57 void onCameraChanged();
58
59private:
60 QGstreamerImageCapture(QImageCapture *parent);
61
62 void setResolution(const QSize &resolution);
63 int doCapture(const QString &fileName);
64 static gboolean saveImageFilter(GstElement *element, GstBuffer *buffer, GstPad *pad,
65 QGstreamerImageCapture *capture);
66
67 void saveBufferToImage(GstBuffer *buffer);
68
69 mutable QRecursiveMutex
70 m_mutex; // guard all elements accessed from probeBuffer/saveBufferToImage
71 QGstreamerMediaCaptureSession *m_session = nullptr;
72 int m_lastId = 0;
73 QImageEncoderSettings m_settings;
74
75 struct PendingImage {
76 int id;
77 QString filename;
78 QMediaMetaData metaData;
79 };
80
81 QQueue<PendingImage> pendingImages;
82
83 QGstBin bin;
84 QGstElement queue;
85 QGstElement filter;
86 QGstElement videoConvert;
87 QGstElement encoder;
88 QGstElement muxer;
89 QGstElement sink;
90 QGstPad videoSrcPad;
91
92 bool passImage = false;
93 bool cameraActive = false;
94
95 QGObjectHandlerScopedConnection m_handoffConnection;
96
97 QMap<int, QFuture<void>> m_pendingFutures;
98 int futureIDAllocator = 0;
99
100 template <typename Functor>
101 void invokeDeferred(Functor &&fn)
102 {
103 QMetaObject::invokeMethod(this, std::forward<decltype(fn)>(fn), Qt::QueuedConnection);
104 };
105};
106
107QT_END_NAMESPACE
108
109#endif // QGSTREAMERCAPTURECORNTROL_H
110

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtmultimedia/src/plugins/multimedia/gstreamer/mediacapture/qgstreamerimagecapture_p.h