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

Commit 27431de0 authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "Fix a bug on subtitle (SRT)." into jb-dev

parents 04853745 0a2f0e04
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ status_t TimedTextSRTSource::readNextLine(off64_t *offset, AString *data) {
status_t TimedTextSRTSource::getText(
        const MediaSource::ReadOptions *options,
        AString *text, int64_t *startTimeUs, int64_t *endTimeUs) {
    if (mTextVector.size() == 0) {
        return ERROR_END_OF_STREAM;
    }
    text->clear();
    int64_t seekTimeUs;
    MediaSource::ReadOptions::SeekMode mode;
@@ -225,31 +228,38 @@ status_t TimedTextSRTSource::getText(
            mIndex = 0;
        } else {
            // binary search
            ssize_t low = 0;
            ssize_t high = mTextVector.size() - 1;
            ssize_t mid = 0;
            size_t low = 0;
            size_t high = mTextVector.size() - 1;
            size_t mid = 0;
            int64_t currTimeUs;

            while (low <= high) {
                mid = low + (high - low)/2;
                currTimeUs = mTextVector.keyAt(mid);
                const int diff = currTimeUs - seekTimeUs;
                const int64_t diffTime = currTimeUs - seekTimeUs;

                if (diff == 0) {
                if (diffTime == 0) {
                    break;
                } else if (diff < 0) {
                } else if (diffTime < 0) {
                    low = mid + 1;
                } else {
                    if ((high == mid + 1)
                        && (seekTimeUs < mTextVector.keyAt(high))) {
                        break;
                    }
                    if (mid < 1) {
                        break;
                    }
                    high = mid - 1;
                }
            }
            mIndex = mid;
        }
    }

    if (mIndex >= mTextVector.size()) {
        return ERROR_END_OF_STREAM;
    }
    const TextInfo &info = mTextVector.valueAt(mIndex);
    *startTimeUs = mTextVector.keyAt(mIndex);
    *endTimeUs = info.endTimeUs;
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ private:
        int textLen;
    };

    int mIndex;
    size_t mIndex;
    KeyedVector<int64_t, TextInfo> mTextVector;

    void reset();