Merge "audio remote submix: fix write blocked on input standby" am: 8705f278a3

Change-Id: I7b3edc2e7e6591af49d3ffb3938c7b2396ade48e
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index dda0d0e..30b96ee 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -821,12 +821,21 @@
         return 0;
     }
 
-    // If the write to the sink would block when no input stream is present, flush enough frames
+    // If the write to the sink would block, flush enough frames
     // from the pipe to make space to write the most recent data.
+    // We DO NOT block if:
+    // - no peer input stream is present
+    // - the peer input is in standby AFTER having been active.
+    // We DO block if:
+    // - the input was never activated to avoid discarding first frames
+    // in the pipe in case capture start was delayed
     {
         const size_t availableToWrite = sink->availableToWrite();
         sp<MonoPipeReader> source = rsxadev->routes[out->route_handle].rsxSource;
-        if (rsxadev->routes[out->route_handle].input == NULL && availableToWrite < frames) {
+        const struct submix_stream_in *in = rsxadev->routes[out->route_handle].input;
+        const bool dont_block = (in == NULL)
+                || (in->input_standby && (in->read_counter_frames != 0));
+        if (dont_block && availableToWrite < frames) {
             static uint8_t flush_buffer[64];
             const size_t flushBufferSizeFrames = sizeof(flush_buffer) / frame_size;
             size_t frames_to_flush_from_source = frames - availableToWrite;