## gstmultichannel

gstmultichannel — Support for multichannel audio elements

## Synopsis

    #include <gst/audio/multichannel.h>

    enum                GstAudioChannelPosition;
    GstAudioChannelPosition * gst_audio_fixate_channel_positions
                                                            (GstStructure *str);
    GstAudioChannelPosition * gst_audio_get_channel_positions
                                                            (GstStructure *str);
    void                gst_audio_set_caps_channel_positions_list
                                                            (GstCaps *caps,
                                                             const GstAudioChannelPosition *pos,
                                                             gint num_positions);
    void                gst_audio_set_channel_positions     (GstStructure *str,
                                                             const GstAudioChannelPosition *pos);
    void                gst_audio_set_structure_channel_positions_list
                                                            (GstStructure *str,
                                                             const GstAudioChannelPosition *pos,
                                                             gint num_positions);
    gboolean            gst_audio_check_channel_positions   (const GstAudioChannelPosition *pos,
                                                             guint channels);

## Description

This module contains some helper functions and a enum to work with multichannel audio.

## Details

### enum GstAudioChannelPosition

    typedef enum {
      GST_AUDIO_CHANNEL_POSITION_INVALID = -1,

      /* Main front speakers. Mono and left/right are mututally exclusive! */
      GST_AUDIO_CHANNEL_POSITION_FRONT_MONO,
      GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
      GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,

      /* rear. Left/right and center are mututally exclusive! */
      GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
      GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
      GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,

      /* subwoofer/low-frequency */
      GST_AUDIO_CHANNEL_POSITION_LFE,

      /* Center front speakers. Center and left/right_of_center cannot be
       * used together! */
      GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
      GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER,
      GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER,

      /* sides */
      GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
      GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,

      /* for multi-channel input and output with more than 8 channels,
       * incompatible with all other positions, either all positions
       * are defined or all positions are undefined, but can't mix'n'match  */
      GST_AUDIO_CHANNEL_POSITION_NONE,
    } GstAudioChannelPosition;

Audio channel positions.

`GST_AUDIO_CHANNEL_POSITION_INVALID` | invalid position
`GST_AUDIO_CHANNEL_POSITION_FRONT_MONO` | front mono
`GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT` | front left
`GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT` | front right
`GST_AUDIO_CHANNEL_POSITION_REAR_CENTER` | rear center
`GST_AUDIO_CHANNEL_POSITION_REAR_LEFT` | rear left
`GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT` | rear right
`GST_AUDIO_CHANNEL_POSITION_LFE` | subwoofer
`GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER` | front center
`GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER` | front left of center
`GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER` | front right of center
`GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT` | side left
`GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT` | side right
`GST_AUDIO_CHANNEL_POSITION_NONE` | used for position-less channels, e.g. from a sound card that records 1024 channels; mutually exclusive with any other channel position

### gst_audio_fixate_channel_positions ()

    GstAudioChannelPosition * gst_audio_fixate_channel_positions
                                                            (GstStructure *str);

Custom fixate function. Elements that implement some sort of channel conversion algorithm should use this function for fixating on GstAudioChannelPosition properties. It will take care of equal channel positioning (left/right). Caller `g_free()`s the return value. The input properties may be (and are supposed to be) unfixed. Note that this function is mostly a hack because we currently have no way to add default fixation functions for new GTypes.

`str` : | a GstStructure containing a (possibly unfixed) "channel-positions" field.
Returns : | fixed values that the caller could use as a fixed set of GstAudioChannelPosition values.

### gst_audio_get_channel_positions ()

    GstAudioChannelPosition * gst_audio_get_channel_positions
                                                            (GstStructure *str);

Retrieves a number of (fixed!) audio channel positions from the provided GstStructure and returns it as a newly allocated array. The caller should `g_free()` this array. The caller should also check that the members in this GstStructure are indeed "fixed" before calling this function.

`str` : | A GstStructure to retrieve channel positions from.
Returns : | a newly allocated array containing the channel positions as provided in the given GstStructure. Returns NULL on error.

### gst_audio_set_caps_channel_positions_list ()

    void                gst_audio_set_caps_channel_positions_list
                                                            (GstCaps *caps,
                                                             const GstAudioChannelPosition *pos,
                                                             gint num_positions);

Sets a (possibly non-fixed) list of possible audio channel positions (given in pos) on the given caps. Each of the structures of the caps, after this function has been called, will contain a "channel-positions" field with an array. Each value in the array will contain each of the values given in the pos array. Note that the size of the caps might be increased by this, since each structure with a "channel- positions" field needs to have a fixed "channels" field. The input caps is not required to have this.

`caps` : | GstCaps to set the list of channel positions on.
`pos` : | the array containing one or more possible audio channel positions that we should add in each value of the array in the given structure.
`num_positions` : | the number of values in pos.

### gst_audio_set_channel_positions ()

    void                gst_audio_set_channel_positions     (GstStructure *str,
                                                             const GstAudioChannelPosition *pos);

Adds a "channel-positions" field to the given GstStructure, which will represent the channel positions as given in the provided GstAudioChannelPosition array.

`str` : | A GstStructure to set channel positions on.
`pos` : | an array of channel positions. The number of members in this array should be equal to the (fixed!) number of the "channels" field in the given GstStructure.

### gst_audio_set_structure_channel_positions_list ()

    void                gst_audio_set_structure_channel_positions_list
                                                            (GstStructure *str,
                                                             const GstAudioChannelPosition *pos,
                                                             gint num_positions);

Sets a (possibly non-fixed) list of possible audio channel positions (given in pos) on the given structure. The structure, after this function has been called, will contain a "channel-positions" field with an array of the size of the "channels" field value in the given structure (note that this means that the channels field in the provided structure should be fixed!). Each value in the array will contain each of the values given in the pos array.

`str` : | GstStructure to set the list of channel positions on.
`pos` : | the array containing one or more possible audio channel positions that we should add in each value of the array in the given structure.
`num_positions` : | the number of values in pos.

### gst_audio_check_channel_positions ()

    gboolean            gst_audio_check_channel_positions   (const GstAudioChannelPosition *pos,
                                                             guint channels);

This functions checks if the given channel positions are valid. Channel positions are valid if:

- No channel positions appears twice or all positions are `GST_AUDIO_CHANNEL_POSITION_NONE`.

- Either all or none of the channel positions are `GST_AUDIO_CHANNEL_POSITION_NONE`.

- `GST_AUDIO_CHANNEL_POSITION_FRONT_MONO` and `GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT` or `GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT` don't appear together in the given positions.

`pos` : | An array of GstAudioChannelPosition.
`channels` : | The number of elements in `pos`.
Returns : | `TRUE` if the given channel positions are valid and `FALSE` otherwise.

Since 0.10.20