Example #1
0
void Player::setUri(const QString & uri)
{
    QString realUri = uri;

    //if uri is not a real uri, assume it is a file path
    if (realUri.indexOf("://") < 0) {
        realUri = QUrl::fromLocalFile(realUri).toEncoded();
    }

    if (!m_pipeline) {
        m_pipeline = QGst::ElementFactory::make("playbin2").dynamicCast<QGst::Pipeline>();
        if (m_pipeline) {
            //let the video widget watch the pipeline for new video sinks
            watchPipeline(m_pipeline);

            //watch the bus for messages
            QGst::BusPtr bus = m_pipeline->bus();
            bus->addSignalWatch();
            QGlib::connect(bus, "message", this, &Player::onBusMessage);
        } else {
            qCritical() << "Failed to create the pipeline";
        }
    }

    if (m_pipeline) {
        m_pipeline->setProperty("uri", realUri);
    }
}
GStreamerPipeline::GStreamerPipeline( QObject *parent ) :
    QObject(parent)
{
    mPipeline = QGst::ElementFactory::make("pipeline").dynamicCast<QGst::Pipeline>();
    mPlaySink = QGst::ElementFactory::make("playsink");
    mQueue = QGst::ElementFactory::make("multiqueue");

    Q_ASSERT( !mPipeline.isNull() && !mPlaySink.isNull() && !mQueue.isNull() );

    mPipeline->add( mPlaySink );
    mPipeline->add( mQueue );

    mPlaySink->setProperty( "flags", DEFAULT_PLAYSINK_FLAGS );
    mQueue->setProperty( "sync-by-running-time", true );

    QGst::BusPtr bus = mPipeline->bus();
    bus->addSignalWatch();
    QGlib::connect(bus, "message", this, &GStreamerPipeline::handleBusMessage);
}