gst_element_query_duration() fails for certain filetypes

Tim-Philipp Müller t.i.m at zen.co.uk
Sun Jan 27 12:49:38 PST 2013


On Sun, 2013-01-27 at 12:11 -0800, Nate Bogdanowicz wrote:

Hi Nate,

> (...) I am able to play all of the files via GStreamer, just not query
> their duration. Also, I am sure that the pipeline is properly set to
> GST_STATE_PAUSED in all cases, as my code verifies this. I've written
> some sample code that reproduces my problem and included it below:

>     ...
>     gst_element_set_state(pipe, GST_STATE_PAUSED);
>     GstStateChangeReturn res = gst_element_get_state(pipe, NULL, NULL,
> ((GstClockTime)1e9));
>     if (res != GST_STATE_CHANGE_SUCCESS) {
>         fprintf(stderr, "State change failed!\n");
>         exit(1);
>     }
>     
>     gint64 duration;
>     GstFormat format = GST_FORMAT_DEFAULT;
>     
>     if (gst_element_query_duration(GST_ELEMENT(dec), &format,
> &duration)) {
>         printf("duration = %d\n", duration);
>     } else {
>         printf("The query could not be performed!\n");
>     }
> }

The problem is that the state change to PAUSED/PLAYING will take place
asynchronously in another thread. You will have to wait until the
pipeline is prerolled (has reached PAUSED state) before you query the
duration.

Either wait for the ASYNC_DONE message on the bus, or do a _get_state()
call with a timeout to wait for the state change to complete.

Cheers
 -Tim

PS: you may find GST_SECOND more convenient than (GstClockTime)1e9



More information about the gstreamer-devel mailing list