static STATUS handleOffer()

in main/AppCommon.c [238:273]


static STATUS handleOffer(PAppConfiguration pAppConfiguration, PStreamingSession pStreamingSession, PSignalingMessage pSignalingMessage)
{
    STATUS retStatus = STATUS_SUCCESS;
    PRtcSessionDescriptionInit pOfferSessionDescriptionInit = NULL;
    NullableBool canTrickle;
    BOOL mediaThreadStarted;

    CHK(NULL != (pOfferSessionDescriptionInit = (PRtcSessionDescriptionInit) MEMCALLOC(1, SIZEOF(RtcSessionDescriptionInit))), STATUS_APP_COMMON_NOT_ENOUGH_MEMORY);
    MEMSET(&pStreamingSession->answerSessionDescriptionInit, 0x00, SIZEOF(RtcSessionDescriptionInit));

    CHK_STATUS((deserializeSessionDescriptionInit(pSignalingMessage->payload, pSignalingMessage->payloadLen, pOfferSessionDescriptionInit)));
    CHK_STATUS((setRemoteDescription(pStreamingSession->pPeerConnection, pOfferSessionDescriptionInit)));
    canTrickle = canTrickleIceCandidates(pStreamingSession->pPeerConnection);
    // cannot be null after setRemoteDescription
    CHECK(!NULLABLE_CHECK_EMPTY(canTrickle));
    pStreamingSession->remoteCanTrickleIce = canTrickle.value;
    CHK_STATUS((setLocalDescription(pStreamingSession->pPeerConnection, &pStreamingSession->answerSessionDescriptionInit)));

    // If remote support trickle ice, send answer now. Otherwise answer will be sent once ice candidate gathering is complete.
    if (pStreamingSession->remoteCanTrickleIce) {
        CHK_STATUS((createAnswer(pStreamingSession->pPeerConnection, &pStreamingSession->answerSessionDescriptionInit)));
        CHK_STATUS((respondWithAnswer(pStreamingSession)));
        DLOGD("time taken to send answer %" PRIu64 " ms", (GETTIME() - pStreamingSession->offerReceiveTime) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND);
    }

    mediaThreadStarted = ATOMIC_EXCHANGE_BOOL(&pAppConfiguration->mediaThreadStarted, TRUE);
    if (!mediaThreadStarted) {
        THREAD_CREATE_EX(&pAppConfiguration->mediaSenderTid, "media_control", 4096, mediaSenderRoutine, (PVOID) pAppConfiguration);
    }

CleanUp:
    SAFE_MEMFREE(pOfferSessionDescriptionInit);
    CHK_LOG_ERR((retStatus));

    return retStatus;
}