コード例 #1
0
        /// <summary>
        ///    Parses boxes for a specified range, looking for tags and
        ///    properties.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="long" /> value specifying the seek position
        ///    at which to start reading.
        /// </param>
        /// <param name="end">
        ///    A <see cref="long" /> value specifying the seek position
        ///    at which to stop reading.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object that applied to the
        ///    range being searched.
        /// </param>
        private void ParseTagAndProperties(long start, long end,
                                           IsoHandlerBox handler)
        {
            BoxHeader header;

            for (long position = start; position < end;
                 position += header.TotalBoxSize)
            {
                header = new BoxHeader(file, position);
                ByteVector type = header.BoxType;

                if (type == BoxType.Moov ||
                    type == BoxType.Mdia ||
                    type == BoxType.Minf ||
                    type == BoxType.Stbl ||
                    type == BoxType.Trak)
                {
                    ParseTagAndProperties(
                        header.HeaderSize + position,
                        header.TotalBoxSize + position,
                        handler);
                }
                else if (type == BoxType.Stsd)
                {
                    stsd_boxes.Add(BoxFactory.CreateBox(
                                       file, header, handler));
                }
                else if (type == BoxType.Hdlr)
                {
                    handler = BoxFactory.CreateBox(file,
                                                   header, handler) as
                              IsoHandlerBox;
                }
                else if (mvhd_box == null &&
                         type == BoxType.Mvhd)
                {
                    mvhd_box = BoxFactory.CreateBox(file,
                                                    header, handler) as
                               IsoMovieHeaderBox;
                }
                else if (udta_box == null &&
                         type == BoxType.Udta)
                {
                    udta_box = BoxFactory.CreateBox(file,
                                                    header, handler) as
                               IsoUserDataBox;
                }
                else if (type == BoxType.Mdat)
                {
                    mdat_start = position;
                    mdat_end   = position + header.TotalBoxSize;
                }

                if (header.TotalBoxSize == 0)
                {
                    break;
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///    Parses boxes for a specified range, looking for tags and
        ///    properties.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="long" /> value specifying the seek position
        ///    at which to start reading.
        /// </param>
        /// <param name="end">
        ///    A <see cref="long" /> value specifying the seek position
        ///    at which to stop reading.
        /// </param>
        /// <param name="handler">
        ///    A <see cref="IsoHandlerBox" /> object that applied to the
        ///    range being searched.
        /// </param>
        /// <param name="parents">
        ///    A <see cref="T:List" /> of <see cref="BoxHeader" /> parents.
        /// </param>
        void ParseTagAndProperties(long start, long end, IsoHandlerBox handler, List <BoxHeader> parents)
        {
            BoxHeader header;

            for (long position = start; position < end; position += header.TotalBoxSize)
            {
                header = new BoxHeader(file, position);
                ByteVector type = header.BoxType;

                if (type == BoxType.Moov)
                {
                    ParseTagAndProperties(header.HeaderSize + position, header.TotalBoxSize + position, handler, AddParent(parents, header));
                }
                else if (type == BoxType.Mdia ||
                         type == BoxType.Minf ||
                         type == BoxType.Stbl ||
                         type == BoxType.Trak)
                {
                    ParseTagAndProperties(header.HeaderSize + position, header.TotalBoxSize + position, handler, AddParent(parents, header));
                }
                else if (type == BoxType.Stsd)
                {
                    stsd_boxes.Add(BoxFactory.CreateBox(file, header, handler));
                }
                else if (type == BoxType.Hdlr)
                {
                    handler = BoxFactory.CreateBox(file, header, handler) as IsoHandlerBox;
                }
                else if (mvhd_box == null &&
                         type == BoxType.Mvhd)
                {
                    mvhd_box = BoxFactory.CreateBox(file, header, handler) as IsoMovieHeaderBox;
                }
                else if (type == BoxType.Udta)
                {
                    var udtaBox = BoxFactory.CreateBox(file, header, handler) as IsoUserDataBox;

                    // Since we can have multiple udta boxes, save the parent for each one
                    List <BoxHeader> new_parents = AddParent(parents, header);
                    udtaBox.ParentTree = new_parents.ToArray();

                    udta_boxes.Add(udtaBox);
                }
                else if (type == BoxType.Mdat)
                {
                    mdat_start = position;
                    mdat_end   = position + header.TotalBoxSize;
                }

                if (header.TotalBoxSize == 0)
                {
                    break;
                }
            }
        }
コード例 #3
0
ファイル: FileParser.cs プロジェクト: ecortez91/Murganizer
 /// <summary>
 ///    Resets all internal fields.
 /// </summary>
 private void ResetFields()
 {
     mvhd_box = null;
     udta_boxes.Clear();
     moov_tree = null;
     udta_tree = null;
     stco_boxes.Clear();
     stsd_boxes.Clear();
     mdat_start = -1;
     mdat_end   = -1;
 }
コード例 #4
0
 private void Read(ReadStyle propertiesStyle)
 {
     tag  = new CombinedTag();
     Mode = AccessMode.Read;
     try
     {
         FileParser parser = new FileParser(this);
         if (propertiesStyle == ReadStyle.None)
         {
             parser.ParseTag();
         }
         else
         {
             parser.ParseTagAndProperties();
         }
         InvariantStartPosition = parser.MdatStartPosition;
         InvariantEndPosition   = parser.MdatEndPosition;
         udta_boxes.AddRange(parser.UserDataBoxes);
         if (udta_boxes.Count == 0)
         {
             IsoUserDataBox dummy = new IsoUserDataBox();
             udta_boxes.Add(dummy);
         }
         if (IsAppleTagUdtaPresent())
         {
             TagTypesOnDisk |= TagTypes.Apple;
         }
         IsoUserDataBox udtaBox = FindAppleTagUdta();
         if (null == udtaBox)
         {
             udtaBox = new IsoUserDataBox();
         }
         apple_tag = new AppleTag(udtaBox);
         tag.SetTags(apple_tag);
         if (propertiesStyle == ReadStyle.None)
         {
             Mode = AccessMode.Closed;
             return;
         }
         IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
         if (mvhd_box == null)
         {
             Mode = AccessMode.Closed;
             throw new CorruptFileException("mvhd box not found.");
         }
         IsoAudioSampleEntry  audio_sample_entry  = parser.AudioSampleEntry;
         IsoVisualSampleEntry visual_sample_entry = parser.VisualSampleEntry;
         properties = new Properties(mvhd_box.Duration, audio_sample_entry, visual_sample_entry);
     }
     finally
     {
         Mode = AccessMode.Closed;
     }
 }
コード例 #5
0
ファイル: File.cs プロジェクト: talun2075/SonosAPI
        /// <summary>
        ///    Reads the file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        private void Read(ReadStyle propertiesStyle)
        {
            // 2TODO: Support Id3v2 boxes!!!
            tag  = new CombinedTag();
            Mode = AccessMode.Read;
            try {
                FileParser parser = new FileParser(this);

                if (propertiesStyle == ReadStyle.None)
                {
                    parser.ParseTag();
                }
                else
                {
                    parser.ParseTagAndProperties();
                }

                InvariantStartPosition = parser.MdatStartPosition;
                InvariantEndPosition   = parser.MdatEndPosition;

                udta_boxes.AddRange(parser.UserDataBoxes);

                // Ensure our collection contains at least a single empty box
                if (udta_boxes.Count == 0)
                {
                    IsoUserDataBox dummy = new IsoUserDataBox();
                    udta_boxes.Add(dummy);
                }

                // Check if a udta with ILST actually exists
                if (IsAppleTagUdtaPresent())
                {
                    TagTypesOnDisk |= TagTypes.Apple;                           //There is an udta present with ILST info
                }
                // Find the udta box with the Apple Tag ILST
                IsoUserDataBox udtaBox = FindAppleTagUdta();
                if (null == udtaBox)
                {
                    udtaBox = new IsoUserDataBox();
                }
                apple_tag = new AppleTag(udtaBox);
                tag.SetTags(apple_tag);

                // If we're not reading properties, we're done.
                if (propertiesStyle == ReadStyle.None)
                {
                    Mode = AccessMode.Closed;
                    return;
                }

                // Get the movie header box.
                IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
                if (mvhd_box == null)
                {
                    Mode = AccessMode.Closed;
                    throw new CorruptFileException(
                              "mvhd box not found.");
                }

                IsoAudioSampleEntry audio_sample_entry =
                    parser.AudioSampleEntry;
                IsoVisualSampleEntry visual_sample_entry =
                    parser.VisualSampleEntry;

                // Read the properties.
                properties = new Properties(mvhd_box.Duration,
                                            audio_sample_entry, visual_sample_entry);
            } finally {
                Mode = AccessMode.Closed;
            }
        }
コード例 #6
0
		/// <summary>
		///    Resets all internal fields.
		/// </summary>
		private void ResetFields ()
		{
			mvhd_box = null;
			udta_boxes.Clear ();
			moov_tree = null;
			udta_tree = null;
			stco_boxes.Clear ();
			stsd_boxes.Clear ();
			mdat_start = -1;
			mdat_end = -1;
		}
コード例 #7
0
		/// <summary>
		///    Parses boxes for a specified range, looking for tags and
		///    properties.
		/// </summary>
		/// <param name="start">
		///    A <see cref="long" /> value specifying the seek position
		///    at which to start reading.
		/// </param>
		/// <param name="end">
		///    A <see cref="long" /> value specifying the seek position
		///    at which to stop reading.
		/// </param>
		/// <param name="handler">
		///    A <see cref="IsoHandlerBox" /> object that applied to the
		///    range being searched.
		/// </param>
		private void ParseTagAndProperties (long start, long end,
		                                    IsoHandlerBox handler, List<BoxHeader> parents)
		{
			BoxHeader header;
			
			for (long position = start; position < end;
				position += header.TotalBoxSize) {
				header = new BoxHeader (file, position);
				ByteVector type = header.BoxType;
				
				if (type == BoxType.Moov) {
					ParseTagAndProperties (header.HeaderSize + position,
						header.TotalBoxSize + position,
						handler,
						AddParent (parents, header));
				} else if (type == BoxType.Mdia ||
					type == BoxType.Minf ||
					type == BoxType.Stbl ||
					type == BoxType.Trak) {
					ParseTagAndProperties (
						header.HeaderSize + position,
						header.TotalBoxSize + position,
						handler,
						AddParent (parents, header));
				} else if (type == BoxType.Stsd) {
					stsd_boxes.Add (BoxFactory.CreateBox (
						file, header, handler));
				} else if (type == BoxType.Hdlr) {
					handler = BoxFactory.CreateBox (file,
						header, handler) as
							IsoHandlerBox;
				} else if (mvhd_box == null &&
					type == BoxType.Mvhd) {
					mvhd_box = BoxFactory.CreateBox (file,
						header, handler) as
							IsoMovieHeaderBox;
				} else if (type == BoxType.Udta) {
					IsoUserDataBox udtaBox = BoxFactory.CreateBox (file,
						header, handler) as
							IsoUserDataBox;

					// Since we can have multiple udta boxes, save the parent for each one
					List<BoxHeader> new_parents = AddParent (
						parents, header);
					udtaBox.ParentTree = new_parents.ToArray ();

					udta_boxes.Add(udtaBox);
				} else if (type == BoxType.Mdat) {
					mdat_start = position;
					mdat_end = position + header.TotalBoxSize;
				}
				
				if (header.TotalBoxSize == 0)
					break;
			}
		}
コード例 #8
0
ファイル: FileParser.cs プロジェクト: Sephiroth25896/Projects
		/// <summary>
		///    Parses boxes for a specified range, looking for tags and
		///    properties.
		/// </summary>
		/// <param name="start">
		///    A <see cref="long" /> value specifying the seek position
		///    at which to start reading.
		/// </param>
		/// <param name="end">
		///    A <see cref="long" /> value specifying the seek position
		///    at which to stop reading.
		/// </param>
		/// <param name="handler">
		///    A <see cref="IsoHandlerBox" /> object that applied to the
		///    range being searched.
		/// </param>
		private void ParseTagAndProperties (long start, long end,
		                                    IsoHandlerBox handler)
		{
			BoxHeader header;
			
			for (long position = start; position < end;
				position += header.TotalBoxSize) {
				header = new BoxHeader (file, position);
				ByteVector type = header.BoxType;
				
				if (type == BoxType.Moov ||
					type == BoxType.Mdia ||
					type == BoxType.Minf ||
					type == BoxType.Stbl ||
					type == BoxType.Trak) {
					ParseTagAndProperties (
						header.HeaderSize + position,
						header.TotalBoxSize + position,
						handler);
				} else if (type == BoxType.Stsd) {
					stsd_boxes.Add (BoxFactory.CreateBox (
						file, header, handler));
				} else if (type == BoxType.Hdlr) {
					handler = BoxFactory.CreateBox (file,
						header, handler) as
							IsoHandlerBox;
				} else if (mvhd_box == null &&
					type == BoxType.Mvhd) {
					mvhd_box = BoxFactory.CreateBox (file,
						header, handler) as
							IsoMovieHeaderBox;
				} else if (udta_box == null &&
					type == BoxType.Udta) {
					udta_box = BoxFactory.CreateBox (file,
						header, handler) as
							IsoUserDataBox;
				} else if (type == BoxType.Mdat) {
					mdat_start = position;
					mdat_end = position + header.TotalBoxSize;
				}
				
				if (header.TotalBoxSize == 0)
					break;
			}
		}
コード例 #9
0
        /// <summary>
        ///    Reads the file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        private void Read(ReadStyle propertiesStyle)
        {
            // TODO: Support Id3v2 boxes!!!
            tag  = new CombinedTag();
            Mode = AccessMode.Read;
            try {
                FileParser parser = new FileParser(this);

                if (propertiesStyle == ReadStyle.None)
                {
                    parser.ParseTag();
                }
                else
                {
                    parser.ParseTagAndProperties();
                }

                InvariantStartPosition = parser.MdatStartPosition;
                InvariantEndPosition   = parser.MdatEndPosition;

                udta_box = parser.UserDataBox;

                if (udta_box != null && udta_box.GetChild(BoxType.Meta)
                    != null && udta_box.GetChild(BoxType.Meta
                                                 ).GetChild(BoxType.Ilst) != null)
                {
                    TagTypesOnDisk |= TagTypes.Apple;
                }

                if (udta_box == null)
                {
                    udta_box = new IsoUserDataBox();
                }

                apple_tag = new AppleTag(udta_box);
                tag.SetTags(apple_tag);

                // If we're not reading properties, we're done.
                if (propertiesStyle == ReadStyle.None)
                {
                    Mode = AccessMode.Closed;
                    return;
                }

                // Get the movie header box.
                IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
                if (mvhd_box == null)
                {
                    Mode = AccessMode.Closed;
                    throw new CorruptFileException(
                              "mvhd box not found.");
                }

                IsoAudioSampleEntry audio_sample_entry =
                    parser.AudioSampleEntry;
                IsoVisualSampleEntry visual_sample_entry =
                    parser.VisualSampleEntry;

                // Read the properties.
                properties = new Properties(mvhd_box.Duration,
                                            audio_sample_entry, visual_sample_entry);
            } finally {
                Mode = AccessMode.Closed;
            }
        }
コード例 #10
0
 private void ResetFields()
 {
     this.mvhd_box = null;
     this.udta_box = null;
     this.moov_tree = null;
     this.udta_tree = null;
     this.stco_boxes.Clear();
     this.stsd_boxes.Clear();
     this.mdat_start = -1L;
     this.mdat_end = -1L;
 }
コード例 #11
0
 private void ParseTagAndProperties(long start, long end, IsoHandlerBox handler)
 {
     BoxHeader header;
     for (long i = start; i < end; i += header.TotalBoxSize)
     {
         header = new BoxHeader(this.file, i);
         ByteVector boxType = header.BoxType;
         if (((boxType == BoxType.Moov) || (boxType == BoxType.Mdia)) || (((boxType == BoxType.Minf) || (boxType == BoxType.Stbl)) || (boxType == BoxType.Trak)))
         {
             this.ParseTagAndProperties(header.HeaderSize + i, header.TotalBoxSize + i, handler);
         }
         else if (boxType == BoxType.Stsd)
         {
             this.stsd_boxes.Add(BoxFactory.CreateBox(this.file, header, handler));
         }
         else if (boxType == BoxType.Hdlr)
         {
             handler = BoxFactory.CreateBox(this.file, header, handler) as IsoHandlerBox;
         }
         else if ((this.mvhd_box == null) && (boxType == BoxType.Mvhd))
         {
             this.mvhd_box = BoxFactory.CreateBox(this.file, header, handler) as IsoMovieHeaderBox;
         }
         else if ((this.udta_box == null) && (boxType == BoxType.Udta))
         {
             this.udta_box = BoxFactory.CreateBox(this.file, header, handler) as IsoUserDataBox;
         }
         else if (boxType == BoxType.Mdat)
         {
             this.mdat_start = i;
             this.mdat_end = i + header.TotalBoxSize;
         }
         if (header.TotalBoxSize == 0)
         {
             break;
         }
     }
 }