Merge pull request #77 from TsudaKageyu/largefilesupport

Support large files over 2GB
This commit is contained in:
Lukáš Lalinský 2012-11-04 01:29:45 -07:00
commit b01f45e141
52 changed files with 321 additions and 268 deletions

View File

@ -66,10 +66,10 @@ public:
delete properties;
}
long APELocation;
offset_t APELocation;
uint APESize;
long ID3v1Location;
offset_t ID3v1Location;
TagUnion tag;
@ -272,7 +272,7 @@ void APE::File::read(bool readProperties, Properties::ReadStyle /* propertiesSty
}
}
long APE::File::findAPE()
offset_t APE::File::findAPE()
{
if(!isValid())
return -1;
@ -282,7 +282,7 @@ long APE::File::findAPE()
else
seek(-32, End);
long p = tell();
offset_t p = tell();
if(readBlock(8) == APE::Tag::fileIdentifier())
return p;
@ -290,13 +290,13 @@ long APE::File::findAPE()
return -1;
}
long APE::File::findID3v1()
offset_t APE::File::findID3v1()
{
if(!isValid())
return -1;
seek(-128, End);
long p = tell();
offset_t p = tell();
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
return p;

View File

@ -189,8 +189,8 @@ namespace TagLib {
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
void scan();
long findID3v1();
long findAPE();
offset_t findID3v1();
offset_t findAPE();
class FilePrivate;
FilePrivate *d;

View File

@ -39,7 +39,7 @@ using namespace TagLib;
class APE::Properties::PropertiesPrivate
{
public:
PropertiesPrivate(File *file, long streamLength) :
PropertiesPrivate(File *file, offset_t streamLength) :
length(0),
bitrate(0),
sampleRate(0),
@ -58,7 +58,7 @@ public:
int bitsPerSample;
uint sampleFrames;
File *file;
long streamLength;
offset_t streamLength;
};
////////////////////////////////////////////////////////////////////////////////
@ -119,7 +119,7 @@ TagLib::uint APE::Properties::sampleFrames() const
void APE::Properties::read()
{
// First we are searching the descriptor
long offset = findDescriptor();
offset_t offset = findDescriptor();
if(offset < 0)
return;
@ -138,9 +138,9 @@ void APE::Properties::read()
}
}
long APE::Properties::findDescriptor()
offset_t APE::Properties::findDescriptor()
{
long ID3v2Location = findID3v2();
offset_t ID3v2Location = findID3v2();
long ID3v2OriginalSize = 0;
bool hasID3v2 = false;
if(ID3v2Location >= 0) {
@ -150,7 +150,7 @@ long APE::Properties::findDescriptor()
hasID3v2 = true;
}
long offset = 0;
offset_t offset = 0;
if(hasID3v2)
offset = d->file->find("MAC ", ID3v2Location + ID3v2OriginalSize);
else
@ -164,7 +164,7 @@ long APE::Properties::findDescriptor()
return offset;
}
long APE::Properties::findID3v2()
offset_t APE::Properties::findID3v2()
{
if(!d->file->isValid())
return -1;
@ -201,7 +201,7 @@ void APE::Properties::analyzeCurrent()
uint finalFrameBlocks = header.mid(8, 4).toUInt(false);
d->sampleFrames = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
}
void APE::Properties::analyzeOld()
@ -226,6 +226,6 @@ void APE::Properties::analyzeOld()
uint finalFrameBlocks = header.mid(22, 4).toUInt(false);
uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = totalBlocks / d->sampleRate;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
}

View File

@ -84,8 +84,8 @@ namespace TagLib {
void read();
long findDescriptor();
long findID3v2();
offset_t findDescriptor();
offset_t findID3v2();
void analyzeCurrent();
void analyzeOld();

View File

@ -49,7 +49,7 @@ public:
TagPrivate() : file(0), footerLocation(-1), tagLength(0) {}
TagLib::File *file;
long footerLocation;
offset_t footerLocation;
long tagLength;
Footer footer;
@ -66,7 +66,7 @@ APE::Tag::Tag() : TagLib::Tag()
d = new TagPrivate;
}
APE::Tag::Tag(TagLib::File *file, long footerLocation) : TagLib::Tag()
APE::Tag::Tag(TagLib::File *file, offset_t footerLocation) : TagLib::Tag()
{
d = new TagPrivate;
d->file = file;

View File

@ -66,7 +66,7 @@ namespace TagLib {
* Create an APE tag and parse the data in \a file with APE footer at
* \a tagOffset.
*/
Tag(TagLib::File *file, long footerLocation);
Tag(TagLib::File *file, offset_t footerLocation);
/*!
* Destroys this Tag instance.

View File

@ -158,7 +158,7 @@ ASF::File::HeaderExtensionObject::~HeaderExtensionObject()
void ASF::File::BaseObject::parse(ASF::File *file, unsigned int size)
{
data.clear();
if (size > 24 && size <= (unsigned int)(file->length()))
if (size > 24 && static_cast<offset_t>(size) <= file->length())
data = file->readBlock(size - 24);
else
data = ByteVector::null;

View File

@ -78,10 +78,10 @@ public:
}
const ID3v2::FrameFactory *ID3v2FrameFactory;
long ID3v2Location;
offset_t ID3v2Location;
uint ID3v2OriginalSize;
long ID3v1Location;
offset_t ID3v1Location;
TagUnion tag;
@ -90,9 +90,9 @@ public:
ByteVector xiphCommentData;
List<MetadataBlock *> blocks;
long flacStart;
long streamStart;
long streamLength;
offset_t flacStart;
offset_t streamStart;
offset_t streamLength;
bool scanned;
bool hasXiphComment;
@ -237,7 +237,7 @@ bool FLAC::File::save()
// Adjust the padding block(s)
long originalLength = d->streamStart - d->flacStart;
uint originalLength = static_cast<uint>(d->streamStart - d->flacStart);
int paddingLength = originalLength - data.size() - 4;
if (paddingLength < 0) {
paddingLength = MinPaddingLength;
@ -356,7 +356,7 @@ ByteVector FLAC::File::xiphCommentData() const
return (isValid() && d->hasXiphComment) ? d->xiphCommentData : ByteVector();
}
long FLAC::File::streamLength()
offset_t FLAC::File::streamLength()
{
return d->streamLength;
}
@ -371,7 +371,7 @@ void FLAC::File::scan()
if(!isValid())
return;
long nextBlockOffset;
offset_t nextBlockOffset;
if(d->hasID3v2)
nextBlockOffset = find("fLaC", d->ID3v2Location + d->ID3v2OriginalSize);
@ -486,13 +486,13 @@ void FLAC::File::scan()
d->scanned = true;
}
long FLAC::File::findID3v1()
offset_t FLAC::File::findID3v1()
{
if(!isValid())
return -1;
seek(-128, End);
long p = tell();
offset_t p = tell();
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
return p;
@ -500,7 +500,7 @@ long FLAC::File::findID3v1()
return -1;
}
long FLAC::File::findID3v2()
offset_t FLAC::File::findID3v2()
{
if(!isValid())
return -1;

View File

@ -215,7 +215,7 @@ namespace TagLib {
*
* \deprecated This method will not be public in a future release.
*/
long streamLength(); // BIC: remove
offset_t streamLength(); // BIC: remove
/*!
* Returns a list of pictures attached to the FLAC file.
@ -247,10 +247,10 @@ namespace TagLib {
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
void scan();
long findID3v2();
long findID3v1();
offset_t findID3v2();
offset_t findID3v1();
ByteVector xiphCommentData() const;
long findPaddingBreak(long nextPageOffset, long targetOffset, bool *isLast);
offset_t findPaddingBreak(long nextPageOffset, long targetOffset, bool *isLast);
class FilePrivate;
FilePrivate *d;

View File

@ -34,7 +34,7 @@ using namespace TagLib;
class FLAC::Properties::PropertiesPrivate
{
public:
PropertiesPrivate(ByteVector d, long st, ReadStyle s) :
PropertiesPrivate(ByteVector d, offset_t st, ReadStyle s) :
data(d),
streamLength(st),
style(s),
@ -46,7 +46,7 @@ public:
sampleFrames(0) {}
ByteVector data;
long streamLength;
offset_t streamLength;
ReadStyle style;
int length;
int bitrate;
@ -61,7 +61,7 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
FLAC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : AudioProperties(style)
FLAC::Properties::Properties(ByteVector data, offset_t streamLength, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate(data, streamLength, style);
read();
@ -155,7 +155,7 @@ void FLAC::Properties::read()
d->sampleFrames = (hi << 32) | lo;
if(d->sampleRate > 0)
d->length = int(d->sampleFrames / d->sampleRate);
d->length = static_cast<int>(d->sampleFrames / d->sampleRate);
// Uncompressed bitrate:
@ -163,7 +163,7 @@ void FLAC::Properties::read()
// Real bitrate:
d->bitrate = d->length > 0 ? ((d->streamLength * 8UL) / d->length) / 1000 : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
d->signature = d->data.mid(pos, 32);
}

View File

@ -50,7 +50,7 @@ namespace TagLib {
* ByteVector \a data.
*/
// BIC: switch to const reference
Properties(ByteVector data, long streamLength, ReadStyle style = Average);
Properties(ByteVector data, offset_t streamLength, ReadStyle style = Average);
/*!
* Create an instance of FLAC::Properties with the data read from the

View File

@ -155,7 +155,7 @@ bool IT::File::save()
if(!readU16L(special))
return false;
ulong fileSize = File::length();
ulong fileSize = static_cast<ulong>(File::length());
if(special & Properties::MessageAttached) {
seek(54);
if(!readU16L(messageLength) || !readU32L(messageOffset))

View File

@ -152,7 +152,7 @@ MP4::Atom::path(MP4::AtomList &path, const char *name1, const char *name2, const
MP4::Atoms::Atoms(File *file)
{
file->seek(0, File::End);
long end = file->tell();
offset_t end = file->tell();
file->seek(0);
while(file->tell() + 8 <= end) {
MP4::Atom *atom = new MP4::Atom(file);

View File

@ -82,7 +82,7 @@ namespace TagLib {
Atom *find(const char *name1, const char *name2 = 0, const char *name3 = 0, const char *name4 = 0);
bool path(AtomList &path, const char *name1, const char *name2 = 0, const char *name3 = 0);
AtomList findall(const char *name, bool recursive = false);
long offset;
offset_t offset;
long length;
TagLib::ByteVector name;
AtomList children;

View File

@ -514,7 +514,7 @@ MP4::Tag::updateParents(AtomList &path, long delta, int ignore)
}
void
MP4::Tag::updateOffsets(long delta, long offset)
MP4::Tag::updateOffsets(long delta, offset_t offset)
{
MP4::Atom *moov = d->atoms->find("moov");
if(moov) {
@ -597,7 +597,7 @@ MP4::Tag::saveNew(ByteVector &data)
data = renderAtom("udta", data);
}
long offset = path[path.size() - 1]->offset + 8;
offset_t offset = path[path.size() - 1]->offset + 8;
d->file->insert(data, offset, 0);
updateParents(path, data.size());
@ -608,7 +608,7 @@ void
MP4::Tag::saveExisting(ByteVector &data, AtomList &path)
{
MP4::Atom *ilst = path[path.size() - 1];
long offset = ilst->offset;
offset_t offset = ilst->offset;
long length = ilst->length;
MP4::Atom *meta = path[path.size() - 2];

View File

@ -96,7 +96,7 @@ namespace TagLib {
TagLib::ByteVector renderCovr(const ByteVector &name, Item &item);
void updateParents(AtomList &path, long delta, int ignore = 0);
void updateOffsets(long delta, long offset);
void updateOffsets(long delta, offset_t offset);
void saveNew(TagLib::ByteVector &data);
void saveExisting(TagLib::ByteVector &data, AtomList &path);

View File

@ -64,13 +64,13 @@ public:
delete properties;
}
long APELocation;
offset_t APELocation;
uint APESize;
long ID3v1Location;
offset_t ID3v1Location;
ID3v2::Header *ID3v2Header;
long ID3v2Location;
offset_t ID3v2Location;
uint ID3v2Size;
TagUnion tag;
@ -314,7 +314,7 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle /* propertiesSty
}
}
long MPC::File::findAPE()
offset_t MPC::File::findAPE()
{
if(!isValid())
return -1;
@ -324,7 +324,7 @@ long MPC::File::findAPE()
else
seek(-32, End);
long p = tell();
offset_t p = tell();
if(readBlock(8) == APE::Tag::fileIdentifier())
return p;
@ -332,13 +332,13 @@ long MPC::File::findAPE()
return -1;
}
long MPC::File::findID3v1()
offset_t MPC::File::findID3v1()
{
if(!isValid())
return -1;
seek(-128, End);
long p = tell();
offset_t p = tell();
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
return p;
@ -346,7 +346,7 @@ long MPC::File::findID3v1()
return -1;
}
long MPC::File::findID3v2()
offset_t MPC::File::findID3v2()
{
if(!isValid())
return -1;

View File

@ -191,9 +191,9 @@ namespace TagLib {
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
void scan();
long findAPE();
long findID3v1();
long findID3v2();
offset_t findAPE();
offset_t findID3v1();
offset_t findID3v2();
class FilePrivate;
FilePrivate *d;

View File

@ -36,7 +36,7 @@ using namespace TagLib;
class MPC::Properties::PropertiesPrivate
{
public:
PropertiesPrivate(long length, ReadStyle s) :
PropertiesPrivate(offset_t length, ReadStyle s) :
streamLength(length),
style(s),
version(0),
@ -51,7 +51,7 @@ public:
albumGain(0),
albumPeak(0) {}
long streamLength;
offset_t streamLength;
ReadStyle style;
int version;
int length;
@ -71,13 +71,13 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
MPC::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
MPC::Properties::Properties(const ByteVector &data, offset_t streamLength, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate(streamLength, style);
readSV7(data);
}
MPC::Properties::Properties(File *file, long streamLength, ReadStyle style) : AudioProperties(style)
MPC::Properties::Properties(File *file, offset_t streamLength, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate(streamLength, style);
ByteVector magic = file->readBlock(4);
@ -214,7 +214,7 @@ void MPC::Properties::readSV8(File *file)
d->channels = flags[7] * 8 + flags[6] * 4 + flags[5] * 2 + flags[4] + 1;
if((d->sampleFrames - begSilence) != 0)
d->bitrate = (int)(d->streamLength * 8.0 * d->sampleRate / (d->sampleFrames - begSilence));
d->bitrate = static_cast<int>(d->streamLength * 8.0 * d->sampleRate / (d->sampleFrames - begSilence));
d->bitrate = d->bitrate / 1000;
d->length = (d->sampleFrames - begSilence) / d->sampleRate;
@ -311,6 +311,6 @@ void MPC::Properties::readSV7(const ByteVector &data)
d->length = d->sampleRate > 0 ? (d->sampleFrames + (d->sampleRate / 2)) / d->sampleRate : 0;
if(!d->bitrate)
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
}

View File

@ -53,13 +53,13 @@ namespace TagLib {
*
* This constructor is deprecated. It only works for MPC version up to 7.
*/
Properties(const ByteVector &data, long streamLength, ReadStyle style = Average);
Properties(const ByteVector &data, offset_t streamLength, ReadStyle style = Average);
/*!
* Create an instance of MPC::Properties with the data read directly
* from a MPC::File.
*/
Properties(File *file, long streamLength, ReadStyle style = Average);
Properties(File *file, offset_t streamLength, ReadStyle style = Average);
/*!
* Destroys this MPC::Properties instance.

View File

@ -38,7 +38,7 @@ public:
TagPrivate() : file(0), tagOffset(-1), track(0), genre(255) {}
File *file;
long tagOffset;
offset_t tagOffset;
String title;
String artist;
@ -80,7 +80,7 @@ ID3v1::Tag::Tag() : TagLib::Tag()
d = new TagPrivate;
}
ID3v1::Tag::Tag(File *file, long tagOffset) : TagLib::Tag()
ID3v1::Tag::Tag(File *file, offset_t tagOffset) : TagLib::Tag()
{
d = new TagPrivate;
d->file = file;

View File

@ -111,7 +111,7 @@ namespace TagLib {
* Create an ID3v1 tag and parse the data in \a file starting at
* \a tagOffset.
*/
Tag(File *file, long tagOffset);
Tag(File *file, offset_t tagOffset);
/*!
* Destroys this Tag instance.

View File

@ -59,7 +59,7 @@ public:
}
File *file;
long tagOffset;
offset_t tagOffset;
const FrameFactory *factory;
Header header;
@ -101,7 +101,7 @@ ID3v2::Tag::Tag() : TagLib::Tag()
d->factory = FrameFactory::instance();
}
ID3v2::Tag::Tag(File *file, long tagOffset, const FrameFactory *factory) :
ID3v2::Tag::Tag(File *file, offset_t tagOffset, const FrameFactory *factory) :
TagLib::Tag()
{
d = new TagPrivate;

View File

@ -159,7 +159,7 @@ namespace TagLib {
*
* \see FrameFactory
*/
Tag(File *file, long tagOffset,
Tag(File *file, offset_t tagOffset,
const FrameFactory *factory = FrameFactory::instance());
/*!

View File

@ -70,14 +70,14 @@ public:
const ID3v2::FrameFactory *ID3v2FrameFactory;
long ID3v2Location;
offset_t ID3v2Location;
uint ID3v2OriginalSize;
long APELocation;
long APEFooterLocation;
offset_t APELocation;
offset_t APEFooterLocation;
uint APEOriginalSize;
long ID3v1Location;
offset_t ID3v1Location;
TagUnion tag;
@ -368,7 +368,7 @@ void MPEG::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory)
d->ID3v2FrameFactory = factory;
}
long MPEG::File::nextFrameOffset(long position)
offset_t MPEG::File::nextFrameOffset(offset_t position)
{
bool foundLastSyncPattern = false;
@ -394,13 +394,13 @@ long MPEG::File::nextFrameOffset(long position)
}
}
long MPEG::File::previousFrameOffset(long position)
offset_t MPEG::File::previousFrameOffset(offset_t position)
{
bool foundFirstSyncPattern = false;
ByteVector buffer;
while (position > 0) {
long size = ulong(position) < bufferSize() ? position : bufferSize();
uint size = position < static_cast<offset_t>(bufferSize()) ? static_cast<uint>(position) : bufferSize();
position -= size;
seek(position);
@ -422,9 +422,9 @@ long MPEG::File::previousFrameOffset(long position)
return -1;
}
long MPEG::File::firstFrameOffset()
offset_t MPEG::File::firstFrameOffset()
{
long position = 0;
offset_t position = 0;
if(ID3v2Tag())
position = d->ID3v2Location + ID3v2Tag()->header()->completeTagSize();
@ -432,7 +432,7 @@ long MPEG::File::firstFrameOffset()
return nextFrameOffset(position);
}
long MPEG::File::lastFrameOffset()
offset_t MPEG::File::lastFrameOffset()
{
return previousFrameOffset(ID3v1Tag() ? d->ID3v1Location - 1 : length());
}
@ -503,7 +503,7 @@ void MPEG::File::read(bool readProperties, Properties::ReadStyle propertiesStyle
ID3v1Tag(true);
}
long MPEG::File::findID3v2()
offset_t MPEG::File::findID3v2()
{
// This method is based on the contents of TagLib::File::find(), but because
// of some subtlteies -- specifically the need to look for the bit pattern of
@ -513,7 +513,7 @@ long MPEG::File::findID3v2()
// The position in the file that the current buffer starts at.
long bufferOffset = 0;
offset_t bufferOffset = 0;
ByteVector buffer;
// These variables are used to keep track of a partial match that happens at
@ -525,7 +525,7 @@ long MPEG::File::findID3v2()
// Save the location of the current read pointer. We will restore the
// position using seek() before all returns.
long originalPosition = tell();
offset_t originalPosition = tell();
// Start the search at the beginning of the file.
@ -614,11 +614,11 @@ long MPEG::File::findID3v2()
return -1;
}
long MPEG::File::findID3v1()
offset_t MPEG::File::findID3v1()
{
if(isValid()) {
seek(-128, End);
long p = tell();
offset_t p = tell();
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
return p;
@ -631,7 +631,7 @@ void MPEG::File::findAPE()
if(isValid()) {
seek(d->hasID3v1 ? -160 : -32, End);
long p = tell();
offset_t p = tell();
if(readBlock(8) == APE::Tag::fileIdentifier()) {
d->APEFooterLocation = p;

View File

@ -282,24 +282,24 @@ namespace TagLib {
/*!
* Returns the position in the file of the first MPEG frame.
*/
long firstFrameOffset();
offset_t firstFrameOffset();
/*!
* Returns the position in the file of the next MPEG frame,
* using the current position as start
*/
long nextFrameOffset(long position);
offset_t nextFrameOffset(offset_t position);
/*!
* Returns the position in the file of the previous MPEG frame,
* using the current position as start
*/
long previousFrameOffset(long position);
offset_t previousFrameOffset(offset_t position);
/*!
* Returns the position in the file of the last MPEG frame.
*/
long lastFrameOffset();
offset_t lastFrameOffset();
/*!
* Returns whether or not the file on disk contains ID3v1 tag.
@ -321,8 +321,8 @@ namespace TagLib {
File &operator=(const File &);
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
long findID3v2();
long findID3v1();
offset_t findID3v2();
offset_t findID3v1();
void findAPE();
/*!

View File

@ -151,7 +151,7 @@ void MPEG::Properties::read()
// Since we've likely just looked for the ID3v1 tag, start at the end of the
// file where we're least likely to have to have to move the disk head.
long last = d->file->lastFrameOffset();
offset_t last = d->file->lastFrameOffset();
if(last < 0) {
debug("MPEG::Properties::read() -- Could not find a valid last MPEG frame in the stream.");
@ -161,7 +161,7 @@ void MPEG::Properties::read()
d->file->seek(last);
Header lastHeader(d->file->readBlock(4));
long first = d->file->firstFrameOffset();
offset_t first = d->file->firstFrameOffset();
if(first < 0) {
debug("MPEG::Properties::read() -- Could not find a valid first MPEG frame in the stream.");
@ -170,7 +170,7 @@ void MPEG::Properties::read()
if(!lastHeader.isValid()) {
long pos = last;
offset_t pos = last;
while(pos > first) {
@ -234,7 +234,7 @@ void MPEG::Properties::read()
// Xing header.
if(firstHeader.frameLength() > 0 && firstHeader.bitrate() > 0) {
int frames = (last - first) / firstHeader.frameLength() + 1;
int frames = static_cast<int>((last - first) / firstHeader.frameLength() + 1);
d->length = int(float(firstHeader.frameLength() * frames) /
float(firstHeader.bitrate() * 125) + 0.5);

View File

@ -56,8 +56,8 @@ public:
Properties *properties;
ByteVector streamInfoData;
ByteVector xiphCommentData;
long streamStart;
long streamLength;
offset_t streamStart;
offset_t streamLength;
bool scanned;
bool hasXiphComment;
@ -173,7 +173,7 @@ ByteVector Ogg::FLAC::File::xiphCommentData()
return d->xiphCommentData;
}
long Ogg::FLAC::File::streamLength()
offset_t Ogg::FLAC::File::streamLength()
{
scan();
return d->streamLength;
@ -190,7 +190,7 @@ void Ogg::FLAC::File::scan()
return;
int ipacket = 0;
long overhead = 0;
offset_t overhead = 0;
ByteVector metadataHeader = packet(ipacket);
if(metadataHeader.isNull())

View File

@ -108,7 +108,7 @@ namespace TagLib {
* Returns the length of the audio-stream, used by FLAC::Properties for
* calculating the bitrate.
*/
long streamLength();
offset_t streamLength();
private:
File(const File &);

View File

@ -157,7 +157,7 @@ const Ogg::PageHeader *Ogg::File::firstPageHeader()
if(d->firstPageHeader)
return d->firstPageHeader->isValid() ? d->firstPageHeader : 0;
long firstPageHeaderOffset = find("OggS");
offset_t firstPageHeaderOffset = find("OggS");
if(firstPageHeaderOffset < 0)
return 0;
@ -171,7 +171,7 @@ const Ogg::PageHeader *Ogg::File::lastPageHeader()
if(d->lastPageHeader)
return d->lastPageHeader->isValid() ? d->lastPageHeader : 0;
long lastPageHeaderOffset = rfind("OggS");
offset_t lastPageHeaderOffset = rfind("OggS");
if(lastPageHeaderOffset < 0)
return 0;
@ -224,7 +224,7 @@ Ogg::File::File(IOStream *stream) : TagLib::File(stream)
bool Ogg::File::nextPage()
{
long nextPageOffset;
offset_t nextPageOffset;
int currentPacket;
if(d->pages.isEmpty()) {

View File

@ -35,7 +35,7 @@ using namespace TagLib;
class Ogg::Page::PagePrivate
{
public:
PagePrivate(File *f = 0, long pageOffset = -1) :
PagePrivate(File *f = 0, offset_t pageOffset = -1) :
file(f),
fileOffset(pageOffset),
packetOffset(0),
@ -50,8 +50,8 @@ public:
}
File *file;
long fileOffset;
long packetOffset;
offset_t fileOffset;
offset_t packetOffset;
int dataSize;
List<int> packetSizes;
PageHeader header;
@ -63,7 +63,7 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
Ogg::Page::Page(Ogg::File *file, long pageOffset)
Ogg::Page::Page(Ogg::File *file, offset_t pageOffset)
{
d = new PagePrivate(file, pageOffset);
}
@ -73,7 +73,7 @@ Ogg::Page::~Page()
delete d;
}
long Ogg::Page::fileOffset() const
offset_t Ogg::Page::fileOffset() const
{
return d->fileOffset;
}

View File

@ -55,14 +55,14 @@ namespace TagLib {
/*!
* Read an Ogg page from the \a file at the position \a pageOffset.
*/
Page(File *file, long pageOffset);
Page(File *file, offset_t pageOffset);
virtual ~Page();
/*!
* Returns the page's position within the file (in bytes).
*/
long fileOffset() const;
offset_t fileOffset() const;
/*!
* Returns a pointer to the header for this page. This pointer will become

View File

@ -39,7 +39,7 @@ using namespace TagLib;
class Ogg::PageHeader::PageHeaderPrivate
{
public:
PageHeaderPrivate(File *f, long pageOffset) :
PageHeaderPrivate(File *f, offset_t pageOffset) :
file(f),
fileOffset(pageOffset),
isValid(false),
@ -55,7 +55,7 @@ public:
{}
File *file;
long fileOffset;
offset_t fileOffset;
bool isValid;
List<int> packetSizes;
bool firstPacketContinued;
@ -73,7 +73,7 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
Ogg::PageHeader::PageHeader(Ogg::File *file, long pageOffset)
Ogg::PageHeader::PageHeader(Ogg::File *file, offset_t pageOffset)
{
d = new PageHeaderPrivate(file, pageOffset);
if(file && pageOffset >= 0)

View File

@ -52,7 +52,7 @@ namespace TagLib {
* create a page with no (and as such, invalid) data that must be set
* later.
*/
PageHeader(File *file = 0, long pageOffset = -1);
PageHeader(File *file = 0, offset_t pageOffset = -1);
/*!
* Deletes this instance of the PageHeader.

View File

@ -35,7 +35,7 @@ using namespace TagLib;
struct Chunk
{
ByteVector name;
TagLib::uint offset;
offset_t offset;
TagLib::uint size;
char padding;
};
@ -103,7 +103,7 @@ TagLib::uint RIFF::File::chunkDataSize(uint i) const
return d->chunks[i].size;
}
TagLib::uint RIFF::File::chunkOffset(uint i) const
offset_t RIFF::File::chunkOffset(uint i) const
{
return d->chunks[i].offset;
}
@ -182,20 +182,25 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo
// Couldn't find an existing chunk, so let's create a new one.
uint i = d->chunks.size() - 1;
ulong offset = d->chunks[i].offset + d->chunks[i].size;
offset_t offset = d->chunks[i].offset + d->chunks[i].size;
// First we update the global size
d->size += (offset & 1) + data.size() + 8;
d->size += static_cast<uint>(offset & 1) + data.size() + 8;
insert(ByteVector::fromUInt(d->size, d->endianness == BigEndian), 4, 4);
// Now add the chunk to the file
writeChunk(name, data, offset, std::max<long>(0, length() - offset), (offset & 1) ? 1 : 0);
writeChunk(
name,
data,
offset,
static_cast<uint>(std::max<offset_t>(0, length() - offset)),
static_cast<uint>(offset & 1));
// And update our internal structure
if (offset & 1) {
if(offset & 1) {
d->chunks[i].padding = 1;
offset++;
}
@ -204,7 +209,7 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo
chunk.name = name;
chunk.size = data.size();
chunk.offset = offset + 8;
chunk.padding = (data.size() & 0x01) ? 1 : 0;
chunk.padding = static_cast<char>(data.size() & 1);
d->chunks.push_back(chunk);
}
@ -282,8 +287,8 @@ void RIFF::File::read()
// check padding
chunk.padding = 0;
long uPosNotPadded = tell();
if((uPosNotPadded & 0x01) != 0) {
offset_t uPosNotPadded = tell();
if(uPosNotPadded & 1) {
ByteVector iByte = readBlock(1);
if((iByte.size() != 1) || (iByte[0] != 0)) {
// not well formed, re-seek
@ -299,7 +304,7 @@ void RIFF::File::read()
}
void RIFF::File::writeChunk(const ByteVector &name, const ByteVector &data,
ulong offset, ulong replace, uint leadingPadding)
offset_t offset, TagLib::uint replace, TagLib::uint leadingPadding)
{
ByteVector combined;
if(leadingPadding) {

View File

@ -71,7 +71,7 @@ namespace TagLib {
/*!
* \return The offset within the file for the selected chunk number.
*/
uint chunkOffset(uint i) const;
offset_t chunkOffset(uint i) const;
/*!
* \return The size of the chunk data.
@ -135,7 +135,7 @@ namespace TagLib {
void read();
void writeChunk(const ByteVector &name, const ByteVector &data,
ulong offset, ulong replace = 0,
offset_t offset, uint replace = 0,
uint leadingPadding = 0);
class FilePrivate;

View File

@ -44,6 +44,17 @@
#include <string>
#ifndef _WIN32
# ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE
# endif
# define _FILE_OFFSET_BITS 64
# include <sys/types.h>
#endif
#ifdef __APPLE__
# include <libkern/OSAtomic.h>
# define TAGLIB_ATOMIC_MAC
@ -83,6 +94,14 @@ namespace TagLib {
typedef unsigned int uint;
typedef unsigned long ulong;
// Offset or length type for I/O streams.
// In Win32, always 64bit. Otherwise, equivalent to off_t.
#ifdef _WIN32
typedef LONGLONG offset_t;
#else
typedef off_t offset_t;
#endif
/*!
* Unfortunately std::wstring isn't defined on some systems, (i.e. GCC < 3)
* so I'm providing something here that should be constant.

View File

@ -28,9 +28,9 @@
#include "tdebug.h"
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
using namespace TagLib;
@ -40,7 +40,7 @@ public:
ByteVectorStreamPrivate(const ByteVector &data);
ByteVector data;
long position;
offset_t position;
};
ByteVectorStream::ByteVectorStreamPrivate::ByteVectorStreamPrivate(const ByteVector &data) :
@ -68,12 +68,12 @@ FileName ByteVectorStream::name() const
return FileName(""); // XXX do we need a name?
}
ByteVector ByteVectorStream::readBlock(ulong length)
ByteVector ByteVectorStream::readBlock(uint length)
{
if(length == 0)
return ByteVector::null;
ByteVector v = d->data.mid(d->position, length);
ByteVector v = d->data.mid(static_cast<uint>(d->position), length);
d->position += v.size();
return v;
}
@ -81,14 +81,14 @@ ByteVector ByteVectorStream::readBlock(ulong length)
void ByteVectorStream::writeBlock(const ByteVector &data)
{
uint size = data.size();
if(long(d->position + size) > length()) {
if(static_cast<offset_t>(d->position + size) > length())
truncate(d->position + size);
}
memcpy(d->data.data() + d->position, data.data(), size);
d->position += size;
}
void ByteVectorStream::insert(const ByteVector &data, ulong start, ulong replace)
void ByteVectorStream::insert(const ByteVector &data, offset_t start, uint replace)
{
long sizeDiff = data.size() - replace;
if(sizeDiff < 0) {
@ -96,21 +96,27 @@ void ByteVectorStream::insert(const ByteVector &data, ulong start, ulong replace
}
else if(sizeDiff > 0) {
truncate(length() + sizeDiff);
ulong readPosition = start + replace;
ulong writePosition = start + data.size();
memmove(d->data.data() + writePosition, d->data.data() + readPosition, length() - sizeDiff - readPosition);
offset_t readPosition = start + replace;
offset_t writePosition = start + data.size();
memmove(
d->data.data() + static_cast<ptrdiff_t>(writePosition),
d->data.data() + static_cast<ptrdiff_t>(readPosition),
static_cast<size_t>(length() - sizeDiff - readPosition));
}
seek(start);
writeBlock(data);
}
void ByteVectorStream::removeBlock(ulong start, ulong length)
void ByteVectorStream::removeBlock(offset_t start, uint length)
{
ulong readPosition = start + length;
ulong writePosition = start;
if(readPosition < ulong(ByteVectorStream::length())) {
ulong bytesToMove = ByteVectorStream::length() - readPosition;
memmove(d->data.data() + writePosition, d->data.data() + readPosition, bytesToMove);
offset_t readPosition = start + length;
offset_t writePosition = start;
if(readPosition < ByteVectorStream::length()) {
size_t bytesToMove = static_cast<size_t>(ByteVectorStream::length() - readPosition);
memmove(
d->data.data() + static_cast<ptrdiff_t>(writePosition),
d->data.data() + static_cast<ptrdiff_t>(readPosition),
bytesToMove);
writePosition += bytesToMove;
}
d->position = writePosition;
@ -127,7 +133,7 @@ bool ByteVectorStream::isOpen() const
return true;
}
void ByteVectorStream::seek(long offset, Position p)
void ByteVectorStream::seek(offset_t offset, Position p)
{
switch(p) {
case Beginning:
@ -146,19 +152,19 @@ void ByteVectorStream::clear()
{
}
long ByteVectorStream::tell() const
offset_t ByteVectorStream::tell() const
{
return d->position;
}
long ByteVectorStream::length()
offset_t ByteVectorStream::length()
{
return d->data.size();
return static_cast<offset_t>(d->data.size());
}
void ByteVectorStream::truncate(long length)
void ByteVectorStream::truncate(offset_t length)
{
d->data.resize(length);
d->data.resize(static_cast<uint>(length));
}
ByteVector *ByteVectorStream::data()

View File

@ -61,7 +61,7 @@ namespace TagLib {
/*!
* Reads a block of size \a length at the current get pointer.
*/
ByteVector readBlock(ulong length);
ByteVector readBlock(uint length);
/*!
* Attempts to write the block \a data at the current get pointer. If the
@ -81,7 +81,7 @@ namespace TagLib {
* \note This method is slow since it requires rewriting all of the file
* after the insertion point.
*/
void insert(const ByteVector &data, ulong start = 0, ulong replace = 0);
void insert(const ByteVector &data, offset_t start = 0, uint replace = 0);
/*!
* Removes a block of the file starting a \a start and continuing for
@ -90,7 +90,7 @@ namespace TagLib {
* \note This method is slow since it involves rewriting all of the file
* after the removed portion.
*/
void removeBlock(ulong start = 0, ulong length = 0);
void removeBlock(offset_t start = 0, uint length = 0);
/*!
* Returns true if the file is read only (or if the file can not be opened).
@ -109,7 +109,7 @@ namespace TagLib {
*
* \see Position
*/
void seek(long offset, Position p = Beginning);
void seek(offset_t offset, Position p = Beginning);
/*!
* Reset the end-of-file and error flags on the file.
@ -119,17 +119,17 @@ namespace TagLib {
/*!
* Returns the current offset within the file.
*/
long tell() const;
offset_t tell() const;
/*!
* Returns the length of the file.
*/
long length();
offset_t length();
/*!
* Truncates the file to a \a length.
*/
void truncate(long length);
void truncate(offset_t length);
ByteVector *data();

View File

@ -132,7 +132,7 @@ PropertyMap File::setProperties(const PropertyMap &properties)
return tag()->setProperties(properties);
}
ByteVector File::readBlock(ulong length)
ByteVector File::readBlock(uint length)
{
return d->stream->readBlock(length);
}
@ -142,14 +142,14 @@ void File::writeBlock(const ByteVector &data)
d->stream->writeBlock(data);
}
long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &before)
offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVector &before)
{
if(!d->stream || pattern.size() > d->bufferSize)
return -1;
// The position in the file that the current buffer starts at.
long bufferOffset = fromOffset;
offset_t bufferOffset = fromOffset;
ByteVector buffer;
// These variables are used to keep track of a partial match that happens at
@ -161,7 +161,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
// Save the location of the current read pointer. We will restore the
// position using seek() before all returns.
long originalPosition = tell();
offset_t originalPosition = tell();
// Start the search at the offset.
@ -238,7 +238,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
}
long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &before)
offset_t File::rfind(const ByteVector &pattern, offset_t fromOffset, const ByteVector &before)
{
if(!d->stream || pattern.size() > d->bufferSize)
return -1;
@ -258,11 +258,11 @@ long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &b
// Save the location of the current read pointer. We will restore the
// position using seek() before all returns.
long originalPosition = tell();
offset_t originalPosition = tell();
// Start the search at the offset.
long bufferOffset;
offset_t bufferOffset;
if(fromOffset == 0) {
seek(-1 * int(d->bufferSize), End);
bufferOffset = tell();
@ -306,12 +306,12 @@ long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &b
return -1;
}
void File::insert(const ByteVector &data, ulong start, ulong replace)
void File::insert(const ByteVector &data, offset_t start, uint replace)
{
d->stream->insert(data, start, replace);
}
void File::removeBlock(ulong start, ulong length)
void File::removeBlock(offset_t start, uint length)
{
d->stream->removeBlock(start, length);
}
@ -331,12 +331,12 @@ bool File::isValid() const
return isOpen() && d->valid;
}
void File::seek(long offset, Position p)
void File::seek(offset_t offset, Position p)
{
d->stream->seek(offset, IOStream::Position(p));
}
void File::truncate(long length)
void File::truncate(offset_t length)
{
d->stream->truncate(length);
}
@ -346,12 +346,12 @@ void File::clear()
d->stream->clear();
}
long File::tell() const
offset_t File::tell() const
{
return d->stream->tell();
}
long File::length()
offset_t File::length()
{
return d->stream->length();
}

