From c4aaeef6b1f1ababff65d7465f993c36572acfcf Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 17 Jan 2017 11:26:51 +0200 Subject: [PATCH] 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 --- src/sound/mpg123_decoder.cpp | 51 ++++-------------------------------- src/sound/mpg123_decoder.h | 1 - 2 files changed, 5 insertions(+), 47 deletions(-) diff --git a/src/sound/mpg123_decoder.cpp b/src/sound/mpg123_decoder.cpp index 9d1fff97ec..0a2ba94f1b 100644 --- a/src/sound/mpg123_decoder.cpp +++ b/src/sound/mpg123_decoder.cpp @@ -14,25 +14,22 @@ static bool inited = false; off_t MPG123Decoder::file_lseek(void *handle, off_t offset, int whence) { - MPG123Decoder *self = reinterpret_cast(handle); - FileReader *reader = self->Reader; + FileReader *reader = reinterpret_cast(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 && diff --git a/src/sound/mpg123_decoder.h b/src/sound/mpg123_decoder.h index 1d5b883ead..051473abb1 100644 --- a/src/sound/mpg123_decoder.h +++ b/src/sound/mpg123_decoder.h @@ -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);