Patch from Allan to add support for compressed frames.
authorScott Wheeler <wheeler@kde.org>
Fri, 10 Sep 2004 01:29:49 +0000 (01:29 +0000)
committerScott Wheeler <wheeler@kde.org>
Fri, 10 Sep 2004 01:29:49 +0000 (01:29 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@345351 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

configure.in.in
mpeg/id3v2/Makefile.am
mpeg/id3v2/id3v2frame.cpp
mpeg/id3v2/id3v2framefactory.cpp

index 367494b654352ff35b0e677bf6ad0d64e42b4b09..9d678d6dfa41a8041ccd80acfa8ff0efdf3c3079 100644 (file)
@@ -1,3 +1,18 @@
 #AM_INIT_AUTOMAKE(taglib,1.0)
 dnl don't remove the below
 dnl AC_OUTPUT(taglib/taglib-config)
+
+AC_DEFUN([AC_HAVE_ZLIB],
+[
+       AC_DEFINE(HAVE_ZLIB, 1, [have zlib])
+       have_zlib=true
+])
+
+AC_DEFUN([AC_NO_ZLIB],
+[
+       AC_DEFINE(HAVE_ZLIB, 0, [have zlib])
+       have_zlib=false
+])
+
+AC_CHECK_HEADER(zlib.h, AC_HAVE_ZLIB, AC_NO_ZLIB)
+AM_CONDITIONAL(link_zlib, test x$have_zlib = xtrue)
index 2fba3dc5b125312f2c19afe761940feeb26c7a9d..a58c83e9579977ded1ee6f1c96ec72d1297020c6 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = frames 
+SUBDIRS = frames
 INCLUDES = \
        -I$(top_srcdir)/taglib \
        -I$(top_srcdir)/taglib/toolkit \
@@ -11,13 +11,18 @@ noinst_LTLIBRARIES = libid3v2.la
 libid3v2_la_SOURCES = \
        id3v2framefactory.cpp id3v2synchdata.cpp id3v2tag.cpp \
        id3v2header.cpp id3v2frame.cpp id3v2footer.cpp \
-       id3v2extendedheader.cpp 
+       id3v2extendedheader.cpp
 
 taglib_include_HEADERS = \
        id3v2extendedheader.h id3v2frame.h id3v2header.h \
        id3v2synchdata.h id3v2footer.h id3v2framefactory.h id3v2tag.h
 
 taglib_includedir = $(includedir)/taglib
-libid3v2_la_LIBADD = ./frames/libframes.la
+
+if link_zlib
+zlib = -lz
+endif
+
+libid3v2_la_LIBADD = ./frames/libframes.la $(zlib)
 
 EXTRA_DIST = $(libid3v2_la_SOURCES) $(taglib_include_HEADERS) id3v2.4.0-frames.txt id3v2.4.0-structure.txt
index 84b3f8d358a586d6f9dd737a9ac515ed80db986d..6f96c7c4b8dc0d66ca4ab7252ca1245981204474 100644 (file)
  *   USA                                                                   *
  ***************************************************************************/
 
+#include <config.h>
+
 #include <bitset>
 
+#if HAVE_ZLIB
+#include <zlib.h>
+#endif
+
 #include <tdebug.h>
 
 #include "id3v2frame.h"
@@ -156,12 +162,26 @@ ByteVector Frame::fieldData(const ByteVector &frameData) const
   uint frameDataOffset = headerSize;
   uint frameDataLength = size();
 
-  if(d->header->dataLengthIndicator()) {
+  if(d->header->compression() || d->header->dataLengthIndicator()) {
     frameDataLength = frameData.mid(headerSize, 4).toUInt();
     frameDataOffset += 4;
   }
 
-  return frameData.mid(frameDataOffset, frameDataLength);  
+#if HAVE_ZLIB
+  if(d->header->compression()) {
+    ByteVector data(frameDataLength);
+    uLongf uLongTmp = frameDataLength;
+    ::uncompress((Bytef *) data.data(),
+                 (uLongf *) &uLongTmp,
+                 (Bytef *) frameData.data() + frameDataOffset,
+                 size());
+    return data;
+#else
+    return frameData.mid(frameDataOffset, frameDataLength);
+#endif
+  }
+  else
+    return frameData.mid(frameDataOffset, frameDataLength);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -258,7 +278,7 @@ void Frame::Header::setData(const ByteVector &data, uint version)
   case 1:
   case 2:
   {
-    // ID3v2.2 
+    // ID3v2.2
 
     if(data.size() < 3) {
       debug("You must at least specify a frame ID.");
index 5b23d8db6f1d619a640b7d7fe960513e9e0131ad..858e46372a8bddeb5f7b2443a7b299a405682b4c 100644 (file)
@@ -19,6 +19,8 @@
  *   USA                                                                   *
  ***************************************************************************/
 
+#include <config.h>
+
 #include <tdebug.h>
 
 #include "id3v2framefactory.h"
@@ -66,16 +68,18 @@ Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const
 {
   Frame::Header *header = new Frame::Header(data, version);
 
-  // TagLib doesn't mess with encrypted or compressed frames, so just treat them
+  // TagLib doesn't mess with encrypted frames, so just treat them
   // as unknown frames.
 
+#if HAVE_ZLIB == 0
   if(header->compression()) {
-      debug("Compressed frames are currently not supported.");
-      return new UnknownFrame(data, header);
+    debug("Compressed frames are currently not supported.");
+    return new UnknownFrame(data, header);
   }
+#endif
   if(header->encryption()) {
-      debug("Entrypted frames are currently not supported.");
-      return new UnknownFrame(data, header);
+    debug("Encrypted frames are currently not supported.");
+    return new UnknownFrame(data, header);
   }
 
   TagLib::ByteVector frameID = header->frameID();
@@ -84,7 +88,7 @@ Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const
   // characters.  Also make sure that there is data in the frame.
 
   if(!frameID.size() == (version < 3 ? 3 : 4) || header->frameSize() <= 0)
-      return 0;
+    return 0;
 
   for(ByteVector::ConstIterator it = frameID.begin(); it != frameID.end(); it++) {
     if( (*it < 'A' || *it > 'Z') && (*it < '1' || *it > '9') ) {