Author: bnickel
Date: 2007-05-07 05:11:30 -0400 (Mon, 07 May 2007)
New Revision: 76811

Modified:
   trunk/taglib-sharp/ChangeLog
   trunk/taglib-sharp/src/TagLib/Asf/StreamPropertiesObject.cs
   trunk/taglib-sharp/src/TagLib/Riff/AviHeaderList.cs
   trunk/taglib-sharp/src/TagLib/Riff/AviStream.cs
   trunk/taglib-sharp/src/TagLib/Riff/BitmapInfoHeader.cs
   trunk/taglib-sharp/src/TagLib/Riff/File.cs
   trunk/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs
Log:
2007-05-07  Brian Nickel <[EMAIL PROTECTED]>

        * src/TagLib/Riff/File.cs: Add support for WAVE files. Better improve
        "Read ()" to handle other extensions. (Still pretty ugly.)
        * src/TagLib/Riff/AviStream.cs:
        * src/TagLib/Riff/BitmapInfoHeader.cs:
        * src/TagLib/Riff/AviHeaderList.cs:
        * src/TagLib/Riff/WaveFormatEx.cs:
        * src/TagLib/Asf/StreamPropertiesObject.cs: De-stupidify. Make
        WaveFormatEx and BitmapInfoHeader inheric I*Codec and remove excess
        formats.


Modified: trunk/taglib-sharp/ChangeLog
===================================================================
--- trunk/taglib-sharp/ChangeLog        2007-05-07 08:49:24 UTC (rev 76810)
+++ trunk/taglib-sharp/ChangeLog        2007-05-07 09:11:30 UTC (rev 76811)
@@ -1,5 +1,17 @@
-2007-05-04  Brian Nickel <[EMAIL PROTECTED]>
+2007-05-07  Brian Nickel <[EMAIL PROTECTED]>
 
+       * src/TagLib/Riff/File.cs: Add support for WAVE files. Better improve
+       "Read ()" to handle other extensions. (Still pretty ugly.)
+       * src/TagLib/Riff/AviStream.cs:
+       * src/TagLib/Riff/BitmapInfoHeader.cs:
+       * src/TagLib/Riff/AviHeaderList.cs:
+       * src/TagLib/Riff/WaveFormatEx.cs:
+       * src/TagLib/Asf/StreamPropertiesObject.cs: De-stupidify. Make
+       WaveFormatEx and BitmapInfoHeader inheric I*Codec and remove excess
+       formats.
+
+2007-05-07  Brian Nickel <[EMAIL PROTECTED]>
+
        * src/TagLib/Id3v2/Frames/RelativeVolumeFrame.cs:
        * src/TagLib/Id3v2/Frames/AttachedPictureFrame.cs:
        * src/TagLib/Id3v2/Frames/UniqueFileIdentifierFrame.cs:

Modified: trunk/taglib-sharp/src/TagLib/Asf/StreamPropertiesObject.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Asf/StreamPropertiesObject.cs 2007-05-07 
08:49:24 UTC (rev 76810)
+++ trunk/taglib-sharp/src/TagLib/Asf/StreamPropertiesObject.cs 2007-05-07 
09:11:30 UTC (rev 76811)
@@ -76,10 +76,10 @@
       public ICodec GetCodec ()
       {
          if (stream_type.Equals (Guid.AsfAudioMedia))
-            return new AudioStreamProperties (TypeSpecificData);
+            return new Riff.WaveFormatEx (type_specific_data, 0);
          
          if (stream_type.Equals (Guid.AsfVideoMedia))
-            return new VideoStreamProperties (TypeSpecificData);
+            return new TagLib.Riff.BitmapInfoHeader (type_specific_data, 11);
          
          return null;
       }
@@ -94,37 +94,4 @@
       public ByteVector ErrorCorrectionData {get {return 
error_correction_data;}}
 #endregion
    }
-   
-   public class AudioStreamProperties : IAudioCodec
-   {
-      private Riff.WaveFormatEx wave_format_ex;
-      
-      public AudioStreamProperties (ByteVector type_specific_data)
-      {
-         wave_format_ex = new Riff.WaveFormatEx (type_specific_data, 0);
-      }
-      
-      public int AudioSampleRate {get {return (int) 
wave_format_ex.SamplesPerSecond;}}
-      public int AudioChannels {get {return wave_format_ex.Channels;}}
-      public int AudioBitrate {get {return (int) Math.Round 
(wave_format_ex.AverageBytesPerSecond * 8d / 1000d);}}
-      public string Description {get {return wave_format_ex.Description;}}
-      public MediaTypes MediaTypes {get {return MediaTypes.Audio;}}
-      public TimeSpan Duration {get {return TimeSpan.Zero;}}
-   }
-   
-   public class VideoStreamProperties : IVideoCodec
-   {
-      TagLib.Riff.BitmapInfoHeader header;
-      
-      public VideoStreamProperties (ByteVector data)
-      {
-         header = new TagLib.Riff.BitmapInfoHeader (data, 11);
-      }
-      
-      public int VideoWidth  {get {return (int) header.Width;}}
-      public int VideoHeight {get {return (int) header.Height;}}
-      public string Description {get {return header.Description;}}
-      public MediaTypes MediaTypes {get {return MediaTypes.Video;}}
-      public TimeSpan Duration {get {return TimeSpan.Zero;}}
-   }
 }

Modified: trunk/taglib-sharp/src/TagLib/Riff/AviHeaderList.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/AviHeaderList.cs 2007-05-07 08:49:24 UTC 
(rev 76810)
+++ trunk/taglib-sharp/src/TagLib/Riff/AviHeaderList.cs 2007-05-07 09:11:30 UTC 
(rev 76811)
@@ -6,7 +6,7 @@
    public class AviHeaderList : List
    {
       AviHeader header;
-      List<AviStream> streams = new List<AviStream> ();
+      List<ICodec> codecs = new List<ICodec> ();
       
       public AviHeaderList (TagLib.File file, long position, int length) : 
base (file, position, length)
       {
@@ -22,17 +22,12 @@
          foreach (ByteVector list_data in this ["LIST"])
          {
             if (list_data.StartsWith ("strl"))
-               streams.Add (AviStream.ParseStreamList (list_data));
+               codecs.Add (AviStream.ParseStreamList (list_data).Codec);
          }
       }
       
       public AviHeader Header {get {return header;}}
-      public AviStream [] Streams {get {return streams.ToArray ();}}
-      
-      public Properties ToProperties ()
-      {
-         return new Properties (Header.Duration, Streams);
-      }
+      public ICodec [] Codecs {get {return codecs.ToArray ();}}
    }
    
    public struct AviHeader

Modified: trunk/taglib-sharp/src/TagLib/Riff/AviStream.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/AviStream.cs     2007-05-07 08:49:24 UTC 
(rev 76810)
+++ trunk/taglib-sharp/src/TagLib/Riff/AviStream.cs     2007-05-07 09:11:30 UTC 
(rev 76811)
@@ -3,13 +3,15 @@
 
 namespace TagLib.Riff
 {
-       public abstract class AviStream : ICodec
+       public abstract class AviStream
        {
       private AviStreamHeader header;
-      
+          private ICodec codec;
+          
       public AviStream (AviStreamHeader header)
       {
          this.header = header;
+         codec = null;
       }
       
       public virtual void ParseItem (ByteVector id, ByteVector data, int 
start, int length)
@@ -46,15 +48,12 @@
          return stream;
       }
       
-      public abstract string Description {get;}
-      public abstract MediaTypes MediaTypes {get;}
-      public TimeSpan Duration {get {return TimeSpan.Zero;}}
+      protected void SetCodec (ICodec codec) {this.codec = codec;}
+      public ICodec Codec {get {return codec;}}
        }
    
-   public class AviAudioStream : AviStream, IAudioCodec
+   public class AviAudioStream : AviStream
    {
-      private WaveFormatEx wave_format_ex;
-      
       public AviAudioStream (AviStreamHeader stream_header) : base 
(stream_header)
       {
       }
@@ -62,20 +61,12 @@
       public override void ParseItem (ByteVector id, ByteVector data, int 
start, int length)
       {
          if (id == "strf")
-            wave_format_ex = new WaveFormatEx (data, start);
+            SetCodec (new WaveFormatEx (data, start));
       }
-      
-      public int AudioSampleRate {get {return (int) 
wave_format_ex.SamplesPerSecond;}}
-      public int AudioChannels {get {return wave_format_ex.Channels;}}
-      public int AudioBitrate {get {return (int) Math.Round 
(wave_format_ex.AverageBytesPerSecond * 8d / 1000d);}}
-      public override string Description {get {return 
wave_format_ex.Description;}}
-      public override MediaTypes MediaTypes {get {return MediaTypes.Audio;}}
    }
    
-   public class AviVideoStream : AviStream, IVideoCodec
+   public class AviVideoStream : AviStream
    {
-      BitmapInfoHeader header;
-      
       public AviVideoStream (AviStreamHeader stream_header) : base 
(stream_header)
       {
       }
@@ -83,13 +74,8 @@
       public override void ParseItem (ByteVector id, ByteVector data, int 
start, int length)
       {
          if (id == "strf")
-            header = new BitmapInfoHeader (data, start);
+            SetCodec (new BitmapInfoHeader (data, start));
       }
-      
-      public int VideoWidth  {get {return (int) header.Width;}}
-      public int VideoHeight {get {return (int) header.Height;}}
-      public override string Description {get {return header.Description;}}
-      public override MediaTypes MediaTypes {get {return MediaTypes.Video;}}
    }
    
    public struct AviStreamHeader

