GStreamer: fix memory leaks.
Many GStreamer objects were not properly managed or never released. Change-Id: I38b3854e8b9e2264b5b647f331d3bb16b886e2d6 Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
This commit is contained in:
committed by
The Qt Project
parent
60ba0afbde
commit
023c6ebcb9
@@ -72,7 +72,11 @@ bool QGstAppSrc::setup(GstElement* appsrc)
|
||||
if (m_setup || m_stream == 0 || appsrc == 0)
|
||||
return false;
|
||||
|
||||
if (m_appSrc)
|
||||
gst_object_unref(G_OBJECT(m_appSrc));
|
||||
|
||||
m_appSrc = GST_APP_SRC(appsrc);
|
||||
gst_object_ref(G_OBJECT(m_appSrc));
|
||||
gst_app_src_set_callbacks(m_appSrc, (GstAppSrcCallbacks*)&m_callbacks, this, (GDestroyNotify)&QGstAppSrc::destroy_notify);
|
||||
|
||||
g_object_get(G_OBJECT(m_appSrc), "max-bytes", &m_maxBytes, NULL);
|
||||
|
||||
@@ -93,6 +93,9 @@ QGstCodecsInfo::QGstCodecsInfo(QGstCodecsInfo::ElementType elementType)
|
||||
|
||||
gst_caps_remove_structure(caps, 0);
|
||||
}
|
||||
|
||||
gst_caps_unref(caps);
|
||||
gst_caps_unref(allCaps);
|
||||
#else
|
||||
Q_UNUSED(elementType);
|
||||
#endif // GST_CHECK_VERSION(0,10,31)
|
||||
@@ -143,7 +146,7 @@ GstCaps* QGstCodecsInfo::supportedElementCaps(GstElementFactoryListType elementT
|
||||
padTemplates = padTemplates->next;
|
||||
|
||||
if (padTemplate->direction == padDirection) {
|
||||
const GstCaps *caps = gst_static_caps_get(&padTemplate->static_caps);
|
||||
GstCaps *caps = gst_static_caps_get(&padTemplate->static_caps);
|
||||
for (uint i=0; i<gst_caps_get_size(caps); i++) {
|
||||
const GstStructure *structure = gst_caps_get_structure(caps, i);
|
||||
|
||||
@@ -173,6 +176,7 @@ GstCaps* QGstCodecsInfo::supportedElementCaps(GstElementFactoryListType elementT
|
||||
|
||||
gst_caps_merge_structure(res, newStructure);
|
||||
}
|
||||
gst_caps_unref(caps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,7 @@ GstElement *QGstreamerGLTextureRenderer::videoSink()
|
||||
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink");
|
||||
m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include "qgstreamervideorenderer_p.h"
|
||||
#include <private/qvideosurfacegstsink_p.h>
|
||||
#include <private/qgstutils_p.h>
|
||||
#include <qabstractvideosurface.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -62,8 +63,7 @@ GstElement *QGstreamerVideoRenderer::videoSink()
|
||||
{
|
||||
if (!m_videoSink && m_surface) {
|
||||
m_videoSink = QVideoSurfaceGstSink::createSink(m_surface);
|
||||
gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership
|
||||
gst_object_sink(GST_OBJECT(m_videoSink));
|
||||
qt_gst_object_ref_sink(GST_OBJECT(m_videoSink)); //Take ownership
|
||||
}
|
||||
|
||||
return reinterpret_cast<GstElement*>(m_videoSink);
|
||||
|
||||
@@ -137,8 +137,7 @@ void QGstreamerVideoWidgetControl::createVideoWidget()
|
||||
if (!m_videoSink)
|
||||
m_videoSink = gst_element_factory_make ("ximagesink", NULL);
|
||||
|
||||
gst_object_ref (GST_OBJECT (m_videoSink)); //Take ownership
|
||||
gst_object_sink (GST_OBJECT (m_videoSink));
|
||||
qt_gst_object_ref_sink(GST_OBJECT (m_videoSink)); //Take ownership
|
||||
|
||||
|
||||
}
|
||||
@@ -219,6 +218,7 @@ void QGstreamerVideoWidgetControl::updateNativeVideoSize()
|
||||
//find video native size to update video widget size hint
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink");
|
||||
GstCaps *caps = gst_pad_get_negotiated_caps(pad);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
|
||||
if (caps) {
|
||||
m_widget->setNativeSize(QGstUtils::capsCorrectedResolution(caps));
|
||||
|
||||
@@ -63,11 +63,11 @@ QGstreamerVideoWindow::QGstreamerVideoWindow(QObject *parent, const char *elemen
|
||||
m_videoSink = gst_element_factory_make("xvimagesink", NULL);
|
||||
|
||||
if (m_videoSink) {
|
||||
gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership
|
||||
gst_object_sink(GST_OBJECT(m_videoSink));
|
||||
qt_gst_object_ref_sink(GST_OBJECT(m_videoSink)); //Take ownership
|
||||
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink");
|
||||
m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ bool QGstreamerVideoWindow::processSyncMessage(const QGstreamerMessage &message)
|
||||
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink");
|
||||
m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -319,6 +320,7 @@ void QGstreamerVideoWindow::updateNativeVideoSize()
|
||||
//find video native size to update video widget size hint
|
||||
GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink");
|
||||
GstCaps *caps = gst_pad_get_negotiated_caps(pad);
|
||||
gst_object_unref(GST_OBJECT(pad));
|
||||
|
||||
if (caps) {
|
||||
m_nativeSize = QGstUtils::capsCorrectedResolution(caps);
|
||||
|
||||
@@ -401,4 +401,22 @@ QMultimedia::SupportEstimate QGstUtils::hasSupport(const QString &mimeType,
|
||||
return QMultimedia::MaybeSupported;
|
||||
}
|
||||
|
||||
void qt_gst_object_ref_sink(gpointer object)
|
||||
{
|
||||
#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 24)
|
||||
gst_object_ref_sink(object);
|
||||
#else
|
||||
g_return_if_fail (GST_IS_OBJECT(object));
|
||||
|
||||
GST_OBJECT_LOCK(object);
|
||||
if (G_LIKELY(GST_OBJECT_IS_FLOATING(object))) {
|
||||
GST_OBJECT_FLAG_UNSET(object, GST_OBJECT_FLOATING);
|
||||
GST_OBJECT_UNLOCK(object);
|
||||
} else {
|
||||
GST_OBJECT_UNLOCK(object);
|
||||
gst_object_ref(object);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user