5#include "private/qcapturablewindow_p.h"
7#include "private/qabstractvideobuffer_p.h"
14#include <ApplicationServices/ApplicationServices.h>
15#include <IOKit/graphics/IOGraphicsLib.h>
16#include <AppKit/NSScreen.h>
17#include <AppKit/NSApplication.h>
18#include <AppKit/NSWindow.h>
22std::optional<qreal> frameRateForWindow(CGWindowID )
44 auto provider = CGImageGetDataProvider(
image);
45 m_data = CGDataProviderCopyData(provider);
46 m_bytesPerLine = CGImageGetBytesPerRow(
image);
62 mapData.
size[0] =
static_cast<int>(CFDataGetLength(m_data));
73 size_t m_bytesPerLine = 0;
96 m_waitForFormat.
wait(&m_formatMutex);
103 if (
auto rate = frameRateForWindow(m_wid))
106 auto imageRef = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow,
107 m_wid, kCGWindowImageBoundsIgnoreFraming);
114 auto imageDeleter =
qScopeGuard([imageRef]() { CGImageRelease(imageRef); });
116 if (CGImageGetBitsPerPixel(imageRef) != 32
117 || CGImageGetPixelFormatInfo(imageRef) != kCGImagePixelFormatPacked
118 || CGImageGetByteOrderInfo(imageRef) != kCGImageByteOrder32Little) {
119 qWarning() <<
"Unexpected image format. PixelFormatInfo:"
120 << CGImageGetPixelFormatInfo(imageRef)
121 <<
"BitsPerPixel:" << CGImageGetBitsPerPixel(imageRef) <<
"AlphaInfo"
122 << CGImageGetAlphaInfo(imageRef)
123 <<
"ByteOrderInfo:" << CGImageGetByteOrderInfo(imageRef);
141 if (!m_format || m_format !=
frame.surfaceFormat()) {
144 m_format =
frame.surfaceFormat();
156 std::optional<QVideoFrameFormat> m_format;
157 mutable QMutex m_formatMutex;
164 CGRequestScreenCaptureAccess();
172 if (!CGPreflightScreenCaptureAccess()) {
184 m_grabber = std::make_unique<Grabber>(*
this,
handle->id);
190 return active ==
static_cast<bool>(m_grabber);
200#include "moc_qcgwindowcapture_p.cpp"
The QAbstractVideoBuffer class is an abstraction for video data. \inmodule QtMultimedia.
void unmap() override
Releases the memory mapped by the map() function.
~QCGImageVideoBuffer() override
MapData map(QVideoFrame::MapMode mode) override
Independently maps the planes of a video buffer to memory.
QCGImageVideoBuffer(CGImageRef image)
QVideoFrame::MapMode mapMode() const override
QVideoFrameFormat frameFormat() const
void onNewFrame(QVideoFrame frame)
QVideoFrame grabFrame() override
Grabber(QCGWindowCapture &capture, CGWindowID wid)
QVideoFrameFormat frameFormat() const override
bool setActiveInternal(bool active) override
~QCGWindowCapture() override
static const QCapturableWindowPrivate * handle(const QCapturableWindow &window)
void addFrameCallback(Object &object, Method method)
void errorUpdated(QPlatformSurfaceCapture::Error error, const QString &description)
void setFrameRate(qreal rate)
QScreen * primaryScreen
the primary (or default) screen of the application.
void unlock() noexcept
Unlocks this mutex locker.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
qreal refreshRate
the approximate vertical refresh rate of the screen in Hz
void start(Priority=InheritPriority)
The QVideoFrame class represents a frame of video data.
MapMode
Enumerates how a video buffer's data is mapped to system memory.
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
Combined button and popup list for selecting options.
GLuint64 GLenum void * handle
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
static QAbstractVideoBuffer::MapData mapData(const camera_frame_nv12_t &frame, unsigned char *baseAddress)
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
QLatin1StringView QLatin1String