public Mp4BoxSampleTable(Mp4ContainerBox stbl, Mp4Stream sampleStream)
 {
     this.SampleStream = sampleStream;
     this.StscAtom     = stbl.GetChild <Mp4StscBox>(Mp4BoxType.STSC);
     this.StcoAtom     = stbl.GetChild <Mp4StcoBox>(Mp4BoxType.STCO);
     this.StszAtom     = stbl.GetChild <Mp4StszBox>(Mp4BoxType.STSZ);
     this.SttsAtom     = stbl.GetChild <Mp4SttsBox>(Mp4BoxType.STTS);
     this.CttsAtom     = stbl.GetChild <Mp4CttsBox>(Mp4BoxType.CTTS);
     this.StsdAtom     = stbl.GetChild <Mp4StsdBox>(Mp4BoxType.STSD);
     this.StssAtom     = stbl.GetChild <Mp4StssBox>(Mp4BoxType.STSS);
     this.Co64Atom     = stbl.GetChild <Mp4Co64Box>(Mp4BoxType.CO64);
 }
Exemple #2
0
        public Mp4Track(Mp4TrakBox box, Mp4Stream stream, uint movieTimeScale)
        {
            this.TrakBox = box;
            Mp4HdlrBox box2 = box.FindChild <Mp4HdlrBox>("mdia/hdlr");

            if (box2 != null)
            {
                uint handlerType = box2.HandlerType;
                if (handlerType == Mp4HandlerType.SOUN)
                {
                    this.Type = Mp4TrackType.AUDIO;
                }
                else if (handlerType == Mp4HandlerType.VIDE)
                {
                    this.Type = Mp4TrackType.VIDEO;
                }
                else if (handlerType == Mp4HandlerType.HINT)
                {
                    this.Type = Mp4TrackType.HINT;
                }
                else if ((handlerType == Mp4HandlerType.ODSM) || (handlerType == Mp4HandlerType.SDSM))
                {
                    this.Type = Mp4TrackType.SYSTEM;
                }
                else if ((handlerType == Mp4HandlerType.TEXT) || (handlerType == Mp4HandlerType.TX3G))
                {
                    this.Type = Mp4TrackType.TEXT;
                }
                else if (handlerType == Mp4HandlerType.JPEG)
                {
                    this.Type = Mp4TrackType.JPEG;
                }
            }
            Mp4ContainerBox stbl = box.FindChild <Mp4ContainerBox>("mdia/minf/stbl");

            if (stbl != null)
            {
                this.SampleTable = new Mp4BoxSampleTable(stbl, stream);
            }
        }
Exemple #3
0
        public Mp4TrakBox(Mp4SampleTable sampleTable, uint hdlrType, string hdlrName, uint trackId, DateTime creationTime, DateTime modificationTime, ulong trackDuration, uint mediaTimeScale, ulong mediaDuration, ushort volume, string language, uint width, uint height) : base(8, Mp4BoxType.TRAK)
        {
            Mp4Box box4;

            this.TkhdBox = new Mp4TkhdBox(creationTime, modificationTime, trackId, trackDuration, volume, width, height);
            Mp4MdiaBox      child = new Mp4MdiaBox();
            Mp4HdlrBox      box2  = new Mp4HdlrBox(hdlrType, hdlrName);
            Mp4ContainerBox box3  = new Mp4ContainerBox(8, Mp4BoxType.MINF);

            if (hdlrType == Mp4HandlerType.VIDE)
            {
                box4 = new Mp4VmhdBox(0, 0, 0, 0);
            }
            else if (hdlrType == Mp4HandlerType.SOUN)
            {
                box4 = new Mp4SmhdBox(0);
            }
            else
            {
                box4 = new Mp4NmhdBox();
            }
            Mp4ContainerBox box5 = new Mp4ContainerBox(8, Mp4BoxType.DINF);
            Mp4Box          box6 = new Mp4UrlBox();
            Mp4DrefBox      box7 = new Mp4DrefBox(new Mp4Box[] { box6 });
            Mp4ContainerBox box8 = sampleTable?.GenerateStblAtom();

            box5.AddChild(box7);
            box3.AddChild(box4);
            box3.AddChild(box5);
            if (box8 != null)
            {
                box3.AddChild(box8);
            }
            this.MdhdBox = new Mp4MdhdBox(creationTime, modificationTime, mediaTimeScale, mediaDuration, language);
            child.AddChild(this.MdhdBox);
            child.AddChild(box2);
            child.AddChild(box3);
            base.AddChild(this.TkhdBox);
            base.AddChild(child);
        }
