summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/id3
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2013-06-17 16:14:39 -0700
committerMarco Nelissen <marcone@google.com>2013-06-17 16:14:39 -0700
commit72a43b68da48890273508cb1c9d646b7d75fc101 (patch)
treed59911fded34d7f14104793e5db81a46f1654cb7 /media/libstagefright/id3
parent04411d3ed343added179703837c6c24444acce3b (diff)
downloadframeworks_av-72a43b68da48890273508cb1c9d646b7d75fc101.zip
frameworks_av-72a43b68da48890273508cb1c9d646b7d75fc101.tar.gz
frameworks_av-72a43b68da48890273508cb1c9d646b7d75fc101.tar.bz2
Speed up id3v2 unsynchronization
Instead of doing many overlapping memmoves, do a single copy pass that skips over the inserted unsynchronization bytes. For some files this reduces parsing time from minutes to milliseconds. b/9463262 Change-Id: I735b7051e77a093d86fb7a3e46209875946225ed
Diffstat (limited to 'media/libstagefright/id3')
-rw-r--r--media/libstagefright/id3/ID3.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp
index 8d3013b..34d671a 100644
--- a/media/libstagefright/id3/ID3.cpp
+++ b/media/libstagefright/id3/ID3.cpp
@@ -357,17 +357,22 @@ bool ID3::removeUnsynchronizationV2_4(bool iTunesHack) {
}
if (flags & 2) {
- // Unsynchronization added.
+ // This file has "unsynchronization", so we have to replace occurrences
+ // of 0xff 0x00 with just 0xff in order to get the real data.
+ size_t readOffset = offset + 11;
+ size_t writeOffset = offset + 11;
for (size_t i = 0; i + 1 < dataSize; ++i) {
- if (mData[offset + 10 + i] == 0xff
- && mData[offset + 11 + i] == 0x00) {
- memmove(&mData[offset + 11 + i], &mData[offset + 12 + i],
- mSize - offset - 12 - i);
+ if (mData[readOffset - 1] == 0xff
+ && mData[readOffset] == 0x00) {
+ ++readOffset;
--mSize;
--dataSize;
}
+ mData[writeOffset++] = mData[readOffset++];
}
+ // move the remaining data following this frame
+ memmove(&mData[writeOffset], &mData[readOffset], oldSize - readOffset);
flags &= ~2;
}