C # Remote monitoring (4) Receive-side RTP package reassembly Split-screen display

Source: Internet
Author: User

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&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.