コード例 #1
0
        //SUpparioucly thought that the last frame would remain in a not final state so one should check that the Goodbye has not been received when processing the event...
        //Shows what happpens when packets get out of order too badely..
        public void TestFrameChangedEvents()
        {
            using (Rtp.RtpClient rtpClient = new Rtp.RtpClient())
            {
                //Fire Frames with single packets and order = 3, 1, 2.
                //Each have marker

                //What is the expected order(3 final, 1 final, 2 final)? and count (3)!

                int count = 0, fcount = 0;

                Rtp.RtpClient.TransportContext tc = new Rtp.RtpClient.TransportContext(0, 1, 0);

                //Needed to resolve packet payload and avoid exception when validating packet... :(
                tc.MediaDescription = new Sdp.MediaDescription(Sdp.MediaType.unknown, 0, "RTP", 0);

                rtpClient.AddContext(tc);

                rtpClient.FrameChangedEventsEnabled = true;

                rtpClient.RtpFrameChanged += (s, z, t, f) =>
                {
                    ++count;

                    if (f)
                    {
                        ++fcount;
                    }

                    Console.WriteLine("RtpFrameChanged=>" + z.HighestSequenceNumber + z.HasMarker + f);
                };

                Console.WriteLine("Count: " + count);

                Console.WriteLine("Final Count: " + fcount);

                int tests = 4;

                Rtp.RtpPacket rtpPacket           = new Rtp.RtpPacket(12)
                {
                    Timestamp      = tests * 1000,
                    SequenceNumber = tests,
                    Marker         = true
                };

                for (int i = tests; i >= 0; --i)
                {
                    rtpPacket.Timestamp -= tests * 1000;

                    rtpPacket.SequenceNumber = i;

                    rtpClient.HandleIncomingRtpPacket(null, rtpPacket, tc);
                }

                //8 Frame Changes only 3 are final...
                if (count != tests || fcount != tests)
                {
                    throw new Exception();
                }

                count = fcount = 0;

                rtpPacket.SequenceNumber = 4;
                rtpPacket.Timestamp      = 4000;

                rtpClient.HandleIncomingRtpPacket(null, rtpPacket, tc);

                rtpPacket.SequenceNumber = 1;
                rtpPacket.Timestamp      = 1000;

                rtpClient.HandleIncomingRtpPacket(null, rtpPacket, tc);

                rtpPacket.SequenceNumber = 3;
                rtpPacket.Timestamp      = 3000;

                rtpClient.HandleIncomingRtpPacket(null, rtpPacket, tc);

                rtpPacket.SequenceNumber = 2;
                rtpPacket.Timestamp      = 2000;

                rtpClient.HandleIncomingRtpPacket(null, rtpPacket, tc);

                if (count != tests || fcount != tests)
                {
                    throw new Exception();
                }
            }
        }