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

Commit 14bf24d9 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Merge cherrypicks of [2474947] into oc-dr1-release

Change-Id: I83f1d2fbb1c203dca5999bd944f7c153541d977f
parents 5c9350b5 e3ad31f2
Loading
Loading
Loading
Loading
+21 −55
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ public:
    int64_t getDurationUs() const;
    int64_t getEstimatedTrackSizeBytes() const;
    void writeTrackHeader(bool use32BitOffset = true);
    int64_t getMinCttsOffsetTimeUs();
    void bufferChunk(int64_t timestampUs);
    bool isAvc() const { return mIsAvc; }
    bool isHevc() const { return mIsHevc; }
@@ -308,8 +307,7 @@ private:
    ListTableEntries<uint32_t, 2> *mCttsTableEntries;

    int64_t mMinCttsOffsetTimeUs;
    int64_t mMinCttsOffsetTicks;
    int64_t mMaxCttsOffsetTicks;
    int64_t mMaxCttsOffsetTimeUs;

    // Save the last 10 frames' timestamp for debug.
    std::list<std::pair<int64_t, int64_t>> mTimestampDebugHelper;
@@ -345,7 +343,7 @@ private:

    void dumpTimeStamps();

    int64_t getStartTimeOffsetTimeUs() const;
    int64_t getStartTimeOffsetScaledTimeUs() const;
    int32_t getStartTimeOffsetScaledTime() const;

    static void *ThreadWrapper(void *me);
@@ -1136,20 +1134,9 @@ void MPEG4Writer::writeMoovBox(int64_t durationUs) {
        writeUdtaBox();
    }
    writeMetaBox();
    // Loop through all the tracks to get the global time offset if there is
    // any ctts table appears in a video track.
    int64_t minCttsOffsetTimeUs = kMaxCttsOffsetTimeUs;
    int32_t id = 1;
    for (List<Track *>::iterator it = mTracks.begin();
        it != mTracks.end(); ++it) {
        minCttsOffsetTimeUs =
            std::min(minCttsOffsetTimeUs, (*it)->getMinCttsOffsetTimeUs());
    }

    // Adjust the global start time.
    mStartTimestampUs += minCttsOffsetTimeUs - kMaxCttsOffsetTimeUs;

    for (List<Track *>::iterator it = mTracks.begin();
        it != mTracks.end(); ++it) {
        it != mTracks.end(); ++it, ++id) {
        (*it)->writeTrackHeader(mUse32BitOffset);
    }
    endBox();  // moov
