Example #1
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);

                TrackHeaderBox.Read(reader);
                while (this.Size > (ulong)(reader.BaseStream.Position - (long)this.Offset))
                {
                    long    pos  = reader.BaseStream.Position;
                    BoxType next = reader.PeekNextBoxType();
                    if (next == BoxTypes.Edts)
                    {
                        EdtsBox = new EdtsBox();
                        EdtsBox.movieTimeScale = movieTimeScale;
                        EdtsBox.Read(reader);
                    }
                    else if (next == BoxTypes.TrackReference)
                    {
                        TrackReferenceBox = new TrackReferenceBox();
                        TrackReferenceBox.Read(reader);
                    }
                    else if (next == BoxTypes.Media)
                    {
                        MediaBox = new MediaBox(this);
                        MediaBox.Read(reader);
                    }
                    else
                    {
                        Box unknown = new Box(BoxTypes.Any);
                        unknown.Read(reader);
                        Debug.WriteLine(string.Format("Unknow box type {0} in Trak box, skipped", next.ToString()));
                    }
                }
            }
        }
Example #2
0
        public TrackBox(IsochronousTrackInfo trackInfo)
            : this()
        {
            float height = 0.0f;
              float width = 0.0f;
              if (trackInfo is RawVideoTrackInfo)
              {
            // set the TRACK width, which may differ from SampleDescription width and height, depending on Aspect Ratio
            RawVideoTrackInfo rvti = (RawVideoTrackInfo)trackInfo;
            height = rvti.Height;
            width = rvti.Width * ((float)rvti.AspectRatioX / (float)rvti.AspectRatioY);
              }
              ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfo.MovieTimeScale, trackInfo.DurationIn100NanoSecs);
              TrackHeaderBox = new TrackHeaderBox((uint)trackInfo.TrackID, scaledDuration, height, width);
              // TrackHeaderBox = new TrackHeaderBox((uint)trackInfo.TrackID, (trackInfo.Duration * oneSecondTicks) / trackInfo.TimeScale, height, width);
              this.Size += TrackHeaderBox.Size;

              // skip the TrackReferenceBox for now
              //TrackReferenceBox = new TrackReferenceBox((uint)trackInfo.TrackID);
              //this.Size += TrackReferenceBox.Size;

            #if EDTS_OUT
              EdtsBox = (EdtsBox)trackInfo.GetEdtsBox();
              if (EdtsBox != null)
              {
            this.Size += EdtsBox.Size;
            EdtsBox.ScaleToTarget(trackInfo.MovieTimeScale, trackInfo.TimeScale);
              }
            #endif

              MediaBox = new MediaBox(trackInfo);
              // MediaBox.Size can only be determined during FinalizeBox
              // NOTE: NO Esds Box
        }
Example #3
0
 public void ScaleToTarget(uint newMovieTimeScale, uint newTrackTimeScale, EdtsBox parent)
 {
     for (int i = 0; i < entryCount; i++)
     {
         editList[i].segmentDuration = (ulong)(((decimal)editList[i].segmentDuration / parent.movieTimeScale) * newMovieTimeScale);
         editList[i].mediaTime       = (long)(((decimal)editList[i].mediaTime / parent.trackTimeScale) * newTrackTimeScale);
     }
 }
Example #4
0
        /// <summary>
        /// InitSampleStreamFromSampleTableBox
        /// Generate the list of StreamDataBlockInfo instances from this SampleTableBox.
        /// 1. Call GetStartAndEndAddress;
        /// 2. Call InitSampleStreamFromSampleTableBox.
        /// </summary>
        /// <param name="edtsBox">EdtsBox</param>
        /// <param name="sampleTimeScale">uint - sample time scale</param>
        /// <param name="startTime">ulong - start time</param>
        /// <param name="endTime">ulong - end time</param>
        /// <param name="lastEnd">ulong - last end</param>
        /// <returns></returns>
        public List <StreamDataBlockInfo> InitSampleStreamFromSampleTableBox(EdtsBox edtsBox, uint sampleTimeScale, ulong startTime, ulong endTime, ref ulong lastEnd)
        {
            uint startIndex, endIndex;

            GetStartAndEndIndex(edtsBox, sampleTimeScale, startTime, endTime, out startIndex, out endIndex);
            if (endIndex <= startIndex)
            {
                return(null);
            }

            return(InitSampleStreamFromSampleTableBox(sampleTimeScale, (int)startIndex, (int)endIndex, ref lastEnd));
        }
Example #5
0
 public override void Write(BoxWriter writer)
 {
     using (new SizeCalculator(this, writer))
     {
         base.Write(writer);
         TrackHeaderBox.Write(writer);
         if (EdtsBox != null)
         {
             EdtsBox.Write(writer);
             //this.Size -= EdtsBox.Size;
         }
         MediaBox.Write(writer);
         if (TrackReferenceBox != null)
         {
             TrackReferenceBox.Write(writer);
         }
     }
 }
