20.3. GStreamer types

GStreamer assigns a unique number to all registered MIME types. GStreamer also keeps a reference to a function that can be used to determine if a given buffer is of the given MIME type.

There is also an association between a MIME type and a file extension, but the use of typefind functions (similar to file(1)) is preferred.

The type information is maintained in a list of GstType. The definition of a GstType is like:


typedef GstCaps (*GstTypeFindFunc) (GstBuffer *buf,gpointer *priv);
 
typedef struct _GstType GstType;

struct _GstType {
  guint16 id;                   /* type id (assigned) */

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

  GstTypeFindFunc typefindfunc; /* typefind function */
};
      

All operations on GstType occur via their guint16 id numbers, with the GstType structure private to the GStreamer library.

20.3.1. MIME type to id conversion

We can obtain the id for a given MIME type with the following piece of code:


  guint16 id;
  
  id = gst_type_find_by_mime ("audio/mpeg");
      

This function will return 0 if the type was not known.

20.3.2. id to GstType conversion

We can obtain the GstType for a given id with the following piece of code:


  GstType *type;
  
  type = gst_type_find_by_id (id);
      

This function will return NULL if the id was not associated with any known GstType

20.3.3. extension to id conversion

We can obtain the id for a given file extension with the following piece of code:


  guint16 id;
  
  id = gst_type_find_by_ext (".mp3");
      

This function will return 0 if the extension was not known.

For more information, see Chapter 28.