public List <Nalu> ToRTP(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); }
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; }
public static FuHeader Parse(byte data) { FuHeader fh = new FuHeader(); fh.IsStart = ((data & 0x80) >> 7) == 1; fh.IsEnd = ((data & 0x40) >> 6) == 1; fh.Type = (data & 0x1F); fh._data = data; return(fh); }
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; }
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); }
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); }
public static List <Nalu> ToRTPPayload(Nalu src) { List <Nalu> nList = new List <Nalu>(); if (src.TotalBytes < MTU) { nList.Add(src); } else { List <byte[]> slices = SplitPayload(src); NaluHeader indicator = new NaluHeader(false, src.Header.NRI, NaluTypes.FU_A); for (int i = 0; i < slices.Count; i++) { bool start = i == 0; bool end = i == slices.Count - 1; FuHeader fuh = new FuHeader(start, end, src.Header.Type); nList.Add(new FragUnitA(indicator, fuh, slices[i]).ToNalu()); } } return(nList); }