diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2013-01-11 19:47:42 -0500 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2013-03-26 14:50:24 -0400 |
commit | 2c19591ca948fc302508b2afbdd232b219d92e2a (patch) | |
tree | ff9c2db12bd5c535c6d4f7871881175474f4c9f3 | |
parent | 77df96b6b6fad5aac69dc73c06816d050f60a735 (diff) | |
download | farstream-2c19591ca948fc302508b2afbdd232b219d92e2a.tar.gz |
session: Add API to set the transmitter parameters as a GHashTable
-rwxr-xr-x | examples/gui/fs-gui.py | 24 | ||||
-rw-r--r-- | farstream/fs-stream.c | 99 | ||||
-rw-r--r-- | farstream/fs-stream.h | 5 |
3 files changed, 114 insertions, 14 deletions
diff --git a/examples/gui/fs-gui.py b/examples/gui/fs-gui.py index c16f58cc..0ec16ac9 100755 --- a/examples/gui/fs-gui.py +++ b/examples/gui/fs-gui.py @@ -382,7 +382,7 @@ class FsUISession: def new_stream(self, id, participant): "Creates a new stream for a specific participant" - transmitter_params = [] + transmitter_params = {} # If its video, we start at port 9078, to make it more easy # to differentiate it in a tcpdump log if self.source.get_type() == Farstream.MediaType.VIDEO and \ @@ -390,18 +390,14 @@ class FsUISession: cand = Farstream.Candidate.new("",Farstream.ComponentType.RTP, Farstream.CandidateType.HOST, Farstream.NetworkProtocol.UDP, - "", 9078) - param = GObject.Parameter() - param.name = "preferred-local-candidates" - param.cand.set_boxed(cand) - transmitter_params.append(params) - print transmitter_params - print participant.fsparticipant + None, 9078) + value = GObject.Value() + Farstream.value_set_candidate_list(value, [cand]) + transmitter_params["preferred-local-candidates"] = value realstream = self.fssession.new_stream(participant.fsparticipant, Farstream.StreamDirection.BOTH) - print TRANSMITTER - print transmitter_params - realstream.set_transmitter(TRANSMITTER, transmitter_params) + print TRANSMITTER + ": " + str(transmitter_params) + realstream.set_transmitter_ht(TRANSMITTER, transmitter_params) stream = FsUIStream(id, self, participant, realstream) self.streams.add(stream) return stream @@ -455,11 +451,11 @@ class FsUIStream: def new_local_candidate(self, candidate): "Callback from FsStream" if "." in candidate.ip: - print "IPv4 Candidate: " +candidate.ip + print "IPv4 Candidate: %s %s" % (candidate.ip, candidate.port) elif ":" in candidate.ip: - print "IPv6 Candidate: " +candidate.ip + print "IPv6 Candidate: %s %s" % (candidate.ip, candidate.port) else: - print "STRANGE Candidate: " +candidate.ip + print "STRANGE Candidate: " + candidate.ip self.connect.send_candidate(self.participant.id, self.id, candidate) def __src_pad_added(self, stream, pad, codec): "Callback from FsStream" diff --git a/farstream/fs-stream.c b/farstream/fs-stream.c index cde69c25..c81e8788 100644 --- a/farstream/fs-stream.c +++ b/farstream/fs-stream.c @@ -648,6 +648,105 @@ fs_stream_set_transmitter (FsStream *stream, } /** + * fs_stream_set_transmitter_ht: + * @stream: a #FsStream + * @transmitter: Name of the type of transmitter to use for this stream + * @stream_transmitter_parameters: (element-type utf8 GValue) (allow-none): + * A #GHashTable of <String->GValue) containing the parameters. + * @error: location of a #GError, or %NULL if no error occured + * + * Set the transmitter to use for this stream. This function will only succeed + * once. + * + * The parameters correspond to the varios GObject properties of the + * selected stream transmitter. + * + * This is the same as fs_stream_set_transmitter() except that the parameters + * are passed in a #GHashTable to make it more friendly to GObject introspection + * + * Returns: %TRUE if the transmitter could be set, %FALSE otherwise + */ +gboolean fs_stream_set_transmitter_ht (FsStream *stream, + const gchar *transmitter, + GHashTable *stream_transmitter_parameters, + GError **error) +{ + GParameter *params = NULL; + gboolean ret = FALSE; + guint n_params = 0; + guint i = 0; + + if (stream_transmitter_parameters && + g_hash_table_size (stream_transmitter_parameters) != 0) + { + FsSession *session = NULL; + GType st_type; + GObjectClass *st_class = NULL; + GHashTableIter iter; + gpointer key, value; + + n_params = g_hash_table_size (stream_transmitter_parameters); + + g_object_get (stream, "session", &session, NULL); + + if (!session) { + g_set_error_literal (error, FS_ERROR, FS_ERROR_DISPOSED, + "Stream has already been disposed"); + return FALSE; + } + + st_type = fs_session_get_stream_transmitter_type (session, + transmitter); + g_object_unref (session); + + if (st_type == 0) { + g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, + "Unknown transmitter: %s", transmitter); + return FALSE; + } + + params = g_new0 (GParameter, n_params); + st_class = g_type_class_ref (st_type); + + g_hash_table_iter_init (&iter, stream_transmitter_parameters); + while (g_hash_table_iter_next (&iter, &key, &value)) { + GParamSpec *spec; + gchar *name = key; + const GValue *v = value; + + spec = g_object_class_find_property (st_class, name); + + if (!spec) { + g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, + "Unknown argument %s for transmitter %s", name, transmitter); + goto end; + } + + params[i].name = name; + g_value_init (¶ms[i].value, G_PARAM_SPEC_VALUE_TYPE(spec)); + if (!g_value_transform (v, ¶ms[i].value)) { + g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, + "Invalid type of argument %s for transmitter %s", + name, transmitter); + goto end; + } + i++; + } + } + + ret = fs_stream_set_transmitter (stream, transmitter, params, n_params, + error); + +end: + + for (i = 0; i < n_params; i++) + g_value_unset (¶ms[i].value); + g_free (params); + + return ret; +} + +/** * fs_stream_destroy: * @stream: a #FsStream * diff --git a/farstream/fs-stream.h b/farstream/fs-stream.h index a3c82158..5239fddf 100644 --- a/farstream/fs-stream.h +++ b/farstream/fs-stream.h @@ -185,6 +185,11 @@ gboolean fs_stream_set_transmitter (FsStream *stream, guint stream_transmitter_n_parameters, GError **error); +gboolean fs_stream_set_transmitter_ht (FsStream *stream, + const gchar *transmitter, + GHashTable *stream_transmitter_parameters, + GError **error); + void fs_stream_destroy (FsStream *stream); gboolean fs_stream_parse_new_local_candidate (FsStream *stream, |