diff options
Diffstat (limited to 'tinyrtc.c')
-rw-r--r-- | tinyrtc.c | 63 |
1 files changed, 34 insertions, 29 deletions
@@ -42,11 +42,11 @@ /// OPAQUE TYPE DEFINITIONS //////////////////////////////////////////////// -struct trtc_peerconn_t { +struct rtc_peer_connection { bool active; - char offer[TRTC_MAX_SDP_SIZE]; - char answer[TRTC_MAX_SDP_SIZE]; + char offer[TINYRTC_MAX_SDP_SIZE]; + char answer[TINYRTC_MAX_SDP_SIZE]; /* local description */ const char* ldesc; @@ -54,11 +54,11 @@ struct trtc_peerconn_t { /* remote description */ const char* rdesc; - char l_ice_pwd[TRTC_MAX_ICE_PWD_SIZE]; - char l_ice_ufrag[TRTC_MAX_ICE_UFRAG_SIZE]; + char l_ice_pwd[TINYRTC_MAX_ICE_PWD_SIZE]; + char l_ice_ufrag[TINYRTC_MAX_ICE_UFRAG_SIZE]; /* onIceCandidate callback */ - trtc_on_ice_candidate_t* on_ice_candidate; + rtc_on_ice_candidate* on_ice_candidate; void* on_ice_candidate_arg; /* tcp host candidate socket */ @@ -68,12 +68,13 @@ struct trtc_peerconn_t { /// STATIC ALLOCATIONS ///////////////////////////////////////////////////// -static struct trtc_peerconn_t peer_connection_pool[TRTC_MAX_PEER_CONNECTIONS]; +static struct rtc_peer_connection +peer_connection_pool[TINYRTC_MAX_PEER_CONNECTIONS]; /// RTC PEER CONNECTION API //////////////////////////////////////////////// -void trtc_init() { +void rtc_init() { memset(peer_connection_pool, 0, sizeof(peer_connection_pool)); } @@ -82,7 +83,7 @@ void trtc_init() { * * \return 0 on success, -1 on error. */ -static int get_host_candidates(struct trtc_peerconn_t* pc) { +static int get_host_candidates(struct rtc_peer_connection* pc) { struct ifaddrs *ifaddr, *ifa; socklen_t laddrlen; @@ -130,11 +131,11 @@ static int get_host_candidates(struct trtc_peerconn_t* pc) { struct sockaddr_in *sa = (struct sockaddr_in*)ifa->ifa_addr; /* host tcp candidate */ - struct trtc_ice_candidate_t c = { + struct rtc_ice_candidate c = { .sdp_mid = "0", .sdp_mline_index = 0 }; - snprintf(c.candidate, TRTC_MAX_ICE_CANDIDATE_SIZE, + snprintf(c.candidate, TINYRTC_MAX_ICE_CANDIDATE_SIZE, "candidate:2894319779 1 tcp 212260223 %s %d typ host tcptype passive", inet_ntoa(sa->sin_addr), laddr.sin_port); // XXXX @@ -165,12 +166,12 @@ static void* peer_connection_thread(void *arg) { return NULL; } -struct trtc_peerconn_t* trtc_peer_connection(struct trtc_config_t cfg) { - struct trtc_peerconn_t* pc = NULL; +struct rtc_peer_connection* rtc_peer_connection_create(struct rtc_configuration cfg) { + struct rtc_peer_connection* pc = NULL; - for (int i = 0; i < TRTC_MAX_PEER_CONNECTIONS; i++) { + for (int i = 0; i < TINYRTC_MAX_PEER_CONNECTIONS; i++) { if (!peer_connection_pool[i].active) { - memset(&peer_connection_pool[i], 0, sizeof(struct trtc_peerconn_t)); + memset(&peer_connection_pool[i], 0, sizeof(struct rtc_peer_connection)); pc = &peer_connection_pool[i]; break; } @@ -179,7 +180,8 @@ struct trtc_peerconn_t* trtc_peer_connection(struct trtc_config_t cfg) { return pc; } -void trtc_peer_connection_destroy(struct trtc_peerconn_t* pc) { +void rtc_peer_connection_destroy(struct rtc_peer_connection* pc) +{ if (!pc) return; close(pc->host_tcp_fd); @@ -187,11 +189,9 @@ void trtc_peer_connection_destroy(struct trtc_peerconn_t* pc) { // XXX mark as available } -int trtc_set_on_ice_candidate( - struct trtc_peerconn_t* pc, - trtc_on_ice_candidate_t* cb, - void* arg -) { +int rtc_set_on_ice_candidate(struct rtc_peer_connection* pc, + rtc_on_ice_candidate* cb, void* arg) +{ if (!pc || !cb) return -1; pc->on_ice_candidate = cb; @@ -200,21 +200,24 @@ int trtc_set_on_ice_candidate( return 0; } -int trtc_add_ice_candidate(struct trtc_peerconn_t *pc, const struct trtc_ice_candidate_t c) { +int rtc_add_ice_candidate(struct rtc_peer_connection* pc, + const struct rtc_ice_candidate c) +{ return -1; }; -const char * trtc_create_answer(struct trtc_peerconn_t *pc) { +const char* rtc_create_answer(struct rtc_peer_connection* pc) +{ unsigned char fp[32]; - snprintf(pc->l_ice_ufrag, TRTC_MAX_ICE_UFRAG_SIZE, "xxxx"); // XXX - snprintf(pc->l_ice_pwd, TRTC_MAX_ICE_PWD_SIZE, "xxxxxxxxxxxxxxxxxxxxxx"); // XXX + snprintf(pc->l_ice_ufrag, TINYRTC_MAX_ICE_UFRAG_SIZE, "xxxx"); // XXX + snprintf(pc->l_ice_pwd, TINYRTC_MAX_ICE_PWD_SIZE, "xxxxxxxxxxxxxxxxxxxxxx"); // XXX - snprintf(pc->answer, TRTC_MAX_SDP_SIZE, + snprintf(pc->answer, TINYRTC_MAX_SDP_SIZE, "v=0\\r\\n" "o=- 2210401696197537454 2 IN IP4 127.0.0.1\\r\\n" // XXX "s=-\\r\\n" - "u=https://tinyrtc.org/\\r\\n" + "u=https://liburtc.org/\\r\\n" "t=0 0\\r\\n" "a=group:BUNDLE 0\\r\\n" "a=msid-semantic: WMS\\r\\n" @@ -249,13 +252,15 @@ const char * trtc_create_answer(struct trtc_peerconn_t *pc) { return pc->answer; }; -int trtc_set_local_description(struct trtc_peerconn_t *pc, const char *sdp) { +int rtc_set_local_description(struct rtc_peer_connection* pc, const char* sdp) +{ pc->ldesc = sdp; get_host_candidates(pc); return -1; }; -int trtc_set_remote_description(struct trtc_peerconn_t *pc, const char *sdp) { +int rtc_set_remote_description(struct rtc_peer_connection* pc, const char* sdp) +{ pc->rdesc = sdp; return -1; }; |