return text;
}
+/* Use g_free() to free the sdp parameter. */
+int ms_webrtc_get_sdp_from_message(const char *sdp_msg, gchar **sdp)
+{
+ int ret = MEDIA_STREAMER_ERROR_NONE;
+ JsonNode *root;
+ JsonObject *object;
+ JsonObject *child;
+ JsonParser *parser;
+ const gchar *member_sdp;
+ const gchar *member_type;
+
+ ms_retvm_if(sdp_msg == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sdp_msg is NULL");
+ ms_retvm_if(sdp == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "sdp is NULL");
+
+ parser = json_parser_new();
+ if (!JSON_IS_PARSER(parser))
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+
+ if (!json_parser_load_from_data(parser, sdp_msg, -1, NULL)) {
+ ms_error("Unknown message: %s", sdp_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ root = json_parser_get_root(parser);
+ if (!JSON_NODE_HOLDS_OBJECT(root)) {
+ ms_error("It does not contain a JsonObject: %s", sdp_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ object = json_node_get_object(root);
+ if (!json_object_has_member(object, "sdp")) {
+ ms_error("It does not contain 'sdp' member: %s", sdp_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ child = json_object_get_object_member(object, "sdp");
+
+ member_type = json_object_get_string_member(child, "type");
+ if (!member_type || !(g_str_equal(member_type, "answer") || g_str_equal(member_type, "offer"))) {
+ ms_error("Could not find valid type member: %s", sdp_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ member_sdp = json_object_get_string_member(child, "sdp");
+ if (!member_sdp) {
+ ms_error("Could not find sdb member: %s", sdp_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ *sdp = g_strdup(member_sdp);
+
+ ms_debug("sdp: %s", *sdp);
+end:
+ g_object_unref (parser);
+ return ret;
+}
+
+/* Use g_free() to free the candidate parameter. */
+int ms_webrtc_get_ice_candidate_from_message(const char *ice_msg, gchar **candidate, gint *mlineindex)
+{
+ int ret = MEDIA_STREAMER_ERROR_NONE;
+ JsonNode *root;
+ JsonObject *object;
+ JsonObject *child;
+ JsonParser *parser;
+ const gchar *_candidate;
+
+ ms_retvm_if(ice_msg == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "ice_msg is NULL");
+ ms_retvm_if(candidate == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "candidate is NULL");
+ ms_retvm_if(mlineindex == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "mlineindex is NULL");
+
+ parser = json_parser_new();
+ if (!JSON_IS_PARSER(parser))
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+
+ if (!json_parser_load_from_data(parser, ice_msg, -1, NULL)) {
+ ms_error("Unknown message: %s", ice_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ root = json_parser_get_root(parser);
+ if (!JSON_NODE_HOLDS_OBJECT(root)) {
+ ms_error("It does not contain a JsonObject: %s", ice_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ object = json_node_get_object(root);
+ if (!json_object_has_member(object, "ice")) {
+ ms_error("It does not contain 'ice' member: %s", ice_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ child = json_object_get_object_member(object, "ice");
+
+ _candidate = json_object_get_string_member(child, "candidate");
+ if (!_candidate) {
+ ms_error("Could not find candidate member: %s", ice_msg);
+ ret = MEDIA_STREAMER_ERROR_INVALID_PARAMETER;
+ goto end;
+ }
+
+ *candidate = g_strdup(_candidate);
+ *mlineindex = json_object_get_int_member(child, "sdpMLineIndex");
+
+ ms_debug("candidate: %s", *candidate);
+ ms_debug("sdpMLineIndex: %d", *mlineindex);
+end:
+ g_object_unref(parser);
+ return ret;
+}
+
//LCOV_EXCL_START
static void __global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)