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

Commit 85fcbd6a authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Try not to have sample durations vary too much

Change-Id: Ibbd0f0a253cc74e241236b7a30d1c931e18af753
parent 1d6fa7af
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -2278,6 +2278,22 @@ status_t MPEG4Writer::Track::threadEntry() {
            return UNKNOWN_ERROR;
        }

        // if the duration is different for this sample, see if it is close enough to the previous
        // duration that we can fudge it and use the same value, to avoid filling the stts table
        // with lots of near-identical entries.
        // "close enough" here means that the current duration needs to be adjusted by less
        // than 0.1 milliseconds
        if (lastDurationTicks && (currDurationTicks != lastDurationTicks)) {
            int64_t deltaUs = ((lastDurationTicks - currDurationTicks) * 1000000LL
                    + (mTimeScale / 2)) / mTimeScale;
            if (deltaUs > -100 && deltaUs < 100) {
                // use previous ticks, and adjust timestamp as if it was actually that number
                // of ticks
                currDurationTicks = lastDurationTicks;
                timestampUs += deltaUs;
            }
        }

        mStszTableEntries->add(htonl(sampleSize));
        if (mStszTableEntries->count() > 2) {