diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index 23cbd608..87d9e2fd 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -143,6 +143,7 @@ CameraBinSession::CameraBinSession(GstElementFactory *sourceFactory, QObject *pa m_sourceFactory(sourceFactory), m_viewfinderHasChanged(true), m_inputDeviceHasChanged(true), + m_inputDeviceHasChangedAndOpened(false), m_usingWrapperCameraBinSrc(false), m_viewfinderProbe(this), m_audioSrc(0), @@ -153,6 +154,9 @@ CameraBinSession::CameraBinSession(GstElementFactory *sourceFactory, QObject *pa m_videoEncoder(0), m_muxer(0) { +#if CAMERABIN_DEBUG + qDebug() << "CameraBin Constructing..."; +#endif if (m_sourceFactory) gst_object_ref(GST_OBJECT(m_sourceFactory)); m_camerabin = gst_element_factory_make(QT_GSTREAMER_CAMERABIN_ELEMENT_NAME, "camerabin"); @@ -196,10 +200,17 @@ CameraBinSession::CameraBinSession(GstElementFactory *sourceFactory, QObject *pa g_object_set(G_OBJECT(m_camerabin), PREVIEW_CAPS_PROPERTY, previewCaps, NULL); gst_caps_unref(previewCaps); +#if CAMERABIN_DEBUG + qDebug() << "CameraBin Constructed."; +#endif } CameraBinSession::~CameraBinSession() { +#if CAMERABIN_DEBUG + qDebug() << "CameraBin Destructing..."; +#endif + if (m_camerabin) { if (m_viewfinderInterface) m_viewfinderInterface->stopRenderer(); @@ -220,6 +231,10 @@ CameraBinSession::~CameraBinSession() if (m_videoSrc) gst_object_unref(GST_OBJECT(m_videoSrc)); + +#if CAMERABIN_DEBUG + qDebug() << "CameraBin Destructed."; +#endif } #if QT_CONFIG(gstreamer_photography) @@ -477,6 +492,24 @@ GstElement *CameraBinSession::buildCameraSource() m_inputDeviceHasChanged = false; m_usingWrapperCameraBinSrc = false; + if (m_inputDeviceHasChangedAndOpened) { + m_inputDeviceHasChangedAndOpened = false; +#if CAMERABIN_DEBUG + qDebug().noquote() << QString("CameraBinSession: deviceChangedAndOpened. camera=0x%1 ref=%2") \ + .arg((quintptr)m_cameraSrc, QT_POINTER_SIZE * 2, 16, QChar('0')) \ + .arg(GST_OBJECT_REFCOUNT_VALUE(GST_OBJECT_CAST(m_cameraSrc))); +#endif + // m_videoSrcがm_cameraSrcを握っているかもしれないのでunrefしてみる + if (m_videoSrc) { + gst_object_unref(GST_OBJECT(m_videoSrc)); + m_videoSrc = 0; + } + if (m_cameraSrc) { + gst_object_unref(GST_OBJECT(m_cameraSrc)); + m_cameraSrc = 0; + } + } + GstElement *camSrc = 0; g_object_get(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, &camSrc, NULL); @@ -489,6 +522,9 @@ GstElement *CameraBinSession::buildCameraSource() if (m_cameraSrc) { #if CAMERABIN_DEBUG + qDebug().noquote() << QString("CameraBinSession: set camera... camera=0x%1 ref=%2") \ + .arg((quintptr)m_cameraSrc, QT_POINTER_SIZE * 2, 16, QChar('0')) \ + .arg(GST_OBJECT_REFCOUNT_VALUE(GST_OBJECT_CAST(m_cameraSrc))); qDebug() << "set camera device" << m_inputDevice; #endif m_usingWrapperCameraBinSrc = qstrcmp(qt_gst_element_get_factory_name(m_cameraSrc), "wrappercamerabinsrc") == 0; @@ -556,6 +592,11 @@ GstElement *CameraBinSession::buildCameraSource() } } } +#if CAMERABIN_DEBUG + qDebug().noquote() << QString("CameraBinSession: set_src... camera=0x%1 ref=%2") \ + .arg((quintptr)m_cameraSrc, QT_POINTER_SIZE * 2, 16, QChar('0')) \ + .arg(GST_OBJECT_REFCOUNT_VALUE(GST_OBJECT_CAST(m_cameraSrc))); +#endif if (m_cameraSrc != camSrc) { g_object_set(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, m_cameraSrc, NULL); @@ -564,6 +605,11 @@ GstElement *CameraBinSession::buildCameraSource() gst_object_unref(GST_OBJECT(camSrc)); } +#if CAMERABIN_DEBUG + qDebug().noquote() << QString("CameraBinSession: build end. camera=0x%1 ref=%2") \ + .arg((quintptr)m_cameraSrc, QT_POINTER_SIZE * 2, 16, QChar('0')) \ + .arg(GST_OBJECT_REFCOUNT_VALUE(GST_OBJECT_CAST(m_cameraSrc))); +#endif return m_cameraSrc; } @@ -625,6 +671,9 @@ void CameraBinSession::setDevice(const QString &device) if (m_inputDevice != device) { m_inputDevice = device; m_inputDeviceHasChanged = true; + if (m_cameraSrc) { + m_inputDeviceHasChangedAndOpened = true; + } } } diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h index 999398fa..e6603c56 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.h +++ b/src/plugins/gstreamer/camerabin/camerabinsession.h @@ -258,6 +258,7 @@ private: GstElementFactory *m_sourceFactory; bool m_viewfinderHasChanged; bool m_inputDeviceHasChanged; + bool m_inputDeviceHasChangedAndOpened; bool m_usingWrapperCameraBinSrc; class ViewfinderProbe : public QGstreamerVideoProbeControl {