1 /* GStreamer Jack utility functions
2 * Copyright (C) 2010 Tristan Matthews <tristan@sat.qc.ca>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "gstjackutil.h"
21 #include <gst/audio/multichannel.h>
23 static const GstAudioChannelPosition default_positions[8][8] = {
26 GST_AUDIO_CHANNEL_POSITION_FRONT_MONO,
30 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
31 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
33 /* 3 channels (2.1) */
35 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
36 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
37 GST_AUDIO_CHANNEL_POSITION_LFE, /* or FRONT_CENTER for 3.0? */
39 /* 4 channels (4.0 or 3.1?) */
41 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
42 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
43 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
44 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
48 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
49 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
50 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
51 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
52 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
56 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
57 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
58 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
59 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
60 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
61 GST_AUDIO_CHANNEL_POSITION_LFE,
65 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
66 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
67 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
68 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
69 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
70 GST_AUDIO_CHANNEL_POSITION_LFE,
71 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER,
75 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
76 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
77 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
78 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
79 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
80 GST_AUDIO_CHANNEL_POSITION_LFE,
81 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
82 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
87 /* if channels are less than or equal to 8, we set a default layout,
88 * otherwise set layout to an array of GST_AUDIO_CHANNEL_POSITION_NONE */
90 gst_jack_set_layout_on_caps (GstCaps ** caps, gint channels)
94 GValue chanpos = { 0 };
95 gst_caps_unref (*caps);
98 g_assert (channels >= 1);
99 gst_audio_set_channel_positions (gst_caps_get_structure (*caps, 0),
100 default_positions[channels - 1]);
102 g_value_init (&chanpos, GST_TYPE_ARRAY);
103 g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
104 for (c = 0; c < channels; c++) {
105 g_value_set_enum (&pos, GST_AUDIO_CHANNEL_POSITION_NONE);
106 gst_value_array_append_value (&chanpos, &pos);
108 g_value_unset (&pos);
109 gst_structure_set_value (gst_caps_get_structure (*caps, 0),
110 "channel-positions", &chanpos);
111 g_value_unset (&chanpos);
113 gst_caps_ref (*caps);