a non working workaround for some strange mp3 files

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5613 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2003-12-07 16:11:23 +00:00
parent b7d16bdff5
commit 2648dc48d8
2 changed files with 43 additions and 7 deletions

View File

@ -359,20 +359,28 @@ mp3Reader::GetNextChunk(void *cookie,
mediaHeader->start_time = (data->framePosition * 1000000) / data->frameRate;
mediaHeader->file_pos = data->position;
retry:
if (4 != Source()->ReadAt(fDataStart + data->position, data->chunkBuffer, 4)) {
TRACE("mp3Reader::GetNextChunk: unexpected read error\n");
return B_ERROR;
}
data->position += 4;
maxbytes -= 4;
int size = GetFrameLength(data->chunkBuffer) - 4;
if (size <= 0) {
TRACE("mp3Reader::GetNextChunk: invalid frame encountered\n");
// try to synchronize again here!
return B_ERROR;
TRACE("mp3Reader::GetNextChunk: invalid frame encountered at position %Ld, header %02x %02x %02x %02x \n",
data->position, (uint8)data->chunkBuffer[0], (uint8)data->chunkBuffer[1], (uint8)data->chunkBuffer[2], (uint8)data->chunkBuffer[3]);
if (ResynchronizeStream(data)) {
TRACE("mp3Reader::GetNextChunk: synchronized again at position %Ld\n", data->position);
goto retry;
} else {
TRACE("mp3Reader::GetNextChunk: synchronization failed\n");
return B_ERROR;
}
}
data->position += 4;
maxbytes -= 4;
if (size > maxbytes)
size = maxbytes;
@ -395,6 +403,30 @@ mp3Reader::GetNextChunk(void *cookie,
return B_OK;
}
bool
mp3Reader::ResynchronizeStream(mp3data *data)
{
// we are at data->position and that's not a valid frame header
// XXX this is a hack and needs to be improved
const int readmax = 16384;
uint8 buffer[readmax];
while ((data->position + 100) < fDataSize) {
data->position++;
int bytes = min_c(fDataSize - data->position, readmax);
if (bytes != Source()->ReadAt(fDataStart + data->position, buffer, bytes)) {
TRACE("mp3Reader::ResynchronizeStream: read error\n");
return false;
}
if (IsValidStream(buffer, bytes))
return true;
}
return false;
}
bool
mp3Reader::ParseFile()
@ -849,7 +881,7 @@ mp3Reader::GetFrameLength(void *header)
int framerate = frame_rate_table[mpeg_version_index][sampling_rate_index];
if (!bitrate || !framerate)
return -1;
return -1;
int length;
if (layer_index == 3) // layer 1

View File

@ -3,6 +3,8 @@
#include "ReaderPlugin.h"
struct mp3data;
namespace BPrivate { namespace media {
class mp3Reader : public Reader
@ -30,7 +32,7 @@ public:
status_t GetNextChunk(void *cookie,
void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader);
BPositionIO *Source() { return fSeekableSource; }
private:
@ -53,6 +55,8 @@ private:
void ParseFraunhoferVbrHeader(int64 pos);
int64 XingSeekPoint(float percent);
bool ResynchronizeStream(mp3data *data);
private:
BPositionIO * fSeekableSource;