summaryrefslogtreecommitdiffstats
path: root/src/plugins/gstreamer/camerabin
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2014-03-20 19:20:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-21 19:16:09 +0100
commit023c6ebcb9d990042f0e9a750fd6238d22001022 (patch)
treeb98e068ccbdae0a587179d657541cc857c9daf0c /src/plugins/gstreamer/camerabin
parent60ba0afbde0ef53a12afb6c755ca6fd64aabf5da (diff)
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>
Diffstat (limited to 'src/plugins/gstreamer/camerabin')
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp14
-rw-r--r--src/plugins/gstreamer/camerabin/camerabincontainer.cpp14
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinrecorder.cpp12
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinsession.cpp22
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp2
5 files changed, 42 insertions, 22 deletions
diff --git a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp
index 0fa854cc5..332891a47 100644
--- a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp
@@ -114,11 +114,15 @@ GstEncodingProfile *CameraBinAudioEncoder::createProfile()
else
caps = gst_caps_from_string(codec.toLatin1());
- return (GstEncodingProfile *)gst_encoding_audio_profile_new(
- caps,
- !preset.isEmpty() ? preset.toLatin1().constData() : NULL, //preset
- NULL, //restriction
- 0); //presence
+ GstEncodingProfile *profile = (GstEncodingProfile *)gst_encoding_audio_profile_new(
+ caps,
+ !preset.isEmpty() ? preset.toLatin1().constData() : NULL, //preset
+ NULL, //restriction
+ 0); //presence
+
+ gst_caps_unref(caps);
+
+ return profile;
}
QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp b/src/plugins/gstreamer/camerabin/camerabincontainer.cpp
index 4c2a3bda9..44eb36818 100644
--- a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabincontainer.cpp
@@ -124,11 +124,15 @@ GstEncodingContainerProfile *CameraBinContainer::createProfile()
caps = gst_caps_from_string(format.toLatin1());
}
- return (GstEncodingContainerProfile *)gst_encoding_container_profile_new(
- "camerabin2_profile",
- (gchar *)"custom camera profile",
- caps,
- NULL); //preset
+ GstEncodingContainerProfile *profile = (GstEncodingContainerProfile *)gst_encoding_container_profile_new(
+ "camerabin2_profile",
+ (gchar *)"custom camera profile",
+ caps,
+ NULL); //preset
+
+ gst_caps_unref(caps);
+
+ return profile;
}
/*!
diff --git a/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp b/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp
index 4ac0d942e..7cef82a69 100644
--- a/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp
@@ -191,10 +191,14 @@ GstEncodingContainerProfile *CameraBinRecorder::videoProfile()
GstEncodingProfile *audioProfile = m_session->audioEncodeControl()->createProfile();
GstEncodingProfile *videoProfile = m_session->videoEncodeControl()->createProfile();
- if (audioProfile)
- gst_encoding_container_profile_add_profile(containerProfile, audioProfile);
- if (videoProfile)
- gst_encoding_container_profile_add_profile(containerProfile, videoProfile);
+ if (audioProfile) {
+ if (!gst_encoding_container_profile_add_profile(containerProfile, audioProfile))
+ gst_encoding_profile_unref(audioProfile);
+ }
+ if (videoProfile) {
+ if (!gst_encoding_container_profile_add_profile(containerProfile, videoProfile))
+ gst_encoding_profile_unref(videoProfile);
+ }
}
return containerProfile;
diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp
index 8ca6bfd83..6e3448ffe 100644
--- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp
@@ -61,6 +61,7 @@
#include "camerabincapturebufferformat.h"
#include <private/qgstreamerbushelper_p.h>
#include <private/qgstreamervideorendererinterface_p.h>
+#include <private/qgstutils_p.h>
#include <qmediarecorder.h>
#ifdef HAVE_GST_PHOTOGRAPHY
@@ -108,9 +109,6 @@
#define CAMERABIN_IMAGE_MODE 1
#define CAMERABIN_VIDEO_MODE 2
-#define gstRef(element) { gst_object_ref(GST_OBJECT(element)); gst_object_sink(GST_OBJECT(element)); }
-#define gstUnref(element) { if (element) { gst_object_unref(GST_OBJECT(element)); element = 0; } }
-
#define PREVIEW_CAPS_4_3 \
"video/x-raw-rgb, width = (int) 640, height = (int) 480"
@@ -146,7 +144,7 @@ CameraBinSession::CameraBinSession(QObject *parent)
{
m_camerabin = gst_element_factory_make("camerabin2", "camerabin2");
g_signal_connect(G_OBJECT(m_camerabin), "notify::idle", G_CALLBACK(updateBusyStatus), this);
- gstRef(m_camerabin);
+ qt_gst_object_ref_sink(m_camerabin);
m_bus = gst_element_get_bus(m_camerabin);
@@ -192,9 +190,11 @@ CameraBinSession::~CameraBinSession()
gst_element_set_state(m_camerabin, GST_STATE_NULL);
gst_element_get_state(m_camerabin, NULL, NULL, GST_CLOCK_TIME_NONE);
- gstUnref(m_camerabin);
- gstUnref(m_viewfinderElement);
+ gst_object_unref(GST_OBJECT(m_bus));
+ gst_object_unref(GST_OBJECT(m_camerabin));
}
+ if (m_viewfinderElement)
+ gst_object_unref(GST_OBJECT(m_viewfinderElement));
}
#ifdef HAVE_GST_PHOTOGRAPHY
@@ -239,7 +239,7 @@ bool CameraBinSession::setupCameraBin()
qWarning() << "Staring camera without viewfinder available";
m_viewfinderElement = gst_element_factory_make("fakesink", NULL);
}
- gst_object_ref(GST_OBJECT(m_viewfinderElement));
+ qt_gst_object_ref_sink(GST_OBJECT(m_viewfinderElement));
gst_element_set_state(m_camerabin, GST_STATE_NULL);
g_object_set(G_OBJECT(m_camerabin), VIEWFINDER_SINK_PROPERTY, m_viewfinderElement, NULL);
}
@@ -438,6 +438,9 @@ GstElement *CameraBinSession::buildCameraSource()
if (m_videoSrc != videoSrc)
g_object_set(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL);
+ if (videoSrc)
+ gst_object_unref(GST_OBJECT(videoSrc));
+
return m_videoSrc;
}
@@ -680,10 +683,12 @@ void CameraBinSession::setState(QCamera::State newState)
m_recorderControl->applySettings();
+ GstEncodingContainerProfile *profile = m_recorderControl->videoProfile();
g_object_set (G_OBJECT(m_camerabin),
"video-profile",
- m_recorderControl->videoProfile(),
+ profile,
NULL);
+ gst_encoding_profile_unref(profile);
setAudioCaptureCaps();
@@ -803,6 +808,7 @@ void CameraBinSession::setMetaData(const QMap<QByteArray, QVariant> &data)
}
}
}
+ gst_iterator_free(elements);
}
}
diff --git a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp
index cb479d8df..146e150ec 100644
--- a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp
@@ -175,6 +175,8 @@ GstEncodingProfile *CameraBinVideoEncoder::createProfile()
NULL, //restriction
1); //presence
+ gst_caps_unref(caps);
+
gst_encoding_video_profile_set_pass(profile, 0);
gst_encoding_video_profile_set_variableframerate(profile, TRUE);