Merge "When using "secure input buffer mode" we instantiate a different OMX component"
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 67f6c79..9c9bc2d 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -1157,6 +1157,8 @@
     mSurface.clear();
     if (surfaceTexture != NULL) {
         setNativeWindow_l(new SurfaceTextureClient(surfaceTexture));
+    } else {
+        setNativeWindow_l(NULL);
     }
 }
 
@@ -1769,7 +1771,8 @@
         }
     }
 
-    if (mVideoRendererIsPreview || mVideoRenderer == NULL) {
+    if ((mNativeWindow != NULL)
+            && (mVideoRendererIsPreview || mVideoRenderer == NULL)) {
         mVideoRendererIsPreview = false;
 
         initRenderer_l();
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 8c9ff87..5f58090 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -1172,6 +1172,9 @@
 void MPEG4Writer::Track::addOneSttsTableEntry(
         size_t sampleCount, int32_t duration) {
 
+    if (duration == 0) {
+        LOGW("%d 0-duration samples found: %d", sampleCount);
+    }
     SttsTableEntry sttsEntry(sampleCount, duration);
     mSttsTableEntries.push_back(sttsEntry);
     ++mNumSttsTableEntries;
@@ -2001,17 +2004,18 @@
             mTrackDurationUs = timestampUs;
         }
 
+        // We need to use the time scale based ticks, rather than the
+        // timestamp itself to determine whether we have to use a new
+        // stts entry, since we may have rounding errors.
+        // The calculation is intended to reduce the accumulated
+        // rounding errors.
+        currDurationTicks =
+            ((timestampUs * mTimeScale + 500000LL) / 1000000LL -
+                (lastTimestampUs * mTimeScale + 500000LL) / 1000000LL);
+
         mSampleSizes.push_back(sampleSize);
         ++mNumSamples;
         if (mNumSamples > 2) {
-            // We need to use the time scale based ticks, rather than the
-            // timestamp itself to determine whether we have to use a new
-            // stts entry, since we may have rounding errors.
-            // The calculation is intended to reduce the accumulated
-            // rounding errors.
-            currDurationTicks =
-                     ((timestampUs * mTimeScale + 500000LL) / 1000000LL -
-                     (lastTimestampUs * mTimeScale + 500000LL) / 1000000LL);
 
             // Force the first sample to have its own stts entry so that
             // we can adjust its value later to maintain the A/V sync.