View File

@ -128,7 +128,7 @@ namespace TagLib {
/*!
* Reads a block of size \a length at the current get pointer.
*/
ByteVector readBlock(ulong length);
ByteVector readBlock(uint length);
/*!
* Attempts to write the block \a data at the current get pointer. If the
@ -153,8 +153,8 @@ namespace TagLib {
* \note This has the practial limitation that \a pattern can not be longer
* than the buffer size used by readBlock(). Currently this is 1024 bytes.
*/
long find(const ByteVector &pattern,
long fromOffset = 0,
offset_t find(const ByteVector &pattern,
offset_t fromOffset = 0,
const ByteVector &before = ByteVector::null);
/*!
@ -169,8 +169,8 @@ namespace TagLib {
* \note This has the practial limitation that \a pattern can not be longer
* than the buffer size used by readBlock(). Currently this is 1024 bytes.
*/
long rfind(const ByteVector &pattern,
long fromOffset = 0,
offset_t rfind(const ByteVector &pattern,
offset_t fromOffset = 0,
const ByteVector &before = ByteVector::null);
/*!
@ -180,7 +180,7 @@ namespace TagLib {
* \note This method is slow since it requires rewriting all of the file
* after the insertion point.
*/
void insert(const ByteVector &data, ulong start = 0, ulong replace = 0);
void insert(const ByteVector &data, offset_t start = 0, uint replace = 0);
/*!
* Removes a block of the file starting a \a start and continuing for
@ -189,7 +189,7 @@ namespace TagLib {
* \note This method is slow since it involves rewriting all of the file
* after the removed portion.
*/
void removeBlock(ulong start = 0, ulong length = 0);
void removeBlock(offset_t start = 0, uint length = 0);
/*!
* Returns true if the file is read only (or if the file can not be opened).
@ -213,7 +213,7 @@ namespace TagLib {
*
* \see Position
*/
void seek(long offset, Position p = Beginning);
void seek(offset_t offset, Position p = Beginning);
/*!
* Reset the end-of-file and error flags on the file.
@ -223,12 +223,12 @@ namespace TagLib {
/*!
* Returns the current offset within the file.
*/
long tell() const;
offset_t tell() const;
/*!
* Returns the length of the file.
*/
long length();
offset_t length();
/*!
* Returns true if \a file can be opened for reading. If the file does not
@ -276,7 +276,7 @@ namespace TagLib {
/*!
* Truncates the file to a \a length.
*/
void truncate(long length);
void truncate(offset_t length);
/*!
* Returns the buffer size that is used for internal buffering.

View File

@ -27,19 +27,16 @@
#include "tstring.h"
#include "tdebug.h"
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#ifdef _WIN32
# include <wchar.h>
# include <windows.h>
# include <io.h>
#else
#ifndef _WIN32
# include <stdio.h>
# include <unistd.h>
#endif
#include <stdlib.h>
#include <limits>
using namespace TagLib;
@ -114,7 +111,7 @@ public:
FileNameHandle name;
bool readOnly;
ulong size;
offset_t size;
static const uint bufferSize = 1024;
};
@ -170,7 +167,7 @@ FileName FileStream::name() const
return d->name;
}
ByteVector FileStream::readBlock(ulong length)
ByteVector FileStream::readBlock(uint length)
{
if(!d->file) {
debug("FileStream::readBlock() -- Invalid File");
@ -181,14 +178,14 @@ ByteVector FileStream::readBlock(ulong length)
return ByteVector::null;
if(length > FileStreamPrivate::bufferSize &&
length > ulong(FileStream::length()))
static_cast<offset_t>(length) > FileStream::length())
{
length = FileStream::length();
length = static_cast<uint>(FileStream::length());
}
ByteVector v(static_cast<uint>(length));
const int count = fread(v.data(), sizeof(char), length, d->file);
v.resize(count);
ByteVector v(length);
const size_t count = fread(v.data(), sizeof(char), length, d->file);
v.resize(static_cast<uint>(count));
return v;
}
@ -205,7 +202,7 @@ void FileStream::writeBlock(const ByteVector &data)
fwrite(data.data(), sizeof(char), data.size(), d->file);
}
void FileStream::insert(const ByteVector &data, ulong start, ulong replace)
void FileStream::insert(const ByteVector &data, offset_t start, uint replace)
{
if(!d->file)
return;
@ -232,15 +229,15 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace)
// the *differnce* in the tag sizes. We want to avoid overwriting parts
// that aren't yet in memory, so this is necessary.
ulong bufferLength = bufferSize();
size_t bufferLength = bufferSize();
while(data.size() - replace > bufferLength)
bufferLength += bufferSize();
// Set where to start the reading and writing.
long readPosition = start + replace;
long writePosition = start;
offset_t readPosition = start + replace;
offset_t writePosition = start;
ByteVector buffer;
ByteVector aboutToOverwrite(static_cast<uint>(bufferLength));
@ -252,7 +249,7 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace)
// That's a bit slower than using char *'s so, we're only doing it here.
seek(readPosition);
int bytesRead = fread(aboutToOverwrite.data(), sizeof(char), bufferLength, d->file);
size_t bytesRead = fread(aboutToOverwrite.data(), sizeof(char), bufferLength, d->file);
readPosition += bufferLength;
seek(writePosition);
@ -281,7 +278,7 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace)
// Check to see if we just read the last block. We need to call clear()
// if we did so that the last write succeeds.
if(ulong(bytesRead) < bufferLength)
if(bytesRead < bufferLength)
clear();
// Seek to the write position and write our buffer. Increment the
@ -301,21 +298,24 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace)
bufferLength = bytesRead;
}
// Clear the file size cache.
d->size = 0;
}
void FileStream::removeBlock(ulong start, ulong length)
void FileStream::removeBlock(offset_t start, uint length)
{
if(!d->file)
return;
ulong bufferLength = bufferSize();
size_t bufferLength = bufferSize();
long readPosition = start + length;
long writePosition = start;
offset_t readPosition = start + length;
offset_t writePosition = start;
ByteVector buffer(static_cast<uint>(bufferLength));
ulong bytesRead = 1;
size_t bytesRead = 1;
while(bytesRead != 0) {
seek(readPosition);
@ -345,7 +345,7 @@ bool FileStream::isOpen() const
return (d->file != NULL);
}
void FileStream::seek(long offset, Position p)
void FileStream::seek(offset_t offset, Position p)
{
if(!d->file) {
debug("File::seek() -- trying to seek in a file that isn't opened.");
@ -367,7 +367,9 @@ void FileStream::seek(long offset, Position p)
break;
}
SetFilePointer(d->file, offset, NULL, whence);
LARGE_INTEGER largeOffset = {};
largeOffset.QuadPart = offset;
SetFilePointerEx(d->file, largeOffset, nullptr, whence);
#else
@ -384,7 +386,15 @@ void FileStream::seek(long offset, Position p)
break;
}
fseek(d->file, offset, whence);
# ifdef _LARGEFILE_SOURCE
fseeko(d->file, offset, whence);
# else
fseek(d->file, static_cast<long>(offset), whence);
# endif
#endif
}
@ -402,20 +412,33 @@ void FileStream::clear()
#endif
}
long FileStream::tell() const
offset_t FileStream::tell() const
{
#ifdef _WIN32
return (long)SetFilePointer(d->file, 0, NULL, FILE_CURRENT);
LARGE_INTEGER largeOffset = {};
LARGE_INTEGER newPointer;
SetFilePointerEx(d->file, largeOffset, &newPointer, FILE_CURRENT);
return newPointer.QuadPart;
#else
return ftell(d->file);
# ifdef _LARGEFILE_SOURCE
return ftello(d->file);
# else
return static_cast<offset_t>(ftell(d->file));
# endif
#endif
}
long FileStream::length()
offset_t FileStream::length()
{
// Do some caching in case we do multiple calls.
@ -425,31 +448,31 @@ long FileStream::length()
if(!d->file)
return 0;
long curpos = tell();
offset_t currentPosition = tell();
seek(0, End);
long endpos = tell();
offset_t endPosition = tell();
seek(curpos, Beginning);
seek(currentPosition, Beginning);
d->size = endpos;
return endpos;
d->size = endPosition;
return endPosition;
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
void FileStream::truncate(long length)
void FileStream::truncate(offset_t length)
{
#ifdef _WIN32
long currentPos = tell();
offset_t currentPosition = tell();
seek(length);
SetEndOfFile(d->file);
seek(currentPos);
seek(currentPosition);
#else

View File

@ -67,7 +67,7 @@ namespace TagLib {
/*!
* Reads a block of size \a length at the current get pointer.
*/
ByteVector readBlock(ulong length);
ByteVector readBlock(uint length);
/*!
* Attempts to write the block \a data at the current get pointer. If the
@ -87,7 +87,7 @@ namespace TagLib {
* \note This method is slow since it requires rewriting all of the file
* after the insertion point.
*/
void insert(const ByteVector &data, ulong start = 0, ulong replace = 0);
void insert(const ByteVector &data, offset_t start = 0, uint replace = 0);
/*!
* Removes a block of the file starting a \a start and continuing for
@ -96,7 +96,7 @@ namespace TagLib {
* \note This method is slow since it involves rewriting all of the file
* after the removed portion.
*/
void removeBlock(ulong start = 0, ulong length = 0);
void removeBlock(offset_t start = 0, uint length = 0);
/*!
* Returns true if the file is read only (or if the file can not be opened).
@ -115,7 +115,7 @@ namespace TagLib {
*
* \see Position
*/
void seek(long offset, Position p = Beginning);
void seek(offset_t offset, Position p = Beginning);
/*!
* Reset the end-of-file and error flags on the file.
@ -125,17 +125,17 @@ namespace TagLib {
/*!
* Returns the current offset within the file.
*/
long tell() const;
offset_t tell() const;
/*!
* Returns the length of the file.
*/
long length();
offset_t length();
/*!
* Truncates the file to a \a length.
*/
void truncate(long length);
void truncate(offset_t length);
protected:

View File

@ -80,7 +80,7 @@ namespace TagLib {
/*!
* Reads a block of size \a length at the current get pointer.
*/
virtual ByteVector readBlock(ulong length) = 0;
virtual ByteVector readBlock(uint length) = 0;
/*!
* Attempts to write the block \a data at the current get pointer. If the
@ -100,7 +100,7 @@ namespace TagLib {
* \note This method is slow since it requires rewriting all of the file
* after the insertion point.
*/
virtual void insert(const ByteVector &data, ulong start = 0, ulong replace = 0) = 0;
virtual void insert(const ByteVector &data, offset_t start = 0, uint replace = 0) = 0;
/*!
* Removes a block of the file starting a \a start and continuing for
@ -109,7 +109,7 @@ namespace TagLib {
* \note This method is slow since it involves rewriting all of the file
* after the removed portion.
*/
virtual void removeBlock(ulong start = 0, ulong length = 0) = 0;
virtual void removeBlock(offset_t start = 0, uint length = 0) = 0;
/*!
* Returns true if the file is read only (or if the file can not be opened).
@ -128,7 +128,7 @@ namespace TagLib {
*
* \see Position
*/
virtual void seek(long offset, Position p = Beginning) = 0;
virtual void seek(offset_t offset, Position p = Beginning) = 0;
/*!
* Reset the end-of-stream and error flags on the stream.
@ -138,17 +138,17 @@ namespace TagLib {
/*!
* Returns the current offset within the stream.
*/
virtual long tell() const = 0;
virtual offset_t tell() const = 0;
/*!
* Returns the length of the stream.
*/
virtual long length() = 0;
virtual offset_t length() = 0;
/*!
* Truncates the stream to a \a length.
*/
virtual void truncate(long length) = 0;
virtual void truncate(offset_t length) = 0;
private:
IOStream(const IOStream &);

View File

@ -64,10 +64,10 @@ public:
}
const ID3v2::FrameFactory *ID3v2FrameFactory;
long ID3v2Location;
offset_t ID3v2Location;
uint ID3v2OriginalSize;
long ID3v1Location;
offset_t ID3v1Location;
TagUnion tag;
@ -284,13 +284,13 @@ void TrueAudio::File::read(bool readProperties, Properties::ReadStyle /* propert
}
}
long TrueAudio::File::findID3v1()
offset_t TrueAudio::File::findID3v1()
{
if(!isValid())
return -1;
seek(-128, End);
long p = tell();
offset_t p = tell();
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
return p;
@ -298,7 +298,7 @@ long TrueAudio::File::findID3v1()
return -1;
}
long TrueAudio::File::findID3v2()
offset_t TrueAudio::File::findID3v2()
{
if(!isValid())
return -1;

View File

@ -206,8 +206,8 @@ namespace TagLib {
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
void scan();
long findID3v1();
long findID3v2();
offset_t findID3v1();
offset_t findID3v2();
class FilePrivate;
FilePrivate *d;

View File

@ -39,7 +39,7 @@ using namespace TagLib;
class TrueAudio::Properties::PropertiesPrivate
{
public:
PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
PropertiesPrivate(const ByteVector &d, offset_t length, ReadStyle s) :
data(d),
streamLength(length),
style(s),
@ -52,7 +52,7 @@ public:
sampleFrames(0) {}
ByteVector data;
long streamLength;
offset_t streamLength;
ReadStyle style;
int version;
int length;
@ -67,7 +67,7 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
TrueAudio::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
TrueAudio::Properties::Properties(const ByteVector &data, offset_t streamLength, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate(data, streamLength, style);
read();
@ -145,6 +145,6 @@ void TrueAudio::Properties::read()
d->sampleFrames = d->data.mid(pos, 4).toUInt(false);
d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
}
}

View File

@ -54,7 +54,7 @@ namespace TagLib {
* Create an instance of TrueAudio::Properties with the data read from the
* ByteVector \a data.
*/
Properties(const ByteVector &data, long streamLength, ReadStyle style = Average);
Properties(const ByteVector &data, offset_t streamLength, ReadStyle style = Average);
/*!
* Destroys this TrueAudio::Properties instance.

View File

@ -62,10 +62,10 @@ public:
delete properties;
}
long APELocation;
offset_t APELocation;
uint APESize;
long ID3v1Location;
offset_t ID3v1Location;
TagUnion tag;
@ -261,7 +261,7 @@ void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertie
}
}
long WavPack::File::findAPE()
offset_t WavPack::File::findAPE()
{
if(!isValid())
return -1;
@ -271,7 +271,7 @@ long WavPack::File::findAPE()
else
seek(-32, End);
long p = tell();
offset_t p = tell();
if(readBlock(8) == APE::Tag::fileIdentifier())
return p;
@ -279,13 +279,13 @@ long WavPack::File::findAPE()
return -1;
}
long WavPack::File::findID3v1()
offset_t WavPack::File::findID3v1()
{
if(!isValid())
return -1;
seek(-128, End);
long p = tell();
offset_t p = tell();
if(readBlock(3) == ID3v1::Tag::fileIdentifier())
return p;

View File

@ -177,8 +177,8 @@ namespace TagLib {
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
void scan();
long findID3v1();
long findAPE();
offset_t findID3v1();
offset_t findAPE();
class FilePrivate;
FilePrivate *d;

View File

@ -38,7 +38,7 @@ using namespace TagLib;
class WavPack::Properties::PropertiesPrivate
{
public:
PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
PropertiesPrivate(const ByteVector &d, offset_t length, ReadStyle s) :
data(d),
streamLength(length),
style(s),
@ -52,7 +52,7 @@ public:
file(0) {}
ByteVector data;
long streamLength;
offset_t streamLength;
ReadStyle style;
int length;
int bitrate;
@ -68,13 +68,13 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
WavPack::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
WavPack::Properties::Properties(const ByteVector &data, offset_t streamLength, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate(data, streamLength, style);
read();
}
WavPack::Properties::Properties(File *file, long streamLength, ReadStyle style) : AudioProperties(style)
WavPack::Properties::Properties(File *file, offset_t streamLength, ReadStyle style) : AudioProperties(style)
{
ByteVector data = file->readBlock(32);
d = new PropertiesPrivate(data, streamLength, style);
@ -170,14 +170,14 @@ void WavPack::Properties::read()
d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
d->sampleFrames = samples;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
}
unsigned int WavPack::Properties::seekFinalIndex()
{
ByteVector blockID("wvpk", 4);
long offset = d->streamLength;
offset_t offset = d->streamLength;
while(offset > 0) {
offset = d->file->rfind(blockID, offset);
if(offset == -1)

View File

@ -58,13 +58,13 @@ namespace TagLib {
* \deprecated This constructor will be dropped in favor of the one below
* in a future version.
*/
Properties(const ByteVector &data, long streamLength, ReadStyle style = Average);
Properties(const ByteVector &data, offset_t streamLength, ReadStyle style = Average);
/*!
* Create an instance of WavPack::Properties.
*/
// BIC: merge with the above constructor
Properties(File *file, long streamLength, ReadStyle style = Average);
Properties(File *file, offset_t streamLength, ReadStyle style = Average);
/*!
* Destroys this WavPack::Properties instance.