KPipewire

pwhelpers.h
1/*
2 SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include "pipewiresourcestream.h"
10#include <QByteArray>
11#include <epoxy/egl.h>
12#include <kpipewire_export.h>
13
14typedef unsigned int GLenum;
15
16/**
17 * The @class PipeWireFrameCleanupFunction is used to track the lifetime of a pipewire frame.
18 *
19 * It is used to have a ref-counted class that will call the cleanup function when
20 * it's left with no references.
21 * This is useful so that it can be passed to QImage() if necessary without having to
22 * track if the QImage itself outlives the buffer.
23 */
25{
26 Q_DISABLE_COPY(PipeWireFrameCleanupFunction)
27public:
28 PipeWireFrameCleanupFunction(std::function<void()> cleanup)
29 : m_ref(0)
30 , m_cleanup(cleanup)
31 {
32 }
33
34 void ref()
35 {
36 m_ref++;
37 }
38 static void unref(void *x)
39 {
40 if (!x) {
41 return;
42 }
43 auto self = static_cast<PipeWireFrameCleanupFunction *>(x);
44 self->m_ref--;
45 if (self->m_ref == 0) {
46 self->m_cleanup();
47 delete self;
48 }
49 }
50
51private:
52 QAtomicInt m_ref;
53 std::function<void()> m_cleanup;
54};
55
56namespace PWHelpers
57{
58
59KPIPEWIRE_EXPORT QImage
60SpaBufferToQImage(const uchar *data, int width, int height, qsizetype bytesPerLine, spa_video_format format, PipeWireFrameCleanupFunction *cleanup);
61}
The to track the lifetime of a pipewire frame.
Definition pwhelpers.h:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.