Stefano Mtangoo
Stefano Mtangoo

Reputation: 6550

Gstreamer 1.0 Pause signal

I need to detect when the current playing audio/video is paused. I cannot find anything for 1.0. My app is a bit complex but here is condensed code

/* This function is called when the pipeline changes states. We use it to
* keep track of the current state. */
static void state_changed_cb(GstBus *bus, GstMessage *msg, CustomData *data)
{
    GstState old_state, new_state, pending_state;
    gst_message_parse_state_changed(msg, &old_state, &new_state, &pending_state);

    if(GST_MESSAGE_SRC(msg) == GST_OBJECT(data->playbin))
    {
        g_print("State set to %s\n", gst_element_state_get_name(new_state));            
    }
}


gst_init(&wxTheApp->argc, &argv);
m_playbin = gst_element_factory_make("playbin", "playbin");
if(!m_playbin)
{
    g_printerr("Not all elements could be created.\n");
    exit(1);
}

CustomData* data = new CustomData(xid, m_playbin);

GstBus *bus = gst_element_get_bus(m_playbin);
gst_bus_set_sync_handler(bus, (GstBusSyncHandler) create_window, data, NULL);//here I do video overly stuffs

g_signal_connect (G_OBJECT (bus), "message::state-changed", (GCallback)state_changed_cb, &data);

What do I do wrong? I cannot find working example on connecting such events on Gstreamer 1.0 and 0.x seems a bit different than 1.0 so the vast exaples there don't help

UPDATE

I have found a way to get signals. I run wxWidgets timer with 500ms time span and each time timer fires I call

GstMessage* msg = gst_bus_pop(m_bus);
if(msg!=NULL)
{
    g_print ("New Message -- %s\n", gst_message_type_get_name(msg->type));
}

Now I get a lot of 'state-change' messages. Still I want to know if that message is for Pause or Stop or Play or End of Media (I mean way to differentiate which message is this) so that I can notify the UI.

So while I get signals now, the basic problem, to get specific signals, remains unsolved.

Upvotes: 0

Views: 1086

Answers (1)

Sebastian Dröge
Sebastian Dröge

Reputation: 2143

You have to call gst_bus_add_signal_watch() (like in 0.10) to enable emission of the signals. Without that you can only use the other ways to get notified about GstMessages on that bus.

Also just to be sure, you need a running GLib main loop on the default main context for this to work. Otherwise you need to do things a bit different.

For the updated question:

Check the documentation: gst_message_parse_state_changed() can be used to parse the old, new and pending state from the message. This is also still the same as in 0.10. From the application point of view, and conceptionally nothing much has changed really between 0.10 and 1.0

Also you shouldn't do this timeout-waiting as it will block your wxwidget main loop. Easiest solution would be to use a sync bus handler (which you already have) and dispatch all messages from there to some callback on the wxwidget main loop.

Upvotes: 2

Related Questions