GStreamer does not release camera resource on pipeline shutdown

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

GStreamer does not release camera resource on pipeline shutdown

I have a pipeline which simply streams data from the camera using QtGStreamer. The pipeline works and I can stream without any problems. The pipeline is defined as:

    bool retval = true;
    if (!m_streaming_pipeline) {
            m_streaming_pipeline = QGst::Pipeline::create("Streamer");
            if (m_streaming_pipeline) {
                qDebug() << "Creating streamer";
                QGst::ElementPtr source = QGst::ElementFactory::make("autovideosrc");
                QGst::ElementPtr capsfilter = QGst::ElementFactory::make("capsfilter", "capsfilter");
                capsfilter->setProperty("caps", QGst::Caps::fromString("video/x-raw, width=1920, height=1080"));
                QGst::ElementPtr scale = QGst::ElementFactory::make("videoscale");
                scale->setProperty("caps", QGst::Caps::fromString("video/x-raw, width=480,height=270"));
                m_videoSink->setProperty("sync", false);
                m_videoSink->setProperty("async", false);
                m_videoSink->setProperty("enable-last-sample", true);
                m_streaming_pipeline->setProperty("video-sink", m_videoSink);
                m_streaming_pipeline->add(source, capsfilter, scale, m_videoSink);
                retval &= source->link(capsfilter);
                retval &= capsfilter->link(scale);
                retval &= scale->link(m_videoSink);
                QGst::BusPtr bus = m_streaming_pipeline->bus();
                QGlib::connect(bus, "message", this, &Recorder::onStreamerBusMessage);

This works fine and when I am done, I dispose of the pipeline as:

    if (m_streaming_pipeline) {
            QGst::StateChangeReturn r = m_streaming_pipeline->setState(QGst::StateNull);
            qDebug() << "State: " << r;
            QGst::State currentState;
            m_streaming_pipeline->getState(&currentState, NULL, -1);
            if (currentState == QGst::StateNull) {
                qDebug() << "NULL State";

However, the issue is that this does not seem to release my camera resource. Trying to start the pipeline again or using an app like `cheese` comes back with the error that the camera resource is busy.

How can I ensure that the pipeline is really gone and all the resources are freed.