Example #1
0
 public TrackFragmentBox(byte[] boxBytes, int start, int end) : base(ID.traf)
 {
     while (start < end)
     {
         Box box = Mp4Utils.GetBox(boxBytes, ref start, end);
         if (box != null)
         {
             ID iD = box.ID;
             if (iD == ID.tfhd)
             {
                 this.tfhd = (box as TrackFragmentHeaderBox);
             }
             else if (iD == ID.sdtp)
             {
                 this.sdtp = (box as SampleDependencyTypeBox);
             }
             else if (iD == ID.trun)
             {
                 this.trun = (box as TrackRunBox);
             }
             else if (iD == ID.tfrf)
             {
                 this.tfrf = (box as TfrfBox);
             }
             else if (iD == ID.tfxd)
             {
                 this.tfxd = (box as TfxdBox);
             }
         }
     }
 }
Example #2
0
 public TrackFragmentHeaderBox(byte[] boxBytes, int start, int end) : base(ID.tfhd)
 {
     // TODO: Don't store field this.tr_flags etc. if not used.
     this.tf_flags = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     this.base_data_offset_present         = ((1u & this.tf_flags) != 0u);
     this.sample_description_index_present = ((2u & this.tf_flags) != 0u);
     this.default_sample_duration_present  = ((8u & this.tf_flags) != 0u);
     this.default_sample_size_present      = ((16u & this.tf_flags) != 0u);
     this.default_sample_flags_present     = ((32u & this.tf_flags) != 0u);
     this.duration_is_empty = ((65536u & this.tf_flags) != 0u);
     this.track_ID          = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     if (this.base_data_offset_present)
     {
         this.base_data_offset = BitConverter.ToUInt64(Mp4Utils.ReadReverseBytes(boxBytes, 8, ref start, end), 0);
     }
     if (this.sample_description_index_present)
     {
         this.sample_description_index = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(
                                                                   boxBytes, 4, ref start, end), 0);
     }
     if (this.default_sample_duration_present)
     {
         this.default_sample_duration = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(
                                                                  boxBytes, 4, ref start, end), 0);
     }
     if (this.default_sample_size_present)
     {
         this.default_sample_size = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     }
     if (this.default_sample_flags_present)
     {
         this.default_sample_flags = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     }
 }
Example #3
0
 public MovieFragmentHeaderBox(byte[] boxBytes, int start, int end) : base(ID.mfhd)
 {
     if (end - start != 8)
     {
         throw new Exception("Invalid '" + base.ID + "' length!");
     }
     start += 4;
     this.SequenceNumber = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
 }
Example #4
0
        public TfrfBox(byte[] boxBytes, int start, int end) : base(ID.tfrf)
        {
            this.Version = Mp4Utils.ReadReverseBytes(boxBytes, 1, ref start, end)[0];
            this.Flags   = Mp4Utils.ReadReverseBytes(boxBytes, 3, ref start, end);
            int fragmentCount = (int)Mp4Utils.ReadReverseBytes(boxBytes, 1, ref start, end)[0];

            this.Array = new TfrfBox.Element[fragmentCount];
            for (int i = 0; i < fragmentCount; i++)
            {
                this.Array[i] = new TfrfBox.Element(boxBytes, this.Version, ref start, end);
            }
            // TODO: Do we want to test start == end (in other classes as well?).
        }
Example #5
0
 public Element(byte[] boxBytes, byte version, ref int start, int end)
 {
     if (version == 0)
     {
         this.FragmentAbsoluteTime = (ulong)BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
         this.FragmentDuration     = (ulong)BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     }
     else
     {
         if (version != 1)
         {
             throw new Exception("Invalid TfrfBox version '" + version + "'!");
         }
         this.FragmentAbsoluteTime = BitConverter.ToUInt64(Mp4Utils.ReadReverseBytes(boxBytes, 8, ref start, end), 0);
         this.FragmentDuration     = BitConverter.ToUInt64(Mp4Utils.ReadReverseBytes(boxBytes, 8, ref start, end), 0);
     }
 }
