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

Commit b54a9178 authored by James Dong's avatar James Dong
Browse files

Single track optimization

We don't need to do interleave when the total number of tracks to be recorded is one.
Metadata-wise, we only need to have one chunk in chunk offset table, and a
single entry in the stsc table.

Change-Id: I46f0e4b3860620311e7a91b68a9067acaa137bb2
parent ef1c48d6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ private:
    void setStartTimestampUs(int64_t timeUs);
    int64_t getStartTimestampUs();  // Not const
    status_t startTracks();
    size_t numTracks();

    void lock();
    void unlock();
+19 −1
Original line number Diff line number Diff line
@@ -559,6 +559,11 @@ int64_t MPEG4Writer::getStartTimestampUs() {
    return mStartTimestampUs;
}

size_t MPEG4Writer::numTracks() {
    Mutex::Autolock autolock(mLock);
    return mTracks.size();
}

////////////////////////////////////////////////////////////////////////////////

MPEG4Writer::Track::Track(
@@ -979,6 +984,16 @@ void MPEG4Writer::Track::threadEntry() {
            mStssTableEntries.push_back(mSampleInfos.size());
        }

        if (mOwner->numTracks() == 1) {
            off_t offset = is_avc? mOwner->addLengthPrefixedSample_l(copy)
                                 : mOwner->addSample_l(copy);
            if (mChunkOffsets.empty()) {
                mChunkOffsets.push_back(offset);
            }
            copy->release();
            copy = NULL;
            continue;
        }

        mChunkSamples.push_back(copy);
        if (interleaveDurationUs == 0) {
@@ -1012,7 +1027,10 @@ void MPEG4Writer::Track::threadEntry() {
    }

    // Last chunk
    if (!mChunkSamples.empty()) {
    if (mOwner->numTracks() == 1) {
        StscTableEntry stscEntry(1, mSampleInfos.size(), 1);
        mStscTableEntries.push_back(stscEntry);
    } else if (!mChunkSamples.empty()) {
        ++nChunks;
        StscTableEntry stscEntry(nChunks, mChunkSamples.size(), 1);
        mStscTableEntries.push_back(stscEntry);