Esempio n. 1
0
        private void decodeE0(byte[] buffer, int index) //视频流
        {
            int length = readUshort(buffer, 4);         //PES packet length:16 位字段,指出了PES 分组中跟在该字段后的字节数目。值为0 表示PES 分组长度要么没有规定要么没有限制。这种情况只允许出现在有效负载包含来源于传输流分组中某个视频基本流的字节的PES 分组中。

            if (length != buffer.Length - 6)
            {
                return;
            }

            int start = 8 + buffer[8];

            index = start + 1;
            int startcodeLen = getStreamStartCode(buffer, index);

            if (startcodeLen == 4 || startcodeLen == 3)
            {
                Nalu nal = Nalu.Parse(BytesHelper.SubBytes(buffer, index + startcodeLen));
                //标记上一个包是一帧的结束。
                if (_lastFg != null)
                {
                    _lastFg.IsFrameEnd = true;
                    toFireUnpacked();
                }
                //因为有header值,因此此包是一帧开始
                _lastFg = new PSFragment(nal.Header, nal.Payload);
            }
            else
            {
                toFireUnpacked();
                _lastFg = new PSFragment(null, BytesHelper.SubBytes(buffer, index));
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private void decodeBA(byte[] buffer, int index)          //节目流包(PS header)
        {
            index += 6;                                          //系统时钟参考字段,系统时钟参考(SCR)是一个分两部分编码的42位字段。第一部分system_clock_reference_base是一个长度为33位的字段,其值SCR_base(i)由式2-19给出;第二部分system_clock_reference_extenstion是一个长度为9位的字段,其值SCR_ext(i)由式2-20给出。SCR字段指出了基本流中包含ESCR_base最后一位的字节到达节目目标解码器输入端的期望时间。
            index += 4;                                          //节目复合速率字段,一个22位整数,规定P-STD在包含该字段的包期间接收节目流的速率。其值以50字节/秒为单位。不允许取0值。该字段所表示的值用于在2.5.2中定义P-STD输入端的字节到达时间。该字段值在本标准中的节目多路复合流的不同包中取值可能不同。
            int pack_stuffing_length = buffer[index - 1] & 0x07; //包填充长度字段,3位整数,规定该字段后填充字节的个数。

            index += pack_stuffing_length;                       //跳过“填充字节”;
            if (index < buffer.Length)
            {
                byte[] sub = BytesHelper.SubBytes(buffer, index);
                UpdateStandardStream(sub);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private List <byte[]> SplitPayload(byte[] data)
        {
            List <byte[]> bList = new List <byte[]>();
            int           index = 0;
            int           len   = MTU - 1;

            while (index < data.Length)
            {
                if (index + len > data.Length)
                {
                    len = data.Length - index;
                }
                bList.Add(BytesHelper.SubBytes(data, index, len));
                index += len;
            }
            return(bList);
        }
Esempio n. 7
0
        private static List <byte[]> SplitPayload(Nalu src)
        {
            List <byte[]> bList = new List <byte[]>();
            int           index = 0;
            int           len   = MTU - 1;

            while (index < src.PayloadLen)
            {
                if (index + len > src.PayloadLen)
                {
                    len = src.PayloadLen - index;
                }
                bList.Add(BytesHelper.SubBytes(src.Payload, index, len));
                index += len;
            }
            return(bList);
        }