Ejemplo n.º 1
0
        public void TestNull()
        {
            //base class?
            //UnitTestBase
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            Media.Rtp.RtpClient rtpClient = default(Media.Rtp.RtpClient);

            try { rtpClient = Media.Rtp.RtpClient.FromSessionDescription(default(Media.Sdp.SessionDescription)); }
            catch { }

            System.Diagnostics.Debug.Assert(rtpClient == null, "Must not have created a RtpClient from a null SessionDescription");


            //Create a client
            using (rtpClient = new Media.Rtp.RtpClient())
            {
                //Attempt to find a context
                Media.Rtp.RtpClient.TransportContext contextAvailable = rtpClient.GetTransportContexts().FirstOrDefault();

                System.Diagnostics.Debug.Assert(contextAvailable == null, "Found a Context when there was no Session or Media Description");

                using (contextAvailable = new Media.Rtp.RtpClient.TransportContext(0, 1, 0))
                {
                    //Usually indicated by the profile
                    bool padding = false, extension = false;

                    //Create a RtpPacket from the
                    using (var rtpPacket = new Media.Rtp.RtpPacket(contextAvailable.Version, padding, extension, null))
                    {
                        System.Diagnostics.Debug.Assert(rtpClient.SendRtpPacket(rtpPacket) == 0, "Sent a packet when there was no Session or Media Description or TransportContext");
                    }
                }
            }
        }
