Merge "audio policy: workaround for truncated touch sounds" into nyc-mr1-dev
diff --git a/media/libstagefright/StagefrightMediaScanner.cpp b/media/libstagefright/StagefrightMediaScanner.cpp
index 8935f6a..f0c27ac 100644
--- a/media/libstagefright/StagefrightMediaScanner.cpp
+++ b/media/libstagefright/StagefrightMediaScanner.cpp
@@ -40,7 +40,7 @@
         ".mpeg", ".ogg", ".mid", ".smf", ".imy", ".wma", ".aac",
         ".wav", ".amr", ".midi", ".xmf", ".rtttl", ".rtx", ".ota",
         ".mkv", ".mka", ".webm", ".ts", ".fl", ".flac", ".mxmf",
-        ".avi", ".mpeg", ".mpg", ".awb", ".mpga"
+        ".avi", ".mpeg", ".mpg", ".awb", ".mpga", ".mov"
     };
     static const size_t kNumValidExtensions =
         sizeof(kValidExtensions) / sizeof(kValidExtensions[0]);
diff --git a/media/libstagefright/omx/SimpleSoftOMXComponent.cpp b/media/libstagefright/omx/SimpleSoftOMXComponent.cpp
index 60c1e2e..13afd45 100644
--- a/media/libstagefright/omx/SimpleSoftOMXComponent.cpp
+++ b/media/libstagefright/omx/SimpleSoftOMXComponent.cpp
@@ -469,6 +469,13 @@
     CHECK_EQ((int)port->mTransition, (int)PortInfo::NONE);
     CHECK(port->mDef.bEnabled == !enable);
 
+    if (port->mDef.eDir != OMX_DirOutput) {
+        ALOGE("Port enable/disable allowed only on output ports.");
+        notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
+        android_errorWriteLog(0x534e4554, "29421804");
+        return;
+    }
+
     if (!enable) {
         port->mDef.bEnabled = OMX_FALSE;
         port->mTransition = PortInfo::DISABLING;
diff --git a/media/libstagefright/rtsp/MyHandler.h b/media/libstagefright/rtsp/MyHandler.h
index abe2582..42a1182 100644
--- a/media/libstagefright/rtsp/MyHandler.h
+++ b/media/libstagefright/rtsp/MyHandler.h
@@ -1843,13 +1843,19 @@
                 // RTSP "PLAY" command should be used to detect the first RTP packet
                 // after seeking.
                 if (track->mAllowedStaleAccessUnits > 0) {
-                    if ((((seqNum ^ track->mFirstSeqNumInSegment) & 0xffff) != 0)) {
+                    uint32_t seqNum16 = seqNum & 0xffff;
+                    uint32_t firstSeqNumInSegment16 = track->mFirstSeqNumInSegment & 0xffff;
+                    if (seqNum16 > firstSeqNumInSegment16 + kMaxAllowedStaleAccessUnits
+                            || seqNum16 < firstSeqNumInSegment16) {
                         // Not the first rtp packet of the stream after seeking, discarding.
                         track->mAllowedStaleAccessUnits--;
                         ALOGV("discarding stale access unit (0x%x : 0x%x)",
                              seqNum, track->mFirstSeqNumInSegment);
                         continue;
                     }
+                    ALOGW_IF(seqNum16 != firstSeqNumInSegment16,
+                            "Missing the first packet(%u), now take packet(%u) as first one",
+                            track->mFirstSeqNumInSegment, seqNum);
                 } else { // track->mAllowedStaleAccessUnits <= 0
                     mNumAccessUnitsReceived = 0;
                     ALOGW_IF(track->mAllowedStaleAccessUnits == 0,
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 9169941..a3dcdcf 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -6246,7 +6246,8 @@
         mTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_SERVER] = systemTime();
 
         // Update server timestamp with kernel stats
-        if (mInput->stream->get_capture_position != nullptr) {
+        if (mInput->stream->get_capture_position != nullptr
+                && mPipeSource.get() == nullptr /* don't obtain for FastCapture, could block */) {
             int64_t position, time;
             int ret = mInput->stream->get_capture_position(mInput->stream, &position, &time);
             if (ret == NO_ERROR) {