From 133f50e35611dc44c73b2c0cb7f4ca81594dd6a4 Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Fri, 10 Sep 2004 01:29:49 +0000 Subject: [PATCH] Patch from Allan to add support for compressed frames. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@345351 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- configure.in.in | 15 +++++++++++++++ mpeg/id3v2/Makefile.am | 11 ++++++++--- mpeg/id3v2/id3v2frame.cpp | 26 +++++++++++++++++++++++--- mpeg/id3v2/id3v2framefactory.cpp | 16 ++++++++++------ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/configure.in.in b/configure.in.in index 367494b6..9d678d6d 100644 --- a/configure.in.in +++ b/configure.in.in @@ -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) diff --git a/mpeg/id3v2/Makefile.am b/mpeg/id3v2/Makefile.am index 2fba3dc5..a58c83e9 100644 --- a/mpeg/id3v2/Makefile.am +++ b/mpeg/id3v2/Makefile.am @@ -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 diff --git a/mpeg/id3v2/id3v2frame.cpp b/mpeg/id3v2/id3v2frame.cpp index 84b3f8d3..6f96c7c4 100644 --- a/mpeg/id3v2/id3v2frame.cpp +++ b/mpeg/id3v2/id3v2frame.cpp @@ -19,8 +19,14 @@ * USA * ***************************************************************************/ +#include + #include +#if HAVE_ZLIB +#include +#endif + #include #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."); diff --git a/mpeg/id3v2/id3v2framefactory.cpp b/mpeg/id3v2/id3v2framefactory.cpp index 5b23d8db..858e4637 100644 --- a/mpeg/id3v2/id3v2framefactory.cpp +++ b/mpeg/id3v2/id3v2framefactory.cpp @@ -19,6 +19,8 @@ * USA * ***************************************************************************/ +#include + #include #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') ) { -- 2.40.0