locker = g_mutex_locker_new(&webrtc->destroy_mutex);
+ g_mutex_lock(&webrtc->desc_mutex);
+ g_cond_signal(&webrtc->desc_cond);
+ g_mutex_unlock(&webrtc->desc_mutex);
+
__post_signaling_state_change_cb_in_idle(webrtc, __signaling_state_info[state].state);
}
int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description, bool is_remote)
{
- int ret = WEBRTC_ERROR_NONE;
- gchar *sdp;
- gchar *type;
+ int ret;
+ g_autofree gchar *sdp = NULL;
+ g_autofree gchar *type = NULL;
GstSDPMessage *gst_sdp;
GstWebRTCSDPType sdp_type;
GstWebRTCSessionDescription *desc;
GstPromise *promise;
+ gint64 end_time;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "description is NULL");
ret = gst_sdp_message_new(&gst_sdp);
if (ret != GST_SDP_OK) {
LOG_ERROR("failed to gst_sdp_message_new()");
- ret = WEBRTC_ERROR_INVALID_OPERATION;
- goto end;
+ return WEBRTC_ERROR_INVALID_OPERATION;
}
ret = gst_sdp_message_parse_buffer((guint8 *)sdp, strlen(sdp), gst_sdp);
if (ret != GST_SDP_OK) {
LOG_ERROR("failed to gst_sdp_message_parse_buffer()");
- ret = WEBRTC_ERROR_INVALID_OPERATION;
- goto end;
+ return WEBRTC_ERROR_INVALID_OPERATION;
}
sdp_type = g_str_equal(type, "answer") ? GST_WEBRTC_SDP_TYPE_ANSWER : GST_WEBRTC_SDP_TYPE_OFFER;
desc = gst_webrtc_session_description_new(sdp_type, gst_sdp);
+ g_mutex_lock(&webrtc->desc_mutex);
+
promise = gst_promise_new();
g_signal_emit_by_name(webrtc->gst.webrtcbin, is_remote ? "set-remote-description" : "set-local-description", desc, promise);
gst_promise_interrupt(promise);
g_free(webrtc->local_desc);
webrtc->local_desc = g_strdup(description);
}
-end:
- g_free(sdp);
- g_free(type);
- return ret;
+ LOG_DEBUG("wait for invoking __webrtcbin_signaling_state_cb()");
+ end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
+ if (!g_cond_wait_until(&webrtc->desc_cond, &webrtc->desc_mutex, end_time))
+ LOG_WARNING("timeout of g_cond_wait_until()");
+
+ g_mutex_unlock(&webrtc->desc_mutex);
+
+ return WEBRTC_ERROR_NONE;
}
/* Use g_free() to release the candidate parameter. */