QXmpp: GstWrapper.h Source File

QXmpp Version: 1.14.3

Loading...
Searching...
No Matches
GstWrapper.h
1// SPDX-FileCopyrightText: 2025 Linus Jahn <lnj@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef GSTWRAPPER_H
6#define GSTWRAPPER_H
7
8#include <gst/gst.h>
9#include <memory>
10
11#include <QLatin1String>
12
13namespace QXmpp::Private {
14
15template<typename T, typename DeleterType, void(destruct)(DeleterType *)>
16class CustomUniquePtr
17{
18 T *m_ptr = nullptr;
19
20public:
21 CustomUniquePtr(T *ptr = nullptr) : m_ptr(ptr) { }
22 CustomUniquePtr(CustomUniquePtr &&other) : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
23 CustomUniquePtr(const CustomUniquePtr &) = delete;
24 ~CustomUniquePtr()
25 {
26 if (m_ptr) {
27 destruct(m_ptr);
28 }
29 }
30 CustomUniquePtr &operator=(const CustomUniquePtr &) = delete;
31 CustomUniquePtr &operator=(CustomUniquePtr &&other)
32 {
33 reset(other.m_ptr);
34 other.m_ptr = nullptr;
35 return *this;
36 };
37 CustomUniquePtr &operator=(T *ptr)
38 {
39 reset(ptr);
40 return *this;
41 }
42 operator T *() const { return m_ptr; }
43 operator bool() const { return m_ptr != nullptr; }
44 T *operator->() const { return m_ptr; }
45 T *get() const { return m_ptr; }
46 T **reassignRef()
47 {
48 reset();
49 return &m_ptr;
50 }
51 void reset(T *ptr = nullptr)
52 {
53 if (m_ptr) {
54 destruct(m_ptr);
55 }
56 m_ptr = ptr;
57 }
58
59 // gobject properties
60 CustomUniquePtr<gchar, void, g_free> getCharProperty(QLatin1String name) { return getCharProperty(m_ptr, name); };
61 int getIntProperty(QLatin1String name) { return getIntProperty(m_ptr, name); }
62};
63
64using GstElementPtr = CustomUniquePtr<GstElement, void, gst_object_unref>;
65using GstElementFactoryPtr = CustomUniquePtr<GstElementFactory, void, gst_object_unref>;
66using GstPadPtr = CustomUniquePtr<GstPad, void, gst_object_unref>;
67using GstSamplePtr = CustomUniquePtr<GstSample, GstSample, gst_sample_unref>;
68using GstBufferPtr = CustomUniquePtr<GstBuffer, GstBuffer, gst_buffer_unref>;
69using GstCapsPtr = CustomUniquePtr<GstCaps, GstCaps, gst_caps_unref>;
70using GCharPtr = CustomUniquePtr<gchar, void, g_free>;
71
72enum class GstDtlsConnectionState {
73 New,
74 Closed,
75 Failed,
76 Connecting,
77 Connected,
78};
79
80bool checkGstFeature(QLatin1String feature);
81GCharPtr getCharProperty(gpointer object, QLatin1String propertyName);
82int getIntProperty(gpointer, QLatin1String propertyName, int defaultValue = -1);
83void linkPads(GstPad *srcPad, GstPad *sinkPad);
84
85} // namespace QXmpp::Private
86
87#endif