Beispiel #1
0
        void ReadMP4Headers()
        {
            BoxType boxType;

              while (this.boxReader.BaseStream.Position < this.boxReader.BaseStream.Length)
              {

            boxType = this.boxReader.PeekNextBoxType();
            if (boxType == BoxTypes.Free)
            {
              FreeBox freeb = new FreeBox();
              freeb.Read(this.boxReader);
              //FreeBoxList.Add(freeb);
            }
            else if (boxType == BoxTypes.MediaData) // mdat
            {
              MediaDataBox mdb = new MediaDataBox();
              mdb.Read(this.boxReader);  // this doesn't really read all of mdat: payload is skipped
              MediaDataBoxList.Add(mdb);
            }
            else if (boxType == BoxTypes.MovieFragmentRandomAccess)
            {
              MovieFragmentRandomAccessBox mfrab = new MovieFragmentRandomAccessBox();
              mfrab.Read(this.boxReader);
            }
            else if (boxType == BoxTypes.Free)
            {
              FreeBox freeBox = new FreeBox();
              freeBox.Read(this.boxReader);
            }
            else
            {
              // invalid box, just stop reading
              break;
              //Box box2 = new Box(boxType);
              //box2.Read(this.boxReader);
              //FreeBoxList.Add(box2);
              //Debug.WriteLine(string.Format("Unknown BoxType: {0}", box2.Type.ToString()));
            }
              } // end of while
        }
Beispiel #2
0
        public override void LazyRead(int requestedBoxCount)
        {
            //this.m_reader.BaseStream.Seek(0L, SeekOrigin.Begin);

            BoxType boxType;

            while (this.m_reader.BaseStream.Position < this.m_reader.BaseStream.Length)
            {
                boxType = this.m_reader.PeekNextBoxType();
                if (boxType == BoxTypes.MovieFragment)
                {
                    IsMediaStreamFragmented = true;
                    break; // don't process fragment here, do it in the ISMV class (which is derived from this one)
                }
                else if (boxType == BoxTypes.FileType)
                {
                    ftb = new FileTypeBox();
                    ftb.Read(this.m_reader);
                    Hints.CompatibleBrands = ftb.CompatibleBrands;
                }
                else if (boxType == BoxTypes.Movie)
                {
                    mmb = new MovieMetadataBox();
                    mmb.Read(this.m_reader);
                    if (mmb.ObjectDescriptorBox != null)
                    {
                        base.ObjectDescriptor = mmb.ObjectDescriptorBox.Contents;
                    }
                    if (mmb.UserDataBox != null)
                    {
                        base.UserData = mmb.UserDataBox.Data;
                    }
                }
                else if (boxType == BoxTypes.Free)
                {
                    FreeBox freeb = new FreeBox();
                    freeb.Read(this.m_reader);
                    FreeBoxList.Add(freeb);
                }
                else if (boxType == BoxTypes.MediaData) // mdat
                {
                    MediaDataBox mdb = new MediaDataBox();
                    mdb.Read(this.m_reader); // this doesn't really read all of mdat: payload is skipped
                    MediaDataBoxList.Add(mdb);
                }
                else if (boxType == BoxTypes.MovieFragmentRandomAccess)
                {
                    MovieFragmentRandomAccessBox = new MovieFragmentRandomAccessBox();
                    MovieFragmentRandomAccessBox.Read(this.m_reader);
                }
                else if (boxType == BoxTypes.Free)
                {
                    FreeBox freeBox = new FreeBox();
                    freeBox.Read(this.m_reader);
                    FreeBoxList.Add(freeBox);
                }
                else
                {
                    // invalid box, just stop reading
                    break;
                    //Box box2 = new Box(boxType);
                    //box2.Read(this.m_reader);
                    //FreeBoxList.Add(box2);
                    //Debug.WriteLine(string.Format("Unknown BoxType: {0}", box2.Type.ToString()));
                }
            } // end of while

            // now that we know all about the input file in memory... fill a few structures to help others gain access to this information...
            // this is for the case in which the mp4 file contains moov boxes (MovieMetadataBoxes).
            if ((mmb != null) && (MediaTracks.Count == 0))
            {
                DurationIn100NanoSecs = (ulong)TimeArithmetic.ConvertToStandardUnit(mmb.MovieHeaderBox.TimeScale, mmb.MovieHeaderBox.Duration);
                Hints.StreamTimeScale = mmb.MovieHeaderBox.TimeScale;
                if (!IsMediaStreamFragmented)
                {
                    CreateTracks <GenericAudioTrack, MP4VideoTrack, MP4TrackFormat>();
                }
            }
        } // end of Read method