- /* Something else happened. Whatevs. */
- break;
- }
-}
-
-static int query_track_length(struct tracklength_state *state,
- long *length_out)
-{
- /* Interrogate the pipeline to find the track length. Return zero on
- * success, or -1 on failure. This is annoying and nonportable.
- */
-
- gint64 t;
-#ifdef HAVE_GSTREAMER_0_10
- GstFormat fmt = GST_FORMAT_TIME;
-#endif
-
-#ifdef HAVE_GSTREAMER_0_10
- if(!gst_element_query_duration(state->pipeline, &fmt, &t) ||
- fmt != GST_FORMAT_TIME)
- return -1;
-#else
- if(!gst_element_query_duration(state->pipeline, GST_FORMAT_TIME, &t))
- return -1;
-#endif
- *length_out = (t + 500000000)/1000000000;
- return 0;
-}
-
-long disorder_tracklength(const char UNUSED *track, const char *path) {
- /* Discover the length of a track. */
-
- struct tracklength_state state;
- GstElement *source, *decode, *sink;
- GstBus *bus = 0;
- int running = 0;
- long length = -1;
-
- /* Fill in the state structure. */
- state.path = path;
- state.state = ST_PAUSE;
- state.pipeline = 0;
- state.loop = 0;
-
- /* Set up the GStreamer machinery. */
- if(!inited_gstreamer) gst_init(0, 0);
-
- /* Create the necessary pipeline elements. */
- source = gst_element_factory_make("filesrc", "file");
- decode = gst_element_factory_make("decodebin", "decode");
- sink = state.sink = gst_element_factory_make("fakesink", "sink");
- state.pipeline = gst_pipeline_new("pipe");
- if(!source || !decode || !sink) {
- disorder_error(0, "failed to create GStreamer elements: "
- "need base and good plugins");
- goto end;
- }
- g_object_set(source, "location", path, END);
-
- /* Add the elements to the pipeline. It will take over responsibility for
- * them.
- */
- gst_bin_add_many(GST_BIN(state.pipeline), source, decode, sink, END);
-
- /* Link the elements together as far as we can. Arrange to link the decoder
- * onto our (dummy) sink when it's ready to produce output.
- */
- if(!gst_element_link(source, decode)) {
- disorder_error(0, "error checking `%s': "
- "failed to link GStreamer elements `file' and `decode'",
- path);