Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qmacscreencapturekit_p.h
Go to the documentation of this file.
1
// Copyright (C) 2026 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
QMACSCREENCAPTUREKIT_P_H
5
#
define
QMACSCREENCAPTUREKIT_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
<
QtCore
/
qobject
.
h
>
19
#
include
<
QtCore
/
qloggingcategory
.
h
>
20
#
include
<
QtCore
/
private
/
qexpected_p
.
h
>
21
22
#
include
<
QtMultimedia
/
qvideoframe
.
h
>
23
#
include
<
QtMultimedia
/
private
/
qavfcamerautility_p
.
h
>
24
25
#
import
<
ScreenCaptureKit
/
ScreenCaptureKit
.
h
>
26
27
#
include
<
functional
>
28
#
include
<
future
>
29
#
include
<
memory
>
30
#
include
<
optional
>
31
#
include
<
vector
>
32
33
// Error-handling for on-going stream
34
@interface QT_MANGLE_NAMESPACE(QMacScreenCaptureStreamDelegate) : NSObject <SCStreamDelegate>
35
@end
36
37
// Receives frame callbacks
38
@interface QT_MANGLE_NAMESPACE(QMacScreenCaptureStreamOutput) : NSObject <SCStreamOutput>
39
@end
40
41
QT_BEGIN_NAMESPACE
42
43
namespace
QFFmpeg
{
44
45
Q_DECLARE_LOGGING_CATEGORY
(
qLcMacScreenCapture
);
46
47
using
QMacScreenCaptureStreamDelegate
=
QT_MANGLE_NAMESPACE
(
QMacScreenCaptureStreamDelegate
);
48
using
QMacScreenCaptureStreamOutput
=
QT_MANGLE_NAMESPACE
(
QMacScreenCaptureStreamOutput
);
49
50
// Helper class for managing a ScreenCaptureKit stream.
51
//
52
// TODO: This class has very few FFmpeg specific components. Move this out of FFmpeg media backend
53
// in the future.
54
class
QMacScreenCaptureKit
:
public
QObject
{
55
Q_OBJECT
56
57
public
:
58
enum
class
StreamId
:
int64_t
{};
59
60
// TODO: May become a runtime parameter in the future.
61
// For now we only support BGRA32.
62
static
constexpr
FourCharCode
cvPixelFormat
=
kCVPixelFormatType_32BGRA
;
63
static
constexpr
QVideoFrameFormat
::
PixelFormat
pixelFormat
=
64
QVideoFrameFormat
::
PixelFormat
::
Format_BGRA8888
;
65
// How many frames can be queued up on the background thread before we start dropping frames
66
// ScreenCaptureKit default is 3.
67
// https://developer.apple.com/documentation/screencapturekit/scstreamconfiguration/queuedepth?language=objc
68
static
constexpr
int
queueDepth
= 3;
69
[[nodiscard]]
static
CFStringRef
cgColorSpace
() {
return
kCGColorSpaceSRGB; }
70
static
constexpr
QVideoFrameFormat
::
ColorSpace
colorSpace
=
71
QVideoFrameFormat
::
ColorSpace
::
ColorSpace_BT709
;
72
static
constexpr
QVideoFrameFormat
::
ColorRange
colorRange
=
73
QVideoFrameFormat
::
ColorRange
::
ColorRange_Full
;
74
static
constexpr
QVideoFrameFormat
::
ColorTransfer
colorTransfer
=
75
QVideoFrameFormat
::
ColorTransfer
::
ColorTransfer_BT709
;
76
77
struct
CapturableItems
{
78
std
::
vector
<
AVFScopedPointer
<
SCDisplay
>>
displays
;
79
std
::
vector
<
AVFScopedPointer
<
SCWindow
>>
windows
;
80
};
81
82
struct
StreamSettings
{
83
std
::
optional
<
qreal
>
frameRate
;
84
bool
overrideIgnoreCursor
=
false
;
85
};
86
87
struct
CreateStreamInfo
{
88
StreamId
streamId
= {};
89
std
::function<
void
(
QMacScreenCaptureKit
&)>
connectionSetupFn
;
90
StreamSettings
streamSettings
= {};
91
};
92
93
QMacScreenCaptureKit
() =
default
;
94
~
QMacScreenCaptureKit
();
95
QMacScreenCaptureKit
(
const
QMacScreenCaptureKit
&) =
delete
;
96
QMacScreenCaptureKit
&
operator
=(
const
QMacScreenCaptureKit
&) =
delete
;
97
QMacScreenCaptureKit
(
QMacScreenCaptureKit
&&other)
noexcept
=
delete
;
98
QMacScreenCaptureKit
&
operator
=(
QMacScreenCaptureKit
&&other) =
delete
;
99
100
[[nodiscard]]
StreamId
streamId
()
const
noexcept
{
return
m_streamId; }
101
102
[[
nodiscard
]]
static
std
::
future
<
q23
::
expected
<
CapturableItems
,
QString
>>
enumerateCapturableItems
();
103
104
[[
nodiscard
]]
static
std
::
future
<
q23
::
expected
<
std
::
unique_ptr
<
QMacScreenCaptureKit
>,
QString
>>
105
createStreamFromDisplay
(
106
CreateStreamInfo
const
&,
107
SCDisplay
*);
108
109
[[
nodiscard
]]
static
std
::
future
<
q23
::
expected
<
std
::
unique_ptr
<
QMacScreenCaptureKit
>,
QString
>>
110
createStreamFromFilter
(
111
CreateStreamInfo
const
&,
112
SCContentFilter
*);
113
114
[[
nodiscard
]]
static
std
::
future
<
q23
::
expected
<
std
::
unique_ptr
<
QMacScreenCaptureKit
>,
QString
>>
115
createStreamFromWindow
(
116
CreateStreamInfo
const
&,
117
SCWindow
*);
118
119
// Switches the ongoing stream over to capture new content, without restarting it.
120
// Presentation times continue on from the old content. The future is signaled
121
// once the switch is complete and the frames already queued for the old content
122
// have been flushed. The future must be waited on before destroying this object.
123
[[
nodiscard
]]
std
::
future
<
q23
::
expected
<
void
,
QString
>>
switchToFilter
(
SCContentFilter
*);
124
125
[[
nodiscard
]]
std
::
future
<
q23
::
expected
<
void
,
QString
>>
switchToDisplay
(
SCDisplay
*);
126
127
[[
nodiscard
]]
std
::
future
<
q23
::
expected
<
void
,
QString
>>
switchToWindow
(
SCWindow
*);
128
129
// Called from background thread when stream needs to be configured with new
130
// output resolution. Don't call directly.
131
void
updateStream
(QSize resolutionPx);
132
133
Q_SIGNALS
:
134
void
newVideoFrameGenerated
(
StreamId
streamId
,
QVideoFrame
);
135
// This is commonly signaled if the user stops the stream by
136
// interacting with the system UI, or the stream has stopped
137
// for unknown reasons.
138
// Message is not suitable for forwarding to UI.
139
void
streamStoppedWithError
(StreamId streamId,
QString
);
140
141
private
:
142
StreamId m_streamId = {};
143
144
// A copy of the stream settings when this class was created. Does
145
// not change after stream has started. Used for auto-reconfiguring
146
// our stream with new size when needed.
147
StreamSettings
m_streamSettings = {};
148
149
AVFScopedPointer<SCStream> m_stream;
150
AVFScopedPointer<dispatch_queue_t> m_dispatchQueue;
151
AVFScopedPointer<QMacScreenCaptureStreamDelegate> m_streamDelegate;
152
AVFScopedPointer<QMacScreenCaptureStreamOutput> m_streamOutput;
153
154
static
void
startStreamReconfigure(
155
SCStream *scStream,
156
QSize resolutionPx,
157
StreamSettings
const
&);
158
};
159
160
}
161
162
QT_END_NAMESPACE
163
164
#
endif
// QMACSCREENCAPTUREKIT_P_H
QFFmpeg::QMacScreenCaptureKit
Definition
qmacscreencapturekit_p.h:54
QFFmpeg::QMacScreenCaptureKit::operator=
QMacScreenCaptureKit & operator=(QMacScreenCaptureKit &&other)=delete
QFFmpeg::QMacScreenCaptureKit::pixelFormat
static constexpr QVideoFrameFormat::PixelFormat pixelFormat
Definition
qmacscreencapturekit_p.h:63
QFFmpeg::QMacScreenCaptureKit::queueDepth
static constexpr int queueDepth
Definition
qmacscreencapturekit_p.h:68
QFFmpeg::QMacScreenCaptureKit::QMacScreenCaptureKit
QMacScreenCaptureKit(const QMacScreenCaptureKit &)=delete
QFFmpeg::QMacScreenCaptureKit::streamStoppedWithError
void streamStoppedWithError(StreamId streamId, QString)
QFFmpeg::QMacScreenCaptureKit::cvPixelFormat
static constexpr FourCharCode cvPixelFormat
Definition
qmacscreencapturekit_p.h:62
QFFmpeg::QMacScreenCaptureKit::~QMacScreenCaptureKit
~QMacScreenCaptureKit()
Definition
qmacscreencapturekit.mm:418
QFFmpeg::QMacScreenCaptureKit::colorTransfer
static constexpr QVideoFrameFormat::ColorTransfer colorTransfer
Definition
qmacscreencapturekit_p.h:74
QFFmpeg::QMacScreenCaptureKit::QMacScreenCaptureKit
QMacScreenCaptureKit(QMacScreenCaptureKit &&other) noexcept=delete
QFFmpeg::QMacScreenCaptureKit::operator=
QMacScreenCaptureKit & operator=(const QMacScreenCaptureKit &)=delete
QFFmpeg::QMacScreenCaptureKit::updateStream
void updateStream(QSize resolutionPx)
Definition
qmacscreencapturekit.mm:725
QFFmpeg::QMacScreenCaptureKit::streamId
StreamId streamId() const noexcept
Definition
qmacscreencapturekit_p.h:100
QFFmpeg::QMacScreenCaptureKit::colorRange
static constexpr QVideoFrameFormat::ColorRange colorRange
Definition
qmacscreencapturekit_p.h:72
QFFmpeg::QMacScreenCaptureKit::QMacScreenCaptureKit
QMacScreenCaptureKit()=default
QFFmpeg::QMacScreenCaptureKit::cgColorSpace
static CFStringRef cgColorSpace()
Definition
qmacscreencapturekit_p.h:69
QFFmpeg::QMacScreenCaptureKit::colorSpace
static constexpr QVideoFrameFormat::ColorSpace colorSpace
Definition
qmacscreencapturekit_p.h:70
QFFmpeg
Definition
qandroidcacertificates.cpp:26
QFFmpeg::createStreamConfig
static AVFScopedPointer< SCStreamConfiguration > createStreamConfig(QSize resolutionPx, QMacScreenCaptureKit::StreamSettings const &settings)
Definition
qmacscreencapturekit.mm:304
QFFmpeg::createDisplayFilter
static AVFScopedPointer< SCContentFilter > createDisplayFilter(SCDisplay *scDisplay)
Definition
qmacscreencapturekit.mm:383
QFFmpeg::Q_DECLARE_LOGGING_CATEGORY
Q_DECLARE_LOGGING_CATEGORY(qLcMacScreenCapture)
QFFmpeg::handleFrameOutput
static void handleFrameOutput(QMacScreenCaptureStreamOutput &scStreamOutput, CMSampleBufferRef sampleBufferRef)
Definition
qmacscreencapturekit.mm:254
QFFmpeg::createEndOfStreamFrame
static QVideoFrame createEndOfStreamFrame(std::chrono::microseconds baseTime)
Definition
qmacscreencapturekit.mm:238
QFFmpeg::createQVideoFrame
static q23::expected< QVideoFrame, QString > createQVideoFrame(QMacScreenCaptureStreamOutput &scStreamOutput, CMSampleBufferRef sampleBufferRef)
Definition
qmacscreencapturekit.mm:165
QFFmpeg::createStreamOutput
static q23::expected< AVFScopedPointer< QMacScreenCaptureStreamOutput >, QString > createStreamOutput(QMacScreenCaptureKit &macScreenCaptureKit, uint32_t cvPixelFormat, QSize resolution)
Definition
qmacscreencapturekit.mm:356
QFFmpeg::createWindowFilter
static AVFScopedPointer< SCContentFilter > createWindowFilter(SCWindow *scWindow)
Definition
qmacscreencapturekit.mm:391
QFFmpeg::configureStreamDelegate
static void configureStreamDelegate(QMacScreenCaptureStreamDelegate &streamDelegate, QMacScreenCaptureKit::StreamId streamId, const QMacScreenCaptureKit &macScreenCaptureKit)
Definition
qmacscreencapturekit.mm:342
QFFmpeg::readFrameInfo
static q23::expected< FrameInfo, QString > readFrameInfo(CMSampleBufferRef sampleBuffer)
Definition
qmacscreencapturekit.mm:123
QFFmpeg::resolutionForFilter
static q23::expected< QSize, QString > resolutionForFilter(SCContentFilter *scContentFilter)
Definition
qmacscreencapturekit.mm:400
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
Q_LOGGING_CATEGORY_IMPL
Q_LOGGING_CATEGORY_IMPL(QT_PREPEND_NAMESPACE(QFFmpeg::qLcMacScreenCapture), "qt.multimedia.screencapture.macscreencapturekit")
QFFmpeg::FrameInfo
Definition
qmacscreencapturekit.mm:111
QFFmpeg::FrameInfo::contentRect
QSize contentRect
Definition
qmacscreencapturekit.mm:116
QFFmpeg::FrameInfo::status
SCFrameStatus status
Definition
qmacscreencapturekit.mm:112
QFFmpeg::QMacScreenCaptureKit::CapturableItems
Definition
qmacscreencapturekit_p.h:77
QFFmpeg::QMacScreenCaptureKit::CapturableItems::displays
std::vector< AVFScopedPointer< SCDisplay > > displays
Definition
qmacscreencapturekit_p.h:78
QFFmpeg::QMacScreenCaptureKit::CapturableItems::windows
std::vector< AVFScopedPointer< SCWindow > > windows
Definition
qmacscreencapturekit_p.h:79
QFFmpeg::QMacScreenCaptureKit::CreateStreamInfo
Definition
qmacscreencapturekit_p.h:87
QFFmpeg::QMacScreenCaptureKit::CreateStreamInfo::connectionSetupFn
std::function< void(QMacScreenCaptureKit &)> connectionSetupFn
Definition
qmacscreencapturekit_p.h:89
QFFmpeg::QMacScreenCaptureKit::CreateStreamInfo::streamSettings
StreamSettings streamSettings
Definition
qmacscreencapturekit_p.h:90
QFFmpeg::QMacScreenCaptureKit::CreateStreamInfo::streamId
StreamId streamId
Definition
qmacscreencapturekit_p.h:88
QFFmpeg::QMacScreenCaptureKit::StreamSettings
Definition
qmacscreencapturekit_p.h:82
QFFmpeg::QMacScreenCaptureKit::StreamSettings::frameRate
std::optional< qreal > frameRate
Definition
qmacscreencapturekit_p.h:83
QFFmpeg::QMacScreenCaptureKit::StreamSettings::overrideIgnoreCursor
bool overrideIgnoreCursor
Definition
qmacscreencapturekit_p.h:84
qtmultimedia
src
plugins
multimedia
ffmpeg
darwin
qmacscreencapturekit_p.h
Generated on
for Qt by
1.18.0