pal: Use increase/decrease StreamUserCounter to protect getTimestamp

1) Pcm Offload write takes 80ms and held agm session obj lock for 80ms,
   and if getTimestamp comes during this period, it is blocked by
   agm session obj lock.
2) getTimestamp for all streams is protected by resourceManager lock
   and active stream lock.
3) Active stream lock will block LL get timestamp and writing.
4) LL underrun happened.

Fix it by using increase/decrease StreamUserCounter to protect getTimestamp

Change-Id: Ib985fe26f5ec34b0e8a739bb3984d4f78e69128c
diff --git a/Pal.cpp b/Pal.cpp
index 46b3b86..e0fc84f 100644
--- a/Pal.cpp
+++ b/Pal.cpp
@@ -892,13 +892,19 @@
     }
 
     rm->lockActiveStream();
-    if (rm->isActiveStream(stream_handle)) {
-        s =  reinterpret_cast<Stream *>(stream_handle);
-        status = s->getTimestamp(stime);
-    } else {
-        PAL_ERR(LOG_TAG, "stream handle in stale state.\n");
+    s =  reinterpret_cast<Stream *>(stream_handle);
+    status = rm->increaseStreamUserCounter(s);
+    if (0 != status) {
+        rm->unlockActiveStream();
+        PAL_ERR(LOG_TAG, "failed to increase stream user count");
+        return status;
     }
     rm->unlockActiveStream();
+    status = s->getTimestamp(stime);
+
+    rm->lockActiveStream();
+    rm->decreaseStreamUserCounter(s);
+    rm->unlockActiveStream();
 
     if (0 != status) {
         PAL_ERR(LOG_TAG, "pal_get_timestamp failed with status %d\n", status);