/* Use g_free() to release the sdp and type parameter. */
static int __get_sdp_from_description(const char *description, gchar **sdp, gchar **type)
{
- int ret = WEBRTC_ERROR_NONE;
+ g_autoptr(JsonParser) parser = NULL;
JsonNode *root;
JsonObject *object;
JsonObject *child;
- JsonParser *parser;
const gchar *member_sdp;
const gchar *member_type;
if (!json_parser_load_from_data(parser, description, -1, NULL)) {
LOG_ERROR("unknown description: %s", description);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
root = json_parser_get_root(parser);
if (!JSON_NODE_HOLDS_OBJECT(root)) {
LOG_ERROR("it does not contain a JsonObject: %s", description);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
object = json_node_get_object(root);
if (!json_object_has_member(object, "sdp")) {
LOG_ERROR("it does not contain 'sdp' member: %s", description);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
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"))) {
LOG_ERROR("could not find valid type member: %s", description);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
member_sdp = json_object_get_string_member(child, "sdp");
if (!member_sdp) {
LOG_ERROR("could not find sdb member: %s", description);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
*type = g_strdup(member_type);
LOG_DEBUG("type: %s", *type);
LOG_DEBUG("sdp:\n%s", *sdp);
-end:
- g_object_unref(parser);
- return ret;
+
+ return WEBRTC_ERROR_NONE;
}
int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description, bool is_remote)
/* Use g_free() to release the candidate parameter. */
static int __get_ice_candidate_from_message(const char *ice_message, gchar **candidate, gint *mlineindex)
{
- int ret = WEBRTC_ERROR_NONE;
+ g_autoptr(JsonParser) parser = NULL;
JsonNode *root;
JsonObject *object;
JsonObject *child;
- JsonParser *parser;
const gchar *_candidate;
RET_VAL_IF(ice_message == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ice_message is NULL");
if (!json_parser_load_from_data(parser, ice_message, -1, NULL)) {
LOG_ERROR("unknown message: %s", ice_message);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
root = json_parser_get_root(parser);
if (!JSON_NODE_HOLDS_OBJECT(root)) {
LOG_ERROR("it does not contain a JsonObject: %s", ice_message);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
object = json_node_get_object(root);
if (!json_object_has_member(object, "ice")) {
LOG_ERROR("It does not contain 'ice' member: %s", ice_message);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
child = json_object_get_object_member(object, "ice");
_candidate = json_object_get_string_member(child, "candidate");
if (!_candidate) {
LOG_ERROR("Could not find candidate member: %s", ice_message);
- ret = WEBRTC_ERROR_INVALID_PARAMETER;
- goto end;
+ return WEBRTC_ERROR_INVALID_PARAMETER;
}
*candidate = g_strdup(_candidate);
LOG_DEBUG("candidate: %s", *candidate);
LOG_DEBUG("sdpMLineIndex: %d", *mlineindex);
-end:
- g_object_unref(parser);
- return ret;
+
+ return WEBRTC_ERROR_NONE;
}
int _webrtcbin_add_ice_candidate(webrtc_s *webrtc, const char *candidate)
static void __handle_json_structured_message(connection_s *conn, const gchar *text)
{
+ g_autoptr(JsonParser) parser = NULL;
JsonNode *root;
JsonObject *object;
- JsonParser *parser;
RET_IF(!conn, "conn is NULL");
RET_IF(!text, "text is NULL");
if (!json_parser_load_from_data(parser, text, -1, NULL)) {
g_printerr("unknown message [%s]\n", text);
- g_object_unref(parser);
return;
}
root = json_parser_get_root(parser);
if (!JSON_NODE_HOLDS_OBJECT(root)) {
g_printerr("unknown JSON message [%s]\n", text);
- g_object_unref(parser);
return;
}
} else {
g_printerr("neither 'sdp' nor 'ice' member exist in JSON message [%s]\n", text);
}
-
- g_object_unref(parser);
}
static void __auto_configure_handle_room_message(gchar *peer_id, gchar *message)