Exemple #4
0
        public virtual Mp4ContainerBox GenerateStblAtom()
        {
            Mp4ContainerBox box              = new Mp4ContainerBox(8, Mp4BoxType.STBL);
            Mp4StsdBox      child            = new Mp4StsdBox(this);
            Mp4StszBox      box3             = new Mp4StszBox();
            Mp4StscBox      box4             = new Mp4StscBox();
            Mp4SttsBox      box5             = new Mp4SttsBox();
            Mp4StssBox      box6             = new Mp4StssBox();
            Mp4CttsBox      box7             = null;
            uint            num              = 0;
            uint            num2             = 0;
            ulong           item             = 0L;
            uint            samplesPerChunk  = 0;
            uint            descriptionIndex = 0;
            uint            sampleDelta      = 0;
            uint            sampleCount      = 0;
            uint            sampleOffset     = 0;
            uint            num9             = 0;
            List <ulong>    list             = new List <ulong>();
            bool            flag             = false;
            int             num10            = this.SampleCount;

            for (int i = 0; i < num10; i++)
            {
                Mp4Sample sample   = this.GetSample(i);
                uint      duration = sample.Duration;
                if ((duration != sampleDelta) && (sampleCount != 0))
                {
                    box5.Entries.Add(new Mp4SttsEntry(sampleCount, sampleDelta));
                    sampleCount = 0;
                }
                sampleCount++;
                sampleDelta = duration;
                uint ctsDelta = sample.CtsDelta;
                if ((ctsDelta != sampleOffset) && (num9 != 0))
                {
                    if (box7 == null)
                    {
                        box7 = new Mp4CttsBox();
                    }
                    box7.Entries.Add(new Mp4CttsEntry(num9, sampleOffset));
                    num9 = 0;
                }
                num9++;
                sampleOffset     = ctsDelta;
                descriptionIndex = sample.DescriptionIndex;
                box3.Entries.Add((uint)sample.Size);
                if (sample.IsSync)
                {
                    box6.Entries.Add((uint)(i + 1));
                    if (i == 0)
                    {
                        flag = true;
                    }
                }
                else
                {
                    flag = false;
                }
                uint chunkIndex      = 0;
                uint positionInChunk = 0;
                this.GetSampleChunkPosition((uint)i, out chunkIndex, out positionInChunk);
                if ((chunkIndex != num) && (samplesPerChunk != 0))
                {
                    list.Add(item);
                    item += num2;
                    box4.Entries.Add(new Mp4StscEntry(1, samplesPerChunk, descriptionIndex + 1));
                    samplesPerChunk = 0;
                    num2            = 0;
                }
                num   = chunkIndex;
                num2 += (uint)sample.Size;
                samplesPerChunk++;
            }
            box5.Entries.Add(new Mp4SttsEntry(sampleCount, sampleDelta));
            if (box7 != null)
            {
                if (num9 == 0)
                {
                    throw new Exception("ASSERT(current_cts_delta_run != 0)");
                }
                box7.Entries.Add(new Mp4CttsEntry(num9, sampleOffset));
            }
            if (samplesPerChunk != 0)
            {
                list.Add(item);
                box4.Entries.Add(new Mp4StscEntry(1, samplesPerChunk, descriptionIndex + 1));
            }
            box.AddChild(child);
            box.AddChild(box3);
            box.AddChild(box4);
            box.AddChild(box5);
            if (box7 != null)
            {
                box.AddChild(box7);
            }
            if (!flag && (box6.Entries.Count != 0))
            {
                box.AddChild(box6);
            }
            uint count = (uint)list.Count;

            if (item <= 0xffffffffL)
            {
                uint[] entries = new uint[count];
                for (uint j = 0; j < count; j++)
                {
                    entries[j] = (uint)list[(int)j];
                }
                Mp4StcoBox box8 = new Mp4StcoBox(entries);
                box.AddChild(box8);
                return(box);
            }
            Mp4Co64Box box9 = new Mp4Co64Box(list.ToArray());

            box.AddChild(box9);
            return(box);
        }