RET_IF(webrtc == NULL, "webrtc is NULL");
if (webrtc->is_start_sync) {
- webrtc->state = WEBRTC_STATE_NEGOTIATING;
+ if (webrtc->state == WEBRTC_STATE_IDLE)
+ webrtc->state = WEBRTC_STATE_NEGOTIATING;
g_mutex_lock(&webrtc->state_mutex);
g_cond_signal(&webrtc->state_cond);
g_mutex_unlock(&webrtc->state_mutex);
} else {
- _post_state_cb_in_idle(webrtc, WEBRTC_STATE_NEGOTIATING);
+ if (webrtc->state == WEBRTC_STATE_IDLE)
+ _post_state_cb_in_idle(webrtc, WEBRTC_STATE_NEGOTIATING);
}
if (webrtc->negotiation_needed_cb.callback == NULL) {
LOG_ERROR("codec must be set to the null source");
return WEBRTC_ERROR_INVALID_OPERATION;
}
- break;
+ /* NOTE: null source does not need ssrc, hence it does not need to wait for the signal */
+ goto complete_source;
}
}
/* TODO: add resource check */
+ if (webrtc->state >= WEBRTC_STATE_NEGOTIATING) {
+ g_mutex_lock(&webrtc->state_mutex);
+ webrtc->is_start_sync = true;
+ LOG_DEBUG("start sync... state[%d]", webrtc->state);
+ }
+
+complete_source:
ret = __complete_source(webrtc, source);
- RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to complete sources");
+ if (ret != WEBRTC_ERROR_NONE)
+ goto out;
+
+ if (webrtc->is_start_sync) {
+ gint64 end_time = g_get_monotonic_time() + 10 * G_TIME_SPAN_SECOND;
+ LOG_DEBUG("wait...");
+ if (!g_cond_wait_until(&webrtc->state_cond, &webrtc->state_mutex, end_time)) {
+ LOG_ERROR("timeout of g_cond_wait_until()");
+ ret = WEBRTC_ERROR_INVALID_OPERATION;
+ goto out;
+ }
+ }
LOG_INFO("webrtc[%p] source[type:%d, id:%u]", webrtc, source->type, source_id);
- return WEBRTC_ERROR_NONE;
+out:
+ if (webrtc->is_start_sync) {
+ webrtc->is_start_sync = false;
+ g_mutex_unlock(&webrtc->state_mutex);
+ }
+
+ return ret;
}
int _build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool use_mic, int ssrc)