We used the RTP protocol in the previous issue and were configured to package the video data, which we reorganized and displayed on the receiving end of the data we sent. Finally, it is extended to support multi-client video sending, and display on the receiving end of the screen. Complete the remote monitoring simulation.
Let's start with one.
private bool Newrtppacket (Rtppacket packet) {if (! Clients.containskey (packet. SSRC)//If the receiving end receives data from a source for the first time, it is added to {if (Clients.count < 4)//If the sending end is 4, the package { Clients.add (packet. SSRC, new list<rtppacket> {packet}); Imagesboxmapping[imagesboxmapping.first (pair = = pair. Value = = null). Key] = packet. SSRC; }} else {Clients[packet. SSRC]. ADD (packet); } if (packet. Marker)//If it has been sent {//Lost packet detection var orderpackets = Clients[packet. SSRC]. (Rtppacket = Rtppacket.sequencenumber); if (Clients[packet. SSRC]. Count! = (Orderpackets.last (). Sequencenumber-orderpackets.first (). SequenceNumber + 1)) {Clients[packet. SSRC]. Clear ();//empty buffer return true; }//1. package restructuring Var CouNT = Clients[packet. SSRC]. Sum (rtppacket = rtppacket.datasize);//Data total var newdata = new Byte[count]; Long OffSet = 0; foreach (Var rtppacket in Clients[packet. SSRC]) {array.copy (rtppacket.datapointer, 0, NewData, OffSet, rtppacket.datasize); OffSet + = Rtppacket.datasize; } clients[packet. SSRC]. Clear ();//Empty buffer var ms = new MemoryStream (NewData); try {var bmp = new Bitmap (Image.fromstream (ms)); var img = new IMAGE<BGR, byte> (BMP); Imagesboxmapping.first (pair = = pair. Value = = packet. SSRC). Key.image = img; } catch (Exception) {} finally { Ms. Close (); }} return true; }
Complete code can be downloaded to Baidu Cloud: including the sending and receiving end
C # Remote monitoring (4) Receive-side RTP package reassembly Split-screen display