diff options
author | Robert Shih <robertshih@google.com> | 2018-05-09 15:16:17 -0700 |
---|---|---|
committer | Tim Schumacher <timschumi@gmx.de> | 2018-07-16 20:17:40 +0200 |
commit | dc3b246bb1422b805937343e65b513d246952eb6 (patch) | |
tree | 01d3d174e822ce7d44ad5a278e0ae3152daed60a | |
parent | c81197623a895ae05354b4ad713066ab63978b81 (diff) | |
download | frameworks_av-dc3b246bb1422b805937343e65b513d246952eb6.tar.gz frameworks_av-dc3b246bb1422b805937343e65b513d246952eb6.tar.bz2 frameworks_av-dc3b246bb1422b805937343e65b513d246952eb6.zip |
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.
Similar to commit 72a43b68da but for v2.2 and v2.3.
Bug: 78029004
Test: poc
Change-Id: I735b7051e77a093d86fb7a3e46209875946225ed
(cherry picked from commit f9d87cc850a589b9b0cc3658cf222187822bcc00)
-rw-r--r-- | media/libstagefright/id3/ID3.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp index ed52b12d88..d97d444bd6 100644 --- a/media/libstagefright/id3/ID3.cpp +++ b/media/libstagefright/id3/ID3.cpp @@ -328,12 +328,25 @@ struct id3_header { } void ID3::removeUnsynchronization() { - for (size_t i = 0; i + 1 < mSize; ++i) { - if (mData[i] == 0xff && mData[i + 1] == 0x00) { - memmove(&mData[i + 1], &mData[i + 2], mSize - i - 2); - --mSize; + + // 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 writeOffset = 1; + for (size_t readOffset = 1; readOffset < mSize; ++readOffset) { + if (mData[readOffset - 1] == 0xff && mData[readOffset] == 0x00) { + continue; } + // Only move data if there's actually something to move. + // This handles the special case of the data being only [0xff, 0x00] + // which should be converted to just 0xff if unsynchronization is on. + mData[writeOffset++] = mData[readOffset]; } + + if (writeOffset < mSize) { + mSize = writeOffset; + } + } static void WriteSyncsafeInteger(uint8_t *dst, size_t x) { |