Files
video-v1/vav1/Vav1Player/Container/Mp4Box.cs
2025-09-17 04:16:34 +09:00

54 lines
1.6 KiB
C#

using System.Text;
namespace Vav1Player.Container;
public struct Mp4Box
{
public uint Size { get; set; }
public string Type { get; set; }
public byte[] Data { get; set; }
public long Position { get; set; }
public Mp4Box(uint size, string type, byte[] data, long position)
{
Size = size;
Type = type;
Data = data;
Position = position;
}
public bool IsContainer => Type == "moov" || Type == "trak" || Type == "mdia" || Type == "minf" || Type == "stbl";
}
public static class Mp4Reader
{
public static uint ReadUInt32BigEndian(ReadOnlySpan<byte> buffer, int offset)
{
return ((uint)buffer[offset] << 24) |
((uint)buffer[offset + 1] << 16) |
((uint)buffer[offset + 2] << 8) |
buffer[offset + 3];
}
public static string ReadFourCC(ReadOnlySpan<byte> buffer, int offset)
{
return Encoding.ASCII.GetString(buffer.Slice(offset, 4));
}
public static ushort ReadUInt16BigEndian(ReadOnlySpan<byte> buffer, int offset)
{
return (ushort)(((ushort)buffer[offset] << 8) | buffer[offset + 1]);
}
public static ulong ReadUInt64BigEndian(ReadOnlySpan<byte> buffer, int offset)
{
return ((ulong)buffer[offset] << 56) |
((ulong)buffer[offset + 1] << 48) |
((ulong)buffer[offset + 2] << 40) |
((ulong)buffer[offset + 3] << 32) |
((ulong)buffer[offset + 4] << 24) |
((ulong)buffer[offset + 5] << 16) |
((ulong)buffer[offset + 6] << 8) |
buffer[offset + 7];
}
}