Пример #1
0
        public List <Nalu> ToRTPPayload(PSFragment ps)
        {
            if (ps.IsFrameStart)
            {
                _header = ps.Header;
            }
            if (_header == null)
            {
                return(new List <Nalu>());
            }

            List <Nalu> nList = new List <Nalu>();

            if (ps.Data.Length < MTU && ps.IsFrameStart && ps.IsFrameEnd)
            {
                nList.Add(new Nalu(_header, ps.Data));
            }
            else
            {
                List <byte[]> slices    = SplitPayload(ps.Data);
                NaluHeader    indicator = new NaluHeader(false, _header.NRI, NaluTypes.FU_A);
                for (int i = 0; i < slices.Count; i++)
                {
                    bool     start = (i == 0) && ps.IsFrameStart;
                    bool     end   = (i == slices.Count - 1 && ps.IsFrameEnd);
                    FuHeader fuh   = new FuHeader(start, end, _header.Type);
                    nList.Add(new FragUnitA(indicator, fuh, slices[i]).ToNalu());
                }
            }
            return(nList);
        }
Пример #2
0
        public static NaluHeader Parse(byte data)
        {
            NaluHeader a = new NaluHeader();

            a.Forbidden = ((data & 0x80) >> 7) == 1;
            a.NRI       = (data & 0x60) >> 5;
            a.Type      = (data & 0x1F);
            a._data     = data;
            return(a);
        }
Пример #3
0
 public FragUnitA(NaluHeader indicator, FuHeader header, byte[] payload)
 {
     Indicator = indicator;
     if (indicator.Type != NALU_TYPE)
     {
         throw new ArgumentException($"FU-B封包的指示字节的类型必须是{NALU_TYPE}", nameof(indicator));
     }
     Header  = header;
     Payload = payload;
 }
Пример #4
0
 public FragUnitB(NaluHeader indicator, FuHeader header, short don, byte[] payload)
 {
     if (indicator.Type != NALU_TYPE)
     {
         throw new ArgumentException($"FU-B封包的指示字节的类型必须是{NALU_TYPE}", nameof(indicator));
     }
     Indicator = indicator;
     Header    = header;
     Don       = don;
     Payload   = payload;
 }
Пример #5
0
        public static Nalu Parse(byte[] data)
        {
            int sIndex = getStartCodeLen(data);

            byte[] ndata = BytesHelper.SubBytes(data, sIndex);
            Nalu   a     = new Nalu();

            a.Header  = NaluHeader.Parse(ndata[0]);
            a.Payload = BytesHelper.SubBytes(ndata, 1);
            return(a);
        }
Пример #6
0
        public static FragUnitA Parse(byte[] data)
        {
            FragUnitA fu = new FragUnitA();

            fu.Indicator = NaluHeader.Parse(data[0]);
            if (fu.Indicator.Type != NALU_TYPE)
            {
                throw new ArgumentException($"FU-B封包的指示字节的类型必须是{NALU_TYPE},当前类型是:" + fu.Indicator.Type);
            }
            fu.Header  = FuHeader.Parse(data[1]);
            fu.Payload = BytesHelper.SubBytes(data, 2);
            return(fu);
        }
Пример #7
0
        public static FragUnitB Parse(byte[] data)
        {
            FragUnitB fu = new FragUnitB();

            fu.Indicator = NaluHeader.Parse(data[0]);
            if (fu.Indicator.Type != NALU_TYPE)
            {
                throw new ArgumentException($"FU-B封包的指示字节的类型必须是{NALU_TYPE},当前类型是:" + fu.Indicator.Type);
            }
            fu.Header = FuHeader.Parse(data[1]);
            //TODO:我们暂时认为所有的字节序均为BigEndian,如果传输失败,再做改正。
            byte[] donBytes = new byte[] { data[3], data[2] };
            fu.Don     = BitConverter.ToInt16(donBytes, 0);
            fu.Payload = BytesHelper.SubBytes(data, 4);
            return(fu);
        }
Пример #8
0
 public PSFragment(NaluHeader header, byte[] data)
 {
     Header = header;
     Data   = data;
 }
Пример #9
0
 public Nalu(NaluHeader header, byte[] payload)
 {
     Header  = header;
     Payload = payload;
     buildData();
 }