简体   繁体   中英

C++/Qt 5 GStreamer continues loop

I'm currently trying to experiment with GSteamer playing a video on loop. I have it currently implemented like this:

void VPlayer::playFile(QString video_filename, bool loop)
{
    m_isLooping = loop;
    QString cmdstr = "gst-launch-1.0 -v filesrc location=" + video_filename + " ! qtdemux ! queue max-size-buffers=0 max-size-time=0 ! vpudec frame-drop=0 ! queue ! imxv4l2sink device=/dev/video16";
    GError **l_error = NULL;;
    m_gst_pipeline = gst_parse_launch (cmdstr.toUtf8().data(), l_error);

    m_gst_bus = gst_pipeline_get_bus (GST_PIPELINE(m_gst_pipeline));
    gst_bus_set_sync_handler (m_gst_bus, GStreamerBusCallback, this, nullptr);
    gst_object_ref (m_gst_bus);
    gst_object_ref(m_gst_pipeline);

    gst_element_set_state (m_gst_pipeline, GST_STATE_NULL);
    gst_element_seek_simple (m_gst_pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, 0);
    gst_element_set_state (m_gst_pipeline, GST_STATE_PLAYING);
}

GstBusSyncReply VPlayer::GStreamerBusCallback(GstBus *bus, GstMessage *msg, gpointer data)
{
    VPlayer* player = (VPlayer*) data;
    GstElement *pipeline = player->getPipeline();
    switch (GST_MESSAGE_TYPE(msg))
    {
    case GST_MESSAGE_EOS:
        /* restart playback if at end */
        qDebug() << "PLAYBACK FINISHED";
        if(player->isLooping())
        {
            qDebug() << "LOOPING";
            gst_element_seek_simple (pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, 0);
            gst_element_set_state (pipeline, GST_STATE_PLAYING);
        }

        break;
    default:
        break;
    }

    return GST_BUS_PASS;
}

When I run this example I get the EOS as expected and also the debug output is ok, but instead of seeking the image freezes and nothing happens. Also the looping does not seem to continue.

What did I miss here?

At least this needs to be fixed:

GError *l_error = NULL;
m_gst_pipeline = gst_parse_launch (cmdstr.toUtf8().data(), &l_error);

and I'm assuming you call gst_init(...); somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM