Removed homebrew MP3 format detection

It didn't work for all files so let libmpg123 handle all quirks for us
See https://mantis.zdoom.org/view.php?id=60
This commit is contained in:
alexey.lysiuk 2017-01-17 11:26:51 +02:00
parent c317a4cbf3
commit c4aaeef6b1
2 changed files with 5 additions and 47 deletions

View file

@ -14,25 +14,22 @@ static bool inited = false;
off_t MPG123Decoder::file_lseek(void *handle, off_t offset, int whence)
{
MPG123Decoder *self = reinterpret_cast<MPG123Decoder*>(handle);
FileReader *reader = self->Reader;
FileReader *reader = reinterpret_cast<MPG123Decoder*>(handle)->Reader;
if(whence == SEEK_SET)
offset += self->StartOffset;
else if(whence == SEEK_CUR)
if(whence == SEEK_CUR)
{
if(offset < 0 && reader->Tell()+offset < self->StartOffset)
if(offset < 0 && reader->Tell()+offset < 0)
return -1;
}
else if(whence == SEEK_END)
{
if(offset < 0 && reader->GetLength()+offset < self->StartOffset)
if(offset < 0 && reader->GetLength()+offset < 0)
return -1;
}
if(reader->Seek(offset, whence) != 0)
return -1;
return reader->Tell() - self->StartOffset;
return reader->Tell();
}
ssize_t MPG123Decoder::file_read(void *handle, void *buffer, size_t bytes)
@ -71,45 +68,7 @@ bool MPG123Decoder::open(FileReader *reader)
}
Reader = reader;
StartOffset = 0;
char data[10];
if(file_read(this, data, 10) != 10)
return false;
int start_offset = 0;
// Check for ID3 tags and skip them
if(memcmp(data, "ID3", 3) == 0 &&
(BYTE)data[3] <= 4 && (BYTE)data[4] != 0xff &&
(data[5]&0x0f) == 0 && (data[6]&0x80) == 0 &&
(data[7]&0x80) == 0 && (data[8]&0x80) == 0 &&
(data[9]&0x80) == 0)
{
// ID3v2
start_offset = (data[6]<<21) | (data[7]<<14) |
(data[8]<< 7) | (data[9] );
start_offset += ((data[5]&0x10) ? 20 : 10);
}
StartOffset = start_offset;
if(file_lseek(this, 0, SEEK_SET) != 0)
return false;
// Check for a frame header
bool frame_ok = false;
if(file_read(this, data, 3) == 3)
{
if((BYTE)data[0] == 0xff &&
((data[1]&0xfe) == 0xfa/*MPEG-1*/ || (data[1]&0xfe) == 0xf2/*MPEG-2*/))
{
int brate_idx = (data[2]>>4) & 0x0f;
int srate_idx = (data[2]>>2) & 0x03;
if(brate_idx != 0 && brate_idx != 15 && srate_idx != 3)
frame_ok = (file_lseek(this, 0, SEEK_SET) == 0);
}
}
if(frame_ok)
{
MPG123 = mpg123_new(NULL, NULL);
if(mpg123_replace_reader_handle(MPG123, file_read, file_lseek, NULL) == MPG123_OK &&

View file

@ -30,7 +30,6 @@ private:
bool Done;
FileReader *Reader;
int StartOffset;
static off_t file_lseek(void *handle, off_t offset, int whence);
static ssize_t file_read(void *handle, void *buffer, size_t bytes);