示例#1
0
        public static SampleSizeTable createVariable(Mp4Reader reader, int count)
        {
            // That's not a small amount of data, maybe a megabyte or 2. Bypassing the GC with malloc/free.
            IntPtr nativePointer = Marshal.AllocHGlobal(count * 4);

            try
            {
                Span <int> entries = Unsafe.writeSpan <int>(nativePointer, count);

                reader.read(entries.asBytes());
                ComputeUtils.flipEndiannessAndComputeMax(entries, out uint maxValue);

                if (maxValue > 0xFFFFFF)
                {
                    return(new SampleSizeVariable32(entries.ToArray(), (int)maxValue));
                }

                if (maxValue > 0xFFFF)
                {
                    return(new SampleSizeVariable24(entries, (int)maxValue));
                }

                return(new SampleSizeVariable16(entries, (int)maxValue));
            }
            finally
            {
                Marshal.FreeHGlobal(nativePointer);
            }
        }
示例#2
0
 public SampleSizeVariable8(Mp4Reader mp4, int count) : base(count)
 {
     Debug.Assert(mp4.currentBox == eBoxType.stz2);
     entries = new byte[count];
     mp4.read(entries.AsSpan());
     maxSampleSize = ComputeUtils.computeMax(entries.AsSpan());
 }
示例#3
0
 public SampleSizeVariable16(ReadOnlySpan <int> entries, int maxValue) :
     base(entries.Length)
 {
     this.entries = new ushort[entries.Length];
     ComputeUtils.packIntegers16(this.entries.AsSpan(), entries);
     maxSampleSize = maxValue;
 }
示例#4
0
 public SampleSizeVariable16(Mp4Reader mp4, int count) :
     base(count)
 {
     Debug.Assert(mp4.currentBox == eBoxType.stz2);
     entries = new ushort[count];
     mp4.read(entries.AsSpan().asBytes());
     maxSampleSize = ComputeUtils.swapEndiannessAndComputeMax(entries.AsSpan());
 }
示例#5
0
        public SampleSizeVariable24(ReadOnlySpan <int> entries, int maxValue) :
            base(entries.Length)
        {
            // For performance reasons we load 4 bytes, this way the indexer is just 2 instructions, load and bitwise and.
            // We don't want to crash reading the last element, that's why the "+1"
            int length = (entries.Length * 3) + 1;

            this.entries = new byte[length];
            ComputeUtils.packIntegers24(this.entries.AsSpan(), entries);
            maxSampleSize = maxValue;
        }
示例#6
0
        static CompositionTimeDeltas parseSigned(Span <CttsEntrySigned> source)
        {
            uint maxCount;
            int  maxOffset, minOffset;

            ComputeUtils.swapEndiannessAndComputeRange(source, out maxCount, out minOffset, out maxOffset);

            int index = countSize(maxCount);

            if (maxOffset < 0x80 && minOffset >= -0x80)
            {
                index |= 1;
            }
            else if (maxOffset < 0x8000 && minOffset >= -0x8000)
            {
                index |= 2;
            }
            else
            {
                index |= 4;
            }

            switch (index)
            {
            // byte count
            case 0x11: return(new Deltas <byte, byteCountTraits, sbyte, sbyteValueTraits>(source));

            case 0x12: return(new Deltas <byte, byteCountTraits, short, shortValueTraits>(source));

            case 0x14: return(new Deltas <byte, byteCountTraits, int, intValueTraits>(source));

            // ushort count
            case 0x21: return(new Deltas <ushort, ushortCountTraits, sbyte, sbyteValueTraits>(source));

            case 0x22: return(new Deltas <ushort, ushortCountTraits, short, shortValueTraits>(source));

            case 0x24: return(new Deltas <ushort, ushortCountTraits, int, intValueTraits>(source));

            // uint count
            case 0x41: return(new Deltas <uint, uintCountTraits, sbyte, sbyteValueTraits>(source));

            case 0x42: return(new Deltas <uint, uintCountTraits, short, shortValueTraits>(source));

            case 0x44: return(new Deltas <uint, uintCountTraits, int, intValueTraits>(source));
            }
            throw new ApplicationException();
        }