ByteVector::toUInt() takes offset and length

This commit is contained in:
Tsuda kageyu
2013-04-18 18:36:19 +09:00
parent c9209cc99e
commit 439f27640a
31 changed files with 254 additions and 159 deletions

View File

@ -241,7 +241,7 @@ void Ogg::FLAC::File::scan()
char blockType = header[0] & 0x7f;
bool lastBlock = (header[0] & 0x80) != 0;
uint length = header.mid(1, 3).toUInt();
uint length = header.toUInt(1, 3, true);
overhead += length;
// Sanity: First block should be the stream_info metadata
@ -251,7 +251,7 @@ void Ogg::FLAC::File::scan()
return;
}
d->streamInfoData = metadataHeader.mid(4,length);
d->streamInfoData = metadataHeader.mid(4, length);
// Search through the remaining metadata
@ -264,7 +264,7 @@ void Ogg::FLAC::File::scan()
header = metadataHeader.mid(0, 4);
blockType = header[0] & 0x7f;
lastBlock = (header[0] & 0x80) != 0;
length = header.mid(1, 3).toUInt();
length = header.toUInt(1, 3, true);
overhead += length;
if(blockType == 1) {

View File

@ -255,9 +255,9 @@ void Ogg::PageHeader::read()
d->firstPageOfStream = flags.test(1);
d->lastPageOfStream = flags.test(2);
d->absoluteGranularPosition = data.mid(6, 8).toLongLong(false);
d->streamSerialNumber = data.mid(14, 4).toUInt(false);
d->pageSequenceNumber = data.mid(18, 4).toUInt(false);
d->absoluteGranularPosition = data.toLongLong(6, false);
d->streamSerialNumber = data.toUInt(14, false);
d->pageSequenceNumber = data.toUInt(18, false);
// Byte number 27 is the number of page segments, which is the only variable
// length portion of the page header. After reading the number of page

View File

@ -118,7 +118,7 @@ void Opus::Properties::read()
ByteVector data = d->file->packet(0);
// *Magic Signature*
int pos = 8;
uint pos = 8;
// *Version* (8 bits, unsigned)
d->opusVersion = uchar(data.at(pos));
@ -129,11 +129,11 @@ void Opus::Properties::read()
pos += 1;
// *Pre-skip* (16 bits, unsigned, little endian)
ushort preSkip = data.mid(pos, 2).toUShort(false);
const ushort preSkip = data.toUShort(pos, false);
pos += 2;
// *Input Sample Rate* (32 bits, unsigned, little endian)
d->inputSampleRate = data.mid(pos, 4).toUInt(false);
d->inputSampleRate = data.toUInt(pos, false);
pos += 4;
// *Output Gain* (16 bits, signed, little endian)

View File

@ -113,32 +113,32 @@ void Speex::Properties::read()
ByteVector data = d->file->packet(0);
int pos = 28;
uint pos = 28;
// speex_version_id; /**< Version for Speex (for checking compatibility) */
d->speexVersion = data.mid(pos, 4).toUInt(false);
d->speexVersion = data.toUInt(pos, false);
pos += 4;
// header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */
pos += 4;
// rate; /**< Sampling rate used */
d->sampleRate = data.mid(pos, 4).toUInt(false);
d->sampleRate = data.toUInt(pos, false);
pos += 4;
// mode; /**< Mode used (0 for narrowband, 1 for wideband) */
d->mode = data.mid(pos, 4).toUInt(false);
d->mode = data.toUInt(pos, false);
pos += 4;
// mode_bitstream_version; /**< Version ID of the bit-stream */
pos += 4;
// nb_channels; /**< Number of channels encoded */
d->channels = data.mid(pos, 4).toUInt(false);
d->channels = data.toUInt(pos, false);
pos += 4;
// bitrate; /**< Bit-rate used */
d->bitrate = data.mid(pos, 4).toUInt(false);
d->bitrate = data.toUInt(pos, false);
pos += 4;
// frame_size; /**< Size of frames */
@ -146,7 +146,7 @@ void Speex::Properties::read()
pos += 4;
// vbr; /**< 1 for a VBR encoding, 0 otherwise */
d->vbr = data.mid(pos, 4).toUInt(false) == 1;
d->vbr = data.toUInt(pos, false) == 1;
pos += 4;
// frames_per_packet; /**< Number of frames stored per Ogg packet */

View File

@ -133,7 +133,7 @@ void Vorbis::Properties::read()
ByteVector data = d->file->packet(0);
int pos = 0;
uint pos = 0;
if(data.mid(pos, 7) != vorbisSetupHeaderID) {
debug("Vorbis::Properties::read() -- invalid Vorbis identification header");
@ -142,22 +142,22 @@ void Vorbis::Properties::read()
pos += 7;
d->vorbisVersion = data.mid(pos, 4).toUInt(false);
d->vorbisVersion = data.toUInt(pos, false);
pos += 4;
d->channels = uchar(data[pos]);
pos += 1;
d->sampleRate = data.mid(pos, 4).toUInt(false);
d->sampleRate = data.toUInt(pos, false);
pos += 4;
d->bitrateMaximum = data.mid(pos, 4).toUInt(false);
d->bitrateMaximum = data.toUInt(pos, false);
pos += 4;
d->bitrateNominal = data.mid(pos, 4).toUInt(false);
d->bitrateNominal = data.toUInt(pos, false);
pos += 4;
d->bitrateMinimum = data.mid(pos, 4).toUInt(false);
d->bitrateMinimum = data.toUInt(pos, false);
// TODO: Later this should be only the "fast" mode.
d->bitrate = d->bitrateNominal;

View File

@ -340,7 +340,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
uint pos = 0;
uint vendorLength = data.mid(0, 4).toUInt(false);
const uint vendorLength = data.toUInt(0, false);
pos += 4;
d->vendorID = String(data.mid(pos, vendorLength), String::UTF8);
@ -348,7 +348,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
// Next the number of fields in the comment vector.
uint commentFields = data.mid(pos, 4).toUInt(false);
const uint commentFields = data.toUInt(pos, false);
pos += 4;
if(commentFields > (data.size() - 8) / 4) {
@ -360,7 +360,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
// Each comment field is in the format "KEY=value" in a UTF8 string and has
// 4 bytes before the text starts that gives the length.
uint commentLength = data.mid(pos, 4).toUInt(false);
const uint commentLength = data.toUInt(pos, false);
pos += 4;
String comment = String(data.mid(pos, commentLength), String::UTF8);