summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2011-11-08 22:00:19 (GMT)
committerOlivier CrĂȘte <olivier.crete@collabora.com>2011-11-14 18:28:20 (GMT)
commitec877c7a4df94e5ba419ff3c706481a2223c29b8 (patch)
treecc3d1724951bd1bcc399d9a1158b5fc5cb3325b1
parentdaa31cd16df26a73b4d7b99d46c704322afbf2ea (diff)
downloadfarstream-ec877c7a4df94e5ba419ff3c706481a2223c29b8.tar.gz
farstream-ec877c7a4df94e5ba419ff3c706481a2223c29b8.tar.xz
Add parsing functions for all GstMessages
-rw-r--r--farstream/fs-conference.c57
-rw-r--r--farstream/fs-conference.h6
-rw-r--r--farstream/fs-session.c27
-rw-r--r--farstream/fs-session.h16
-rw-r--r--farstream/fs-stream.c217
-rw-r--r--farstream/fs-stream.h18
6 files changed, 322 insertions, 19 deletions
diff --git a/farstream/fs-conference.c b/farstream/fs-conference.c
index fd20a1c..160c69c 100644
--- a/farstream/fs-conference.c
+++ b/farstream/fs-conference.c
@@ -184,3 +184,60 @@ fs_conference_new_participant (FsConference *conf,
return klass->new_participant (conf, error);
}
+
+/**
+ * fs_parse_error:
+ * @object: a #GObject to match against the message
+ * @message: a #GstMessage to parse
+ * @error: (out): Returns the #FsError error number in
+ * the message if not %NULL.
+ * @error_msg: (out) (transfer none):Returns the error message if not %NULL
+ *
+ * Parses a "farstream-farstream" message and checks if it matches
+ * the @object parameters.
+ *
+ * Returns: %TRUE if the message matches the object and is valid.
+ */
+gboolean
+fs_parse_error (GObject *object,
+ GstMessage *message,
+ FsError *error,
+ const gchar **error_msg)
+
+{
+ const GstStructure *s;
+ const GValue *value;
+ GObject *message_object;
+
+ g_return_val_if_fail (object != NULL, FALSE);
+
+ if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
+ return FALSE;
+
+ s = gst_message_get_structure (message);
+
+ if (!gst_structure_has_name (s, "farstream-error"))
+ return FALSE;
+
+ value = gst_structure_get_value (s, "src-object");
+ if (!value || !G_VALUE_HOLDS (value, G_TYPE_OBJECT))
+ return FALSE;
+ message_object = g_value_get_object (value);
+
+ if (object != message_object)
+ return FALSE;
+
+ value = gst_structure_get_value (s, "error-no");
+ if (!value || !G_VALUE_HOLDS (value, FS_TYPE_ERROR))
+ return FALSE;
+ if (error)
+ *error = g_value_get_enum (value);
+
+ value = gst_structure_get_value (s, "error-msg");
+ if (!value || !G_VALUE_HOLDS (value, G_TYPE_STRING))
+ return FALSE;
+ if (error_msg)
+ *error_msg = g_value_get_string (value);
+
+ return TRUE;
+}
diff --git a/farstream/fs-conference.h b/farstream/fs-conference.h
index f35feb2..e13c46e 100644
--- a/farstream/fs-conference.h
+++ b/farstream/fs-conference.h
@@ -176,6 +176,12 @@ FsSession *fs_conference_new_session (FsConference *conference,
FsParticipant *fs_conference_new_participant (FsConference *conference,
GError **error);
+gboolean fs_parse_error (GObject *object,
+ GstMessage *message,
+ FsError *error,
+ const gchar **error_msg);
+
+
G_END_DECLS
diff --git a/farstream/fs-session.c b/farstream/fs-session.c
index 77afa18..4261d85 100644
--- a/farstream/fs-session.c
+++ b/farstream/fs-session.c
@@ -779,8 +779,8 @@ check_message (GstMessage *message,
/**
* fs_session_parse_send_codec_changed:
- * @message: a #GstMessage to parse
* @session: a #FsSession to match against the message
+ * @message: a #GstMessage to parse
* @codec: (out) (transfer none): Returns the #FsCodec in the message if not
* %NULL.
* @secondary_codec: (out) (transfer none) (element-type FsCodec):
@@ -792,8 +792,10 @@ check_message (GstMessage *message,
* Returns: %TRUE if the message matches the session and is valid.
*/
gboolean
-fs_session_parse_send_codec_changed (GstMessage *message, FsSession *session,
- FsCodec **codec, GList **secondary_codecs)
+fs_session_parse_send_codec_changed ( FsSession *session,
+ GstMessage *message,
+ FsCodec **codec,
+ GList **secondary_codecs)
{
const GstStructure *s;
const GValue *value;
@@ -823,8 +825,8 @@ fs_session_parse_send_codec_changed (GstMessage *message, FsSession *session,
/**
* fs_session_parse_codecs_changed:
- * @message: a #GstMessage to parse
* @session: a #FsSession to match against the message
+ * @message: a #GstMessage to parse
*
* Parses a "farstream-codecs-changed" message and checks if it matches
* the @session parameters.
@@ -832,7 +834,8 @@ fs_session_parse_send_codec_changed (GstMessage *message, FsSession *session,
* Returns: %TRUE if the message matches the session and is valid.
*/
gboolean
-fs_session_parse_codecs_changed (GstMessage *message, FsSession *session)
+fs_session_parse_codecs_changed (FsSession *session,
+ GstMessage *message)
{
g_return_val_if_fail (session != NULL, FALSE);
@@ -841,8 +844,8 @@ fs_session_parse_codecs_changed (GstMessage *message, FsSession *session)
/**
* fs_session_parse_telephony_event_started:
- * @message: a #GstMessage to parse
* @session: a #FsSession to match against the message
+ * @message: a #GstMessage to parse
* @method: (out): Returns the #FsDTMFMethod in the message if not %NULL.
* @event: (out): Returns the #FsDTMFEvent in the message if not %NULL.
* @volume: (out): Returns the volume in the message if not %NULL.
@@ -853,8 +856,9 @@ fs_session_parse_codecs_changed (GstMessage *message, FsSession *session)
* Returns: %TRUE if the message matches the session and is valid.
*/
gboolean
-fs_session_parse_telephony_event_started (GstMessage *message,
- FsSession *session, FsDTMFMethod *method, FsDTMFEvent *event,
+fs_session_parse_telephony_event_started (FsSession *session,
+ GstMessage *message,
+ FsDTMFMethod *method, FsDTMFEvent *event,
guint8 *volume)
{
const GstStructure *s;
@@ -889,8 +893,8 @@ fs_session_parse_telephony_event_started (GstMessage *message,
/**
* fs_session_parse_telephony_event_stopped:
- * @message: a #GstMessage to parse
* @session: a #FsSession to match against the message
+ * @message: a #GstMessage to parse
* @method: (out): Returns the #FsDTMFMethod in the message if not %NULL.
*
* Parses a "farstream-telephony-event-stopped" message and checks if it matches
@@ -899,8 +903,9 @@ fs_session_parse_telephony_event_started (GstMessage *message,
* Returns: %TRUE if the message matches the session and is valid.
*/
gboolean
-fs_session_parse_telephony_event_stopped (GstMessage *message,
- FsSession *session, FsDTMFMethod *method)
+fs_session_parse_telephony_event_stopped (FsSession *session,
+ GstMessage *message,
+ FsDTMFMethod *method)
{
const GstStructure *s;
diff --git a/farstream/fs-session.h b/farstream/fs-session.h
index 7c55bdd..15fbe0c 100644
--- a/farstream/fs-session.h
+++ b/farstream/fs-session.h
@@ -196,22 +196,22 @@ GList* fs_session_codecs_need_resend (FsSession *session,
void fs_session_destroy (FsSession *session);
-gboolean fs_session_parse_send_codec_changed (GstMessage *message,
- FsSession *session,
+gboolean fs_session_parse_send_codec_changed (FsSession *session,
+ GstMessage *message,
FsCodec **codec,
GList **secondary_codecs);
-gboolean fs_session_parse_codecs_changed (GstMessage *message,
- FsSession *session);
+gboolean fs_session_parse_codecs_changed (FsSession *session,
+ GstMessage *message);
-gboolean fs_session_parse_telephony_event_started (GstMessage *message,
- FsSession *session,
+gboolean fs_session_parse_telephony_event_started (FsSession *session,
+ GstMessage *message,
FsDTMFMethod *method,
FsDTMFEvent *event,
guint8 *volume);
-gboolean fs_session_parse_telephony_event_stopped (GstMessage *message,
- FsSession *session,
+gboolean fs_session_parse_telephony_event_stopped (FsSession *session,
+ GstMessage *message,
FsDTMFMethod *method);
diff --git a/farstream/fs-stream.c b/farstream/fs-stream.c
index 9c94343..4c7b040 100644
--- a/farstream/fs-stream.c
+++ b/farstream/fs-stream.c
@@ -661,3 +661,220 @@ fs_stream_destroy (FsStream *stream)
g_object_run_dispose (G_OBJECT (stream));
}
+
+
+
+static gboolean
+check_message (GstMessage *message,
+ FsStream *stream,
+ const gchar *message_name)
+{
+ const GstStructure *s;
+ const GValue *value;
+ FsStream *message_stream;
+
+ if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
+ return FALSE;
+
+ s = gst_message_get_structure (message);
+
+ if (!gst_structure_has_name (s, message_name))
+ return FALSE;
+
+ value = gst_structure_get_value (s, "stream");
+ if (!value || !G_VALUE_HOLDS (value, FS_TYPE_STREAM))
+ return FALSE;
+ message_stream = g_value_get_object (value);
+
+ if (stream != message_stream)
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * fs_stream_parse_new_local_candidate:
+ * @stream: a #FsStream to match against the message
+ * @message: a #GstMessage to parse
+ * @candidate: (out) (transfer none): Returns the #FsCandidate in the message
+ * if not %NULL.
+ *
+ * Parses a "farstream-new-local-candidate" message and checks if it matches
+ * the @stream parameters.
+ *
+ * Returns: %TRUE if the message matches the stream and is valid.
+ */
+gboolean
+fs_stream_parse_new_local_candidate (FsStream *stream,
+ GstMessage *message,
+ FsCandidate **candidate)
+{
+ const GstStructure *s;
+ const GValue *value;
+
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ if (!check_message (message, stream, "farstream-new-local-candidate"))
+ return FALSE;
+
+ s = gst_message_get_structure (message);
+
+ value = gst_structure_get_value (s, "candidate");
+ if (!value || !G_VALUE_HOLDS (value, FS_TYPE_CANDIDATE))
+ return FALSE;
+ if (candidate)
+ *candidate = g_value_get_boxed (value);
+
+ return TRUE;
+}
+
+
+/**
+ * fs_stream_parse_local_candidates_prepared:
+ * @stream: a #FsStream to match against the message
+ * @message: a #GstMessage to parse
+ *
+ * Parses a "farstream-local-candidates-prepared" message and checks if it matches
+ * the @stream parameters.
+ *
+ * Returns: %TRUE if the message matches the stream and is valid.
+ */
+gboolean
+fs_stream_parse_local_candidates_prepared (FsStream *stream,
+ GstMessage *message)
+{
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ return check_message (message, stream, "farstream-local-candidates-prepared");
+}
+
+
+/**
+ * fs_stream_parse_new_active_candidate_pair:
+ * @stream: a #FsStream to match against the message
+ * @message: a #GstMessage to parse
+ * @local_candidate: (out) (transfer none): Returns the local #FsCandidate in
+ * the message if not %NULL.
+ * @remote_candidate: (out) (transfer none): Returns the remote #FsCandidate in
+ * the message if not %NULL.
+ *
+ * Parses a "farstream-new-active-candidate-pair" message and checks
+ * if it matches the @stream parameters.
+ *
+ * Returns: %TRUE if the message matches the stream and is valid.
+ */
+gboolean
+fs_stream_parse_new_active_candidate_pair (FsStream *stream,
+ GstMessage *message,
+ FsCandidate **local_candidate,
+ FsCandidate **remote_candidate)
+{
+ const GstStructure *s;
+ const GValue *value;
+
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ if (!check_message (message, stream, "farstream-new-active-candidate-pair"))
+ return FALSE;
+
+ s = gst_message_get_structure (message);
+
+ value = gst_structure_get_value (s, "local-candidate");
+ if (!value || !G_VALUE_HOLDS (value, FS_TYPE_CANDIDATE))
+ return FALSE;
+ if (local_candidate)
+ *local_candidate = g_value_get_boxed (value);
+
+
+ value = gst_structure_get_value (s, "remote-candidate");
+ if (!value || !G_VALUE_HOLDS (value, FS_TYPE_CANDIDATE))
+ return FALSE;
+ if (remote_candidate)
+ *remote_candidate = g_value_get_boxed (value);
+
+ return TRUE;
+}
+
+
+/**
+ * fs_stream_parse_recv_codecs_changed:
+ * @stream: a #FsStream to match against the message
+ * @message: a #GstMessage to parse
+ * @codecs: (out) (transfer none) (element-type FsCodec):
+ * Returns a #GList of #FsCodec of the message if not %NULL
+ *
+ * Parses a "farstream-recv-codecs-changed" message and checks if it matches
+ * the @stream parameters.
+ *
+ * Returns: %TRUE if the message matches the stream and is valid.
+ */
+gboolean
+fs_stream_parse_recv_codecs_changed (FsStream *stream,
+ GstMessage *message,
+ GList **codecs)
+{
+ const GstStructure *s;
+ const GValue *value;
+
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ if (!check_message (message, stream, "farstream-recv-codecs-changed"))
+ return FALSE;
+
+ s = gst_message_get_structure (message);
+
+ value = gst_structure_get_value (s, "codecs");
+ if (!value || !G_VALUE_HOLDS (value, FS_TYPE_CODEC_LIST))
+ return FALSE;
+ if (codecs)
+ *codecs = g_value_get_boxed (value);
+
+ return TRUE;
+}
+
+
+
+/**
+ * fs_stream_parse_component_state_changed:
+ * @stream: a #FsStream to match against the message
+ * @message: a #GstMessage to parse
+ * @component: (out): Returns the component from the #GstMessage if not %NULL
+ * @state: (out): Returns the #FsStreamState from the #GstMessage if not %NULL
+ *
+ * Parses a "farstream-recv-codec-changed" message and checks if it matches
+ * the @stream parameters.
+ *
+ * Returns: %TRUE if the message matches the stream and is valid.
+ */
+gboolean
+fs_stream_parse_component_state_changed (FsStream *stream,
+ GstMessage *message,
+ guint *component,
+ FsStreamState *state)
+{
+ const GstStructure *s;
+ const GValue *value;
+
+ g_return_val_if_fail (stream != NULL, FALSE);
+
+ if (!check_message (message, stream, "farstream-recv-codec-changed"))
+ return FALSE;
+
+ s = gst_message_get_structure (message);
+
+ value = gst_structure_get_value (s, "component");
+ if (!value || !G_VALUE_HOLDS (value, G_TYPE_UINT))
+ return FALSE;
+ if (component)
+ *component = g_value_get_uint (value);
+
+
+ value = gst_structure_get_value (s, "state");
+ if (!value || !G_VALUE_HOLDS (value, G_TYPE_UINT))
+ return FALSE;
+ if (state)
+ *state = g_value_get_uint (value);
+
+ return TRUE;
+}
+
diff --git a/farstream/fs-stream.h b/farstream/fs-stream.h
index 9820603..9637a66 100644
--- a/farstream/fs-stream.h
+++ b/farstream/fs-stream.h
@@ -187,6 +187,24 @@ gboolean fs_stream_set_transmitter (FsStream *stream,
void fs_stream_destroy (FsStream *stream);
+gboolean fs_stream_parse_new_local_candidate (FsStream *stream,
+ GstMessage *message,
+ FsCandidate **candidate);
+gboolean fs_stream_parse_local_candidates_prepared (FsStream *stream,
+ GstMessage *message);
+gboolean fs_stream_parse_new_active_candidate_pair (FsStream *stream,
+ GstMessage *message,
+ FsCandidate **local_candidate,
+ FsCandidate **remote_candidate);
+gboolean fs_stream_parse_recv_codecs_changed (FsStream *stream,
+ GstMessage *message,
+ GList **codecs);
+gboolean fs_stream_parse_component_state_changed (FsStream *stream,
+ GstMessage *message,
+ guint *component,
+ FsStreamState *state);
+
+
G_END_DECLS
#endif /* __FS_STREAM_H__ */