GetBytes() public méthode

public GetBytes ( ) : byte[]
Résultat byte[]
        public void SendRtcpSenderReport(Socket srcRtpSocket, IPEndPoint dstRtpSocket, uint timestamp)
        {
            try
            {
                var ntp          = RTSPSession.DateTimeToNptTimestamp(DateTime.Now);
                var rtcpSRPacket = new RTCPPacket(Ssrc, ntp, timestamp, PacketsSent, OctetsSent);

                if (SrtcpProtect == null)
                {
                    srcRtpSocket.SendTo(rtcpSRPacket.GetBytes(), dstRtpSocket);
                }
                else
                {
                    var    rtcpSRBytes = rtcpSRPacket.GetBytes();
                    byte[] sendBuffer  = new byte[rtcpSRBytes.Length + SRTP_AUTH_KEY_LENGTH];
                    Buffer.BlockCopy(rtcpSRBytes, 0, sendBuffer, 0, rtcpSRBytes.Length);

                    int rtperr = SrtcpProtect(sendBuffer, sendBuffer.Length - SRTP_AUTH_KEY_LENGTH);
                    if (rtperr != 0)
                    {
                        logger.LogWarning("SRTP RTCP packet protection failed, result " + rtperr + ".");
                    }
                    else
                    {
                        srcRtpSocket.SendTo(sendBuffer, dstRtpSocket);
                    }
                }
            }
            catch (Exception excp)
            {
                logger.LogWarning("Exception SendRtcpSenderReport. " + excp.Message);
            }
        }
Exemple #2
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.");
            }
Exemple #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);
            }
        }
Exemple #4
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++;
                }
            }
Exemple #5
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.");
            }
Exemple #6
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++;
                }
            }
Exemple #7
0
        private void SendRtcpSenderReport(ulong ntpTimestamp, uint rtpTimestamp)
        {
            try
            {
                Console.WriteLine("Sending RTCP sender report to remote, ntp timestamp " + ntpTimestamp + ", rtp timestamp " + rtpTimestamp + ", packet count " + _senderPacketCount + ".");

                RTCPPacket senderReport = new RTCPPacket(_syncSource, ntpTimestamp, rtpTimestamp, _senderPacketCount, _senderOctetCount);
                var bytes = senderReport.GetBytes();

                _controlSocket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, _rtcpRemoteEndPoint, SendRtcpCallback, _controlSocket);

                _senderLastSentAt = DateTime.Now;
            }
            catch(Exception excp)
            {
                logger.Error("Exception SendRtcpSenderReport. " + excp);
            }
        }
        /// <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);
            }
        }