Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34863cb6 authored by Robert Shih's avatar Robert Shih Committed by Android (Google) Code Review
Browse files

Merge changes from topic "am-419f3086-5068-4c88-ba99-be1d6eaaa1da" into oc-dev

* changes:
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d am: c0367b94 am: 27d756fb am: 6801c150 am: 71e28ba2 am: 1a7bebd2 am: a30a421c
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d am: c0367b94 am: 27d756fb am: 6801c150 am: 71e28ba2 am: 1a7bebd2
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d am: c0367b94 am: 27d756fb am: 6801c150 am: 71e28ba2
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d am: c0367b94 am: 27d756fb am: 6801c150
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d am: c0367b94 am: 27d756fb
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d am: c0367b94
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a am: 136be01d
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8 am: 4da1490a
  [automerger] Speed up id3v2 unsynchronization am: f9d87cc8
  Speed up id3v2 unsynchronization
parents 20e00b3f 99cafda2
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -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) {