From 09e449609f856dd45da29bd76c8235cf6a37bf25 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 28 Oct 2008 10:01:49 +0000 Subject: gst/rtp/: Add mappings for multichannel support. Does not completely just work because the getcaps function does not ... Original commit message from CVS: * gst/rtp/gstrtpL16depay.c: (gst_rtp_L16_depay_setcaps): * gst/rtp/gstrtpL16pay.c: (gst_rtp_L16_pay_setcaps), (gst_rtp_L16_pay_getcaps): * gst/rtp/gstrtpchannels.c: (check_channels), (gst_rtp_channels_get_by_pos), (gst_rtp_channels_get_by_order), (gst_rtp_channels_create_default): * gst/rtp/gstrtpchannels.h: Add mappings for multichannel support. Does not completely just work because the getcaps function does not yet return the allowed channel mappings. See #556641. --- gst/rtp/gstrtpchannels.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 gst/rtp/gstrtpchannels.c (limited to 'gst/rtp/gstrtpchannels.c') diff --git a/gst/rtp/gstrtpchannels.c b/gst/rtp/gstrtpchannels.c new file mode 100644 index 00000000..05100f0f --- /dev/null +++ b/gst/rtp/gstrtpchannels.c @@ -0,0 +1,136 @@ +/* GStreamer + * Copyright (C) <2008> Wim Taymans + * + * 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 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include "gstrtpchannels.h" + +/* + * RTP channel positions as discussed in RFC 3551 and also RFC 3555 + * + * We can't really represent the described channel positions in GStreamer but we + * implement a (very rough) approximation here. + */ + +static gboolean +check_channels (const GstRTPChannelOrder * order, + const GstAudioChannelPosition * pos) +{ + gint i; + gboolean res = TRUE; + + for (i = 0; i < order->channels; i++) { + if (order->pos[i] != pos[i]) { + res = FALSE; + break; + } + } + return res; +} + +/** + * gst_rtp_channels_get_by_pos: + * @channels: the amount of channels + * @pos: a channel layout + * + * Return a description of the channel layout. + * + * Returns: a #GstRTPChannelOrder with the channel information or NULL when @pos + * is not a valid layout. + */ +const GstRTPChannelOrder * +gst_rtp_channels_get_by_pos (gint channels, const GstAudioChannelPosition * pos) +{ + gint i; + const GstRTPChannelOrder *res = NULL; + + g_return_val_if_fail (pos != NULL, NULL); + + for (i = 0; channel_orders[i].pos; i++) { + if (channel_orders[i].channels != channels) + continue; + + if (check_channels (&channel_orders[i], pos)) { + res = &channel_orders[i]; + break; + } + } + return res; +} + +/** + * gst_rtp_channels_create_default: + * @channels: the amount of channels + * @order: a channel order + * + * Get the channel order info the @order and @channels. + * + * Returns: a #GstRTPChannelOrder with the channel information or NULL when + * @order is not a know layout for @channels. + */ +const GstRTPChannelOrder * +gst_rtp_channels_get_by_order (gint channels, const gchar * order) +{ + gint i; + const GstRTPChannelOrder *res = NULL; + + for (i = 0; channel_orders[i].pos; i++) { + if (channel_orders[i].channels != channels) + continue; + + /* no name but channels match, continue */ + if (!channel_orders[i].name || !order) { + res = &channel_orders[i]; + break; + } + + /* compare names */ + if (g_ascii_strcasecmp (channel_orders[i].name, order)) { + res = &channel_orders[i]; + break; + } + } + return res; +} + +/** + * gst_rtp_channels_create_default: + * @channels: the amount of channels + * + * Create a default none channel mapping for @channels. + * + * Returns: a #GstAudioChannelPosition with all the channel position info set to + * #GST_AUDIO_CHANNEL_POSITION_NONE. + */ +GstAudioChannelPosition * +gst_rtp_channels_create_default (gint channels) +{ + gint i; + GstAudioChannelPosition *posn; + + g_return_val_if_fail (channels > 0, NULL); + + posn = g_new (GstAudioChannelPosition, channels); + + for (i = 0; i < channels; i++) + posn[i] = GST_AUDIO_CHANNEL_POSITION_NONE; + + return posn; +} -- cgit