@@ -1639,9 +1626,6 @@ MPEG4Writer::Track::Track(
      mStssTableEntries(new ListTableEntries<uint32_t, 1>(1000)),
      mSttsTableEntries(new ListTableEntries<uint32_t, 2>(1000)),
      mCttsTableEntries(new ListTableEntries<uint32_t, 2>(1000)),
      mMinCttsOffsetTimeUs(0),
      mMinCttsOffsetTicks(0),
      mMaxCttsOffsetTicks(0),
      mCodecSpecificData(NULL),
      mCodecSpecificDataSize(0),
      mGotAllCodecSpecificData(false),
@@ -2830,16 +2814,16 @@ status_t MPEG4Writer::Track::threadEntry() {

            // Update ctts time offset range
            if (mStszTableEntries->count() == 0) {
                mMinCttsOffsetTicks = currCttsOffsetTimeTicks;
                mMaxCttsOffsetTicks = currCttsOffsetTimeTicks;
                mMinCttsOffsetTimeUs = currCttsOffsetTimeTicks;
                mMaxCttsOffsetTimeUs = currCttsOffsetTimeTicks;
            } else {
                if (currCttsOffsetTimeTicks > mMaxCttsOffsetTicks) {
                    mMaxCttsOffsetTicks = currCttsOffsetTimeTicks;
                } else if (currCttsOffsetTimeTicks < mMinCttsOffsetTicks) {
                    mMinCttsOffsetTicks = currCttsOffsetTimeTicks;
                    mMinCttsOffsetTimeUs = cttsOffsetTimeUs;
                if (currCttsOffsetTimeTicks > mMaxCttsOffsetTimeUs) {
                    mMaxCttsOffsetTimeUs = currCttsOffsetTimeTicks;
                } else if (currCttsOffsetTimeTicks < mMinCttsOffsetTimeUs) {
                    mMinCttsOffsetTimeUs = currCttsOffsetTimeTicks;
                }
            }

        }

        if (mOwner->isRealTimeRecording()) {
@@ -3180,7 +3164,7 @@ void MPEG4Writer::Track::bufferChunk(int64_t timestampUs) {
}

int64_t MPEG4Writer::Track::getDurationUs() const {
    return mTrackDurationUs + getStartTimeOffsetTimeUs();
    return mTrackDurationUs + getStartTimeOffsetScaledTimeUs();
}

int64_t MPEG4Writer::Track::getEstimatedTrackSizeBytes() const {
@@ -3235,16 +3219,6 @@ void MPEG4Writer::Track::writeTrackHeader(bool use32BitOffset) {
    mOwner->endBox();  // trak
}

int64_t MPEG4Writer::Track::getMinCttsOffsetTimeUs() {
    // For video tracks with ctts table, this should return the minimum ctts
    // offset in the table. For non-video tracks or video tracks without ctts
    // table, this will return kMaxCttsOffsetTimeUs.
    if (mMinCttsOffsetTicks == mMaxCttsOffsetTicks) {
        return kMaxCttsOffsetTimeUs;
    }
    return mMinCttsOffsetTimeUs;
}

void MPEG4Writer::Track::writeStblBox(bool use32BitOffset) {
    mOwner->beginBox("stbl");
    mOwner->beginBox("stsd");
@@ -3674,7 +3648,7 @@ void MPEG4Writer::Track::writePaspBox() {
    mOwner->endBox();  // pasp
}

int64_t MPEG4Writer::Track::getStartTimeOffsetTimeUs() const {
int64_t MPEG4Writer::Track::getStartTimeOffsetScaledTimeUs() const {
    int64_t trackStartTimeOffsetUs = 0;
    int64_t moovStartTimeUs = mOwner->getStartTimestampUs();
    if (mStartTimestampUs != -1 && mStartTimestampUs != moovStartTimeUs) {
@@ -3685,30 +3659,23 @@ int64_t MPEG4Writer::Track::getStartTimeOffsetTimeUs() const {
}

int32_t MPEG4Writer::Track::getStartTimeOffsetScaledTime() const {
    return (getStartTimeOffsetTimeUs() * mTimeScale + 500000LL) / 1000000LL;
    return (getStartTimeOffsetScaledTimeUs() *  mTimeScale + 500000LL) / 1000000LL;
}

void MPEG4Writer::Track::writeSttsBox() {
    mOwner->beginBox("stts");
    mOwner->writeInt32(0);  // version=0, flags=0
    if (mMinCttsOffsetTicks == mMaxCttsOffsetTicks) {
        // For non-vdeio tracks or video tracks without ctts table,
        // adjust duration of first sample for tracks to account for
        // first sample not starting at the media start time.
        // TODO: consider signaling this using some offset
        // as this is not quite correct.
    uint32_t duration;
    CHECK(mSttsTableEntries->get(duration, 1));
    duration = htonl(duration);  // Back to host byte order
    mSttsTableEntries->set(htonl(duration + getStartTimeOffsetScaledTime()), 1);
    }
    mSttsTableEntries->write(mOwner);
    mOwner->endBox();  // stts
}

void MPEG4Writer::Track::writeCttsBox() {
    // There is no B frame at all
    if (mMinCttsOffsetTicks == mMaxCttsOffsetTicks) {
    if (mMinCttsOffsetTimeUs == mMaxCttsOffsetTimeUs) {
        return;
    }

@@ -3718,12 +3685,11 @@ void MPEG4Writer::Track::writeCttsBox() {
    }

    ALOGV("ctts box has %d entries with range [%" PRId64 ", %" PRId64 "]",
            mCttsTableEntries->count(), mMinCttsOffsetTicks, mMaxCttsOffsetTicks);
            mCttsTableEntries->count(), mMinCttsOffsetTimeUs, mMaxCttsOffsetTimeUs);

    mOwner->beginBox("ctts");
    mOwner->writeInt32(0);  // version=0, flags=0
    int64_t deltaTimeUs = kMaxCttsOffsetTimeUs - getStartTimeOffsetTimeUs();
    int64_t delta = (deltaTimeUs * mTimeScale + 500000LL) / 1000000LL;
    int64_t delta = mMinCttsOffsetTimeUs - getStartTimeOffsetScaledTime();
    mCttsTableEntries->adjustEntries([delta](size_t /* ix */, uint32_t (&value)[2]) {
        // entries are <count, ctts> pairs; adjust only ctts
        uint32_t duration = htonl(value[1]); // back to host byte order
+0 −4
Original line number Diff line number Diff line
@@ -83,10 +83,6 @@ private:
        kWhatSwitch                          = 'swch',
    };

    enum {
        kMaxCttsOffsetTimeUs = 1000000LL,  // 1 second
    };

    int  mFd;
    int mNextFd;
    sp<MetaData> mStartMeta;