Exemplo n.º 1
0
        private void RestoreTables()
        {
            uint lastRealChunkNumber = STCO.EntryCount + 1;

            ChunksToSamples = new ChunkToSample[STCO.EntryCount];
            var items = STSC.Items;

            for (int i = items.Length - 1; i >= 0; i--)
            {
                var  item = STSC.Items[i];
                uint begRealChunkNumer = item.FirstChunk;
                for (uint chki = begRealChunkNumer - 1; chki < lastRealChunkNumber - 1; ++chki)
                {
                    ChunksToSamples[chki] = new ChunkToSample()
                    {
                        SamplesCount           = item.SamplesPerChunk,
                        SampleDescriptionIndex = item.SampleDescriptionIndex
                    };
                }
                lastRealChunkNumber = begRealChunkNumer;
            }
            UInt32 sampleIndex = 0;

            SampleEntries = new SampleEntry[STSZ.SampleCount];
            for (uint i = 0; i < ChunksToSamples.Length; i++)
            {
                ChunksToSamples[i].FirstSampleIndex = sampleIndex;
                UInt32 indexInChunk = 0;
                for (uint sami = 0; sami != ChunksToSamples[i].SamplesCount; sami++)
                {
                    SampleEntries[sampleIndex] = new SampleEntry()
                    {
                        ChunkIndex   = i,
                        IndexInChunk = indexInChunk,
                    };
                    sampleIndex++;
                    indexInChunk++;
                }
            }
        }
Exemplo n.º 2
0
        static                                SampleEntry[] parseSampleTable(Mp4Reader reader)
        {
            Debug.Assert(reader.currentBox == eBoxType.stsd);

            Span <byte> span = stackalloc byte[8];

            reader.read(span);

            int entryCount = BitConverter.ToInt32(span.Slice(4)).endian();

            SampleEntry[] result = new SampleEntry[entryCount];
            for (int i = 0; i < entryCount; i++)
            {
                reader.read(span);
                int  length = BitConverter.ToInt32(span).endian();
                uint code   = BitConverter.ToUInt32(span.Slice(4));
                switch (code)
                {
                case (uint)eFileType.avc1:
                    result[i] = new AVC1SampleEntry(reader, length - 8);
                    break;

                case (uint)eAudioBoxType.mp4a:
                    result[i] = new MP4AudioSampleEntry(reader, length - 8);
                    break;

                case (uint)eAudioBoxType.ac3:
                    result[i] = new Ac3AudioSampleEntry(reader, length - 8);
                    break;

                default:
                    throw new NotImplementedException("The sample format is not currently supported");
                }
            }
            return(result);
        }