I. Windows documents
Http://www.cnblogs.com/skyseraph/archive/2012/04/07/2435540.html
1. Install cmake
2. Run cmake. In the jrtplib-3.9.1_1 to generate makefile
3. Then make
Then make install
The header file is installed in/usr/local/include/jrtplib3/. Therefore, you need to add-I/usr/local/include/jrtplib3/when compiling the program/
The library file is installed in/usr/local/lib/libjrtp. A. Therefore, you need to add-ljrtp when compiling the program.
4. Compile example1
G ++-O test example1.cpp-ljrtp-I/usr/local/include/jrtplib3/
Error:./test: Error while loading shared libraries: libjrtp. so.3.9.1: cannot open shared object file: no such file or directory
Analysis: jrtp has been installed. Why cannot I find the dynamic library?
Solution: Copy usr/local/lib/libjrtp. so.3.9.1 to usr/lib.
V. debugging
Error: the specified port base is not an even number
Analysis: jrtp does not support odd ports
Appendix:
Sending code: Send. cpp
/* Here's a small IPv4 example: it asks for a portbase and a destination and starts sending packets to that destination. */# include "jrtplib3/rtpsession. H "# include" jrtplib3/rtpudpv4transmitter. H "# include" jrtplib3/rtp00004address. H "# include" jrtplib3/rtpsessionparams. H "# include" jrtplib3/rtperrors. H "# ifndef Win32 # include <netinet/in. h> # include <ARPA/inet. h> # else # include <winsock2.h> # endif // Win32 # include <stdlib. h> # include <stdio. h >#include <iostream >#include <string> using namespace jrtplib; void checkerror (INT rtperr) {If (rtperr <0) // if the value is negative, the error message {STD: cout <"error:" <rtpgterrorstring (rtperr) <STD: Endl; is returned; exit (-1) ;}} int main (void) {# ifdef win32wsadata dat; wsastartup (makeword (2, 2), & dat); # endif // win32rtpsession sess; uint16_t portbase = 8000, destport = 7800; uint32_t destip; STD: String ipstr = "127.0.0.1"; int status, I, num = 10; destip = inet_addr (ipstr. c_str (); // If (destip = inaddr_none) {STD: cerr <"Bad IP address specified" <STD: Endl; return-1;} destip = ntohl (destip); rtpudpv4transmissionparams transparams; rtpsessionparams sessparams; sessparams. setowntimestampunit (1.0/10.0); sessparams. setacceptownpackets (true); transparams. setportbase (portbase); status = sess. create (sessparams, & transparams); checkerror (Status); // check whether the RTP session creation process fails rtp00004address ADDR (destip, destport); // socket status = sess. adddestination (ADDR); // set the destination address for sending data (multiple destination addresses are allowed) checkerror (Status); for (I = 1; I <= num; I ++) {printf ("\ nsending packet % d/% d \ n", I, num); status = sess. sendpacket (void *) "1234567890", 0, false, 10); checkerror (Status); // # ifndef rtp_support_thread // status = sess. poll (); // checkerror (Status); // # endif // rtp_support_threadrtptime: Wait (rtptime (1, 0);} sess. byedestroy (rtptime (10, 0), 0, 0); # ifdef win32wsacleanup (); # endif // win32return 0 ;}
Compile: G ++-o send. cpp-ljrtp-I/usr/local/include/jrtplib3/
Receiver code:
# Include "jrtplib3/rtpsession. H "# include" jrtplib3/rtpudpv4transmitter. H "# include" jrtplib3/rtp00004address. H "# include" jrtplib3/rtpsessionparams. H "# include" jrtplib3/rtperrors. H "# ifndef Win32 # include <netinet/in. h> # include <ARPA/inet. h> # else # include <winsock2.h> # endif // Win32 # include <stdlib. h> # include <stdio. h> # include <iostream> # include <string> using namespace jrtplib; // void checkerror (in T rtperr) {If (rtperr <0) // if the value is negative, the error message {STD: cout <"error:" <rtpgterrorstring (rtperr) <STD:: Endl; exit (-1) ;}} int main (INT argc, char ** argv) {rtpsession sess; int localport; int portbase = 7800; int status; // create an RTP session rtpudpv4transmissionparams transparams; rtpsessionparams sessparams; sessparams. setowntimestampunit (1.0/10.0); sessparams. setacceptownpackets (true); transparams. setportbase (Port Base); status = sess. create (sessparams, & transparams); checkerror (Status); uint32_t destip; STD: String ipstr = "127.0.0.1"; int destport = 7800; destip = inet_addr (ipstr. c_str (); // If (destip = inaddr_none) {STD: cerr <"Bad IP address specified" <STD: Endl; return-1;} destip = ntohl (destip); rtp00004address ADDR (destip, destport); // socket sess. addtoacceptlist (ADDR); STD: cout <"begin receive: \ n "; Sess. begindataaccess (); do {status = sess. poll (); checkerror (Status); If (sess. gotofirstsourcewithdata () {do {rtppacket * pack; while (pack = sess. getnextpacket ())! = NULL) {// you can examine the data hereprintf ("got packet! \ N "); // We don't longer need the packet, so // We'll delete itsess. deletepacket (pack) ;}} while (sess. gotonextsourcewithdata () ;}} while (1); sess. enddataaccess (); Return 0 ;}
Compile: G ++-o receive. cpp-ljrtp-I/usr/local/include/jrtplib3/