[farsight2/master] Add fs_codec_to_gst_caps to be base library

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:19:10 PST 2008


---
 docs/libs/farsight-libs-sections.txt |    1 +
 gst-libs/gst/farsight/fs-codec.c     |   58 ++++++++++++++++++++++++++++++++++
 gst-libs/gst/farsight/fs-codec.h     |    5 ++-
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/docs/libs/farsight-libs-sections.txt b/docs/libs/farsight-libs-sections.txt
index 3e6ce1b..c4652b1 100644
--- a/docs/libs/farsight-libs-sections.txt
+++ b/docs/libs/farsight-libs-sections.txt
@@ -108,6 +108,7 @@ fs_codec_list_copy
 fs_codec_list_from_keyfile
 fs_codec_to_string
 fs_codec_are_equal
+fs_codec_to_gst_caps
 <SUBSECTION Standard>
 FS_TYPE_CODEC
 FS_TYPE_CODEC_LIST
diff --git a/gst-libs/gst/farsight/fs-codec.c b/gst-libs/gst/farsight/fs-codec.c
index bcb5ac1..7537c49 100644
--- a/gst-libs/gst/farsight/fs-codec.c
+++ b/gst-libs/gst/farsight/fs-codec.c
@@ -543,3 +543,61 @@ fs_codec_are_equal (FsCodec *codec1, FsCodec *codec2)
 
   return TRUE;
 }
+
+/**
+ * fs_codec_to_gst_caps
+ * @codec: A #FsCodec to be converted
+ *
+ * This function converts a #FsCodec to a #GstCaps object with media type
+ * application/x-rtp.
+ *
+ * Return value: A newly-allocated #GstCaps
+ */
+
+GstCaps *
+fs_codec_to_gst_caps (FsCodec *codec)
+{
+  GstCaps *caps;
+  GstStructure *structure;
+  GList *item;
+
+  gchar *encoding_name = g_ascii_strup (codec->encoding_name, -1);
+  if (!g_ascii_strcasecmp (encoding_name, "H263-N800")) {
+    g_free (encoding_name);
+    encoding_name = g_strdup ("H263-1998");
+  }
+  structure = gst_structure_new ("application/x-rtp",
+    "encoding-name", G_TYPE_STRING, encoding_name,
+    NULL);
+  g_free (encoding_name);
+
+  if (codec->clock_rate)
+    gst_structure_set (structure,
+      "clock-rate", G_TYPE_INT, codec->clock_rate, NULL);
+
+  if (codec->media_type == FS_MEDIA_TYPE_AUDIO)
+    gst_structure_set (structure, "media", G_TYPE_STRING, "audio", NULL);
+  else if (codec->media_type == FS_MEDIA_TYPE_VIDEO)
+    gst_structure_set (structure, "media", G_TYPE_STRING, "video", NULL);
+
+  if (codec->id >= 0 && codec->id < 128)
+    gst_structure_set (structure, "payload", G_TYPE_INT, codec->id, NULL);
+
+  if (codec->channels)
+    gst_structure_set (structure, "channels", G_TYPE_INT, codec->channels,
+      NULL);
+
+  for (item = codec->optional_params;
+       item;
+       item = g_list_next (item)) {
+    FsCodecParameter *param = item->data;
+    gchar *lower_name = g_ascii_strdown (param->name, -1);
+    gst_structure_set (structure, lower_name, G_TYPE_STRING, param->value,
+      NULL);
+    g_free (lower_name);
+  }
+
+  caps = gst_caps_new_full (structure, NULL);
+
+  return caps;
+}
diff --git a/gst-libs/gst/farsight/fs-codec.h b/gst-libs/gst/farsight/fs-codec.h
index 9795c83..5504ffd 100644
--- a/gst-libs/gst/farsight/fs-codec.h
+++ b/gst-libs/gst/farsight/fs-codec.h
@@ -28,8 +28,7 @@
 #ifndef __FS_CODEC_H__
 #define __FS_CODEC_H__
 
-#include <glib.h>
-#include <glib-object.h>
+#include <gst/gst.h>
 
 G_BEGIN_DECLS
 
@@ -127,6 +126,8 @@ gchar *fs_codec_to_string (FsCodec *codec);
 
 gboolean fs_codec_are_equal (FsCodec *codec1, FsCodec *codec2);
 
+GstCaps *fs_codec_to_gst_caps (FsCodec *codec);
+
 const gchar *fs_media_type_to_string (FsMediaType media_type);
 
 G_END_DECLS
-- 
1.5.6.5




More information about the farsight-commits mailing list