From a3afe7c152a9ccdf64bc6a706a2f8321df9dbafc Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 21 Dec 2023 08:20:41 -0500 Subject: [PATCH] correct RTP offset error; add helper routines; --- FneUtils.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++ RtpHeader.cs | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/FneUtils.cs b/FneUtils.cs index c4e465d..bdef8cb 100644 --- a/FneUtils.cs +++ b/FneUtils.cs @@ -21,6 +21,7 @@ */ using System; +using System.Linq; using System.Security.Cryptography; using System.Reflection; using System.Reflection.Emit; @@ -59,6 +60,49 @@ namespace fnecore memsetDelegate = (Action)dynamicMethod.CreateDelegate(typeof(Action)); } + /// + /// + /// + /// + /// + public static ushort DoReverseEndian(ushort x) + { + //return Convert.ToUInt16((x << 8 & 0xff00) | (x >> 8)); + return BitConverter.ToUInt16(BitConverter.GetBytes(x).Reverse().ToArray(), 0); + } + + /// + /// + /// + /// + /// + public static uint DoReverseEndian(uint x) + { + //return (x << 24 | (x & 0xff00) << 8 | (x & 0xff0000) >> 8 | x >> 24); + return BitConverter.ToUInt32(BitConverter.GetBytes(x).Reverse().ToArray(), 0); + } + + /// + /// + /// + /// + /// + public static ulong DoReverseEndian(ulong x) + { + //return (x << 56 | (x & 0xff00) << 40 | (x & 0xff0000) << 24 | (x & 0xff000000) << 8 | (x & 0xff00000000) >> 8 | (x & 0xff0000000000) >> 24 | (x & 0xff000000000000) >> 40 | x >> 56); + return BitConverter.ToUInt64(BitConverter.GetBytes(x).Reverse().ToArray(), 0); + } + + /// + /// + /// + /// + /// + public static int DoReverseEndian(int x) + { + return BitConverter.ToInt32(BitConverter.GetBytes(x).Reverse().ToArray(), 0); + } + /// /// /// diff --git a/RtpHeader.cs b/RtpHeader.cs index 5eee816..6c2d0e6 100644 --- a/RtpHeader.cs +++ b/RtpHeader.cs @@ -129,7 +129,7 @@ namespace fnecore Sequence = (ushort)((data[2] << 8) | (data[3] << 0)); // Sequence Timestamp = FneUtils.ToUInt32(data, 4); // Timestamp - SSRC = FneUtils.ToUInt32(data, 6); // Synchronization Source ID + SSRC = FneUtils.ToUInt32(data, 8); // Synchronization Source ID return true; }