rtcp package send/recv demo
main.c
#include <stdio.h> #include <rtp.h> #include <rtcp.h> #include <netinet/in.h> #include <netdb.h> #include <math.h> #include <event.h> #include <syn.h> #include <payload.h> #include <sample.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <arpa/inet.h> #include <util.h> #include <frame.h> #include <sys/ioctl.h> #include <sys/stropts.h> #include "main.h" #ifdef LINUX #include <linux/soundcard.h> #endif /* LINUX */ #define MAX_SOURCES 32 int main(int argc, char **argv) { char buf[4000]; unsigned short *samp16 = (unsigned short *) buf; bool found; int audio, port, rv, payloadtype; int count, i, encoding = 0, one = 1; ssrc_t ssrc = 0, sources[MAX_SOURCES]; struct in_addr addr; struct session *psn; struct synsession *pssn; struct timespec time; struct sampparam parameters; struct encoding enc; mediatime_t ts; struct sampreadparam sreadparam; int leeway; /* * Check for correct number of arguments. */ if (argc != 3) { fprintf(stderr, "Usage: %s <addr> <port>\n", argv[0]); exit(0); } addr.s_addr = inet_addr(argv[1]); port = atoi(argv[2]); printf("Session: %s/%d\n", inet_ntoa(addr), port); /* * Open a synchronization layer session. * Use 2k buffers for RTP packets, 64 buffers in pool. */ pssn = synopen(addr, port, 2048, 64); if (pssn == NULL) { fprintf(stderr, "synopen() returned NULL.\n"); exit(1); } /* * Get a handle to the RTP layer session. */ synctl(pssn, SYN_CTL_GETRTPSESSION, (char *) &psn, 0); /* * Look up the encoding represented by payloadtype. * Determine if it's a supported encoding. */ enc = getencoding(payloadtype); printf("enc.en_name: %s\n", enc.en_name); ssrc = 0; printf("Found sender: SSRC = 0x%x Encoding = %s\n", ssrc, enc.en_name); /* * rtcp package send/recv thread. */ rtpctl(psn, RTP_CTL_RTCPCYCLETHREAD, (char *) &payloadtype, 0, ssrc); rtpctl(psn, RTP_CTL_RTCPRECVTHREAD, (char *) &one, 0, ssrc); }
运行
code::blocks工程
https://files.cnblogs.com/files/dong1/rtprtcp_linux_demo.tar.gz