diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-02-14 11:00:16 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-03-02 14:49:44 +0000 |
commit | 2e84ea2c3b13d51bb03c0d386daaea23e9e40226 (patch) | |
tree | 484c919c54224445db073e316637e6a4a8e57a64 /src/multimedia/platform/gstreamer/common | |
parent | 590655b86913187e7867836f6aca95f5674c72cd (diff) |
Safer wrapper classes for GstCaps
Properly do the refcounting that's required.
Change-Id: I17b17f8f841a4d39bf32a34fa17244630c677c11
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/platform/gstreamer/common')
-rw-r--r-- | src/multimedia/platform/gstreamer/common/qgstutils_p.h | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/multimedia/platform/gstreamer/common/qgstutils_p.h b/src/multimedia/platform/gstreamer/common/qgstutils_p.h index 36de4d0e8..d22734e43 100644 --- a/src/multimedia/platform/gstreamer/common/qgstutils_p.h +++ b/src/multimedia/platform/gstreamer/common/qgstutils_p.h @@ -176,18 +176,52 @@ public: }; class QGstCaps { + const GstCaps *caps; public: QGstCaps(const GstCaps *c) : caps(c) {} - const GstCaps *caps; - void unref() { - gst_caps_unref(const_cast<GstCaps *>(caps)); - caps = nullptr; + + bool isNull() const { return !caps; } + + int size() const { return gst_caps_get_size(caps); } + QGstStructure at(int index) { return gst_caps_get_structure(caps, index); } + const GstCaps *get() const { return caps; } +}; + +class QGstMutableCaps { + GstCaps *caps; +public: + enum RefMode { HasRef, NeedsRef }; + QGstMutableCaps(GstCaps *c, RefMode mode = HasRef) + : caps(c) + { + if (mode == NeedsRef) + gst_caps_ref(caps); + } + QGstMutableCaps(const QGstMutableCaps &other) + : caps(other.caps) + { + if (caps) + gst_caps_ref(caps); + } + QGstMutableCaps &operator=(const QGstMutableCaps &other) + { + if (other.caps) + gst_caps_ref(other.caps); + if (caps) + gst_caps_unref(const_cast<GstCaps *>(caps)); + caps = other.caps; + return *this; + } + ~QGstMutableCaps() { + if (caps) + gst_caps_unref(const_cast<GstCaps *>(caps)); } bool isNull() const { return !caps; } int size() const { return gst_caps_get_size(caps); } QGstStructure at(int index) { return gst_caps_get_structure(caps, index); } + GstCaps *get() { return caps; } }; Q_MULTIMEDIA_EXPORT const gchar *qt_gst_element_get_factory_name(GstElement *element); |