diff options
Diffstat (limited to 'src/plugins/gstreamer/camerabin/camerabinsession.cpp')
-rw-r--r-- | src/plugins/gstreamer/camerabin/camerabinsession.cpp | 99 |
1 files changed, 60 insertions, 39 deletions
diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index a835b1ce5..850f8c16c 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -119,7 +111,7 @@ QT_BEGIN_NAMESPACE -CameraBinSession::CameraBinSession(QObject *parent) +CameraBinSession::CameraBinSession(GstElementFactory *sourceFactory, QObject *parent) :QObject(parent), m_recordingActive(false), m_state(QCamera::UnloadedState), @@ -133,6 +125,7 @@ CameraBinSession::CameraBinSession(QObject *parent) m_viewfinderInterface(0), m_videoSrc(0), m_viewfinderElement(0), + m_sourceFactory(sourceFactory), m_viewfinderHasChanged(true), m_videoInputHasChanged(true), m_audioSrc(0), @@ -140,10 +133,16 @@ CameraBinSession::CameraBinSession(QObject *parent) m_capsFilter(0), m_fileSink(0), m_audioEncoder(0), + m_videoEncoder(0), m_muxer(0) { + if (m_sourceFactory) + gst_object_ref(GST_OBJECT(m_sourceFactory)); + m_camerabin = gst_element_factory_make("camerabin2", "camerabin2"); g_signal_connect(G_OBJECT(m_camerabin), "notify::idle", G_CALLBACK(updateBusyStatus), this); + g_signal_connect(G_OBJECT(m_camerabin), "element-added", G_CALLBACK(elementAdded), this); + g_signal_connect(G_OBJECT(m_camerabin), "element-removed", G_CALLBACK(elementRemoved), this); qt_gst_object_ref_sink(m_camerabin); m_bus = gst_element_get_bus(m_camerabin); @@ -195,6 +194,9 @@ CameraBinSession::~CameraBinSession() } if (m_viewfinderElement) gst_object_unref(GST_OBJECT(m_viewfinderElement)); + + if (m_sourceFactory) + gst_object_unref(GST_OBJECT(m_sourceFactory)); } #ifdef HAVE_GST_PHOTOGRAPHY @@ -345,6 +347,9 @@ void CameraBinSession::setupCaptureResolution() } else { g_object_set(m_camerabin, VIEWFINDER_CAPS_PROPERTY, NULL, NULL); } + + if (m_videoEncoder) + m_videoEncodeControl->applySettings(m_videoEncoder); } void CameraBinSession::setAudioCaptureCaps() @@ -371,6 +376,9 @@ void CameraBinSession::setAudioCaptureCaps() GstCaps *caps = gst_caps_new_full(structure, NULL); g_object_set(G_OBJECT(m_camerabin), AUDIO_CAPTURE_CAPS_PROPERTY, caps, NULL); gst_caps_unref(caps); + + if (m_audioEncoder) + m_audioEncodeControl->applySettings(m_audioEncoder); } GstElement *CameraBinSession::buildCameraSource() @@ -383,32 +391,17 @@ GstElement *CameraBinSession::buildCameraSource() m_videoInputHasChanged = false; GstElement *videoSrc = 0; + + if (!videoSrc) g_object_get(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, &videoSrc, NULL); - // If the QT_GSTREAMER_CAMERABIN_SRC environment variable has been set use the source - // it recommends. - const QByteArray envCandidate = qgetenv("QT_GSTREAMER_CAMERABIN_SRC"); - if (!m_videoSrc && !envCandidate.isEmpty()) { - m_videoSrc = gst_element_factory_make(envCandidate.constData(), "camera_source"); - } + if (m_sourceFactory) + m_videoSrc = gst_element_factory_create(m_sourceFactory, "camera_source"); // If gstreamer has set a default source use it. if (!m_videoSrc) m_videoSrc = videoSrc; - // If there's no better guidance try the names of some known camera source elements. - if (!m_videoSrc) { - const QList<QByteArray> candidates = QList<QByteArray>() - << "subdevsrc" - << "wrappercamerabinsrc"; - - foreach (const QByteArray &sourceElementName, candidates) { - m_videoSrc = gst_element_factory_make(sourceElementName.constData(), "camera_source"); - if (m_videoSrc) - break; - } - } - if (m_videoSrc && !m_inputDevice.isEmpty()) { #if CAMERABIN_DEBUG qDebug() << "set camera device" << m_inputDevice; @@ -1309,4 +1302,32 @@ QList<QSize> CameraBinSession::supportedResolutions(QPair<int,int> rate, return res; } +void CameraBinSession::elementAdded(GstBin *, GstElement *element, CameraBinSession *session) +{ + GstElementFactory *factory = gst_element_get_factory(element); + + if (GST_IS_BIN(element)) { + g_signal_connect(G_OBJECT(element), "element-added", G_CALLBACK(elementAdded), session); + g_signal_connect(G_OBJECT(element), "element-removed", G_CALLBACK(elementRemoved), session); + } else if (!factory) { + // no-op + } else if (gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_AUDIO_ENCODER)) { + session->m_audioEncoder = element; + + session->m_audioEncodeControl->applySettings(element); + } else if (gst_element_factory_list_is_type(factory, GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER)) { + session->m_videoEncoder = element; + + session->m_videoEncodeControl->applySettings(element); + } +} + +void CameraBinSession::elementRemoved(GstBin *, GstElement *element, CameraBinSession *session) +{ + if (element == session->m_audioEncoder) + session->m_audioEncoder = 0; + else if (element == session->m_videoEncoder) + session->m_videoEncoder = 0; +} + QT_END_NAMESPACE |