Esempio n. 1
0
        private void Read(bool read_tags, ReadStyle style, out uint riff_size, out long tag_start, out long tag_end)
        {
            Seek(0);
            if (ReadBlock(4) != FileIdentifier)
            {
                throw new CorruptFileException("File does not begin with RIFF identifier");
            }

            riff_size = ReadBlock(4).ToUInt(false);
            ByteVector stream_format = ReadBlock(4);

            tag_start = -1;
            tag_end   = -1;

            long position = 12;
            long length   = Length;

            TimeSpan duration = TimeSpan.Zero;

            ICodec[] codecs = new ICodec [0];

            do
            {
                bool tag_found = false;

                Seek(position);
                string fourcc = ReadBlock(4).ToString(StringType.UTF8);
                uint   size   = ReadBlock(4).ToUInt(false);
                switch (fourcc)
                {
                case "fmt ":
                    if (stream_format == "WAVE" && style != ReadStyle.None)
                    {
                        Seek(position + 8);
                        codecs = new ICodec [] { new WaveFormatEx(ReadBlock(18), 0) };
                    }
                    break;

                case "data":
                    if (stream_format == "WAVE")
                    {
                        if (style != ReadStyle.None && codecs.Length == 1 && codecs [0] is WaveFormatEx)
                        {
                            duration += TimeSpan.FromSeconds((double)size / (double)((WaveFormatEx)codecs [0]).AverageBytesPerSecond);
                        }
                        InvariantStartPosition = position;
                        InvariantEndPosition   = position + size;
                    }
                    break;

                case "LIST":
                {
                    switch (ReadBlock(4).ToString(StringType.UTF8))
                    {
                    case "hdrl":
                        if (stream_format == "AVI " && style != ReadStyle.None)
                        {
                            AviHeaderList header_list = new AviHeaderList(this, position + 12, (int)(size - 4));
                            duration = header_list.Header.Duration;
                            codecs   = header_list.Codecs;
                        }
                        break;

                    case "INFO":
                    {
                        if (read_tags && info_tag == null)
                        {
                            info_tag = new InfoTag(this, position + 12, (int)(size - 4));
                        }
                        tag_found = true;
                        break;
                    }

                    case "MID ":
                        if (read_tags && mid_tag == null)
                        {
                            mid_tag = new MovieIdTag(this, position + 12, (int)(size - 4));
                        }
                        tag_found = true;
                        break;

                    case "movi":
                        if (stream_format == "AVI ")
                        {
                            InvariantStartPosition = position;
                            InvariantEndPosition   = position + size;
                        }
                        break;
                    }
                    break;
                }

                case "ID32":
                    if (read_tags && id32_tag == null)
                    {
                        id32_tag = new Id3v2.Tag(this, position + 8);
                    }
                    tag_found = true;
                    break;

                case "IDVX":
                    if (read_tags && divx_tag == null)
                    {
                        divx_tag = new DivXTag(this, position + 8);
                    }
                    tag_found = true;
                    break;

                case "JUNK":
                    if (tag_end == position)
                    {
                        tag_end = position + 8 + size;
                    }
                    break;
                }

                if (tag_found)
                {
                    if (tag_start == -1)
                    {
                        tag_start = position;
                        tag_end   = position + 8 + size;
                    }
                    else if (tag_end == position)
                    {
                        tag_end = position + 8 + size;
                    }
                }

                position += 8 + size;
            }while (position + 8 < length);

            if (style != ReadStyle.None)
            {
                if (codecs.Length == 0)
                {
                    throw new UnsupportedFormatException("Unsupported RIFF type.");
                }

                properties = new Properties(duration, codecs);
            }

            if (read_tags)
            {
                tag.SetTags(id32_tag, info_tag, mid_tag, divx_tag);
            }
        }
Esempio n. 2
0
      private void Read (bool read_tags, ReadStyle style, out uint riff_size, out long tag_start, out long tag_end)
      {
         Seek (0);
         if (ReadBlock (4) != FileIdentifier)
            throw new CorruptFileException ("File does not begin with RIFF identifier");
         
         riff_size = ReadBlock (4).ToUInt (false);
         ByteVector stream_format = ReadBlock (4);
         tag_start = -1;
         tag_end   = -1;
         
         long position = 12;
         long length = Length;
         
         TimeSpan duration = TimeSpan.Zero;
         ICodec[] codecs = new ICodec [0];
         
         do
         {
            bool tag_found = false;
            
            Seek (position);
            string fourcc = ReadBlock (4).ToString (StringType.UTF8);
            uint   size = ReadBlock (4).ToUInt (false);
            switch (fourcc)
            {
            case "fmt ":
               if (stream_format == "WAVE" && style != ReadStyle.None)
               {
                  Seek (position + 8);
                  codecs = new ICodec [] {new WaveFormatEx (ReadBlock (18), 0)};
               }
               break;
            case "data":
               if (stream_format == "WAVE") {
                  if (style != ReadStyle.None && codecs.Length == 1 && codecs [0] is WaveFormatEx)
                     duration += TimeSpan.FromSeconds ((double) size / (double) ((WaveFormatEx) codecs [0]).AverageBytesPerSecond);
                  InvariantStartPosition = position;
                  InvariantEndPosition = position + size;
               }
               break;
            case "LIST":
            {
					switch (ReadBlock (4).ToString (StringType.UTF8))
					{
					case "hdrl":
						if (stream_format == "AVI " && style != ReadStyle.None)
                  {
                     AviHeaderList header_list = new AviHeaderList (this, position + 12, (int) (size - 4));
                     duration = header_list.Header.Duration;
                     codecs = header_list.Codecs;
                  }
                  break;
               case "INFO":
               {
                  if (read_tags && info_tag == null)
                     info_tag = new InfoTag (this, position + 12, (int) (size - 4));
                  tag_found = true;
                  break;
               }
               case "MID ":
                  if (read_tags && mid_tag == null)
                     mid_tag = new MovieIdTag (this, position + 12, (int) (size - 4));
                  tag_found = true;
                  break;
               case "movi":
                  if (stream_format == "AVI ") {
                     InvariantStartPosition = position;
                     InvariantEndPosition = position + size;
                  }
                  break;
               }
               break;
            }
            case "ID32":
               if (read_tags && id32_tag == null)
                  id32_tag = new Id3v2.Tag (this, position + 8);
               tag_found = true;
               break;
            case "IDVX":
               if (read_tags && divx_tag == null)
                  divx_tag = new DivXTag (this, position + 8);
               tag_found = true;
               break;
            case "JUNK":
               if (tag_end == position)
                  tag_end = position + 8 + size;
               break;
            }
            
            if (tag_found)
            {
               if (tag_start == -1)
               {
                  tag_start = position;
                  tag_end = position + 8 + size;
               }
               else if (tag_end == position)
                  tag_end = position + 8 + size;
            }
            
            position += 8 + size;
         }
         while (position + 8 < length);
         
         if (style != ReadStyle.None)
         {
            if (codecs.Length == 0)
               throw new UnsupportedFormatException ("Unsupported RIFF type.");
            
            properties = new Properties (duration, codecs);
         }
         
         if (read_tags)
            tag.SetTags (id32_tag, info_tag, mid_tag, divx_tag);
      }