summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/ffmpeg/qeglfsscreencapture.cpp
blob: 1837c3c57db07ee329ee38d5019300730ef522cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR
// GPL-3.0-only

#include "qeglfsscreencapture_p.h"
#include "qffmpegsurfacecapturegrabber_p.h"
#include "qguiapplication.h"

QT_BEGIN_NAMESPACE

class QEglfsScreenCapture::Grabber : public QFFmpegSurfaceCaptureGrabber
{
public:
    Grabber(QEglfsScreenCapture &screenCapture, QScreen *screen)
        : QFFmpegSurfaceCaptureGrabber(false)
    {
        setFrameRate(screen->refreshRate());
        addFrameCallback(screenCapture, &QEglfsScreenCapture::newVideoFrame);
        connect(this, &Grabber::errorUpdated, &screenCapture, &QEglfsScreenCapture::updateError);
    }

    ~Grabber() override { stop(); }

    QVideoFrameFormat format() { return m_format; }

    QVideoFrame grabFrame() override
    {
        // To be implemented: take a frame and updare m_format
        return {};
    }

private:
    QVideoFrameFormat m_format;
};

QEglfsScreenCapture::QEglfsScreenCapture() : QPlatformSurfaceCapture(ScreenSource{}) { }

QEglfsScreenCapture::~QEglfsScreenCapture() = default;

QVideoFrameFormat QEglfsScreenCapture::frameFormat() const
{
    return m_grabber ? m_grabber->format() : QVideoFrameFormat();
}

bool QEglfsScreenCapture::setActiveInternal(bool active)
{
    if (m_grabber)
        m_grabber.reset();
    else if (auto screen = source<ScreenSource>(); checkScreenWithError(screen))
        m_grabber = std::make_unique<Grabber>(*this, screen);

    return static_cast<bool>(m_grabber) == active;
}

bool QEglfsScreenCapture::isSupported()
{
    // return QGuiApplication::platformName() == QLatin1String("eglfs"))
    return false;
}

QT_END_NAMESPACE