[gst-devel] gst_element_seek problem

Tim Müller t.i.m at zen.co.uk
Mon Jul 2 19:14:27 CEST 2007


On Mon, 2007-07-02 at 14:56 +0000, bounce bounce wrote:

> I'm using a "playbin" GStreamer element to read video files.
> 
> My problem is that when I'm using the "gst_element_seek" function, the
>  video is not seeking where I want and next if I play the video, it is
>  played from its last position and not from the wanted position. I must
>  repeat the operation twice with a Sleep to seek the video where I
>  want.
> 
> Here you have the code used to seek the video :
> 
> 
> if ( ! gst_element_set_state(playbin, GST_STATE_PAUSED) ) {

gst_element_set_state() does not return a gboolean, you're just lucky
enough that GST_STATE_CHANGE_FAILURE maps to 0 instead of, say, -1 or
whatever. You should check for the failure enum explicitly.


>                 printf("Couldn't set player to GST_STATE_PAUSED state.");
>                 exit (EXIT_FAILURE);
> }

> // seeking to the beginnig of the video
> if ( ! gst_element_seek(vsink, ....) )
>                printf("Error while executing gst_element_seek in video_seek function.");
>                exit (EXIT_FAILURE);
> }
>
> The video is paused but the seeking is not right.
> 
> Is the way I took myself to do that wrong ?
> Could you help me ?
> 
> 
You should probably use gst_element_seek(playbin, ...) or
gst_element_seek_simple(playbin, ...) instead of doing the seek on the
sink directly.

However, your main problem is probably that the state change to PAUSED
or PLAYING state happens asynchroneously in the background, so when
_set_state() returns, it might not have finished yet (and seeking might
not work yet). In other words, you need to wait for playbin to change
to >=PAUSED state before issuing your seek request. By doing an
explicit sleep in between those calls, you're just increasing the
likelihood that playbin has finished prerolling and reached PAUSED
state, but you have no real guarantee (also, you should really be
checking for error as well, since there may be errors happening after
you've instructed the state change).

Hope this helps.

Cheers
 -Tim






More information about the gstreamer-devel mailing list