private static IDataPacket ProducePlayableExport(IResultNode result, IDataPacket h264StartCodePrefixDataPacket) { if (result.DataFormat != CodecID.H264) { return(result); } if (result.FindAttributeByName("StartCodePrefix") != null) { return(result); } string nalUnitType = result.FindAttributeByName("NalUnitType").ValueAsString; int lengthPrefixBytes = ((nalUnitType == "7") || (nalUnitType == "8")) ? 2 : 4; return(h264StartCodePrefixDataPacket.Append(result.GetSubPacket(lengthPrefixBytes, (result.Length - lengthPrefixBytes)))); }
private long TrimResult() { if (_lastHeader == null) { return(0L); } // Trim zero byte stuffing from last header (if any) string zeroByteStuffingName = Enum.GetName(typeof(NalUnitParser.Attribute), NalUnitParser.Attribute.TrailingZeroBytes); var zeroByteStuffingAttribute = _lastHeader.FindAttributeByName(zeroByteStuffingName); if (zeroByteStuffingAttribute == null) { return(0L); } uint byteCount = (uint)zeroByteStuffingAttribute.Value; // Rebuild the last header, omitting the zero byte stuffing attribute var resultNodeBuilder = new ResultNodeBuilder { Name = _lastHeader.Name, Metadata = _lastHeader, DataPacket = _lastHeader.GetSubPacket(0, (_lastHeader.Length - byteCount)) }; foreach (IResultAttribute attribute in _lastHeader.Attributes.Where(a => a.Name != zeroByteStuffingName)) { resultNodeBuilder.AddAttribute(attribute); } // Replace the last header with the new (trimmed) header IResultNode parent = _lastHeader.Parent; parent.RemoveChild(_lastHeader); parent.AddChild(resultNodeBuilder.Build()); // Compensate end offset for zero byte trimming return(-byteCount); }
public IDataPacket GetSubPacket(long offset, long length) { return(_result.GetSubPacket(offset, length)); }