## GstType

GstType — Identifies the data

## Synopsis

    #include <gst/gst.h>

    struct      GstType;
    guint16     gst_type_register               (GstTypeFactory *factory);
    guint16     gst_type_find_by_mime           (const gchar *mime);
    guint16     gst_type_find_by_ext            (const gchar *ext);
    GstType*    gst_type_find_by_id             (guint16 id);
    const GList* gst_type_get_list              (void);

## Description

GstTypes exist to try to make sure data eveyrone is talking about the right kind of data. They aid quite a bit in autoplugging, in fact make it possible. Each well-formed type includes a function (typefind) that will take one or more buffers and determine whether or not it is indeed a stream of that type, and possible a metadata to go with it. It may provide related metadata structure IDs (and must if it provides metadata from the typefind function).

Because multiple elements and plugins are very likely to be using the same types, the process of creating/finding types is designed to be done with a single function call. All operations on GstTypes occur via their guint16 ID numbers, with the GstType structure "private" to the GST library. A plugin wishing to use a give type would contain a static struct of type GstTypeFactory, which lists the MIME type, possible extensions (which may overlap the mime-types file), a typefind function, and any other cruft I decide to add.

A plugin init function would take this typefactory and hand it to the gst_type_new() (FIXME: badly named) function, which would first search for that same MIME type in the current list. If it found one, it would compare the two to see if the new one is "better". Better is defined as having more extentions (to be merged) or a typefind function verses none.

The point of returning an existing MIME type is a result of the goal of unifying types enough to guarantee that, for instance, all MP3 decoders will work interchangably. If MP3 decoder A says "MIME type 'audio/mpeg' with extensions 'mpeg3'" and decoder B says "MIME type 'audio/mpeg' with extensions 'mp3'", we don't want to have two types defined, possibly with two typefind functions. If we did, it's not obvious which of the two would be tried first (luck) and if both would really identify streams as mp3 correctly in all cases. And whichever wins, we're stuck using the associated decoder to play that stream. We lose the choice between any valid mp3 decoder, and thus the whole point of the type system.

## Details

### struct GstType

    struct GstType {

      guint16 id;			/* type id (assigned) */

      gchar *mime;			/* MIME type */
      gchar *exts;			/* space-delimited list of extensions */

      GSList *factories;		/* factories providing this type */
    };

A type.

### gst_type_register ()

    guint16     gst_type_register               (GstTypeFactory *factory);

Register a new type factory to the system.

`factory` : | the type factory to register
Returns : | the new type id

### gst_type_find_by_mime ()

    guint16     gst_type_find_by_mime           (const gchar *mime);

Find the type id of a given mime type.

`mime` : | the mime type to find
Returns : | the type id

### gst_type_find_by_ext ()

    guint16     gst_type_find_by_ext            (const gchar *ext);

Find the type id of a given extention.

`ext` : | the extension to find
Returns : | the type id

### gst_type_find_by_id ()

    GstType*    gst_type_find_by_id             (guint16 id);

Find the type of a given type id.

`id` : | the type id to lookup
Returns : | the type

### gst_type_get_list ()

    const GList* gst_type_get_list              (void);

Return a list of all registered types.

Returns : | a list of GstTypes

## See Also

GstTypeFactory