Direct access to the topic, transferred through the RTP / RTCP protocol to the network through the RTP / RTCP protocol, and this topic is used by the RTP / RTP / RTCP protocol stack, first get the source code of the JRTPLIB package, unzip the configuration compilation, No bugs are OK.
There are several examples in the source package, you can learn from. When setting the Server side, the TCP / IP protocol is different from the TCP / IP protocol, first set a baseport port while initializing the session, setting the IP and Port of the Client side, and then set the timestamp according to the frequency of video sampling, specific settings Functions can be found in Examples and have a good multiplex.
Here, the transmitting and reception of code, send and receive is implemented by thread:
send:
RET = send_rtppacket ((unsigned char *) Videoin.ptframe [frameout], sizeof (struct frame_t) headerframe-> size);
Send the PTFrame [] pointer directly in the send thread function, the data size is SIZEOF (struct frame_t) headerframe-> size, contains the data of the frame, and the data structure described for the frame parameter.
int Send_rtppacket (unsigned char * framepointer, int framelength) {int done = 0; int flage; int sendbyte = 0; int n; do {if (framelength> PacketMaxsize) // set packetmaxsize: 1400, where necessary to oversize the split transaction FLAGE = 0; else flage = 1; if (flage = 1) {n = session.sendpacket (FrameplameLength, 26, 1, 1000); // Send function fourth parameter decision whether it is the Frame last
Data done less than 1400 = 1; // if it is marked complete sendbyte = framelength;} else {n = session.SendPacket (framepointer, PacketMaxsize, 26,0,1000); framepointer = framepointer PacketMaxsize; // update transmitting pointer frameLength = framelength - packetMaxSize; sendbyte = sendbyte packetmaxsize;} f (n <0) {return -1;}}}}} while (! "; returnitude;}
receive:
DO {// Retrieve RTP Data Source Sess.BegindataAccess (); if (sess.gotofirstsourcewithdata ()) {DO {RTPPACKET * Packet; rtpsourceData * srcdata; // Get RTP Datashes PacketFLAGE = 0; recvlength = 0; // Initialization Receive data and data reception indicate while ((packet = sess.getnextpacket ())! = Null && packetFLAGE == 0) {// Receive the remaining data for zero reception of the same packet // printf ("got packet! / N") {PROCKET (* SRCDATA, * PACKET) {packetflage = 1; // processpacket () Returns I have accepted all packet to call decoding, SDL display //printf("de display //printf("Debug...packetflage:% D / n ", packetflage; jpegsize = readjpeg (& buf, headerframe); //printf ("debug":% d / n ", jpegsize); if (! jpegsize && video) close_sdlvideo (); if (JPEGSIZE && ! videoOk) {init_sdlvideo (); pscreen = SDL_SetVideoMode (owidth, oheight, bpp * 8, SDL_DOUBLEBUF | SDL_SWSURFACE); p = (unsigned char *) pscreen-> pixels;} if (jpegsize && videoOk) { jpeg_decode (& picture, buf, & width, & height); resize (p, picture, owidth, oheight, width, height); SDL_WM_SetCaption (titre, NULL); SDL_Flip (pscreen);} if (SDL_PollEvent (& sdlevent) <0) goto error } Else packetflage = 0; // Returns 0, Packet has not received continued sess.getnextPacket () delete packet; // delete RTP Datasheet}} while (sess.gotonextsourceWithData ()); // Receive another packet} Sess.EnddataAccess (); // Accept RTP Data Status = sess.poll (); Checkerror (status); RTPTIME :: Wait (RTPTime (1, 0));} While (1);
int processpacket (const RTPSourceData & srcdat, const RTPPacket & rtppack) {unsigned char * payloadpointer = rtppack.GetPayloadData (); // receive the packet data bool packetmarker = rtppack.HasMarker (); // No View portion of the data that have been transmitted completely Package int flag = 1; //printf ("debug.......... "); if (! Packetmarker) // Unfailed packet {Memcpy (Recvpointer Recvoffset, PayloadPointer, RTPPACK .GetPayloadLength ()); Recvlength = rtPPack.getPayloadLength (); recvoffset = rtPck.getPayloadLength (); // Update the pointer to receive data saved // printf ("debug ........ 2 / n "); flage = 0; // Flag acceptor sites continue sess.GetNextPacket ()} else {memcpy (recvpointer recvoffset, payloadpointer, rtppack.GetPayloadLength ()); recvlength = rtppack.GetPayloadLength (); recvoffset = 0 ; // After passing, initialize // printf ("debug ........ 3 / n");} Return flag;} Summary:
RTP / RTCP flows from data:
Server end:
The duplicate data is sent to the Client side. When the transmission is sent, it is sent to the client in the form of a packet, which means that a packet requires several Packet transmission to be completed. Send the next packet after sending success, always call the function: session.sendpacket ();
Client side:
Call sess.getnextPacket () in turn, call the packet data of a packet, and after the arrival of the packet, after receiving the packets used in the packet, the RTP library re-sequences the received packet based on the timestamp. Final packet. After receiving the data package, call sess.gotonextsourceWithData () to start receiving the next packet