Ejemplo n.º 2
0
                public TestFramework()
                {
                    //  Create a receiving socket.
                    _receiving = new System.Net.Sockets.Socket(_rtspServer.AddressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

                    //  Connect to the server.
                    System.IAsyncResult connectResult = null;
                    connectResult = _receiving.BeginConnect(_rtspServer, new System.AsyncCallback((iar) =>
                    {
                        try { _receiving.EndConnect(iar); }
                        catch { }
                    }), null);

                    //  Get the sender socket to be used by the "server".
                    _sender = _listenSocket.Accept();

                    //  RtspClient default size
                    byte[] buffer = new byte[8192];

                    _client = new Media.Rtp.RtpClient(new Media.Common.MemorySegment(buffer, Media.Rtsp.RtspMessage.MaximumLength, buffer.Length - Media.Rtsp.RtspMessage.MaximumLength));
                    _client.OutOfBandData      += ProcessInterleaveData;
                    _client.RtpPacketReceieved += ProcessRtpPacket;

                    Media.Sdp.MediaDescription md = new Media.Sdp.MediaDescription(Media.Sdp.MediaType.video, 999, "H.264", 0);

                    Media.Rtp.RtpClient.TransportContext tc = new Media.Rtp.RtpClient.TransportContext(0, 1,
                                                                                                       Media.RFC3550.Random32(9876), md, false, _senderSSRC);
                    //  Create a Duplexed reciever using the RtspClient socket.
                    tc.Initialize(_receiving);

                    _client.TryAddContext(tc);
                }
Ejemplo n.º 3
0
 void RtpClientPacketReceieved(object sender, Common.IPacket packet = null, Media.Rtp.RtpClient.TransportContext tc = null)
 {
     if (sender is Rtp.RtpClient)
     {
         WritePacket(Attached.Keys.FirstOrDefault(s => (s as RtpSource).RtpClient == sender as Rtp.RtpClient), packet);
     }
 }
Ejemplo n.º 4
0
                void ProcessRtpPacket(object sender, Media.Rtp.RtpPacket packet, Media.Rtp.RtpClient.TransportContext tc = null)
                {
                    ConsoleColor previousForegroundColor = Console.ForegroundColor;

                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("ProcessRtpPacket(): SequenceNumber = " + packet.SequenceNumber +
                                      ", Payload.Offset = " + packet.Payload.Offset + ", Payload.Count = " + packet.Payload.Count);
                    Console.ForegroundColor = previousForegroundColor;
                }
Ejemplo n.º 5
0
 void ShowRtpPacket(object sender, Media.Rtp.RtpPacket packet, Media.Rtp.RtpClient.TransportContext tc = null)
 {
     try
     {
         if (this.InvokeRequired)
         {
             Invoke(new FillGridRtp(AddRtp), packet.Clone(true, true, true, true, true));
         }
         else
         {
             RTPPacketBinding.Add((IPacket)packet.Clone(true, true, true, true, true));
         }
     }
     catch { }
 }
Ejemplo n.º 6
0
        private void RTSPClient_RtpFrameChanged(object sender, Media.Rtp.RtpFrame frame = null, Media.Rtp.RtpClient.TransportContext tc = null, bool final = false)
        {
            if (InvokeRequired)
            {
                MethodInvoker del = delegate { RTSPClient_RtpFrameChanged(sender, frame, tc, final); };
                Invoke(del);
            }
            else
            {
                RTSPMessagesTextBox.AppendText("RTSPClient_RtpFrameChanged" + Environment.NewLine);
                RTSPMessagesTextBox.AppendText("@" + frame.Created.ToUniversalTime().ToString() + " - " + frame.ToString() + Environment.NewLine);

                frame.Depacketize();

                //If the frame has depacketize data
                if (frame.HasDepacketized)
                {
                    RTSPMessagesTextBox.AppendText("BufferSize = " + frame.Buffer.Length.ToString() + Environment.NewLine);
                    RTSPMessagesTextBox.AppendText("Packets = " + frame.Count.ToString() + Environment.NewLine);

                    System.IO.Stream buffer = frame.Buffer;

                    /*
                     * //Check for the expected length
                     * if (buffer.Length != frameCount) throw new Exception("More data in buffer than expected");
                     *
                     * //Read the buffer
                     * while (buffer.Position < frameCount)
                     * {
                     *      //If the byte is out of order then throw an exception
                     *      if (buffer.ReadByte() != expected++) throw new Exception("Data at wrong position");
                     * }
                     */
                }
                else
                {
                    RTSPMessagesTextBox.AppendText("Not DEPACKETIZED" + Environment.NewLine);
                }
            }
        }
Ejemplo n.º 7
0
        private void RTSPClient_RtpPacketReceieved(object sender, Media.Rtp.RtpPacket packet = null, Media.Rtp.RtpClient.TransportContext tc = null)
        {
            if (InvokeRequired)
            {
                MethodInvoker del = delegate { RTSPClient_RtpPacketReceieved(sender, packet, tc); };
                Invoke(del);
            }
            else
            {
                if ((m_rtspClient != null))
                {
                    if (!m_rtspClient.LivePlay)
                    {
                        label2.Text = "Remaining: " +
                                      (DateTime.UtcNow - m_rtspClient.StartedPlaying.Value).Subtract(m_rtspClient.EndTime.Value).ToString();
                    }
                }
                RTSPMessagesTextBox.AppendText("RTSPClient_RtpPacketReceieved" + Environment.NewLine);
                RTSPMessagesTextBox.AppendText("@" + packet.Created.ToUniversalTime().ToString() + " - " + packet.ToString() + Environment.NewLine);

                RTSPMessagesTextBox.AppendText("IsComplete = " + packet.IsComplete.ToString() + ", ");
                RTSPMessagesTextBox.AppendText("IsCompressed = " + packet.IsCompressed.ToString() + ", ");
                RTSPMessagesTextBox.AppendText("Length = " + packet.Length.ToString() + ", ");
                RTSPMessagesTextBox.AppendText("SequenceNumber = " + packet.SequenceNumber.ToString() + ", ");
                RTSPMessagesTextBox.AppendText("PayloadType = " + packet.PayloadType.ToString() + ", " + Environment.NewLine);

#if DRIBBLE
                try
                {
                    int count     = 0;
                    int byteCount = 40;

                    foreach (byte payloadByte in packet.PayloadData)
                    {
                        RTSPMessagesTextBox.AppendText(String.Format("{0:X2}", payloadByte));
                        RTSPMessagesTextBox.AppendText(" ");
                        if (count++ > byteCount)
                        {
                            break;
                        }
                    }

                    RTSPMessagesTextBox.AppendText(Environment.NewLine);
                }
                catch (Exception ex)
                {
                    RTSPMessagesTextBox.AppendText("Image Exception:" + ex.Message + Environment.NewLine);
                }
#endif

                RTSPMessagesTextBox.AppendText(Environment.NewLine);
            }
        }
Ejemplo n.º 8
0
        private void RTSPClient_RtcpPacketReceieved(object sender, Media.Rtcp.RtcpPacket packet = null, Media.Rtp.RtpClient.TransportContext tc = null)
        {
            if (InvokeRequired)
            {
                MethodInvoker del = delegate { RTSPClient_RtcpPacketReceieved(sender, packet, tc); };
                Invoke(del);
            }
            else
            {
                if (m_rtspClient != null)
                {
                    if (!m_rtspClient.LivePlay)
                    {
                        label2.Text = "Remaining: " +
                                      (DateTime.UtcNow - m_rtspClient.StartedPlaying.Value).Subtract(m_rtspClient.EndTime.Value).ToString();
                    }
                }

                /*
                 * RTSPMessagesTextBox.AppendText("RTSPClient_RtcpPacketReceieved" + Environment.NewLine);
                 * RTSPMessagesTextBox.AppendText("@" + packet.Created.ToUniversalTime().ToString() + " - " + packet.ToString() + Environment.NewLine);
                 *
                 * RTSPMessagesTextBox.AppendText("IsComplete = " + packet.IsComplete.ToString() + ", " );
                 * RTSPMessagesTextBox.AppendText("IsCompressed = " + packet.IsCompressed.ToString() + ", " );
                 * RTSPMessagesTextBox.AppendText("Length = " + packet.Length.ToString() + ", " );
                 * RTSPMessagesTextBox.AppendText("PayloadType = " + packet.PayloadType.ToString() + ", " + Environment.NewLine);
                 */
            }
        }
Ejemplo n.º 9
0
        public void TestNull()
        {
            //base class?
            //UnitTestBase
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            Media.Rtp.RtpClient rtpClient = default(Media.Rtp.RtpClient);

            try { rtpClient = Media.Rtp.RtpClient.FromSessionDescription(default(Media.Sdp.SessionDescription)); }
            catch { }

            System.Diagnostics.Debug.Assert(rtpClient == null, "Must not have created a RtpClient from a null SessionDescription");

            //Create a client
            using (rtpClient = new Media.Rtp.RtpClient())
            {
                //Attempt to find a context
                Media.Rtp.RtpClient.TransportContext contextAvailable = rtpClient.GetTransportContexts().FirstOrDefault();

                System.Diagnostics.Debug.Assert(contextAvailable == null, "Found a Context when there was no Session or Media Description");

                using (contextAvailable = new Media.Rtp.RtpClient.TransportContext(0, 1, 0))
                {
                    //Usually indicated by the profile
                    bool padding = false, extension = false;

                    //Create a RtpPacket from the
                    using (var rtpPacket = new Media.Rtp.RtpPacket(contextAvailable.Version, padding, extension, null))
                    {
                        System.Diagnostics.Debug.Assert(rtpClient.SendRtpPacket(rtpPacket) == 0, "Sent a packet when there was no Session or Media Description or TransportContext");
                    }
                }
            }
        }
Ejemplo n.º 10
0
                public TestFramework()
                {
                    //  Create a receiving socket.
                    _receiving = new System.Net.Sockets.Socket(_rtspServer.AddressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

                    //  Connect to the server.
                    System.IAsyncResult connectResult = null;
                    connectResult = _receiving.BeginConnect(_rtspServer, new System.AsyncCallback((iar) =>
                    {
                        try { _receiving.EndConnect(iar); }
                        catch { }
                    }), null);

                    //  Get the sender socket to be used by the "server".
                    _sender = _listenSocket.Accept();

                    //  RtspClient default size
                    byte[] buffer = new byte[8192];

                    _client = new Media.Rtp.RtpClient(new Media.Common.MemorySegment(buffer, Media.Rtsp.RtspMessage.MaximumLength, buffer.Length - Media.Rtsp.RtspMessage.MaximumLength));
                    _client.InterleavedData += ProcessInterleaveData;
                    _client.RtpPacketReceieved += ProcessRtpPacket;

                    Media.Sdp.MediaDescription md = new Media.Sdp.MediaDescription(Media.Sdp.MediaType.video, 999, "H.264", 0);

                    Media.Rtp.RtpClient.TransportContext tc = new Media.Rtp.RtpClient.TransportContext(0, 1,
                        Media.RFC3550.Random32(9876), md, false, _senderSSRC);
                    //  Create a Duplexed reciever using the RtspClient socket.
                    tc.Initialize(_receiving, _receiving);

                    _client.TryAddContext(tc);
                }