No video using QGst

Agron Selimaj as9902613 at gmail.com
Mon Aug 12 15:06:58 PDT 2013


Hey guys,

I am just starting to use QGst with Qt and C++ on Linux.

I started off of the recorder.cpp example and tried to show a video from
RTSP into a frame of that is embedded into groupbox on the dialog.

However the frame turns black after onRtpBinPadAdded is called and stays
black forever. But I can see there is a lot of network traffic going on but
the video is just black.


If someone can help, heres the code:



#include "recorder.h"


#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <QtGui/QDialog>
#include <QtGui/QMessageBox>
#include <QtGui/QVBoxLayout>


#include <QGlib/Error>
#include <QGlib/Connect>
#include <QGst/Init>
#include <QGst/ElementFactory>
#include <QGst/ChildProxy>
#include <QGst/PropertyProbe>
#include <QGst/Pipeline>
#include <QGst/Pad>
#include <QGst/Event>
#include <QGst/Message>
#include <QGst/Bus>

Recorder::Recorder(QWidget *parent)
    : QDialog(parent)
{
    m_ui.setupUi(this);
}

void Recorder::start()
{
    m_pipeline = QGst::Pipeline::create( "Video Player");

    QGst::ElementPtr src    = QGst::ElementFactory::make("rtspsrc", "src");
    QGst::ElementPtr demux  = QGst::ElementFactory::make("rtpmp4vdepay",
"depay");
    QGst::ElementPtr decode = QGst::ElementFactory::make("ffdec_mpeg4",
"decode");
    QGst::ElementPtr colour =
QGst::ElementFactory::make("ffmpegcolorspace",  "colour");
    QGst::ElementPtr sink   = QGst::ElementFactory::make("autovideosink",
"sink"); //qwidgetvideosink

    if ( !src || !decode || !src || !demux || !sink || !colour) {
        QMessageBox::critical(this, tr("Error"), tr("One or more elements
could not be created. "
                              "Verify that you have all the necessary
element plugins installed."));
        return;
    }

    src->setProperty( "location", "rtsp://192.168.1.11:8554/2.sdp");
    src->setProperty( "latency", 0);

    sink->setProperty( "window-height", 200);
    sink->setProperty( "window-width", 200);

    m_pipeline->add( src, demux, decode, colour, sink);
    src->linkMany(demux, decode, colour, sink);

    m_pVideoWidget = new QGst::Ui::VideoWidget( m_ui.frame);
    m_pVideoWidget->adjustSize();
    sink->unparent();
    m_pVideoWidget->setVideoSink( sink);
    m_pVideoWidget->show();


    //watch for the receiving side src pads
    QGlib::connect(src, "pad-added", this, &Recorder::onRtpBinPadAdded);

    //connect the bus
    m_pipeline->bus()->addSignalWatch();
    QGlib::connect(m_pipeline->bus(), "message", this,
&Recorder::onBusMessage);

    QVBoxLayout* layout = new QVBoxLayout;

    layout->addWidget( m_pVideoWidget);

    m_ui.frame->setLayout( layout);

    //go!
    m_pipeline->setState(QGst::StatePlaying);
    m_ui.startStopButton->setText(tr("Stop recording"));
}

void Recorder::onRtpBinPadAdded(const QGst::PadPtr & pad)
{
    QGst::ElementPtr bin;
    QString str;

    str = pad->caps()->internalStructure(0)->value("media").toString();


    try {
        if (pad->caps()->internalStructure(0)->value("media").toString() ==
QLatin1String("audio"))
        {
            bin = QGst::Bin::fromDescription(
                "rtpspeexdepay ! speexdec ! audioconvert ! autoaudiosink"
            );
        }
        else
        {
            bin = QGst::Bin::fromDescription(
                "rtph264depay ! ffdec_h264 ! ffmpegcolorspace !
autovideosink"
            );
        }
    } catch (const QGlib::Error & error) {
        qCritical() << error;
        qFatal("One ore more required elements are missing. Aborting...");
    }

    bool r = bin.isNull();

    m_pipeline->add(bin);
    bin->syncStateWithParent();
    pad->link(bin->getStaticPad("sink"));
}



void Recorder::stop()
{
    //stop recording
    m_pipeline->setState(QGst::StateNull);

    //clear the pointer, destroying the pipeline as its reference count
drops to zero.
    m_pipeline.clear();

    //restore the button's text
    m_ui.startStopButton->setText(tr("Start recording"));
}

void Recorder::onBusMessage(const QGst::MessagePtr & message)
{
    switch (message->type())
    {
    case QGst::MessageEos:
        //got end-of-stream - stop the pipeline
        stop();
        break;
    case QGst::MessageError:
        //check if the pipeline exists before destroying it,
        //as we might get multiple error messages
        if (m_pipeline)
        {
            stop();
        }
        QMessageBox::critical(this, tr("Pipeline Error"),

message.staticCast<QGst::ErrorMessage>()->error().message());
        break;
    default:
        break;
    }
}

void Recorder::on_startStopButton_clicked()
{
    if (m_pipeline)
    { //pipeline exists - destroy it
        //send an end-of-stream event to flush metadata and cause an
EosMessage to be delivered
        m_pipeline->sendEvent(QGst::EosEvent::create());
    }
    else
    { //pipeline doesn't exist - start a new one
        start();
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20130812/fee06ba1/attachment.html>


More information about the gstreamer-devel mailing list