Created
April 9, 2019 03:28
-
-
Save happyj2me/3e6871f839804f188e9e053c3900f480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.绑定到一个操作系统随机分配的udp端口,绑定成功后获取到这个端口 | |
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | |
if(fd < 0) { | |
JANUS_LOG(LOG_ERR, "Error creating RTCP socket for new RTP forwarder... %d (%s)\n", | |
errno, strerror(errno)); | |
return 0; | |
} | |
struct sockaddr_in address; | |
socklen_t len = sizeof(address); | |
memset(&address, 0, sizeof(address)); | |
address.sin_family = AF_INET; | |
address.sin_port = htons(0); /* The RTCP port we received is the remote one */ | |
address.sin_addr.s_addr = INADDR_ANY; | |
if(bind(fd, (struct sockaddr *)&address, sizeof(struct sockaddr)) < 0 || | |
getsockname(fd, (struct sockaddr *)&address, &len) < 0) { | |
JANUS_LOG(LOG_ERR, "Error binding RTCP socket for new RTP forwarder... %d (%s)\n", | |
errno, strerror(errno)); | |
close(fd); | |
return 0; | |
} | |
local_rtcp_port = ntohs(address.sin_port); | |
JANUS_LOG(LOG_VERB, "Bound local %s RTCP port: %"SCNu16"\n", | |
is_video ? "video" : "audio", local_rtcp_port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment