]> granicus.if.org Git - taglib/commitdiff
Changing the API to something more flexible (And needed for Ogg/FLAC)
authorAllan Sandfeld Jensen <kde@carewolf.com>
Tue, 6 Apr 2004 20:34:28 +0000 (20:34 +0000)
committerAllan Sandfeld Jensen <kde@carewolf.com>
Tue, 6 Apr 2004 20:34:28 +0000 (20:34 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@301824 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

flac/flacfile.cpp
flac/flacfile.h
flac/flacproperties.cpp
flac/flacproperties.h

index 2f5c32c5ea7016b1ed4821fe612bb27e30159265..7346f9ed53c5bdc477bb214c86c49161d74d3dd4 100644 (file)
@@ -256,7 +256,7 @@ void FLAC::File::read(bool readProperties, Properties::ReadStyle propertiesStyle
     d->tag = new FLAC::Tag(new Ogg::XiphComment);
 
   if(readProperties)
-    d->properties = new Properties(this, propertiesStyle);
+    d->properties = new Properties(streamInfoData(), streamLength(), propertiesStyle);
 }
 
 ByteVector FLAC::File::streamInfoData()
index f84fdab4245fb92e74a33be45ea24657233ce81b..71a12f0b1c2fc1c6749dac4efcb3b555cd9421c7 100644 (file)
@@ -97,12 +97,6 @@ namespace TagLib {
        */
       void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
 
-      /*!
-       * Returns the block of data used by FLAC::Properties for parsing the
-       * stream properties.
-       */
-      ByteVector streamInfoData();
-
       /*!
        * Returns the length of the audio-stream, used by FLAC::Properties for
        * calculating the bitrate.
@@ -117,6 +111,7 @@ namespace TagLib {
       void scan();
       long findID3v2();
       long findID3v1();
+      ByteVector streamInfoData();
       ByteVector xiphCommentData();
 
       class FilePrivate;
index e8819fda1cbd3d26bb19a0e7adbce5591dd4d9f3..b4dfb3f33041b0c22a864b63e9d061275d53e902 100644 (file)
@@ -30,8 +30,9 @@ using namespace TagLib;
 class FLAC::Properties::PropertiesPrivate
 {
 public:
-  PropertiesPrivate(File *f, ReadStyle s) :
-    file(f),
+  PropertiesPrivate(ByteVector d, long st, ReadStyle s) :
+    data(d),
+    streamLength(st),
     style(s),
     length(0),
     bitrate(0),
@@ -39,7 +40,8 @@ public:
     sampleWidth(0),
     channels(0) {}
 
-  File *file;
+  ByteVector data;
+  long streamLength;
   ReadStyle style;
   int length;
   int bitrate;
@@ -52,9 +54,9 @@ public:
 // public members
 ////////////////////////////////////////////////////////////////////////////////
 
-FLAC::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
+FLAC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : AudioProperties(style)
 {
-  d = new PropertiesPrivate(file, style);
+  d = new PropertiesPrivate(data, streamLength, style);
   read();
 }
 
@@ -94,10 +96,6 @@ int FLAC::Properties::channels() const
 
 void FLAC::Properties::read()
 {
-  // Get the identification header.
-
-  ByteVector data = d->file->streamInfoData();
-
   int pos = 0;
 
   // Minimum block size (in samples)
@@ -112,7 +110,7 @@ void FLAC::Properties::read()
   // Maximum frame size (in bytes)
   pos += 3;
 
-  uint flags = data.mid(pos, 4).toUInt(true);
+  uint flags = d->data.mid(pos, 4).toUInt(true);
   d->sampleRate = flags >> 12;
   d->channels = ((flags >> 9) & 7) + 1;
   d->sampleWidth = ((flags >> 4) & 31) + 1;
@@ -123,16 +121,18 @@ void FLAC::Properties::read()
   uint highlength = (((flags & 0xf) << 28) / d->sampleRate) << 4;
   pos += 4;
 
-  d->length = (data.mid(pos, 4).toUInt(true)) / d->sampleRate + highlength;
+  d->length = (d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highlength;
   pos += 4;
 
   // Uncompressed bitrate:
   
-  // d->bitrate = ((d->sampleRate * d->channels) / 1000) * d->sampleWidth;
+  //d->bitrate = ((d->sampleRate * d->channels) / 1000) * d->sampleWidth;
   
   // Real bitrate:
   
-  d->bitrate = ((d->file->streamLength()*8L) / d->length)/1000;
-  
+  if (d->length)
+    d->bitrate = ((d->streamLength*8L) / d->length)/1000;
+  else
+    d->bitrate = 0;
   
 }
index 20ecddc69c490b642dcc92f410873c755022ac00..1a8ec7a1d1ef212af6a3540c61cf70e35ae8629d 100644 (file)
@@ -42,9 +42,10 @@ namespace TagLib {
     public:
       /*!
        * Create an instance of FLAC::Properties with the data read from the
-       * FLAC::File \a file.
+       * ByteVector \a data.
+       * BIC: API changed since last stable release
        */
-      Properties(File *file, ReadStyle style = Average);
+      Properties(ByteVector data, long streamLength, ReadStyle style = Average);
 
       /*!
        * Destroys this FLAC::Properties instance.