gst_element_query_duration() fails for certain filetypes

Nate Bogdanowicz natezb at stanford.edu
Sun Jan 27 13:07:44 PST 2013


Hi Tim,

On Sun, Jan 27, 2013 at 12:49 PM, Tim-Philipp Müller <t.i.m at zen.co.uk> wrote:
> 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
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


Thanks for your reply. Thanks for the suggestion about GST_SECOND.
However, as you can see, I already do use a _get_state() call to wait
for the pipeline to be prerolled (that's where I've use the 1e9). I
then verify that the state has successfully changed using
GST_STATE_CHANGE_SUCCESS, and exit(1) if it hasn't.

Furthermore, in my larger program I've also queried the duration
repeatedly *while the pipeline is in the PLAYING state and music is
playing through my speakers* and _query_duration() consistently
returns the same value. It definitely does not seem to be connected to
an incomplete state change.

Thanks,
Nate


More information about the gstreamer-devel mailing list