Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取时间戳rtp数据包_C#_Timestamp_Rtp - Fatal编程技术网

C# 获取时间戳rtp数据包

C# 获取时间戳rtp数据包,c#,timestamp,rtp,C#,Timestamp,Rtp,我正在使用PacketDotNet从RTP报头检索数据。但有时时间戳是负值 GetTimeStamp(UdpPacket packetUdp) { byte[] packet = packetUdp.PayloadData; long timestamp = GetRTPHeaderValue(packet, 32, 63); return timestamp; } private static int GetRTPHeaderValue(

我正在使用PacketDotNet从RTP报头检索数据。但有时时间戳是负值

GetTimeStamp(UdpPacket packetUdp)
{

        byte[] packet = packetUdp.PayloadData;
        long timestamp =  GetRTPHeaderValue(packet, 32, 63);
        return timestamp;

}

private static int GetRTPHeaderValue(byte[] packet, int startBit, int endBit)
    {
        int result = 0;

        // Number of bits in value
        int length = endBit - startBit + 1;

        // Values in RTP header are big endian, so need to do these conversions
        for (int i = startBit; i <= endBit; i++)
        {
            int byteIndex = i / 8;
            int bitShift = 7 - (i % 8);
            result += ((packet[byteIndex] >> bitShift) & 1) *
                      (int)Math.Pow(2, length - i + startBit - 1);
        }
       return result;
    }
GetTimeStamp(udppacketpacketudp)
{
byte[]packet=packetUdp.PayloadData;
长时间戳=GetRTPHeaderValue(数据包,32,63);
返回时间戳;
}
私有静态int GetRTPHeaderValue(字节[]数据包,int startBit,int endBit)
{
int结果=0;
//值中的位数
int length=endBit-startBit+1;
//RTP头中的值是大端的,所以需要进行这些转换
对于(int i=startBit;i>bitShift)&1)*
(int)数学功率(2,长度-i+startBit-1);
}
返回结果;
}

这可能是由RTCP数据包引起的。如果RTP数据来自手机,则手机会定期发送RTCP报告。它们似乎每隔200包就出现一次。格式不同,您的代码可能以相同的方式读取-您需要处理RTCP数据包


数据包格式:

HI@Conrad de Wet本例中的问题是,我在变量结果中是整数,要切换到“long”类型,问题已解决:)