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) { onStreamBuffer(); return; } int start = 8 + buffer[8]; index = start + 1; int startcodeLength = getStreamStartCode(buffer, index); if (startcodeLength == 4 || startcodeLength == 3) { int nalu = buffer[index + startcodeLength]; int nal = nalu & 0x1F; if (nal == 7 || nal == 8)//对应序列参数集SPS和图像参数集PPS { onUnpacked(Nalu.Parse(subBytes(buffer, index))); return;// getStreamBuffer(); } } setStreamBuffer(buffer, index); return; }
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)); } }
void onStreamBuffer() { if (_ms == null) { return; } byte[] buf = _ms.ToArray(); _ms.Close(); _ms = null; if (buf.Length > 0) { Nalu nalu = Nalu.Parse(buf); onUnpacked(nalu); } }