Modified: trunk/taglib-sharp/src/TagLib/Riff/BitmapInfoHeader.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/BitmapInfoHeader.cs      2007-05-07 
08:49:24 UTC (rev 76810)
+++ trunk/taglib-sharp/src/TagLib/Riff/BitmapInfoHeader.cs      2007-05-07 
09:11:30 UTC (rev 76811)
@@ -1,6 +1,6 @@
 namespace TagLib.Riff
 {
-   public struct BitmapInfoHeader
+   public struct BitmapInfoHeader : IVideoCodec
    {
       uint size; 
       uint width; 
@@ -42,6 +42,12 @@
       public uint       YPixelsPerMeter {get {return y_pixels_per_meter;}}
       public uint       ColorsUsed      {get {return colors_used;}}
       public uint       ColorsImportant {get {return colors_important;}}
+      
+      public int VideoWidth  {get {return (int)Width;}}
+      public int VideoHeight {get {return (int)Height;}}
+      public MediaTypes MediaTypes {get {return MediaTypes.Video;}}
+      public System.TimeSpan Duration {get {return System.TimeSpan.Zero;}}
+      
       public string Description
       {
          get

Modified: trunk/taglib-sharp/src/TagLib/Riff/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/File.cs  2007-05-07 08:49:24 UTC (rev 
76810)
+++ trunk/taglib-sharp/src/TagLib/Riff/File.cs  2007-05-07 09:11:30 UTC (rev 
76811)
@@ -5,12 +5,16 @@
 namespace TagLib.Riff
 {
    [SupportedMimeType("taglib/avi", "avi")]
+   [SupportedMimeType("taglib/wav", "wav")]
    [SupportedMimeType("video/avi")]
    [SupportedMimeType("video/msvideo")]
    [SupportedMimeType("video/x-msvideo")]
    [SupportedMimeType("image/avi")]
    [SupportedMimeType("application/x-troff-msvideo")]
    [SupportedMimeType("audio/avi")]
+   [SupportedMimeType("audio/wav")]
+   [SupportedMimeType("audio/wave")]
+   [SupportedMimeType("audio/x-wav")]
    public class File : TagLib.File
    {
       
//////////////////////////////////////////////////////////////////////////
@@ -51,14 +55,15 @@
          tag_start = -1;
          tag_end   = -1;
          
-         if (stream_format != "AVI ")
-            throw new UnsupportedFormatException ("Unsupported RIFF type.");
-         
          long position = 12;
          long length = Length;
+         
+         TimeSpan duration = TimeSpan.Zero;
+         ICodec[] codecs = new ICodec [0];
+         
          do
          {
-            bool   tag_found = false;
+            bool tag_found = false;
             
             Seek (position);
             string fourcc = ReadBlock (4).ToString ();
@@ -66,15 +71,27 @@
             
             switch (fourcc)
             {
+            case "fmt ":
+               if (stream_format == "WAVE" && style != ReadStyle.None)
+               {
+                  Seek (position + 8);
+                  codecs = new ICodec [] {new WaveFormatEx (ReadBlock (18))};
+               }
+               break;
+            case "data":
+               if (stream_format == "WAVE" && style != ReadStyle.None && 
codecs.Length == 1 && codecs [0] is WaveFormatEx)
+                  duration += TimeSpan.FromSeconds ((double) size / (double) 
((WaveFormatEx) codecs [0]).AverageBytesPerSecond);
+               break;
             case "LIST":
             {
                switch (ReadBlock (4).ToString ())
                {
                case "hdrl":
-                  if (stream_format == "AVI " && style != ReadStyle.None && 
properties == null)
+                  if (stream_format == "AVI " && style != ReadStyle.None)
                   {
                      AviHeaderList header_list = new AviHeaderList (this, 
position + 12, (int) (size - 4));
-                     properties = header_list.ToProperties ();
+                     duration = header_list.Header.Duration;
+                     codecs = header_list.Codecs;
                   }
                   break;
                case "INFO":
@@ -123,6 +140,14 @@
          }
          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);
       }

Modified: trunk/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs  2007-05-07 08:49:24 UTC 
(rev 76810)
+++ trunk/taglib-sharp/src/TagLib/Riff/WaveFormatEx.cs  2007-05-07 09:11:30 UTC 
(rev 76811)
@@ -1,6 +1,6 @@
 namespace TagLib.Riff
 {
-   public struct WaveFormatEx
+   public struct WaveFormatEx : IAudioCodec
    {
       ushort format_tag;
       ushort channels;
@@ -31,6 +31,13 @@
       public ushort BitsPerSample         {get {return bits_per_sample;}}
       public ushort ExtraSize             {get {return extra_size;}}
       
+      
+      public int AudioSampleRate {get {return (int) SamplesPerSecond;}}
+      public int AudioChannels {get {return Channels;}}
+      public int AudioBitrate {get {return (int) System.Math.Round 
(AverageBytesPerSecond * 8d / 1000d);}}
+      public MediaTypes MediaTypes {get {return MediaTypes.Audio;}}
+      public System.TimeSpan Duration {get {return System.TimeSpan.Zero;}}
+      
       public string Description
       {
          get

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to