Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsurfacecapturegrabber_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QSURFACECAPTUREGRABBER_P_H
5#define QSURFACECAPTUREGRABBER_P_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/qvideoframe.h>
19#include <QtMultimedia/private/qplatformsurfacecapture_p.h>
20#include <QtMultimedia/qtmultimediaglobal.h>
21
22#include <memory>
23#include <optional>
24
25QT_BEGIN_NAMESPACE
26
27class QThread;
28
29static constexpr qreal DefaultScreenCaptureFrameRate = 60.f;
30static constexpr qreal MinScreenCaptureFrameRate = 1.f;
31
32class Q_MULTIMEDIA_EXPORT QSurfaceCaptureGrabber : public QObject
33{
34 Q_OBJECT
35public:
36 enum ThreadPolicy {
37 UseCurrentThread,
38 CreateGrabbingThread,
39 };
40
41 ~QSurfaceCaptureGrabber() override;
42
43 void start();
44 void stop();
45
46 template<typename Object, typename Method>
47 void addFrameCallback(Object *object, Method method)
48 {
49 connect(this, &QSurfaceCaptureGrabber::frameGrabbed, object, method,
50 Qt::DirectConnection);
51 }
52
53 void setFrameRate(std::optional<qreal>);
54 qreal frameRate() const;
55
56signals:
57 void frameGrabbed(const QVideoFrame&);
58 void errorUpdated(QPlatformSurfaceCapture::Error error, const QString &description);
59
60protected:
61 QSurfaceCaptureGrabber(ThreadPolicy threadPolicy = CreateGrabbingThread);
62
63 void updateError(QPlatformSurfaceCapture::Error error, const QString &description = {});
64
65 virtual QVideoFrame grabFrame() = 0;
66
67 void updateTimerInterval();
68
69 virtual void initializeGrabbingContext();
70 virtual void finalizeGrabbingContext();
71
72 bool isGrabbingContextInitialized() const;
73
74 void injectContextToGrabbingThread(QObject *context);
75
76private:
77 class GrabbingProfiler;
78 struct GrabbingContext;
79 class GrabbingThread;
80
81 std::unique_ptr<GrabbingContext> m_context;
82 std::optional<QPlatformSurfaceCapture::Error> m_prevError;
83 std::unique_ptr<QThread> m_thread;
84
85 qreal m_rate{ DefaultScreenCaptureFrameRate };
86};
87
88QT_END_NAMESPACE
89
90#endif // QSURFACECAPTUREGRABBER_P_H
Combined button and popup list for selecting options.
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
static constexpr qreal MinScreenCaptureFrameRate
static constexpr qreal DefaultScreenCaptureFrameRate