summaryrefslogtreecommitdiff
path: root/media/libstagefright/MP3Extractor.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2011-01-11 18:59:32 -0800
committerJames Dong <jdong@google.com>2011-01-12 09:49:15 -0800
commit7cc497733b7602b99b783decfa8c002bc27e25aa (patch)
tree3004d896aebf64aaeb2c48348021366e020e9cba /media/libstagefright/MP3Extractor.cpp
parentc4c3a2d4123f7dfe8c6ed0c26fb14aeb7b8d8f61 (diff)
Speed up MP3Extractor using cached reads
Change-Id: I53a5ed76bc2f76f0c184f3800b5448f677117ae3
Diffstat (limited to 'media/libstagefright/MP3Extractor.cpp')
-rw-r--r--media/libstagefright/MP3Extractor.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp
index 0bb3a869..00a4dd5e 100644
--- a/media/libstagefright/MP3Extractor.cpp
+++ b/media/libstagefright/MP3Extractor.cpp
@@ -228,22 +228,47 @@ static bool Resync(
off64_t pos = *inout_pos;
bool valid = false;
+
+ const size_t kMaxReadBytes = 1024;
+ const size_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 {
- if (pos >= *inout_pos + 128 * 1024) {
+ if (pos >= *inout_pos + kMaxBytesChecked) {
// Don't scan forever.
LOGV("giving up at offset %ld", pos);
break;
}
- uint8_t tmp[4];
- if (source->readAt(pos, tmp, 4) != 4) {
- break;
+ if (remainingBytes < 4) {
+ if (reachEOS) {
+ break;
+ } else {
+ memcpy(buf, tmp, remainingBytes);
+ bytesToRead = kMaxReadBytes - remainingBytes;
+ totalBytesRead = source->readAt(pos, buf + remainingBytes, bytesToRead);
+ if (totalBytesRead <= 0) {
+ break;
+ }
+ reachEOS = (totalBytesRead != bytesToRead);
+ totalBytesRead += remainingBytes;
+ remainingBytes = totalBytesRead;
+ tmp = buf;
+ continue;
+ }
}
uint32_t header = U32_AT(tmp);
if (match_header != 0 && (header & kMask) != (match_header & kMask)) {
++pos;
+ ++tmp;
+ --remainingBytes;
continue;
}
@@ -253,6 +278,8 @@ static bool Resync(
header, &frame_size,
&sample_rate, &num_channels, &bitrate)) {
++pos;
+ ++tmp;
+ --remainingBytes;
continue;
}
@@ -303,6 +330,8 @@ static bool Resync(
}
++pos;
+ ++tmp;
+ --remainingBytes;
} while (!valid);
return valid;