MPEG: Hide an internal function from the public header.

This commit is contained in:
Tsuda Kageyu
2015-08-01 00:15:51 +09:00
parent 4f621140ce
commit c715ec09e4
2 changed files with 24 additions and 22 deletions

View File

@ -31,14 +31,31 @@
#include <apetag.h>
#include <tdebug.h>
#include <bitset>
#include "mpegfile.h"
#include "mpegheader.h"
#include "tpropertymap.h"
using namespace TagLib;
namespace
{
/*!
* MPEG frames can be recognized by the bit pattern 11111111 111, so the
* first byte is easy to check for, however checking to see if the second byte
* starts with \e 111 is a bit more tricky, hence these functions.
*/
inline bool firstSyncByte(uchar byte)
{
return (byte == 0xFF);
}
inline bool secondSynchByte(uchar byte)
{
return ((byte & 0xE0) == 0xE0);
}
}
namespace
{
enum { ID3v2Index = 0, APEIndex = 1, ID3v1Index = 2 };
@ -388,11 +405,11 @@ long MPEG::File::nextFrameOffset(long position)
return position - 1;
for(uint i = 0; i < buffer.size() - 1; i++) {
if(uchar(buffer[i]) == 0xff && secondSynchByte(buffer[i + 1]))
if(firstSyncByte(buffer[i]) && secondSynchByte(buffer[i + 1]))
return position + i;
}
foundLastSyncPattern = uchar(buffer[buffer.size() - 1]) == 0xff;
foundLastSyncPattern = firstSyncByte(buffer[buffer.size() - 1]);
position += buffer.size();
}
}
@ -412,11 +429,11 @@ long MPEG::File::previousFrameOffset(long position)
if(buffer.size() <= 0)
break;
if(foundFirstSyncPattern && uchar(buffer[buffer.size() - 1]) == 0xff)
if(foundFirstSyncPattern && firstSyncByte(buffer[buffer.size() - 1]))
return position + buffer.size() - 1;
for(int i = buffer.size() - 2; i >= 0; i--) {
if(uchar(buffer[i]) == 0xff && secondSynchByte(buffer[i + 1]))
if(firstSyncByte(buffer[i]) && secondSynchByte(buffer[i + 1]))
return position + i;
}
@ -524,7 +541,7 @@ void MPEG::File::read(bool readProperties)
long MPEG::File::findID3v2(long offset)
{
// This method is based on the contents of TagLib::File::find(), but because
// of some subtlties -- specifically the need to look for the bit pattern of
// of some subtleties -- specifically the need to look for the bit pattern of
// an MPEG sync, it has been modified for use here.
if(isValid() && ID3v2::Header::fileIdentifier().size() <= bufferSize()) {
@ -664,11 +681,3 @@ void MPEG::File::findAPE()
d->APELocation = -1;
d->APEFooterLocation = -1;
}
bool MPEG::File::secondSynchByte(char byte)
{
std::bitset<8> b(byte);
// check to see if the byte matches 111xxxxx
return b.test(7) && b.test(6) && b.test(5);
}

View File

@ -375,13 +375,6 @@ namespace TagLib {
long findID3v1();
void findAPE();
/*!
* MPEG frames can be recognized by the bit pattern 11111111 111, so the
* first byte is easy to check for, however checking to see if the second byte
* starts with \e 111 is a bit more tricky, hence this member function.
*/
static bool secondSynchByte(char byte);
class FilePrivate;
FilePrivate *d;
};