Example #6
0
        public override string ToString()
        {
            StringBuilder xml = new StringBuilder();

            xml.Append(base.ToString());

            xml.Append(TrackHeaderBox.ToString());
            if (MediaBox != null)
            {
                xml.Append(MediaBox.ToString());
            }
            if (TrackReferenceBox != null)
            {
                xml.Append(TrackReferenceBox.ToString());
            }
            if (EdtsBox != null)
            {
                xml.Append(EdtsBox.ToString());
            }
            xml.Append("</box>");
            return(xml.ToString());
        }
Example #7
0
        public TrackBox(IsochronousTrackInfo trackInfo)
            : this()
        {
            float height = 0.0f;
            float width  = 0.0f;

            if (trackInfo is RawVideoTrackInfo)
            {
                // set the TRACK width, which may differ from SampleDescription width and height, depending on Aspect Ratio
                RawVideoTrackInfo rvti = (RawVideoTrackInfo)trackInfo;
                height = rvti.Height;
                width  = rvti.Width * ((float)rvti.AspectRatioX / (float)rvti.AspectRatioY);
            }
            ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfo.MovieTimeScale, trackInfo.DurationIn100NanoSecs);

            TrackHeaderBox = new TrackHeaderBox((uint)trackInfo.TrackID, scaledDuration, height, width);
            // TrackHeaderBox = new TrackHeaderBox((uint)trackInfo.TrackID, (trackInfo.Duration * oneSecondTicks) / trackInfo.TimeScale, height, width);
            this.Size += TrackHeaderBox.Size;

            // skip the TrackReferenceBox for now
            //TrackReferenceBox = new TrackReferenceBox((uint)trackInfo.TrackID);
            //this.Size += TrackReferenceBox.Size;

#if EDTS_OUT
            EdtsBox = (EdtsBox)trackInfo.GetEdtsBox();
            if (EdtsBox != null)
            {
                this.Size += EdtsBox.Size;
                EdtsBox.ScaleToTarget(trackInfo.MovieTimeScale, trackInfo.TimeScale);
            }
#endif

            MediaBox = new MediaBox(trackInfo);
            // MediaBox.Size can only be determined during FinalizeBox
            // NOTE: NO Esds Box
        }
Example #8
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            TrackHeaderBox.Read(reader);
            while (this.Size > (ulong)(reader.BaseStream.Position - (long)this.Offset)) {
              long pos = reader.BaseStream.Position;
              BoxType next = reader.PeekNextBoxType();
              if (next == BoxTypes.Edts)
              {
              EdtsBox = new EdtsBox();
              EdtsBox.movieTimeScale = movieTimeScale;
              EdtsBox.Read(reader);
              }
              else if (next == BoxTypes.TrackReference)
              {
              TrackReferenceBox = new TrackReferenceBox();
              TrackReferenceBox.Read(reader);
              }
              else if (next == BoxTypes.Media)
              {
              MediaBox = new MediaBox(this);
              MediaBox.Read(reader);
              }
              else
              {
              Box unknown = new Box(BoxTypes.Any);
              unknown.Read(reader);
              Debug.WriteLine(string.Format("Unknow box type {0} in Trak box, skipped", next.ToString()));
              }
            }
              }
        }
Example #9
0
        /// <summary>
        /// GetStartAndEndIndex
        /// Given a start time and an end time, determine the start slice index and end slice index.
        /// </summary>
        /// <param name="edtsBox"EditsBox></param>
        /// <param name="sampleTimeScale">uint - sample time scale</param>
        /// <param name="startTime">ulong - start time</param>
        /// <param name="endTime">ulong - end time</param>
        /// <param name="startIndex">out param: start index</param>
        /// <param name="endIndex">out param: end index</param>
        private void GetStartAndEndIndex(EdtsBox edtsBox, uint sampleTimeScale, ulong startTime, ulong endTime, out uint startIndex, out uint endIndex)
        {
            startIndex = 0;
            endIndex   = 0;

            ulong ticksDuration = (ulong)TimeArithmetic.ConvertToStandardUnit(sampleTimeScale, parent.parent.MediaHeaderBox.Duration);

            if (edtsBox != null)
            {
                ticksDuration = (ulong)(edtsBox.GetEditTrackDuration(sampleTimeScale) * (decimal)TimeSpan.TicksPerSecond);
            }
            if (ticksDuration < startTime)
            {
                return;
            }

            DecodingTimeToSampleBox stts = this.DecodingTimeToSampleBox;
            SyncSampleMapBox        stss = this.SyncSampleMapBox;

            uint  sampleCount = 0;
            ulong timeT       = 0;
            ulong currScaledT = 0;
            ulong prevScaledT = 0;

            uint[] counts     = stts.SampleCount;
            uint[] deltaTimes = stts.SampleDelta;
            bool   startSet   = false;


            for (int i = 0; i < stts.EntryCount; i++)
            {
                for (int j = 0; j < counts[i]; j++)
                {
                    if ((currScaledT >= startTime) && (!startSet) && ((stss == null) || (stss.IsIFrame(sampleCount + 1))))
                    {
                        startSet   = true;
                        startIndex = sampleCount + 1;
                    }

                    if (((stss == null) || stss.IsIFrame(sampleCount + 2)) && (currScaledT > endTime))
                    {
                        endIndex = sampleCount + 1;
                        break;
                    } // close of if (currScaledT > endTime)

                    prevScaledT = currScaledT;
                    timeT      += deltaTimes[i];
                    sampleCount++;
                    currScaledT = (ulong)TimeArithmetic.ConvertToStandardUnit(sampleTimeScale, timeT);
                } // end of for j

                if (endIndex > 0) // end sample found
                {
                    break;
                }
            } // end of for i

            if ((endIndex == 0) && startSet) // end sample not found
            {
                endIndex = sampleCount + 1;
            }
        }
