[gst-devel] Several novice questions

Jeffrey Barish jeff_barish at earthlink.net
Fri Jan 18 17:14:03 CET 2008


Edward Hervey wrote:

> Hi,
> 
> On Fri, 2008-01-18 at 08:28 -0700, Jeffrey Barish wrote:
>> 1. I gather that I am expected to change the state of the player on EOS
>> (which seems strange to me as I would have thought that the player would
>> know to stop playing when the stream has ended).  To this end, I included
>> the following code:
>> 
>>     self.player = gst.element_factory_make('playbin', 'player')
>>     bus = self.player.get_bus()
>>     bus.add_signal_watch()
>>     bus.connect('message', self.on_message)
>> 
>> def on_message(self, bus, message):
>>     print "Got message", message  # nothing ever prints
>>     t = message.type
>>     if t in (gst.MESSAGE_EOS, gst.MESSAGE_ERROR):
>>         self.player.set_state(gst.STATE_NULL)
>> 
>> However, on_message is never called.  Any idea what I am doing wrong?
> 
>   Are you running a mainloop ? I think it won't work if you're not
> runnign a mainloop.

I have the impression that pygst takes care of the main loop for me.  I
don't see main_loop in the pygst documentation nor in the tutorial
examples, nor does pygst have a function main_loop or mainloop.

>> 2. get_state() returns a tuple (with 3 elements) of the Element's current
>> state.  Where is the documentation on the elements of the tuple?  It
>> appears that the second element is the actual state.  Is this observation
>> always true?
> 
>   Look in the C API for gst_element_get_state. The returned values are
> the 3 last arguments of that function.

I am getting a tuple with (type GstStateChangeReturn, type GstState, type
GstState), so I guess the first element is the return value of
gst_element_get_state, the second is the current state, and the third is
the pending state.  I am interested in knowing more about how ASYNC state
changes work and when they are used.

>> 3. I would like to know the elapsed ratio so I tried
>> query_position(gst.FORMAT_PERCENT).  I get a query error.  It works to do
>> query_position(gst.FORMAT_TIME) and query_duration(gst.FORMAT_TIME) and
>> compute the ratio, but why doesn't the simpler solution work?  Is
>> gst.FORMAT_PERCENT a percentage (0 to 100), as the name implies, or is it
>> actually a ratio (0 to 1)?
>> 
> 
>    What are you doing that query on ? the pipeline ? the sinks ?

I am doing the query on self.player:

    ratio = self.player.query_position(gst.FORMAT_PERCENT)[0]

This works:

    position = self.player.query_position(gst.FORMAT_TIME)[0]


Thanks for your quick reply.
-- 
Jeffrey Barish





More information about the gstreamer-devel mailing list