remote submix: force pipe shutdown on input close

Force mono pipe shutdown when all input stream clients are closed
so that a pending write is not stuck waiting for available buffer.

Bug: 119057550
Test: abort search on BLE remote
Change-Id: I4391e73874e502da5000b1746436fb61bb2fe869
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 8c0c097..6fac56f 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -488,17 +488,26 @@
     ALOGV("submix_audio_device_destroy_pipe_l()");
     int route_idx = -1;
     if (in != NULL) {
+        bool shut_down = false;
 #if ENABLE_LEGACY_INPUT_OPEN
         const_cast<struct submix_stream_in*>(in)->ref_count--;
         route_idx = in->route_handle;
         ALOG_ASSERT(rsxadev->routes[route_idx].input == in);
         if (in->ref_count == 0) {
             rsxadev->routes[route_idx].input = NULL;
+            shut_down = true;
         }
         ALOGV("submix_audio_device_destroy_pipe_l(): input ref_count %d", in->ref_count);
 #else
         rsxadev->input = NULL;
+        shut_down = true;
 #endif // ENABLE_LEGACY_INPUT_OPEN
+        if (shut_down) {
+            sp <MonoPipe> sink = rsxadev->routes[in->route_handle].rsxSink;
+            if (sink != NULL) {
+              sink->shutdown(true);
+            }
+        }
     }
     if (out != NULL) {
         route_idx = out->route_handle;
@@ -1648,6 +1657,12 @@
     ALOGV("adev_open_input_stream(): about to create pipe");
     submix_audio_device_create_pipe_l(rsxadev, config, DEFAULT_PIPE_SIZE_IN_FRAMES,
                                     DEFAULT_PIPE_PERIOD_COUNT, in, NULL, address, route_idx);
+
+    sp <MonoPipe> sink = rsxadev->routes[route_idx].rsxSink;
+    if (sink != NULL) {
+        sink->shutdown(false);
+    }
+
 #if LOG_STREAMS_TO_FILES
     if (in->log_fd >= 0) close(in->log_fd);
     in->log_fd = open(LOG_STREAM_IN_FILENAME, O_CREAT | O_TRUNC | O_WRONLY,