Exemple #1
0
void add_candidate(OwrSession *session, char *ufrag, char *password, int type, int component, char *foundation, uint priority, int transport_type, char *address, uint port) {
	OwrCandidate *candidate = owr_candidate_new(type, component);
	g_object_set(candidate,
		"foundation", foundation,
		"ufrag", ufrag,
		"password", password,
		"transport-type", transport_type,
		"address", address,
		"port", port,
		"priority", priority,
		NULL);
	owr_session_add_remote_candidate(session, candidate);
}
static void gathering_done(OwrSession *session)
{
    OwrMediaSession *msession = OWR_MEDIA_SESSION(session);
    OwrCandidate *rtp_candidate, *rtcp_candidate;
    GList *candidates;
    guint l_rtp_port, l_rtcp_port, r_rtp_port, r_rtcp_port;

    rtp_candidate = owr_candidate_new(OWR_CANDIDATE_TYPE_HOST, OWR_COMPONENT_TYPE_RTP);
    rtcp_candidate = owr_candidate_new(OWR_CANDIDATE_TYPE_HOST, OWR_COMPONENT_TYPE_RTCP);

    g_object_set(rtp_candidate, "address", remote_addr, "ufrag", remote_addr, "password", stun_pass, "foundation", "3", NULL);
    g_object_set(rtcp_candidate, "address", remote_addr, "ufrag", remote_addr, "password", stun_pass, "foundation", "3", NULL);

    if (msession == send_session_video) {
        l_rtp_port = 5120;
        l_rtcp_port = 5121;
        r_rtp_port = 5122;
        r_rtcp_port = 5123;
    } else if (msession == send_session_audio) {
        l_rtp_port = 5124;
        l_rtcp_port = 5125;
        r_rtp_port = 5126;
        r_rtcp_port = 5127;
    } else if (msession == recv_session_video) {
        l_rtp_port = 5122;
        l_rtcp_port = 5123;
        r_rtp_port = 5120;
        r_rtcp_port = 5121;
    } else if (msession == recv_session_audio) {
        l_rtp_port = 5126;
        l_rtcp_port = 5127;
        r_rtp_port = 5124;
        r_rtcp_port = 5125;
    }

    g_object_set(rtp_candidate, "port", r_rtp_port, NULL);
    g_object_set(rtcp_candidate, "port", r_rtcp_port, NULL);

    owr_session_add_remote_candidate(session, rtp_candidate);
    owr_session_add_remote_candidate(session, rtcp_candidate);

    for (candidates = g_object_get_data(G_OBJECT(session), "local-candidates"); candidates;
            candidates = g_list_next(candidates)) {
        OwrCandidate *local_candidate = candidates->data, *remote_candidate;
        OwrComponentType ctype;
        guint port = 0;
        gchar *addr;

        g_object_get(local_candidate, "address", &addr, "port", &port, "component-type", &ctype, NULL);

        if (!g_str_equal(addr, local_addr)) {
            g_free(addr);
            continue;
        }
        g_free(addr);

        if (port == l_rtp_port && ctype == OWR_COMPONENT_TYPE_RTP)
            remote_candidate = rtp_candidate;
        else if (port == l_rtcp_port && ctype == OWR_COMPONENT_TYPE_RTCP)
            remote_candidate = rtcp_candidate;
        else
            continue;

        owr_session_force_candidate_pair(session, ctype, local_candidate, remote_candidate);
    }
}
OwrCandidate * _owr_candidate_new_from_nice_candidate(NiceCandidate *nice_candidate)
{
    OwrCandidate *owr_candidate;
    OwrCandidateType candidate_type = -1;
    OwrComponentType component_type = -1;
    OwrTransportType transport_type = -1;
    gchar *address;
    guint port;

    g_return_val_if_fail(nice_candidate, NULL);

    switch (nice_candidate->type) {
    case NICE_CANDIDATE_TYPE_HOST:
        candidate_type = OWR_CANDIDATE_TYPE_HOST;
        break;

    case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
        candidate_type = OWR_CANDIDATE_TYPE_SERVER_REFLEXIVE;
        break;

    case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
        candidate_type = OWR_CANDIDATE_TYPE_PEER_REFLEXIVE;
        break;

    case NICE_CANDIDATE_TYPE_RELAYED:
        candidate_type = OWR_CANDIDATE_TYPE_RELAY;
        break;
    }
    g_return_val_if_fail(candidate_type != (OwrCandidateType)-1, NULL);

    switch (nice_candidate->component_id) {
    case NICE_COMPONENT_TYPE_RTP:
        component_type = OWR_COMPONENT_TYPE_RTP;
        break;

    case NICE_COMPONENT_TYPE_RTCP:
        component_type = OWR_COMPONENT_TYPE_RTCP;
        break;
    }
    g_return_val_if_fail(component_type != (OwrComponentType)-1, NULL);

    switch (nice_candidate->transport) {
    case NICE_CANDIDATE_TRANSPORT_UDP:
        transport_type = OWR_TRANSPORT_TYPE_UDP;
        break;

    case NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE:
        transport_type = OWR_TRANSPORT_TYPE_TCP_ACTIVE;
        break;

    case NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE:
        transport_type = OWR_TRANSPORT_TYPE_TCP_PASSIVE;
        break;

    case NICE_CANDIDATE_TRANSPORT_TCP_SO:
        transport_type = OWR_TRANSPORT_TYPE_TCP_SO;
        break;
    }
    g_return_val_if_fail(transport_type != (OwrTransportType)-1, NULL);

    owr_candidate = owr_candidate_new(candidate_type, component_type);

    g_object_set(G_OBJECT(owr_candidate), "transport_type", transport_type, NULL);

    address = g_new0(gchar, NICE_ADDRESS_STRING_LEN);
    nice_address_to_string(&nice_candidate->addr, address);
    g_object_set(G_OBJECT(owr_candidate), "address", address, NULL);
    g_free(address);

    port = nice_address_get_port(&nice_candidate->addr);
    g_object_set(G_OBJECT(owr_candidate), "port", port, NULL);

    address = g_new0(gchar, NICE_ADDRESS_STRING_LEN);
    nice_address_to_string(&nice_candidate->base_addr, address);
    g_object_set(G_OBJECT(owr_candidate), "base-address", address, NULL);
    g_free(address);

    port = nice_address_get_port(&nice_candidate->base_addr);
    g_object_set(G_OBJECT(owr_candidate), "base-port", port, NULL);

    g_object_set(G_OBJECT(owr_candidate), "priority", nice_candidate->priority, NULL);
    g_object_set(G_OBJECT(owr_candidate), "foundation", nice_candidate->foundation, NULL);

    g_object_set(G_OBJECT(owr_candidate), "ufrag", nice_candidate->username, NULL);
    g_object_set(G_OBJECT(owr_candidate), "password", nice_candidate->password, NULL);

    return owr_candidate;
}