am 750600a1: Merge "Single track optimization" into gingerbread

Merge commit '750600a187f699ead85ef026ab33dc2bdd1d2c29' into gingerbread-plus-aosp

* commit '750600a187f699ead85ef026ab33dc2bdd1d2c29':
  Single track optimization
diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h
index 9812e41..d62df46 100644
--- a/include/media/stagefright/MPEG4Writer.h
+++ b/include/media/stagefright/MPEG4Writer.h
@@ -81,6 +81,7 @@
     void setStartTimestampUs(int64_t timeUs);
     int64_t getStartTimestampUs();  // Not const
     status_t startTracks();
+    size_t numTracks();
 
     void lock();
     void unlock();
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index b6bbde7..cd20ec7 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -559,6 +559,11 @@
     return mStartTimestampUs;
 }
 
+size_t MPEG4Writer::numTracks() {
+    Mutex::Autolock autolock(mLock);
+    return mTracks.size();
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 MPEG4Writer::Track::Track(
@@ -979,6 +984,16 @@
             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 @@
     }
 
     // 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);