audio: Fix MonoPipe ownership in StreamRemoteSubmix

MonoPipeReader does not hold a strong reference to MonoPipe.
Thus the client code needs to ensure that their lifetimes
are synchronized. In StreamRemoteSubmix::inRead the code
holds a strong pointer to a MonoPipeReader but not to the
MonoPipe which makes it possible for MonoPipe to be released
from another thread and causing the read operation to crash.

Bug: 377325461
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I400aa91204a3464dcb8fca723c8c87005fb6502f
diff --git a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
index cef0ea6..f8ead16 100644
--- a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
+++ b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
@@ -283,6 +283,15 @@
         }
         return ::android::OK;
     }
+    // get and hold the sink because 'MonoPipeReader' does not hold a strong pointer to it.
+    sp<MonoPipe> sink = mCurrentRoute->getSink();
+    if (sink == nullptr) {
+        if (++mReadErrorCount < kMaxErrorLogs) {
+            LOG(ERROR) << __func__
+                       << ": the sink has been released! (not all errors will be logged)";
+        }
+        return ::android::OK;
+    }
     mReadErrorCount = 0;
 
     LOG(VERBOSE) << __func__ << ": " << mDeviceAddress.toString() << ", " << frameCount