diff options
author | Matt Durgavich <matthew.durgavich@unity3d.com> | 2022-09-24 22:04:54 -0700 |
---|---|---|
committer | Chris Hiszpanski <chris@liburtc.org> | 2022-09-24 22:06:25 -0700 |
commit | 97b0ebc80fa6c975dac3df7ddf3d3158db342366 (patch) | |
tree | b19a6c1fecbcaec627a0d0ad76340ac71bcfcc4d /src | |
parent | 838d2b41ab43ed4779c65f8bf65999f21f59ace5 (diff) |
Signed-off-by: Chris Hiszpanski <chris@liburtc.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/log.h | 16 | ||||
-rw-r--r-- | src/mdns.c | 22 | ||||
-rw-r--r-- | src/sdp.c | 6 | ||||
-rw-r--r-- | src/sdp.h | 7 | ||||
-rw-r--r-- | src/urtc.c | 14 |
5 files changed, 36 insertions, 29 deletions
@@ -33,13 +33,13 @@ extern "C" { #endif -enum level { - TRACE = 0, - DEBUG, - INFO, - WARN, - ERROR, - FATAL, +enum urtc_level { + URTC_TRACE = 0, + URTC_DEBUG, + URTC_INFO, + URTC_WARN, + URTC_ERROR, + URTC_FATAL, NUM_LEVELS // must be last }; @@ -74,7 +74,7 @@ static const char *logr[NUM_LEVELS] = { #define TOSTRING(x) STRINGIFY(x) #define AT __FILE__ ":" TOSTRING(__LINE__) -#define log(lvl, format, ...) \ +#define urtc_log(lvl, format, ...) \ do { \ fprintf(stderr, "%s" AT " %s" format "%s", logl[lvl], logn[lvl], ##__VA_ARGS__, logr[lvl]); \ } while (0); @@ -90,11 +90,11 @@ struct __attribute__((__packed__)) answer { * * \return Socket file descriptor on success, negative on error. */ -int mdns_subscribe() { +int mdns_subscribe(void) { // create socket int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (-1 == sockfd) { - log(ERROR, "%s", strerror(errno)); + urtc_log(URTC_ERROR, "%s", strerror(errno)); goto _fail_create_socket; } @@ -112,7 +112,7 @@ int mdns_subscribe() { &opt, sizeof(opt) )) { - log(ERROR, "%s", strerror(errno)); + urtc_log(URTC_ERROR, "%s", strerror(errno)); goto _fail_enable_addr_reuse; } } @@ -125,7 +125,7 @@ int mdns_subscribe() { .sin_port = htons(MDNS_PORT) }; if (-1 == bind(sockfd, (struct sockaddr *)(&mgroup), sizeof(mgroup))) { - log(ERROR, "%s", strerror(errno)); + urtc_log(URTC_ERROR, "%s", strerror(errno)); goto _fail_bind; } } @@ -140,7 +140,7 @@ int mdns_subscribe() { &opt, sizeof(opt) )) { - log(ERROR, "setsockopt: %s", strerror(errno)); + urtc_log(URTC_ERROR, "setsockopt: %s", strerror(errno)); goto _fail_disable_loopback; } } @@ -158,7 +158,7 @@ int mdns_subscribe() { &imr, sizeof(imr) )) { - log(ERROR, "setsockopt: %s", strerror(errno)); + urtc_log(URTC_ERROR, "setsockopt: %s", strerror(errno)); goto _fail_join_multicast_group; } } @@ -186,7 +186,7 @@ _fail_create_socket: */ int mdns_unsubscribe(int sockfd) { if (-1 == close(sockfd)) { - log(ERROR, "close: %s", strerror(errno)); + urtc_log(URTC_ERROR, "close: %s", strerror(errno)); return -URTC_ERR; } @@ -204,7 +204,7 @@ int mdns_query(const char *name) { // create socket int msockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (-1 == msockfd) { - log(FATAL, "socket: %s", strerror(errno)); + urtc_log(URTC_FATAL, "socket: %s", strerror(errno)); } uint8_t q[512]; @@ -243,7 +243,7 @@ int mdns_query(const char *name) { .sin_port = htons(MDNS_PORT) }; if (-1 == sendto(msockfd, q, qlen, 0, (struct sockaddr *)(&mgroup), sizeof(mgroup))) { - log(FATAL, "sendto: %s", strerror(errno)); + urtc_log(URTC_FATAL, "sendto: %s", strerror(errno)); } return 0; @@ -523,7 +523,7 @@ int mdns_send_response(int sockfd, const char *hostname) { // get linked list of network interfaces if (-1 == getifaddrs(&ifaddrs)) { - log(ERROR, "%s", strerror(errno)); + urtc_log(URTC_ERROR, "%s", strerror(errno)); goto _fail_getifaddrs; } @@ -600,7 +600,7 @@ int mdns_send_response(int sockfd, const char *hostname) { (struct sockaddr *)(&mgroup), sizeof(mgroup) )) { - log(FATAL, "sendto: %s", strerror(errno)); + urtc_log(URTC_FATAL, "sendto: %s", strerror(errno)); } return 0; @@ -176,10 +176,10 @@ static int sdp_parse_attr_rtpmap(struct sdp *sdp, char *val) { if (!val) return -URTC_ERR_SDP_MALFORMED; unsigned int pt; // payload type - char en[7]; // encoding name + char en[10]; // encoding name unsigned int cr; // clock rate - if (3 != sscanf(val, "%3d %6[a-zA-Z0-9]%*c%5d", &pt, en, &cr)) { + if (3 != sscanf(val, "%3d %9[a-zA-Z0-9]%*c%5d", &pt, en, &cr)) { return -URTC_ERR_SDP_MALFORMED_ATTRIBUTE; } @@ -468,7 +468,7 @@ int sdp_parse(struct sdp *dst, const char *str) { for (char *in = copy, *line = strsep(&in, "\r\n"); in; line = strsep(&in, "\r\n")) { retval = sdp_parse_line(dst, line); if (retval != 0) { - log(ERROR, "sdp_parse_line returned %i for %s", retval, line); + urtc_log(URTC_ERROR, "sdp_parse_line returned %i for %s", retval, line); break; } } @@ -113,6 +113,13 @@ typedef struct sdp { int count; } video; + // audio media + struct { + uint16_t port; + struct sdp_rtpmap params[SDP_MAX_RTP_PAYLOAD_TYPES]; + int count; + } audio; + sdp_mode_t mode; // send, receive, and send-and-receive bool rtcp_mux; // is rtcp multiplexed on same socket @@ -212,17 +212,17 @@ static int socket_event_handler(struct peerconn *pc) { // rtp if ((127 < buffer[0]) && (buffer[0] < 192)) { - log(INFO, "[rtp] %s", inet_ntoa(ra.sin_addr)); + urtc_log(URTC_INFO, "[rtp] %s", inet_ntoa(ra.sin_addr)); rtp_handler(pc, buffer, n); } else // dtls if ((19 < buffer[0]) && (buffer[0] < 64)) { - log(INFO, "[dtls] %s", inet_ntoa(ra.sin_addr)); + urtc_log(URTC_INFO, "[dtls] %s", inet_ntoa(ra.sin_addr)); dtls_handler(pc, buffer, n); } else // stun if (buffer[0] < 2) { - log(INFO, "[stun] %s", inet_ntoa(ra.sin_addr)); + urtc_log(URTC_INFO, "[stun] %s", inet_ntoa(ra.sin_addr)); stun_handler(pc, buffer, n); } @@ -265,7 +265,7 @@ static int mdns_handler(struct peerconn *pc) { NULL, NULL ), -1 == n) { - log(ERROR, "%s", strerror(errno)); + urtc_log(URTC_ERROR, "%s", strerror(errno)); goto _fail_recvfrom; } @@ -273,12 +273,12 @@ static int mdns_handler(struct peerconn *pc) { int type = mdns_validate_query(buffer, n, pc->mdns.hostname); if (type > 0) { if (type | TYPE_A) { - log(DEBUG, "[mdns] received A query"); + urtc_log(URTC_DEBUG, "[mdns] received A query"); // ...respond to query with interface addresses mdns_send_response(pc->mdns.sockfd, pc->mdns.hostname); } if (type | TYPE_AAAA) { - log(DEBUG, "[mdns] received AAAA query"); + urtc_log(URTC_DEBUG, "[mdns] received AAAA query"); } } @@ -385,7 +385,7 @@ urtc_peerconn_t * urtc_peerconn_create(const char *stun[]) { // generate a unique local mDNS hostname uuid_create_str(pc->mdns.hostname); - log(INFO, "mDNS hostname is %s.local", pc->mdns.hostname); + urtc_log(URTC_INFO, "mDNS hostname is %s.local", pc->mdns.hostname); // open multicast udp socket for replying to mDNS queries pc->mdns.sockfd = mdns_subscribe(); |