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

Commit 5a372322 authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "Fix a few issues with determining the closest sample to a given time in...

Merge "Fix a few issues with determining the closest sample to a given time in the MPEG4 sampletable implementation."
parents 3908e3c5 140d4edf
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -510,6 +510,10 @@ status_t SampleTable::getDecodingTime(uint32_t sample_index, uint32_t *time) {
    return ERROR_OUT_OF_RANGE;
}

uint32_t abs_difference(uint32_t time1, uint32_t time2) {
    return time1 > time2 ? time1 - time2 : time2 - time1;
}

status_t SampleTable::findClosestSample(
        uint32_t req_time, uint32_t *sample_index, uint32_t flags) {
    Mutex::Autolock autoLock(mLock);
@@ -523,7 +527,16 @@ status_t SampleTable::findClosestSample(
        if (req_time < time + n * delta) {
            int j = (req_time - time) / delta;

            uint32_t time1 = time + j * delta;
            uint32_t time2 = time1 + delta;

            if (i+1 == mTimeToSampleCount
                    || (abs_difference(req_time, time1)
                        < abs_difference(req_time, time2))) {
                *sample_index = cur_sample + j;
            } else {
                *sample_index = cur_sample + j + 1;
            }

            if (flags & kSyncSample_Flag) {
                return findClosestSyncSample(*sample_index, sample_index);
@@ -554,8 +567,9 @@ status_t SampleTable::findClosestSyncSample(
    uint32_t right = mNumSyncSamples;
    while (left < right) {
        uint32_t mid = (left + right) / 2;

        if (mDataSource->readAt(
                    mSyncSampleOffset + 8 + (mid - 1) * 4, &x, 4) != 4) {
                    mSyncSampleOffset + 8 + mid * 4, &x, 4) != 4) {
            return ERROR_IO;
        }