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

Commit 1d515f4b authored by xiahong.bao's avatar xiahong.bao
Browse files

MPEG4Write mdhd duration overflow after recording for 15 hours



MPEG4Write mdhd duration of AV track is larger than INT32_MAX
after record over 15 hours, so write mdhd box as version 1 type
which enhance duration to 64 bit.

Change-Id: I874b0a0ddfb7fb8f5b0a255345d8605b6c8ebf68
Signed-off-by: default avatarxiahong.bao <xiahong.bao@nxp.com>
parent 549e4319
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -3288,13 +3288,22 @@ void MPEG4Writer::Track::writeHdlrBox() {

void MPEG4Writer::Track::writeMdhdBox(uint32_t now) {
    int64_t trakDurationUs = getDurationUs();
    int64_t mdhdDuration = (trakDurationUs * mTimeScale + 5E5) / 1E6;
    mOwner->beginBox("mdhd");

    if (mdhdDuration > UINT32_MAX) {
        mOwner->writeInt32((1 << 24));            // version=1, flags=0
        mOwner->writeInt64((int64_t)now);         // creation time
        mOwner->writeInt64((int64_t)now);         // modification time
        mOwner->writeInt32(mTimeScale);           // media timescale
        mOwner->writeInt64(mdhdDuration);         // media timescale
    } else {
        mOwner->writeInt32(0);                      // version=0, flags=0
        mOwner->writeInt32(now);                    // creation time
        mOwner->writeInt32(now);                    // modification time
        mOwner->writeInt32(mTimeScale);             // media timescale
    int32_t mdhdDuration = (trakDurationUs * mTimeScale + 5E5) / 1E6;
    mOwner->writeInt32(mdhdDuration);  // use media timescale
        mOwner->writeInt32((int32_t)mdhdDuration);  // use media timescale
    }
    // Language follows the three letter standard ISO-639-2/T
    // 'e', 'n', 'g' for "English", for instance.
    // Each character is packed as the difference between its ASCII value and 0x60.