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 for (j = 0; j < order->channels; j++) {
41 if (order->pos[j] == pos[i])
44 if (j == order->channels)
51 * gst_rtp_channels_get_by_pos:
52 * @channels: the amount of channels
53 * @pos: a channel layout
55 * Return a description of the channel layout.
57 * Returns: a #GstRTPChannelOrder with the channel information or NULL when @pos
58 * is not a valid layout.
60 const GstRTPChannelOrder *
61 gst_rtp_channels_get_by_pos (gint channels, const GstAudioChannelPosition * pos)
64 const GstRTPChannelOrder *res = NULL;
66 g_return_val_if_fail (pos != NULL, NULL);
68 for (i = 0; channel_orders[i].pos; i++) {
69 if (channel_orders[i].channels != channels)
72 if (check_channels (&channel_orders[i], pos)) {
73 res = &channel_orders[i];
81 * gst_rtp_channels_create_default:
82 * @channels: the amount of channels
83 * @order: a channel order
85 * Get the channel order info the @order and @channels.
87 * Returns: a #GstRTPChannelOrder with the channel information or NULL when
88 * @order is not a know layout for @channels.
90 const GstRTPChannelOrder *
91 gst_rtp_channels_get_by_order (gint channels, const gchar * order)
94 const GstRTPChannelOrder *res = NULL;
96 for (i = 0; channel_orders[i].pos; i++) {
97 if (channel_orders[i].channels != channels)
100 /* no name but channels match, continue */
101 if (!channel_orders[i].name || !order) {
102 res = &channel_orders[i];
107 if (g_ascii_strcasecmp (channel_orders[i].name, order)) {
108 res = &channel_orders[i];
116 * gst_rtp_channels_get_by_index:
117 * @channels: the amount of channels
118 * @idx: the channel index to retrieve
120 * Get the allowed channel order descriptions for @channels. @idx can be used to
121 * retrieve the desired index.
123 * Returns: a #GstRTPChannelOrder at @idx, NULL when there are no valid channel
126 const GstRTPChannelOrder *
127 gst_rtp_channels_get_by_index (gint channels, guint idx)
130 const GstRTPChannelOrder *res = NULL;
132 for (i = 0; channel_orders[i].pos; i++) {
133 if (channel_orders[i].channels != channels)
137 res = &channel_orders[i];
147 * gst_rtp_channels_create_default:
148 * @channels: the amount of channels
150 * Create a default none channel mapping for @channels.
152 * Returns: a #GstAudioChannelPosition with all the channel position info set to
153 * #GST_AUDIO_CHANNEL_POSITION_NONE.
156 gst_rtp_channels_create_default (gint channels, GstAudioChannelPosition * posn)
160 g_return_if_fail (channels > 0);
162 for (i = 0; i < channels; i++)
163 posn[i] = GST_AUDIO_CHANNEL_POSITION_NONE;