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
public void InitializeForWriting(List<IsochronousTrackInfo> mediaTracks) { string[] brands = new string[3]; brands[0] = "isml"; brands[1] = "piff"; brands[2] = "iso2"; this.ftb = new FileTypeBox(brands); // overwrite base class's ftb this.ftb.MinorVersion = 1; uint[] matrix = new uint[9]; matrix[0] = 0x10000; // 1.0 matrix[4] = 0x10000; // 1.0 matrix[8] = 0x40000000; // 1.0 (see description of RenderMatrix class) this.mmb = new MovieMetadataBox(mediaTracks, 1.0f, 1.0f, matrix); //CreateTracksForWriting<ISMVTrackFormat>(mediaTracks); // create tracks with ISMVTrackFormat // we can finalize the ftyp and moov boxes here, because they shouldn't change when moofs (fragments) are added //this.ftb.Write(m_writer); this.mmb.FinalizeBox(); //this.mmb.Write(m_writer); //this.CurrMDatOffset = this.ftb.Size + this.mmb.Size; // for fragmented files, CurrMDatOffset is really the file offset InitializeForWriting(mediaTracks); // create our tracks (partial moov boxes, which should still exist, even for fragmented tracks) }