Camera3: Improve resilience to stream failures

- Handle binder connection drops (DEAD_OBJECT) for streams
- Just log an error, don't go to an error state when queue/dequeue fails

Bug: 10347526
Change-Id: Ib463ffe15d58db444cf5d8cad176a201c7d1facc
diff --git a/services/camera/libcameraservice/device3/Camera3IOStreamBase.cpp b/services/camera/libcameraservice/device3/Camera3IOStreamBase.cpp
index 727a8c9..da51228 100644
--- a/services/camera/libcameraservice/device3/Camera3IOStreamBase.cpp
+++ b/services/camera/libcameraservice/device3/Camera3IOStreamBase.cpp
@@ -214,19 +214,19 @@
     sp<Fence> releaseFence;
     res = returnBufferCheckedLocked(buffer, timestamp, output,
                                     &releaseFence);
-    if (res != OK) {
-        // NO_INIT means the buffer queue is abandoned, so to be resilient,
-        // still want to decrement in-flight counts.
-        if (res != NO_INIT) {
-            return res;
-        }
-    }
+    // Res may be an error, but we still want to decrement our owned count
+    // to enable clean shutdown. So we'll just return the error but otherwise
+    // carry on
 
-    mCombinedFence = Fence::merge(mName, mCombinedFence, releaseFence);
+    if (releaseFence != 0) {
+        mCombinedFence = Fence::merge(mName, mCombinedFence, releaseFence);
+    }
 
     mDequeuedBufferCount--;
     if (mDequeuedBufferCount == 0 && mState != STATE_IN_CONFIG &&
             mState != STATE_IN_RECONFIG) {
+        ALOGV("%s: Stream %d: All buffers returned; now idle", __FUNCTION__,
+                mId);
         sp<StatusTracker> statusTracker = mStatusTracker.promote();
         if (statusTracker != 0) {
             statusTracker->markComponentIdle(mStatusId, mCombinedFence);
@@ -239,7 +239,7 @@
         mLastTimestamp = timestamp;
     }
 
-    return OK;
+    return res;
 }