예제 #1
0
            public void RTCPHeaderRoundTripTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                RTCPPacket src = new RTCPPacket(12, 122, 561, 6756, 56434);

                byte[]     reports      = new byte[84];
                byte[]     packetBuffer = src.GetBytes(reports);
                RTCPPacket dst          = new RTCPPacket(packetBuffer);

                Console.WriteLine("SenderSyncSource: " + src.SenderSyncSource + ", " + dst.SenderSyncSource);
                Console.WriteLine("NTPTimestamp: " + src.NTPTimestamp + ", " + dst.NTPTimestamp);
                Console.WriteLine("RTPTimestamp: " + src.RTPTimestamp + ", " + dst.RTPTimestamp);
                Console.WriteLine("SenderPacketCount: " + src.SenderPacketCount + ", " + dst.SenderPacketCount);
                Console.WriteLine("SenderOctetCount: " + src.SenderOctetCount + ", " + dst.SenderOctetCount);
                Console.WriteLine("Reports Length: " + src.Reports.Length + ", " + dst.Reports.Length);

                //Console.WriteLine("Raw Header: " + System.Text.Encoding.ASCII.GetString(headerBuffer, 0, headerBuffer.Length));

                Assert.IsTrue(src.SenderSyncSource == dst.SenderSyncSource, "SenderSyncSource was mismatched.");
                Assert.IsTrue(src.NTPTimestamp == dst.NTPTimestamp, "NTPTimestamp was mismatched.");
                Assert.IsTrue(src.RTPTimestamp == dst.RTPTimestamp, "RTPTimestamp was mismatched.");
                Assert.IsTrue(src.SenderPacketCount == dst.SenderPacketCount, "SenderPacketCount was mismatched.");
                Assert.IsTrue(src.SenderOctetCount == dst.SenderOctetCount, "SenderOctetCount was mismatched.");
                Assert.IsTrue(src.Reports.Length == dst.Reports.Length, "Reports length was mismatched.");
            }
예제 #2
0
            public void GetRTCPPacketTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                RTCPPacket rtcpPacket = new RTCPPacket(1, 1, 1, 1, 1);

                byte[] reports      = new byte[84];
                byte[] packetBuffer = rtcpPacket.GetBytes(reports);

                int byteNum = 1;

                foreach (byte packetByte in packetBuffer)
                {
                    Console.WriteLine(byteNum + ": " + packetByte.ToString("x"));
                    byteNum++;
                }
            }
예제 #3
0
        /// <summary>
        /// Sends an RTCP report to the remote agent.
        /// </summary>
        /// <param name="rtcpReport"></param>
        public void SendRTCPReport(RTCPReportTypesEnum reportType, byte[] reportData)
        {
            try
            {
                RTCPPacket rtcpPacket = new RTCPPacket(0, 0, 0, 0, 0);

                RTCPReportPacket rtcpReportPacket      = new RTCPReportPacket(reportType, reportData);
                byte[]           rtcpReportPacketBytes = rtcpReportPacket.GetBytes();
                byte[]           rtcpReportBytes       = rtcpPacket.GetBytes(rtcpReportPacketBytes);

                m_udpListener.Send(rtcpReportBytes, rtcpReportBytes.Length, m_streamEndPoint);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SendRTCPReport. " + excp.Message);
            }
        }
예제 #4
0
        private void RTCPReceive()
        {
            Thread.CurrentThread.Name = "rtpchanrecv-" + _rtpPort;

            byte[] buffer = new byte[1024];

            DateTime packetTimestamp = DateTime.Now;

            try
            {
                EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                while (IsRunning)
                {
                    if (_controlSocket == null || _controlSocket.Available == 0)
                    {
                        Thread.Sleep(50);
                        continue;
                    }
                    int bytesRead = _controlSocket.ReceiveFrom(buffer, ref remoteEndPoint);
                    if (bytesRead > 0)
                    {
                        _rtcpTimestamp = DateTimeToNptTimestamp90K(DateTime.Now);
                        RTCPPacket senderReport = new RTCPPacket(_syncSource, DateTimeToNptTimestamp(packetTimestamp), _rtcpTimestamp, 0, 0);
                        byte[]     rtcpPacket   = senderReport.GetBytes();
                        _controlSocket.SendTo(rtcpPacket, 0, rtcpPacket.Length, SocketFlags.None, remoteEndPoint);
                    }
                    Thread.Sleep(5);
                }
            }
            catch (SocketException)
            {
            }
            catch (Exception ex)
            {
                logger.Error("Exception RTCPChannel.ControlSocketReceive. " + ex);
            }
        }