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
qcgwindowcapture.mm
Go to the documentation of this file.
1// Copyright (C) 2022 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#include <QtFFmpegMediaPluginImpl/private/qcgwindowcapture_p.h>
5
6#include <QtCore/qmutex.h>
7#include <QtCore/qwaitcondition.h>
8
9#include <QtFFmpegMediaPluginImpl/private/qffmpegsurfacecapturegrabber_p.h>
10
11#include <QtGui/qscreen.h>
12#include <QtGui/qguiapplication.h>
13
14#include <QtMultimedia/qabstractvideobuffer.h>
15#include <QtMultimedia/private/qcapturablewindow_p.h>
16#include <QtMultimedia/private/qvideoframe_p.h>
17
18#include <QtCore/private/qcore_mac_p.h>
19
20#include <ApplicationServices/ApplicationServices.h>
21#include <IOKit/graphics/IOGraphicsLib.h>
22
23#import <AppKit/NSScreen.h>
24#import <AppKit/NSApplication.h>
25#import <AppKit/NSWindow.h>
26
27namespace {
28
29std::optional<qreal> frameRateForWindow(CGWindowID /*wid*/)
30{
31 // TODO: detect the frame rate
32 // if (window && window.screen) {
33 // CGDirectDisplayID displayID = [window.screen.deviceDescription[@"NSScreenNumber"]
34 // unsignedIntValue]; const auto displayRefreshRate =
35 // CGDisplayModeGetRefreshRate(CGDisplayCopyDisplayMode(displayID)); if (displayRefreshRate
36 // > 0 && displayRefreshRate < frameRate) frameRate = displayRefreshRate;
37 // }
38
39 return {};
40}
41
42}
43
44QT_BEGIN_NAMESPACE
45
46namespace QFFmpeg {
47
49{
50public:
51 QCGImageVideoBuffer(CGImageRef image)
52 {
53 auto provider = CGImageGetDataProvider(image);
54 m_data = CGDataProviderCopyData(provider);
55 m_bytesPerLine = CGImageGetBytesPerRow(image);
56 }
57
58 MapData map(QVideoFrame::MapMode /*mode*/) override
59 {
60 MapData mapData;
61
62 mapData.planeCount = 1;
63 mapData.bytesPerLine[0] = static_cast<int>(m_bytesPerLine);
64 mapData.data[0] = (uchar *)CFDataGetBytePtr(m_data);
65 mapData.dataSize[0] = static_cast<int>(CFDataGetLength(m_data));
66
67 return mapData;
68 }
69
70 QVideoFrameFormat format() const override { return {}; }
71
72private:
73 QCFType<CFDataRef> m_data;
74 size_t m_bytesPerLine = 0;
75};
76
78{
79public:
90
92
100
101protected:
137
139 {
140 // Since writing of the format is supposed to be only from one thread,
141 // the read-only comparison without a mutex is thread-safe
142 if (!m_format || m_format != frame.surfaceFormat()) {
144
146
147 locker.unlock();
148
150 }
151
153 }
154
155private:
158 mutable QMutex m_formatMutex;
161};
162
167
169
171{
172 if (active) {
175 QLatin1String("Permissions denied"));
176 return false;
177 }
178
179 auto window = source<WindowSource>();
180
182 if (!handle || !handle->id)
184 else
186
187 } else {
189 }
190
191 return active == static_cast<bool>(m_grabber);
192}
193
198
200{
201 return std::make_unique<QCGWindowCapture>();
202}
203
204} // namespace QFFmpeg
205
206QT_END_NAMESPACE
207
208#include "moc_qcgwindowcapture_p.cpp"
MapData map(QVideoFrame::MapMode) override
Maps the planes of a video buffer to memory.
QVideoFrameFormat format() const override
Gets \l QVideoFrameFormat of the underlying video buffer.
QCGImageVideoBuffer(CGImageRef image)
std::unique_ptr< QPlatformSurfaceCapture > makeQCgWindowCapture()
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType