private void ProcessVideo(byte[] payload, byte[] spsPps, long pts, int widthSource, int heightSource) { int nalu_size = 0; while (nalu_size < payload.Length) { int nc_len = (payload[nalu_size + 3] & 0xFF) | ((payload[nalu_size + 2] & 0xFF) << 8) | ((payload[nalu_size + 1] & 0xFF) << 16) | ((payload[nalu_size] & 0xFF) << 24); if (nc_len > 0) { payload[nalu_size] = 0; payload[nalu_size + 1] = 0; payload[nalu_size + 2] = 0; payload[nalu_size + 3] = 1; nalu_size += nc_len + 4; } if (payload.Length - nc_len > 4) { return; } } if (spsPps.Length != 0) { var h264Data = new H264Data(); h264Data.FrameType = payload[4] & 0x1f; if (h264Data.FrameType == 5) { var payloadOut = (byte[])Array.CreateInstance(typeof(byte), payload.Length + spsPps.Length); Array.Copy(spsPps, 0, payloadOut, 0, spsPps.Length); Array.Copy(payload, 0, payloadOut, spsPps.Length, payload.Length); h264Data.Data = payloadOut; h264Data.Length = payload.Length + spsPps.Length; // Release payload payload = null; } else { h264Data.Data = payload; h264Data.Length = payload.Length; } h264Data.Pts = pts; h264Data.Width = widthSource; h264Data.Height = heightSource; _receiver.OnData(h264Data); } }
public void OnData(H264Data data) { OnH264DataReceived?.Invoke(this, data); }