2 * Copyright (C) <2008> Wim Taymans <wim.taymans@gmail.com>
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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "gstrtpchannels.h"
26 * RTP channel positions as discussed in RFC 3551 and also RFC 3555
28 * We can't really represent the described channel positions in GStreamer but we
29 * implement a (very rough) approximation here.
32 static const GstAudioChannelPosition pos_4_1[] = {
33 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
34 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
35 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
36 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
39 static const GstAudioChannelPosition pos_4_2[] = {
40 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
41 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
42 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
43 GST_AUDIO_CHANNEL_POSITION_LFE1
46 static const GstAudioChannelPosition pos_4_3[] = {
47 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
48 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
49 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
50 GST_AUDIO_CHANNEL_POSITION_LFE1
53 static const GstAudioChannelPosition pos_5_1[] = {
54 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
55 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
56 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
57 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
58 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER
61 static const GstAudioChannelPosition pos_6_1[] = {
62 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
63 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
64 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
65 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
66 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
67 GST_AUDIO_CHANNEL_POSITION_LFE1
70 static const GstAudioChannelPosition pos_6_2[] = {
71 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
72 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
73 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
74 GST_AUDIO_CHANNEL_POSITION_LFE1,
75 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
76 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
79 static const GstAudioChannelPosition pos_8_1[] = {
80 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
81 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
82 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
83 GST_AUDIO_CHANNEL_POSITION_LFE1,
84 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
85 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
86 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
87 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT
90 static const GstAudioChannelPosition pos_8_2[] = {
91 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
92 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
93 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
94 GST_AUDIO_CHANNEL_POSITION_LFE1,
95 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
96 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
97 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
98 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT
101 static const GstAudioChannelPosition pos_8_3[] = {
102 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
103 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
104 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
105 GST_AUDIO_CHANNEL_POSITION_LFE1,
106 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
107 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
108 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
109 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT
112 static const GstAudioChannelPosition pos_def_1[] = {
113 GST_AUDIO_CHANNEL_POSITION_MONO
116 static const GstAudioChannelPosition pos_def_2[] = {
117 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
118 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT
121 static const GstAudioChannelPosition pos_def_3[] = {
122 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
123 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
124 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER
127 static const GstAudioChannelPosition pos_def_4[] = {
128 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
129 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
130 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
131 GST_AUDIO_CHANNEL_POSITION_LFE1
134 static const GstAudioChannelPosition pos_def_5[] = {
135 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
136 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
137 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
138 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
139 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT
142 static const GstAudioChannelPosition pos_def_6[] = {
143 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
144 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
145 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
146 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
147 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
148 GST_AUDIO_CHANNEL_POSITION_LFE1
151 const GstRTPChannelOrder gst_rtp_channel_orders[] = {
153 {"DV.LRLsRs", 4, pos_4_1},
154 {"DV.LRCS", 4, pos_4_2},
155 {"DV.LRCWo", 4, pos_4_3},
157 {"DV.LRLsRsC", 5, pos_5_1},
159 {"DV.LRLsRsCS", 6, pos_6_1},
160 {"DV.LmixRmixTWoQ1Q2", 6, pos_6_2},
162 {"DV.LRCWoLsRsLmixRmix", 8, pos_8_1},
163 {"DV.LRCWoLs1Rs1Ls2Rs2", 8, pos_8_2},
164 {"DV.LRCWoLsRsLcRc", 8, pos_8_3},
166 /* default layouts */
167 {NULL, 1, pos_def_1},
168 {NULL, 2, pos_def_2},
169 {NULL, 3, pos_def_3},
170 {NULL, 4, pos_def_4},
171 {NULL, 5, pos_def_5},
172 {NULL, 6, pos_def_6},
174 /* terminator, invalid entry */
179 check_channels (const GstRTPChannelOrder * order,
180 const GstAudioChannelPosition * pos)
185 for (i = 0; i < order->channels; i++) {
186 for (j = 0; j < order->channels; j++) {
187 if (order->pos[j] == pos[i])
190 if (j == order->channels)
197 * gst_rtp_channels_get_by_pos:
198 * @channels: the amount of channels
199 * @pos: a channel layout
201 * Return a description of the channel layout.
203 * Returns: a #GstRTPChannelOrder with the channel information or NULL when @pos
204 * is not a valid layout.
206 const GstRTPChannelOrder *
207 gst_rtp_channels_get_by_pos (gint channels, const GstAudioChannelPosition * pos)
210 const GstRTPChannelOrder *res = NULL;
212 g_return_val_if_fail (pos != NULL, NULL);
214 for (i = 0; channel_orders[i].pos; i++) {
215 if (channel_orders[i].channels != channels)
218 if (check_channels (&channel_orders[i], pos)) {
219 res = &channel_orders[i];
227 * gst_rtp_channels_create_default:
228 * @channels: the amount of channels
229 * @order: a channel order
231 * Get the channel order info the @order and @channels.
233 * Returns: a #GstRTPChannelOrder with the channel information or NULL when
234 * @order is not a know layout for @channels.
236 const GstRTPChannelOrder *
237 gst_rtp_channels_get_by_order (gint channels, const gchar * order)
240 const GstRTPChannelOrder *res = NULL;
242 for (i = 0; channel_orders[i].pos; i++) {
243 if (channel_orders[i].channels != channels)
246 /* no name but channels match, continue */
247 if (!channel_orders[i].name || !order) {
248 res = &channel_orders[i];
253 if (g_ascii_strcasecmp (channel_orders[i].name, order)) {
254 res = &channel_orders[i];
262 * gst_rtp_channels_get_by_index:
263 * @channels: the amount of channels
264 * @idx: the channel index to retrieve
266 * Get the allowed channel order descriptions for @channels. @idx can be used to
267 * retrieve the desired index.
269 * Returns: a #GstRTPChannelOrder at @idx, NULL when there are no valid channel
272 const GstRTPChannelOrder *
273 gst_rtp_channels_get_by_index (gint channels, guint idx)
276 const GstRTPChannelOrder *res = NULL;
278 for (i = 0; channel_orders[i].pos; i++) {
279 if (channel_orders[i].channels != channels)
283 res = &channel_orders[i];
293 * gst_rtp_channels_create_default:
294 * @channels: the amount of channels
296 * Create a default none channel mapping for @channels.
298 * Returns: a #GstAudioChannelPosition with all the channel position info set to
299 * #GST_AUDIO_CHANNEL_POSITION_NONE.
302 gst_rtp_channels_create_default (gint channels, GstAudioChannelPosition * posn)
306 g_return_if_fail (channels > 0);
308 for (i = 0; i < channels; i++)
309 posn[i] = GST_AUDIO_CHANNEL_POSITION_NONE;