Merge "MP3Extractor and MP3 decoder fixes - DO NOT MERGE" into gingerbread
This commit is contained in:
@@ -37,10 +37,10 @@
|
|||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
// Everything must match except for
|
// Everything must match except for
|
||||||
// protection, bitrate, padding, private bits, mode extension,
|
// protection, bitrate, padding, private bits, mode, mode extension,
|
||||||
// copyright bit, original bit and emphasis.
|
// copyright bit, original bit and emphasis.
|
||||||
// Yes ... there are things that must indeed match...
|
// Yes ... there are things that must indeed match...
|
||||||
static const uint32_t kMask = 0xfffe0cc0;
|
static const uint32_t kMask = 0xfffe0c00;
|
||||||
|
|
||||||
static bool get_mp3_frame_size(
|
static bool get_mp3_frame_size(
|
||||||
uint32_t header, size_t *frame_size,
|
uint32_t header, size_t *frame_size,
|
||||||
@@ -344,22 +344,55 @@ static bool Resync(
|
|||||||
|
|
||||||
off_t pos = *inout_pos;
|
off_t pos = *inout_pos;
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
|
|
||||||
|
const size_t kMaxReadBytes = 1024;
|
||||||
|
const off_t kMaxBytesChecked = 128 * 1024;
|
||||||
|
uint8_t buf[kMaxReadBytes];
|
||||||
|
ssize_t bytesToRead = kMaxReadBytes;
|
||||||
|
ssize_t totalBytesRead = 0;
|
||||||
|
ssize_t remainingBytes = 0;
|
||||||
|
bool reachEOS = false;
|
||||||
|
uint8_t *tmp = buf;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (pos >= *inout_pos + 128 * 1024) {
|
if (pos >= *inout_pos + kMaxBytesChecked) {
|
||||||
// Don't scan forever.
|
// Don't scan forever.
|
||||||
LOGV("giving up at offset %ld", pos);
|
LOGV("giving up at offset %ld", pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tmp[4];
|
if (remainingBytes < 4) {
|
||||||
if (source->readAt(pos, tmp, 4) != 4) {
|
if (reachEOS) {
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
memcpy(buf, tmp, remainingBytes);
|
||||||
|
bytesToRead = kMaxReadBytes - remainingBytes;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The next read position should start from the end of
|
||||||
|
* the last buffer, and thus should include the remaining
|
||||||
|
* bytes in the buffer.
|
||||||
|
*/
|
||||||
|
totalBytesRead = source->readAt(pos + remainingBytes,
|
||||||
|
buf + remainingBytes,
|
||||||
|
bytesToRead);
|
||||||
|
if (totalBytesRead <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
reachEOS = (totalBytesRead != bytesToRead);
|
||||||
|
totalBytesRead += remainingBytes;
|
||||||
|
remainingBytes = totalBytesRead;
|
||||||
|
tmp = buf;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t header = U32_AT(tmp);
|
uint32_t header = U32_AT(tmp);
|
||||||
|
|
||||||
if (match_header != 0 && (header & kMask) != (match_header & kMask)) {
|
if (match_header != 0 && (header & kMask) != (match_header & kMask)) {
|
||||||
++pos;
|
++pos;
|
||||||
|
++tmp;
|
||||||
|
--remainingBytes;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,6 +401,8 @@ static bool Resync(
|
|||||||
if (!get_mp3_frame_size(header, &frame_size,
|
if (!get_mp3_frame_size(header, &frame_size,
|
||||||
&sample_rate, &num_channels, &bitrate)) {
|
&sample_rate, &num_channels, &bitrate)) {
|
||||||
++pos;
|
++pos;
|
||||||
|
++tmp;
|
||||||
|
--remainingBytes;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +452,8 @@ static bool Resync(
|
|||||||
}
|
}
|
||||||
|
|
||||||
++pos;
|
++pos;
|
||||||
|
++tmp;
|
||||||
|
--remainingBytes;
|
||||||
} while (!valid);
|
} while (!valid);
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
|
|||||||
@@ -121,9 +121,11 @@ ERROR_CODE pvmp3_decode_header(tmp3Bits *inputStream,
|
|||||||
uint32 temp;
|
uint32 temp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Verify that at least the header is complete
|
* Verify that at least the header is complete
|
||||||
|
* Note that SYNC_WORD_LNGTH is in unit of bits, but inputBufferCurrentLength
|
||||||
|
* is in unit of bytes.
|
||||||
*/
|
*/
|
||||||
if (inputStream->inputBufferCurrentLength < (SYNC_WORD_LNGTH + 21))
|
if (inputStream->inputBufferCurrentLength < ((SYNC_WORD_LNGTH + 21) >> 3))
|
||||||
{
|
{
|
||||||
return NO_ENOUGH_MAIN_DATA_ERROR;
|
return NO_ENOUGH_MAIN_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user