[farsight2/master] Add rtp implementation of new set_local_codecs_config method
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:22:21 PST 2008
---
gst/fsrtpconference/fs-rtp-session.c | 94 ++++++++++++++++++++-------------
tests/check/main/rtpcodecs.c | 49 +++++++++++++++---
2 files changed, 98 insertions(+), 45 deletions(-)
diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index 3755811..bf8598b 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -182,7 +182,9 @@ static gboolean fs_rtp_session_stop_telephony_event (FsSession *session,
static gboolean fs_rtp_session_set_send_codec (FsSession *session,
FsCodec *send_codec,
GError **error);
-
+static gboolean fs_rtp_session_set_local_codecs_config (FsSession *session,
+ GList *local_codecs_config,
+ GError **error);
static gboolean fs_rtp_session_verify_send_codec_bin_locked (
FsRtpSession *self,
GError **error);
@@ -226,6 +228,8 @@ fs_rtp_session_class_init (FsRtpSessionClass *klass)
session_class->start_telephony_event = fs_rtp_session_start_telephony_event;
session_class->stop_telephony_event = fs_rtp_session_stop_telephony_event;
session_class->set_send_codec = fs_rtp_session_set_send_codec;
+ session_class->set_local_codecs_config =
+ fs_rtp_session_set_local_codecs_config;
g_object_class_override_property (gobject_class,
PROP_MEDIA_TYPE, "media-type");
@@ -641,42 +645,6 @@ fs_rtp_session_set_property (GObject *object,
case PROP_ID:
self->id = g_value_get_uint (value);
break;
- case PROP_LOCAL_CODECS_CONFIG:
- {
- GList *new_local_codecs_configuration = g_value_dup_boxed (value);
- GList *new_local_codecs = NULL;
- GHashTable *new_local_codec_associations = NULL;
-
- new_local_codecs_configuration =
- validate_codecs_configuration (
- self->priv->media_type, self->priv->blueprints,
- new_local_codecs_configuration);
-
- new_local_codec_associations = create_local_codec_associations (
- self->priv->media_type, self->priv->blueprints,
- new_local_codecs_configuration,
- self->priv->local_codec_associations,
- &new_local_codecs);
-
- if (new_local_codecs && new_local_codec_associations) {
- fs_codec_list_destroy (self->priv->local_codecs);
- g_hash_table_destroy (self->priv->local_codec_associations);
- self->priv->local_codec_associations = new_local_codec_associations;
- self->priv->local_codecs = new_local_codecs;
-
- if (self->priv->local_codecs_configuration)
- fs_codec_list_destroy (self->priv->local_codecs_configuration);
- self->priv->local_codecs_configuration =
- new_local_codecs_configuration;
-
- g_object_notify (object, "local-codecs");
-
- } else {
- GST_WARNING ("Invalid new codec configurations");
- fs_codec_list_destroy (new_local_codecs_configuration);
- }
- }
- break;
case PROP_CONFERENCE:
self->priv->conference = FS_RTP_CONFERENCE (g_value_dup_object (value));
break;
@@ -1317,6 +1285,58 @@ fs_rtp_session_set_send_codec (FsSession *session, FsCodec *send_codec,
return ret;
}
+static gboolean
+fs_rtp_session_set_local_codecs_config (FsSession *session,
+ GList *local_codecs_config,
+ GError **error)
+{
+ FsRtpSession *self = FS_RTP_SESSION (session);
+ GList *new_local_codecs = NULL;
+ GHashTable *new_local_codec_associations = NULL;
+ GList *new_local_codecs_configuration =
+ fs_codec_list_copy (local_codecs_config);
+
+ new_local_codecs_configuration =
+ validate_codecs_configuration (
+ self->priv->media_type, self->priv->blueprints,
+ new_local_codecs_configuration);
+
+ if (new_local_codecs_configuration == NULL)
+ GST_DEBUG ("None of the local codecs configuration passed are usable,"
+ " this will restore the original list of detected codecs");
+
+ new_local_codec_associations = create_local_codec_associations (
+ self->priv->media_type, self->priv->blueprints,
+ new_local_codecs_configuration,
+ self->priv->local_codec_associations,
+ &new_local_codecs);
+
+ if (new_local_codecs && new_local_codec_associations)
+ {
+ fs_codec_list_destroy (self->priv->local_codecs);
+ g_hash_table_destroy (self->priv->local_codec_associations);
+ self->priv->local_codec_associations = new_local_codec_associations;
+ self->priv->local_codecs = new_local_codecs;
+
+ fs_codec_list_destroy (self->priv->local_codecs_configuration);
+ self->priv->local_codecs_configuration =
+ new_local_codecs_configuration;
+
+ g_object_notify ((GObject*) self, "local-codecs");
+ g_object_notify ((GObject*) self, "local-codecs-config");
+
+ return TRUE;
+ }
+ else
+ {
+ GST_WARNING ("Invalid new codec configurations");
+ fs_codec_list_destroy (new_local_codecs_configuration);
+ g_set_error (error, FS_ERROR, FS_ERROR_NO_CODECS,
+ "Codec config would leave no valid local codecs, rejecting");
+ return FALSE;
+ }
+}
+
FsRtpSession *
fs_rtp_session_new (FsMediaType media_type, FsRtpConference *conference,
guint id, GError **error)
diff --git a/tests/check/main/rtpcodecs.c b/tests/check/main/rtpcodecs.c
index e3694f4..2d9191e 100644
--- a/tests/check/main/rtpcodecs.c
+++ b/tests/check/main/rtpcodecs.c
@@ -38,15 +38,16 @@ _notify_local_codecs (GObject *object, GParamSpec *param, gpointer user_data)
GST_START_TEST (test_rtpcodecs_local_codecs_config)
{
struct SimpleTestConference *dat = NULL;
- GList *codecs = NULL, *codecs2 = NULL, *item = NULL;
+ GList *orig_codecs = NULL, *codecs = NULL, *codecs2 = NULL, *item = NULL;
gint has0 = FALSE, has8 = FALSE;
gboolean local_codecs_notified = FALSE;
+ GError *error = NULL;
dat = setup_simple_conference (1, "fsrtpconference", "bob at 127.0.0.1");
- g_object_get (dat->session, "local-codecs", &codecs, NULL);
+ g_object_get (dat->session, "local-codecs", &orig_codecs, NULL);
- for (item = g_list_first (codecs); item; item = g_list_next (item))
+ for (item = g_list_first (orig_codecs); item; item = g_list_next (item))
{
FsCodec *codec = item->data;
if (codec->id == 0)
@@ -57,9 +58,6 @@ GST_START_TEST (test_rtpcodecs_local_codecs_config)
fail_unless (has0 && has8, "You need the PCMA and PCMU encoder and payloades"
" from gst-plugins-good");
- fs_codec_list_destroy (codecs);
- codecs = NULL;
-
codecs = g_list_append (codecs,
fs_codec_new (
FS_CODEC_ID_DISABLE,
@@ -83,7 +81,11 @@ GST_START_TEST (test_rtpcodecs_local_codecs_config)
g_signal_connect (dat->session, "notify::local-codecs",
G_CALLBACK (_notify_local_codecs), &local_codecs_notified);
- g_object_set (dat->session, "local-codecs-config", codecs, NULL);
+ fail_unless (
+ fs_session_set_local_codecs_config (dat->session, codecs, &error),
+ "Could not set local codecs config");
+ fail_unless (error == NULL, "Setting the local codecs config failed,"
+ " but the error is still there");
fail_unless (local_codecs_notified == TRUE, "Not notified of codec changed");
local_codecs_notified = FALSE;
@@ -125,6 +127,36 @@ GST_START_TEST (test_rtpcodecs_local_codecs_config)
fs_codec_list_destroy (codecs);
+ fail_unless (fs_session_set_local_codecs_config (dat->session, NULL, &error),
+ "Could not set local-codecs-config");
+ fail_if (error, "Error set while function succeeded?");
+ fail_unless (local_codecs_notified, "We were not notified of the change"
+ " in local-codecs");
+
+ g_object_get (dat->session, "local-codecs", &codecs, NULL);
+
+ fail_unless (fs_codec_list_are_equal (codecs, orig_codecs),
+ "Resetting local-codecs-config failed, codec lists are not equal");
+
+ fs_codec_list_destroy (orig_codecs);
+
+ for (item = codecs;
+ item;
+ item = g_list_next (item))
+ {
+ FsCodec *codec = item->data;
+ codec->id = FS_CODEC_ID_DISABLE;
+ }
+
+ fail_if (fs_session_set_local_codecs_config (dat->session, codecs,
+ &error),
+ "Disabling all codecs did not fail");
+ fail_unless (error != NULL, "The error is not set");
+ fail_unless (error->code == FS_ERROR_NO_CODECS,
+ "The error code is %d, not FS_ERROR_NO_CODECS");
+
+ fs_codec_list_destroy (codecs);
+
cleanup_simple_conference (dat);
}
GST_END_TEST;
@@ -263,7 +295,8 @@ GST_START_TEST (test_rtpcodecs_reserved_pt)
codecs = g_list_prepend (NULL, fs_codec_new (96, "reserve-pt",
FS_MEDIA_TYPE_AUDIO, 0));
- g_object_set (dat->session, "local-codecs-config", codecs, NULL);
+ fail_unless (fs_session_set_local_codecs_config (dat->session, codecs, NULL),
+ "Could not set local-codes config");
fs_codec_list_destroy (codecs);
--
1.5.6.5
More information about the farsight-commits
mailing list