[gst-devel] Capturing EOS message from the bus. [SOLVED]

Osmo Antero Maatta osmoma at gmail.com
Mon Dec 20 19:21:49 CET 2010


Re-hi,

Ok, I found a solution by studying the source of 
gnome-media-2.30.0/grecord.

My code now calls rec_set_state_to_null() function that sets the 
pipeline to GST_STATE_NULL state.  Rec_state_changed_cb(...) function 
receives now messages so the state goes from PLAYING -> PAUSED -> 
READY/NULL. And the GUI is updated appropriately.

Very good. I can now bake the code to my recorder.

void rec_set_state_to_null() {
     // Copyright notice:
     // Copied from gnome-media-2.30.0/grecord.

     // Set state of pipeline to GST_STATE_NULL.
     GstMessage *msg;
     GstState cur_state, pending;
     GstBus *bus;

     if (!GST_IS_PIPELINE(g_rec.pipeline)) return;

     gst_element_get_state(g_rec.pipeline, &cur_state, &pending, 0);

     if (cur_state == GST_STATE_NULL && pending == GST_STATE_VOID_PENDING)
         return;

     if (cur_state == GST_STATE_NULL && pending != GST_STATE_VOID_PENDING) {
         gst_element_set_state (g_rec.pipeline, GST_STATE_NULL);
         return;
     }

     gst_element_set_state(g_rec.pipeline, GST_STATE_READY);
     gst_element_get_state(g_rec.pipeline, NULL, NULL, -1);

     bus = gst_element_get_bus(g_rec.pipeline);
     if (GST_IS_BUS(bus)) {
         while ((msg = gst_bus_pop(bus))) {
             gst_bus_async_signal_func(bus, msg, NULL);

             gst_message_unref(msg);

         }
         gst_object_unref(bus);
     }

     gst_element_set_state(g_rec.pipeline, GST_STATE_NULL);
}

Thanks.
   Osmo Antero (Moma)
http://www.futuredesktop.org


On 12/20/2010 11:43 AM, Osmo Antero Maatta wrote:
> Hello,
> I have created an audio-recorder application using the GStreamer 
> framework. My question is:
> How to catch and react to the EOS (end of stream, end of recording) 
> message?
>
> When starting a recording the state change from NULL -> PLAYING works 
> fine.
> My program now updates the GUI (buttons, icons in the GUI) when the 
> recording changes state from NULL -> READY -> PLAYING. This works OK.
>
> Also state change from PLAYING -> PAUSED works fine. My program 
> captures the PAUSED message and updates the GUI. This is OK.
>
> But how to catch the STOP message (when the recording stops/ends) ?  
> Obviously Gstreamer has no STOP/STREAM END message.  Are there 
> event-chain for PLAYING -> PAUSED -> STOP/NULL?
>
> *I want to update the GUI solely via the Gstreamer's state-change 
> messages/events. *
> Why? Because the recording can be controlled from various places; 
> directly from the GUI using buttons, it can be controlled from DBus by 
> Media Players (like Amarok/RhythmBox/Banshee and there are threads 
> involved etc.). So I want to update the GUI solely via (event's) state 
> changes.
>
> Here is how I setup the callback functions to receive events/messages 
> from the bus.
> See:  rec_state_changed_cb(...) function in
> http://www.futuredesktop.com/tmp/gst-recorder.c
>
> The message/event handlers are set up like this (in the 
> rec_create_pipeline(...) function) :
>
> // Add a message handlers
> GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
> gst_bus_add_signal_watch(bus);
>
> // Detect state changes
> g_signal_connect(bus, "message::state-changed", 
> G_CALLBACK(rec_state_changed_cb), NULL);
>
> // Monitor sound level/amplitude
> g_signal_connect(bus, "message::element", 
> G_CALLBACK(rec_level_message_cb), NULL);
>
> // Catch error messages
> g_signal_connect(bus, "message::error", 
> G_CALLBACK(rec_pipeline_error_cb), NULL);
>
> // EOS
> g_signal_connect(bus, "message::eos", G_CALLBACK(rec_eos_msg_cb), NULL);
>
> gst_object_unref(bus);
> ----
>
> Thanks,
>   Osmo Antero (Moma)
> http://www.futuredesktop.org
>
>
>
>
>
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20101220/4e6e46d9/attachment.htm>


More information about the gstreamer-devel mailing list