gstjackutil.c 3.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* GStreamer Jack utility functions
 * Copyright (C) 2010 Tristan Matthews <tristan@sat.qc.ca>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
16 17
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
18 19 20
 */

#include "gstjackutil.h"
21
#include <gst/audio/audio.h>
22 23 24 25

static const GstAudioChannelPosition default_positions[8][8] = {
  /* 1 channel */
  {
26
        GST_AUDIO_CHANNEL_POSITION_MONO,
27 28 29 30 31 32 33 34 35 36
      },
  /* 2 channels */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
      },
  /* 3 channels (2.1) */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
37
        GST_AUDIO_CHANNEL_POSITION_LFE1,        /* or FRONT_CENTER for 3.0? */
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
      },
  /* 4 channels (4.0 or 3.1?) */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
        GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
      },
  /* 5 channels */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
        GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
      },
  /* 6 channels */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
        GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
61
        GST_AUDIO_CHANNEL_POSITION_LFE1,
62 63 64 65 66 67 68 69
      },
  /* 7 channels */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
        GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
70
        GST_AUDIO_CHANNEL_POSITION_LFE1,
71 72 73 74 75 76 77 78 79
        GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
      },
  /* 8 channels */
  {
        GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
        GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
        GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
80
        GST_AUDIO_CHANNEL_POSITION_LFE1,
81 82 83 84 85 86 87 88 89
        GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
        GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
      }
};


/* if channels are less than or equal to 8, we set a default layout,
 * otherwise set layout to an array of GST_AUDIO_CHANNEL_POSITION_NONE */
void
90
gst_jack_set_layout (GstAudioRingBuffer * buffer, GstAudioRingBufferSpec * spec)
91
{
92
  gint i;
93

94 95 96 97 98 99 100
  if (spec->info.channels <= 8) {
    for (i = 0; i < spec->info.channels; i++)
      spec->info.position[i] = default_positions[spec->info.channels - 1][i];
    gst_audio_channel_positions_to_valid_order (spec->info.position,
        spec->info.channels);
    gst_audio_ring_buffer_set_channel_positions (buffer,
        default_positions[spec->info.channels - 1]);
101
  } else {
102 103 104 105
    spec->info.flags |= GST_AUDIO_FLAG_UNPOSITIONED;
    for (i = 0; i < G_N_ELEMENTS (spec->info.position); i++)
      spec->info.position[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
    gst_audio_ring_buffer_set_channel_positions (buffer, spec->info.position);
106
  }
107 108 109

  gst_caps_unref (spec->caps);
  spec->caps = gst_audio_info_to_caps (&spec->info);
110
}