static void
newpad_cb (GstElement *decodebin, GstPad *pad, gboolean last, gpointer found)
{
        GstCaps *caps;
        gchar *mimetype;
        GstStructure *structure;

        caps = gst_pad_get_caps (pad);
        structure = gst_caps_get_structure (caps, 0);
        mimetype = gst_structure_get_name (structure);

        if (g_strrstr (mimetype, "video")) {
                *(gboolean *) found |= TRUE;
        } else {
                *(gboolean *) found |= FALSE; /* True if already true. */
        }

        gst_caps_unref (caps);
}

static void
read_metadata (DmapdDAAPRecord *record, const gchar *path)
{
        GstState state;
        GstTagList *tags = NULL;
        GstStateChangeReturn sret;
        gboolean has_video = FALSE;
        GstElement *pipeline, *src, *decode;

        /* Set up pipeline. */
        pipeline = gst_pipeline_new ("pipeline");
        src = gst_element_factory_make ("filesrc", "source");
        decode = gst_element_factory_make ("decodebin", "decoder");
        gst_bin_add_many (GST_BIN (pipeline), src, decode, NULL);
        gst_element_link (src, decode);

        g_object_set (G_OBJECT (src), "location", path, NULL);

        /* Connect callback to identify audio and/or video tracks. */
        g_signal_connect (decode,
                          "new-decoded-pad",
                          G_CALLBACK (newpad_cb),
                          &has_video);

        gst_element_set_state (pipeline, GST_STATE_PAUSED);
        sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
        if (GST_STATE_CHANGE_ASYNC == sret) {
                if (GST_STATE_CHANGE_SUCCESS != gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, 5 * GST_SECOND)) {
                        g_warning ("State change failed for %s.", path);
                        return;
                }
        } else if (sret != GST_STATE_CHANGE_SUCCESS) {
                g_print ("%s - Could not read file\n", path);
                return;
        }

        if (!message_loop (GST_ELEMENT (pipeline), &tags)) {
                g_warning ("Failed in message reading for %s\n", path);
        }

        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (GST_OBJECT (pipeline));

        if (tags) {
                gst_tag_list_foreach (tags, insert_tag, record);
                gst_tag_list_free (tags);
                tags = NULL;
        } else
                g_warning ("No metadata found for %s\n", path);


        g_warning ("%s %s", path, has_video ? "has video" : "doesn't have video");
        record->priv->has_video = has_video;
}
