diff options
author | Zhang Xingtao <xingtao.zhang@yahoo.com> | 2016-04-12 23:48:35 +0800 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@qt.io> | 2016-04-28 12:24:41 +0000 |
commit | 20528da413e68cbff9d2eb1da3257c0e0025b4cd (patch) | |
tree | 90f1390a2e0179527d1f09d068079c2076c7b410 | |
parent | cf44daa75499eecfee8f614837908d722d8741f3 (diff) |
GStreamer camerabin: return the proper camera source
- return m_cameraSrc for function cameraSource() instead of m_videoSrc.
m_videoSrc is not always assigned(default 0), it will crash on:
if (g_object_class_find_property(
G_OBJECT_GET_CLASS(m_session->cameraSource()), "exposure-mode")) {
And as the function name says, it would be better to return the
value m_cameraSrc.
- make sure pointers are not NULL before using them.
Change-Id: I8a56db34a805724b428409b87de7d072ee7bfa57
Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
-rw-r--r-- | src/plugins/gstreamer/camerabin/camerabinlocks.cpp | 21 | ||||
-rw-r--r-- | src/plugins/gstreamer/camerabin/camerabinsession.cpp | 3 | ||||
-rw-r--r-- | src/plugins/gstreamer/camerabin/camerabinsession.h | 2 |
3 files changed, 19 insertions, 7 deletions
diff --git a/src/plugins/gstreamer/camerabin/camerabinlocks.cpp b/src/plugins/gstreamer/camerabin/camerabinlocks.cpp index e6fe9a309..2f44ec057 100644 --- a/src/plugins/gstreamer/camerabin/camerabinlocks.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinlocks.cpp @@ -65,9 +65,12 @@ QCamera::LockTypes CameraBinLocks::supportedLocks() const if (GstPhotography *photography = m_session->photography()) { if (gst_photography_get_capabilities(photography) & GST_PHOTOGRAPHY_CAPS_WB_MODE) locks |= QCamera::LockWhiteBalance; - if (g_object_class_find_property( - G_OBJECT_GET_CLASS(m_session->cameraSource()), "exposure-mode")) { - locks |= QCamera::LockExposure; + + if (GstElement *source = m_session->cameraSource()) { + if (g_object_class_find_property( + G_OBJECT_GET_CLASS(source), "exposure-mode")) { + locks |= QCamera::LockExposure; + } } } #endif @@ -195,9 +198,13 @@ bool CameraBinLocks::isExposureLocked() const void CameraBinLocks::lockExposure(QCamera::LockChangeReason reason) { + GstElement *source = m_session->cameraSource(); + if (!source) + return; + m_pendingLocks &= ~QCamera::LockExposure; g_object_set( - G_OBJECT(m_session->cameraSource()), + G_OBJECT(source), "exposure-mode", GST_PHOTOGRAPHY_EXPOSURE_MODE_MANUAL, NULL); @@ -206,8 +213,12 @@ void CameraBinLocks::lockExposure(QCamera::LockChangeReason reason) void CameraBinLocks::unlockExposure(QCamera::LockStatus status, QCamera::LockChangeReason reason) { + GstElement *source = m_session->cameraSource(); + if (!source) + return; + g_object_set( - G_OBJECT(m_session->cameraSource()), + G_OBJECT(source), "exposure-mode", GST_PHOTOGRAPHY_EXPOSURE_MODE_AUTO, NULL); diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index 3dd200c54..96b31e1b3 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -514,7 +514,8 @@ GstElement *CameraBinSession::buildCameraSource() if (!m_videoSrc) m_videoSrc = gst_element_factory_make("v4l2src", "camera_source"); - g_object_set(G_OBJECT(m_cameraSrc), "video-source", m_videoSrc, NULL); + if (m_videoSrc) + g_object_set(G_OBJECT(m_cameraSrc), "video-source", m_videoSrc, NULL); } if (m_videoSrc) diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h index dda900a8b..ade8916ba 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.h +++ b/src/plugins/gstreamer/camerabin/camerabinsession.h @@ -91,7 +91,7 @@ public: GstPhotography *photography(); #endif GstElement *cameraBin() { return m_camerabin; } - GstElement *cameraSource() { return m_videoSrc; } + GstElement *cameraSource() { return m_cameraSrc; } QGstreamerBusHelper *bus() { return m_busHelper; } QList< QPair<int,int> > supportedFrameRates(const QSize &frameSize, bool *continuous) const; |