Exemplo n.º 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }