static T[] readArray <T>(Mp4Reader reader) where T : unmanaged { sHeader header = reader.readStructure <sHeader>(); int count = header.entry_count.endian(); return(readArray <T>(reader, count)); }
public static ChunkOffsetTable readOffsets32(Mp4Reader reader) { Debug.Assert(reader.currentBox == eBoxType.stco); sHeader header = reader.readStructure <sHeader>(); int count = header.entry_count.endian(); uint[] entries = readArray <uint>(reader, count); return(new ChunkOffsetTable32(entries)); }
internal static CompositionTimeDeltas read(Mp4Reader reader) { Debug.Assert(reader.currentBox == eBoxType.ctts); sHeader header = reader.readStructure <sHeader>(); int count = header.entry_count.endian(); if (count <= 0) { return(null); } bool signedIntegers; switch (header.version) { case 0: signedIntegers = false; break; case 1: signedIntegers = true; break; default: // Warning because videos actually play OK even when ignoring the data from that box. Logger.logWarning("ctts box has unexpected version {0}", header.version); return(null); } // That thing takes couple MB of RAM. Bypassing the GC with malloc/free. IntPtr nativePointer = Marshal.AllocHGlobal(count * 8); try { Span <CttsEntryUnsigned> span = Unsafe.writeSpan <CttsEntryUnsigned>(nativePointer, count); reader.read(span.asBytes()); if (signedIntegers) { var signed = MemoryMarshal.Cast <CttsEntryUnsigned, CttsEntrySigned>(span); return(parseSigned(signed)); } return(parseUnsigned(span)); } finally { Marshal.FreeHGlobal(nativePointer); } }
public static ChunkOffsetTable readOffsets64(Mp4Reader reader) { Debug.Assert(reader.currentBox == eBoxType.co64); sHeader header = reader.readStructure <sHeader>(); int count = header.entry_count.endian(); long[] entries = new long[count]; reader.read(entries.AsSpan().asBytes()); for (int i = 0; i < entries.Length; i++) { entries[i] = entries[i].endian(); } return(new ChunkOffsetTable64(entries)); }
public ZipFile(Stream strm,bool read) { _strm = strm; if (read) _bw = new BinaryWriter(new GZipStream(_strm, CompressionMode.Compress, true)); else { _br = new BinaryReader(new GZipStream(_strm, CompressionMode.Decompress, true)); _files = new Dictionary<string, byte[]>(); while (_br.BaseStream.Position < _br.BaseStream.Length) { sHeader head = new sHeader(_br.ReadBytes(512)); _files.Add(head.Name, _br.ReadBytes((int)head.Size)); } } }