Example #6
0
 public TrackRunBox(byte[] boxBytes, int start, int end) : base(ID.trun)
 {
     // TODO: Don't store field this.tr_flags etc. if not used.
     this.tr_flags                   = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     this.data_offset_present        = ((1u & this.tr_flags) != 0u);
     this.first_sample_flags_present = ((4u & this.tr_flags) != 0u);
     this.sample_duration_present    = ((256u & this.tr_flags) != 0u);
     this.sample_size_present        = ((512u & this.tr_flags) != 0u);
     this.sample_flags_present       = ((1024u & this.tr_flags) != 0u);
     this.sample_composition_time_offsets_present = ((2048u & this.tr_flags) != 0u);
     this.sample_count = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     if (this.data_offset_present)
     {
         this.data_offset = BitConverter.ToInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     }
     if (this.first_sample_flags_present)
     {
         this.first_sample_flags = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     }
     this.array = new TrackRunBox.Element[this.sample_count];
     for (int i = 0; i < this.array.Length; i++)
     {
         uint sample_duration = 0u;
         uint sample_size     = 0u;
         uint sample_flags    = 0u;
         uint sample_composition_time_offset = 0u;
         if (this.sample_duration_present)
         {
             sample_duration = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
         }
         if (this.sample_size_present)
         {
             sample_size = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
         }
         if (this.sample_flags_present)
         {
             sample_flags = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
         }
         if (this.sample_composition_time_offsets_present)
         {
             sample_composition_time_offset = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
         }
         this.array[i] = new TrackRunBox.Element(sample_duration, sample_size, sample_flags, sample_composition_time_offset);
     }
 }
Example #7
0
 public MovieFragmentBox(byte[] boxBytes, int start, int end) : base(ID.moof)
 {
     while (start < end)
     {
         Box box = Mp4Utils.GetBox(boxBytes, ref start, end);
         if (box == null)
         {
         }
         else if (box.ID == ID.traf)
         {
             this.traf = (box as TrackFragmentBox);
         }
         else if (box.ID == ID.mfhd)
         {
             this.mfhd = (box as MovieFragmentHeaderBox);
         }
     }
 }
Example #8
0
 public Fragment(byte[] boxBytes, int start, int end)
 {
     while (start < end)
     {
         Box box = Mp4Utils.GetBox(boxBytes, ref start, end);
         if (box == null)
         {
         }
         else if (box.ID == ID.mdat)
         {
             this.mdat = (box as MediaDataBox);
         }
         else if (box.ID == ID.moof)
         {
             this.moof = (box as MovieFragmentBox);
         }
     }
 }
Example #9
0
        public SampleDependencyTypeBox(byte[] boxBytes, int start, int end) : base(ID.sdtp)
        {
            this.version = BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
            int count = end - start;

            this.array = new SampleDependencyTypeBox.Element[count];
            for (int i = 0; i < count; i++)
            {
                byte b        = Mp4Utils.ReadReverseBytes(boxBytes, 1, ref start, end)[0];
                byte reserved = (byte)(b >> 6);
                b <<= 2;
                byte sample_depends_on = (byte)(b >> 6);
                b <<= 2;
                byte sample_is_depended_on = (byte)(b >> 6);
                b <<= 2;
                byte sample_has_redundancy = (byte)(b >> 6);
                this.array[i] = new SampleDependencyTypeBox.Element(
                    reserved, sample_depends_on, sample_is_depended_on, sample_has_redundancy);
            }
        }
Example #10
0
 public TfxdBox(byte[] boxBytes, int start, int end) : base(ID.tfxd)
 {
     // TODO: Don't read and populate unused fields.
     this.Version = Mp4Utils.ReadReverseBytes(boxBytes, 1, ref start, end)[0];
     this.Flags   = Mp4Utils.ReadReverseBytes(boxBytes, 3, ref start, end);
     if (this.Version == 0)
     {
         this.FragmentAbsoluteTime = (ulong)BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(
                                                                      boxBytes, 4, ref start, end), 0);
         this.FragmentDuration = (ulong)BitConverter.ToUInt32(Mp4Utils.ReadReverseBytes(boxBytes, 4, ref start, end), 0);
     }
     else
     {
         if (this.Version != 1)
         {
             throw new Exception("Invalid TfxdBox version '" + this.Version + "'!");
         }
         this.FragmentAbsoluteTime = BitConverter.ToUInt64(Mp4Utils.ReadReverseBytes(boxBytes, 8, ref start, end), 0);
         this.FragmentDuration     = BitConverter.ToUInt64(Mp4Utils.ReadReverseBytes(boxBytes, 8, ref start, end), 0);
     }
 }