[telepathy-sofiasip/master] Added codec format registration routines and type-based usage functions

Mikhail Zabaluev mikhail.zabaluev at nokia.com
Mon Nov 30 05:51:22 PST 2009


---
 tpsip/codec-param-formats.c |   92 +++++++++++++++++++++++++++++++++++++++++++
 tpsip/codec-param-formats.h |   22 ++++++++--
 2 files changed, 110 insertions(+), 4 deletions(-)

diff --git a/tpsip/codec-param-formats.c b/tpsip/codec-param-formats.c
index 3377aed..32847d2 100644
--- a/tpsip/codec-param-formats.c
+++ b/tpsip/codec-param-formats.c
@@ -31,9 +31,93 @@
 #define FMTP_MATCH_NAME_PARAM "p"
 #define FMTP_MATCH_NAME_VALUE "v"
 
+typedef struct _TpsipCodecParamFormatting {
+  TpsipCodecParamFormatFunc format;
+  TpsipCodecParamParseFunc parse;
+} TpsipCodecParamFormatting;
+
 static GRegex *fmtp_attr_regex = NULL;
 static GRegex *dtmf_events_regex = NULL;
 
+static GHashTable *codec_param_formats[NUM_TP_MEDIA_STREAM_TYPES];
+
+/**
+ * tpsip_codec_param_format:
+ * @media: the media type
+ * @name: name of the codec, as per its MIME subtype registration
+ * @params: the map of codec parameters
+ * @out: a #GString for the output
+ *
+ * Formats the parameters passed in the @params into a string suitable for
+ * <literal>a=fmtp</literal> attribute for an RTP payload description,
+ * as specified for the media type defined by @media and @name.
+ */
+void
+tpsip_codec_param_format (TpMediaStreamType media, const char *name,
+                          GHashTable *params, GString *out)
+{
+  TpsipCodecParamFormatting *fmt;
+
+  /* XXX: thread unsafe, we don't care for now */
+  fmt = g_hash_table_lookup (codec_param_formats[media], name);
+
+  if (fmt != NULL && fmt->format != NULL)
+    fmt->format (params, out);
+  else
+    tpsip_codec_param_format_generic (params, out);
+}
+
+/**
+ * tpsip_codec_param_parse:
+ * @media: the media type
+ * @name: name of the codec, as per its MIME subtype registration
+ * @fmtp: a string with the codec-specific parameter data
+ * @out: the parameter map to populate
+ *
+ * Parses the payload-specific parameter description as coming from an
+ * <literal>a=fmtp</literal> attribute of an RTP payload description.
+ * The media type is defined by @media and @name.
+ */
+void
+tpsip_codec_param_parse (TpMediaStreamType media, const char *name,
+                         const gchar *fmtp, GHashTable *out)
+{
+  TpsipCodecParamFormatting *fmt;
+
+  /* XXX: thread unsafe, we don't care for now */
+  fmt = g_hash_table_lookup (codec_param_formats[media], name);
+
+  if (fmt != NULL && fmt->parse != NULL)
+    fmt->parse (fmtp, out);
+  else
+    tpsip_codec_param_parse_generic (fmtp, out);
+}
+
+/**
+ * tpsip_codec_param_register_format:
+ * @media: the media type
+ * @name: name of the codec, as per its MIME subtype registration. Must be a static string.
+ * @format: pointer to the formatting function
+ * @parse: pointer to the parsing function
+ *
+ * Registers custom SDP payload parameter formatting routines for a media
+ * type.
+ */
+void
+tpsip_codec_param_register_format (TpMediaStreamType media, const char *name,
+                                   TpsipCodecParamFormatFunc format,
+                                   TpsipCodecParamParseFunc parse)
+{
+  TpsipCodecParamFormatting *fmt;
+
+  fmt = g_slice_new (TpsipCodecParamFormatting);
+  fmt->format = format;
+  fmt->parse = parse;
+
+  /* XXX: thread unsafe, we don't care for now */
+  g_hash_table_insert (codec_param_formats[media], name, fmt);
+}
+
 static void
 format_param_generic (gpointer key, gpointer val, gpointer user_data)
 {
@@ -203,11 +287,19 @@ tpsip_codec_param_formats_init ()
 {
   static volatile gsize been_here = 0;
 
+  int i;
+
   if (g_once_init_enter (&been_here))
     g_once_init_leave (&been_here, 1);
   else
     return;
 
+  for (i = 0; i < NUM_TP_MEDIA_STREAM_TYPES; ++i)
+    {
+      /* XXX: we ignore deallocation of values for now */
+      codec_param_formats[i] = g_hash_table_new (g_str_hash, g_str_equal);
+    }
+
   fmtp_attr_regex = g_regex_new (
       "(?<" FMTP_MATCH_NAME_PARAM ">" FMTP_TOKEN_PARAM ")"
       "\\s*=\\s*"
diff --git a/tpsip/codec-param-formats.h b/tpsip/codec-param-formats.h
index 9d07ebd..b7bf435 100644
--- a/tpsip/codec-param-formats.h
+++ b/tpsip/codec-param-formats.h
@@ -23,6 +23,8 @@
 
 #include <glib.h>
 
+#include <telepathy-glib/enums.h>
+
 G_BEGIN_DECLS
 
 /**
@@ -33,8 +35,8 @@ G_BEGIN_DECLS
  * Defines the function pointer signature for codec parameter formatters.
  * A formatter takes a codec parameter map as passed in
  * a org.freedesktop.Telepathy.Media.StreamHandler codec structure,
- * and outputs its SDP representation, as per the value for an a=fmtp
- * attribute, into the string buffer @out.
+ * and outputs its SDP representation, as per the value for an
+ * <literal>a=fmtp</literal> attribute, into the string buffer @out.
  *
  * <note>
  *   <para>The function is allowed to modify the @params hash table.
@@ -52,13 +54,25 @@ typedef void (* TpsipCodecParamFormatFunc) (GHashTable *params, GString *out);
  * @out: the parameter map to populate
  *
  * Defines the function pointer signature for codec parameter parsers.
- * A parser takes the string value coming from an a=fmtp SDP attribute,
- * and populates the parameter hash table.
+ * A parser takes the string value coming from an <literal>a=fmtp</literal>
+ * SDP attribute, and populates the parameter hash table.
  */
 typedef void (* TpsipCodecParamParseFunc) (const gchar *str, GHashTable *out);
 
 void tpsip_codec_param_formats_init (void);
 
+void tpsip_codec_param_format (TpMediaStreamType media, const char *name,
+                               GHashTable *params, GString *out);
+
+void tpsip_codec_param_parse (TpMediaStreamType media, const char *name,
+                              const gchar *fmtp, GHashTable *out);
+
+void tpsip_codec_param_register_format (
+            TpMediaStreamType media,
+            const char *name,
+            TpsipCodecParamFormatFunc format,
+            TpsipCodecParamParseFunc parse);
+
 void tpsip_codec_param_format_generic (GHashTable *params, GString *out);
 
 void tpsip_codec_param_parse_generic (const gchar *str, GHashTable *out);
-- 
1.5.6.5




More information about the telepathy-commits mailing list