Esempio n. 1
0
        public void loop()
        {
            bool done = false;

            try
            {
                while (!done)
                {
                    byte[] bytes = listener.Receive(ref inPoint);
                    //Console.WriteLine("Received Multicast from  {0} : length {1}\n", listenAddress.ToString(), bytes.Length);
                    //Lets get to buisness now
                    rtp _rtp = new rtp(bytes, bytes.Length);

                    if (_rtp.RTP_verify())
                    {
                        //_rtp.RTP_check();
                        byte[] RTPPayload = _rtp.RTP_process();

                        TCPServer _tcp = new TCPServer("192.168.88.12", 1234, RTPPayload);



                        //Console.WriteLine("RTP Packet Length: " + bytes.Length);
                        //Console.WriteLine("RTP Payload Length: " + RTPPayload.Length);
                    }
                    //Lets get to buisness now
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                listener.Close();
                //sender.Close();
            }
        }
Esempio n. 2
0
        const byte P_MPGTS = 0x21;    /* MPEG TS    */


        public bool RTP_check()
        {
            //int error = 9;
            rtp _rtp = new rtp();

            /* check if the buffer is an RTP packet
             *
             * @param buf       buffer to analyze
             * @len             size of the buffer
             * @param is_rtp    variable to set to 1 if data is an RTP packet
             *
             * @return True if there was no error, False otherwise
             */

            int rtp_version      = 0;
            int rtp_payload_type = 0;

            if (len < RTP_MIN_SIZE)
            {
                Console.WriteLine("RTP_check: buffer size {0} is less than minimum {1}\n", (long)len, (long)RTP_MIN_SIZE);
                return(false);
            }
            /* initial assumption: is NOT RTP */
            _rtp.is_rtp = 0;

            if (MPEG_TS_SIG == buf[0])
            {
                Console.WriteLine("MPEG-TS stream detected\n");
                return(true);
            }

            rtp_version = (buf[0] & 0xC0) >> 6;
            Debug.WriteLine("RTP Version: " + rtp_version);
            if (RTP_VER2 != rtp_version)
            {
                Console.WriteLine("RTP_check: wrong RTP version {0} must be {1}\n", (int)rtp_version, (int)RTP_VER2);
                return(false);
            }

            if (len < RTP_HDR_SIZE)
            {
                Console.WriteLine("RTP_check: header size is too small {0}\n", (long)len);
                return(false);
            }

            _rtp.is_rtp = 1;

            rtp_payload_type = (buf[1] & 0x7F);
            Debug.WriteLine("RTP Payload Type: " + rtp_payload_type);
            switch (rtp_payload_type)
            {
            case P_MPGA:
                Console.WriteLine("RTP_check: {0} MPEG audio stream\n", (int)rtp_payload_type);
                break;

            case P_MPGV:
                Console.WriteLine("RTP_check: {0} MPEG video stream\n", (int)rtp_payload_type);
                break;

            case P_MPGTS:
                Console.WriteLine("RTP_check: {0} MPEG TS stream\n", (int)rtp_payload_type);
                break;

            default:
                Console.WriteLine("RTP_check: unsupported RTP payload type {0}\n", (int)rtp_payload_type);
                return(false);
            }
            return(true);
        }