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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, 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.
33 check_channels (const GstRTPChannelOrder * order,
34 const GstAudioChannelPosition * pos)
39 for (i = 0; i < order->channels; i++) {
40 if (order->pos[i] != pos[i]) {
49 * gst_rtp_channels_get_by_pos:
50 * @channels: the amount of channels
51 * @pos: a channel layout
53 * Return a description of the channel layout.
55 * Returns: a #GstRTPChannelOrder with the channel information or NULL when @pos
56 * is not a valid layout.
58 const GstRTPChannelOrder *
59 gst_rtp_channels_get_by_pos (gint channels, const GstAudioChannelPosition * pos)
62 const GstRTPChannelOrder *res = NULL;
64 g_return_val_if_fail (pos != NULL, NULL);
66 for (i = 0; channel_orders[i].pos; i++) {
67 if (channel_orders[i].channels != channels)
70 if (check_channels (&channel_orders[i], pos)) {
71 res = &channel_orders[i];
79 * gst_rtp_channels_create_default:
80 * @channels: the amount of channels
81 * @order: a channel order
83 * Get the channel order info the @order and @channels.
85 * Returns: a #GstRTPChannelOrder with the channel information or NULL when
86 * @order is not a know layout for @channels.
88 const GstRTPChannelOrder *
89 gst_rtp_channels_get_by_order (gint channels, const gchar * order)
92 const GstRTPChannelOrder *res = NULL;
94 for (i = 0; channel_orders[i].pos; i++) {
95 if (channel_orders[i].channels != channels)
98 /* no name but channels match, continue */
99 if (!channel_orders[i].name || !order) {
100 res = &channel_orders[i];
105 if (g_ascii_strcasecmp (channel_orders[i].name, order)) {
106 res = &channel_orders[i];
114 * gst_rtp_channels_get_by_index:
115 * @channels: the amount of channels
116 * @idx: the channel index to retrieve
118 * Get the allowed channel order descriptions for @channels. @idx can be used to
119 * retrieve the desired index.
121 * Returns: a #GstRTPChannelOrder at @idx, NULL when there are no valid channel
124 const GstRTPChannelOrder *
125 gst_rtp_channels_get_by_index (gint channels, guint idx)
128 const GstRTPChannelOrder *res = NULL;
130 for (i = 0; channel_orders[i].pos; i++) {
131 if (channel_orders[i].channels != channels)
135 res = &channel_orders[i];
145 * gst_rtp_channels_create_default:
146 * @channels: the amount of channels
148 * Create a default none channel mapping for @channels.
150 * Returns: a #GstAudioChannelPosition with all the channel position info set to
151 * #GST_AUDIO_CHANNEL_POSITION_NONE.
153 GstAudioChannelPosition *
154 gst_rtp_channels_create_default (gint channels)
157 GstAudioChannelPosition *posn;
159 g_return_val_if_fail (channels > 0, NULL);
161 posn = g_new (GstAudioChannelPosition, channels);
163 for (i = 0; i < channels; i++)
164 posn[i] = GST_AUDIO_CHANNEL_POSITION_NONE;