Example #10
0
        /// <summary>
        /// GetStartAndEndIndex
        /// Given a start time and an end time, determine the start slice index and end slice index.
        /// </summary>
        /// <param name="edtsBox"EditsBox></param>
        /// <param name="sampleTimeScale">uint - sample time scale</param>
        /// <param name="startTime">ulong - start time</param>
        /// <param name="endTime">ulong - end time</param>
        /// <param name="startIndex">out param: start index</param>
        /// <param name="endIndex">out param: end index</param>
        private void GetStartAndEndIndex(EdtsBox edtsBox, uint sampleTimeScale, ulong startTime, ulong endTime, out uint startIndex, out uint endIndex)
        {
            startIndex = 0;
              endIndex = 0;

              ulong ticksDuration = (ulong)TimeArithmetic.ConvertToStandardUnit(sampleTimeScale, parent.parent.MediaHeaderBox.Duration);
              if (edtsBox != null)
              {
            ticksDuration = (ulong)(edtsBox.GetEditTrackDuration(sampleTimeScale) * (decimal)TimeSpan.TicksPerSecond);
              }
              if (ticksDuration < startTime)
            return;

              DecodingTimeToSampleBox stts = this.DecodingTimeToSampleBox;
              SyncSampleMapBox stss = this.SyncSampleMapBox;

              uint sampleCount = 0;
              ulong timeT = 0;
              ulong currScaledT = 0;
              ulong prevScaledT = 0;
              uint[] counts = stts.SampleCount;
              uint[] deltaTimes = stts.SampleDelta;
              bool startSet = false;

              for (int i = 0; i < stts.EntryCount; i++)
              {
            for (int j = 0; j < counts[i]; j++)
            {
              if ((currScaledT >= startTime) && (!startSet) && ((stss == null) || (stss.IsIFrame(sampleCount + 1))))
              {
            startSet = true;
            startIndex = sampleCount + 1;
              }

              if (((stss == null) || stss.IsIFrame(sampleCount + 2)) && (currScaledT > endTime))
              {
            endIndex = sampleCount + 1;
            break;
              } // close of if (currScaledT > endTime)

              prevScaledT = currScaledT;
              timeT += deltaTimes[i];
              sampleCount++;
              currScaledT = (ulong)TimeArithmetic.ConvertToStandardUnit(sampleTimeScale, timeT);
            } // end of for j

            if (endIndex > 0) // end sample found
              break;
              } // end of for i

              if ((endIndex == 0) && startSet) // end sample not found
              {
            endIndex = sampleCount + 1;
              }
        }
Example #11
0
        /// <summary>
        /// InitSampleStreamFromSampleTableBox
        /// Generate the list of StreamDataBlockInfo instances from this SampleTableBox.
        /// 1. Call GetStartAndEndAddress;
        /// 2. Call InitSampleStreamFromSampleTableBox.
        /// </summary>
        /// <param name="edtsBox">EdtsBox</param>
        /// <param name="sampleTimeScale">uint - sample time scale</param>
        /// <param name="startTime">ulong - start time</param>
        /// <param name="endTime">ulong - end time</param>
        /// <param name="lastEnd">ulong - last end</param>
        /// <returns></returns>
        public List<StreamDataBlockInfo> InitSampleStreamFromSampleTableBox(EdtsBox edtsBox, uint sampleTimeScale, ulong startTime, ulong endTime, ref ulong lastEnd)
        {
            uint startIndex, endIndex;

              GetStartAndEndIndex(edtsBox, sampleTimeScale, startTime, endTime, out startIndex, out endIndex);
              if (endIndex <= startIndex)
            return null;

              return InitSampleStreamFromSampleTableBox(sampleTimeScale, (int)startIndex, (int)endIndex, ref lastEnd);
        }
Example #12
0
 public void ScaleToTarget(uint newMovieTimeScale, uint newTrackTimeScale, EdtsBox parent)
 {
     for (int i = 0; i < entryCount; i++)
       {
     editList[i].segmentDuration = (ulong)(((decimal)editList[i].segmentDuration / parent.movieTimeScale) * newMovieTimeScale);
     editList[i].mediaTime = (long)(((decimal)editList[i].mediaTime / parent.trackTimeScale) * newTrackTimeScale);
       }
 }