[farsight2/master] rtpdtmfsoundsource: Use main codec if PCMA/U are not available
Olivier Crête
olivier.crete at collabora.co.uk
Fri Nov 20 16:37:21 PST 2009
---
gst/fsrtpconference/fs-rtp-dtmf-sound-source.c | 191 ++++++++++++++++-------
1 files changed, 133 insertions(+), 58 deletions(-)
diff --git a/gst/fsrtpconference/fs-rtp-dtmf-sound-source.c b/gst/fsrtpconference/fs-rtp-dtmf-sound-source.c
index 4f28e09..75b9200 100644
--- a/gst/fsrtpconference/fs-rtp-dtmf-sound-source.c
+++ b/gst/fsrtpconference/fs-rtp-dtmf-sound-source.c
@@ -154,6 +154,18 @@ _check_element_factory (gchar *name)
return (fact != NULL);
}
+static CodecAssociation *
+_get_main_codec_association (GList *codec_associations, FsCodec *codec)
+{
+ CodecAssociation *ca = lookup_codec_association_by_codec_without_config (
+ codec_associations, codec);
+
+ if (ca && codec_association_is_valid_for_sending (ca, TRUE))
+ return ca;
+ else
+ return NULL;
+}
+
static FsCodec *
fs_rtp_dtmf_sound_source_get_codec (FsRtpSpecialSourceClass *klass,
GList *negotiated_codec_associations,
@@ -162,27 +174,34 @@ fs_rtp_dtmf_sound_source_get_codec (FsRtpSpecialSourceClass *klass,
FsCodec *codec = NULL;
gchar *encoder_name = NULL;
gchar *payloader_name = NULL;
+ CodecAssociation *ca;
if (selected_codec->media_type != FS_MEDIA_TYPE_AUDIO)
return NULL;
- if (selected_codec->clock_rate != 8000)
+ if (!_check_element_factory ("dtmfsrc"))
return NULL;
- codec = get_pcm_law_sound_codec (negotiated_codec_associations,
- &encoder_name, &payloader_name);
- if (!codec)
- return NULL;
+ if (selected_codec->clock_rate != 8000)
+ {
+ codec = get_pcm_law_sound_codec (negotiated_codec_associations,
+ &encoder_name, &payloader_name);
+ if (codec) {
+ if (!_check_element_factory (encoder_name))
+ return NULL;
+ if (!_check_element_factory (payloader_name))
+ return NULL;
+ return codec;
+ }
+ }
- if (!_check_element_factory ("dtmfsrc"))
- return NULL;
+ ca = _get_main_codec_association (negotiated_codec_associations,
+ selected_codec);
- if (!_check_element_factory (encoder_name))
- return NULL;
- if (!_check_element_factory (payloader_name))
+ if (ca)
+ return ca->codec;
+ else
return NULL;
-
- return codec;
}
static GstElement *
@@ -201,9 +220,20 @@ fs_rtp_dtmf_sound_source_build (FsRtpSpecialSource *source,
GstElement *payloader = NULL;
gchar *encoder_name = NULL;
gchar *payloader_name = NULL;
+ CodecAssociation *ca = NULL;
+
- telephony_codec = get_pcm_law_sound_codec (negotiated_codec_associations,
- &encoder_name, &payloader_name);
+ if (selected_codec->clock_rate == 8000)
+ telephony_codec = get_pcm_law_sound_codec (negotiated_codec_associations,
+ &encoder_name, &payloader_name);
+
+ if (!telephony_codec)
+ {
+ ca = _get_main_codec_association (negotiated_codec_associations,
+ selected_codec);
+ if (ca)
+ telephony_codec = ca->codec;
+ }
g_return_val_if_fail (telephony_codec, NULL);
@@ -227,44 +257,6 @@ fs_rtp_dtmf_sound_source_build (FsRtpSpecialSource *source,
goto error;
}
- encoder = gst_element_factory_make (encoder_name, NULL);
- if (!encoder)
- {
- GST_ERROR ("Could not make %s", encoder_name);
- goto error;
- }
- if (!gst_bin_add (GST_BIN (bin), encoder))
- {
- GST_ERROR ("Could not add %s to bin", encoder_name);
- gst_object_unref (dtmfsrc);
- goto error;
- }
-
- if (!gst_element_link_pads (dtmfsrc, "src", encoder, "sink"))
- {
- GST_ERROR ("Could not link the rtpdtmfsrc and %s", encoder_name);
- goto error;
- }
-
- payloader = gst_element_factory_make (payloader_name, NULL);
- if (!payloader)
- {
- GST_ERROR ("Could not make %s", payloader_name);
- goto error;
- }
- if (!gst_bin_add (GST_BIN (bin), payloader))
- {
- GST_ERROR ("Could not add %s to bin", payloader_name);
- gst_object_unref (dtmfsrc);
- goto error;
- }
-
- if (!gst_element_link_pads (encoder, "src", payloader, "sink"))
- {
- GST_ERROR ("Could not link the %s and %s", encoder_name, payloader_name);
- goto error;
- }
-
capsfilter = gst_element_factory_make ("capsfilter", NULL);
if (!capsfilter)
{
@@ -287,12 +279,6 @@ fs_rtp_dtmf_sound_source_build (FsRtpSpecialSource *source,
}
gst_caps_unref (caps);
- if (!gst_element_link_pads (payloader, "src", capsfilter, "sink"))
- {
- GST_ERROR ("Could not link the %s and its capsfilter", payloader_name);
- goto error;
- }
-
pad = gst_element_get_static_pad (capsfilter, "src");
if (!pad)
{
@@ -314,6 +300,95 @@ fs_rtp_dtmf_sound_source_build (FsRtpSpecialSource *source,
}
gst_object_unref (pad);
+
+ if (ca)
+ {
+ gchar *codec_bin_name = g_strdup_printf ("dtmf_send_codecbin_%d",
+ telephony_codec->id);
+ GError *error = NULL;
+ GstElement *codecbin = create_codec_bin_from_blueprint (
+ telephony_codec, ca->blueprint, codec_bin_name, TRUE, &error);
+
+ if (!codecbin)
+ {
+ GST_ERROR ("Could not make %s: %s", codec_bin_name,
+ error ? error->message : "No error message!");
+ g_clear_error (&error);
+ g_free (codec_bin_name);
+ goto error;
+ }
+
+ if (!gst_bin_add (GST_BIN (bin), codecbin))
+ {
+ GST_ERROR ("Could not add %s to bin", codec_bin_name);
+ gst_object_unref (codecbin);
+ g_free (codec_bin_name);
+ goto error;
+ }
+
+ if (!gst_element_link_pads (dtmfsrc, "src", codecbin, "sink"))
+ {
+ GST_ERROR ("Could not link the rtpdtmfsrc and %s", codec_bin_name);
+ g_free (codec_bin_name);
+ goto error;
+ }
+
+ if (!gst_element_link_pads (codecbin, "src", capsfilter, "sink"))
+ {
+ GST_ERROR ("Could not link the %s and its capsfilter", codec_bin_name);
+ g_free (codec_bin_name);
+ goto error;
+ }
+
+ g_free (codec_bin_name);
+ }
+ else
+ {
+ encoder = gst_element_factory_make (encoder_name, NULL);
+ if (!encoder)
+ {
+ GST_ERROR ("Could not make %s", encoder_name);
+ goto error;
+ }
+ if (!gst_bin_add (GST_BIN (bin), encoder))
+ {
+ GST_ERROR ("Could not add %s to bin", encoder_name);
+ gst_object_unref (encoder);
+ goto error;
+ }
+
+ if (!gst_element_link_pads (dtmfsrc, "src", encoder, "sink"))
+ {
+ GST_ERROR ("Could not link the rtpdtmfsrc and %s", encoder_name);
+ goto error;
+ }
+
+ payloader = gst_element_factory_make (payloader_name, NULL);
+ if (!payloader)
+ {
+ GST_ERROR ("Could not make %s", payloader_name);
+ goto error;
+ }
+ if (!gst_bin_add (GST_BIN (bin), payloader))
+ {
+ GST_ERROR ("Could not add %s to bin", payloader_name);
+ gst_object_unref (payloader);
+ goto error;
+ }
+
+ if (!gst_element_link_pads (encoder, "src", payloader, "sink"))
+ {
+ GST_ERROR ("Could not link the %s and %s", encoder_name, payloader_name);
+ goto error;
+ }
+
+ if (!gst_element_link_pads (payloader, "src", capsfilter, "sink"))
+ {
+ GST_ERROR ("Could not link the %s and its capsfilter", payloader_name);
+ goto error;
+ }
+ }
+
return bin;
error:
--
1.5.6.5
More information about the farsight-commits
mailing list