audio: Fix three-way deadlock

This is a fix for a deadlock in the audio HAL
involving three threads. Heres the deadlock sequence.

As part of closing all compress streams during SSR,
Thread1 takes out->lock, adev->lock and releases
out->lock when waiting on a condition variable
in stop_compress_output_l

Concurrently, Thread2 calls out_set_parameter on
the same output take out->lock and is blocked
trying to acquire adev->lock

Meanwhile Thread3 (offload_thread_loop) tries to
acquire out->lock (in order to signal Thread1).

But Thread3 is blocked since Thread2 has already
taken out->lock. This is a deadlock.

CRs-Fixed: 1028547

Change-Id: Ie8a8ff5e4d65c5a73641f925a46d03235d1a0f50
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7978adf..ec99175 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2185,6 +2185,9 @@
         if (adev->adm_deregister_stream)
             adev->adm_deregister_stream(adev->adm_data, out->handle);
 
+        if (is_offload_usecase(out->usecase))
+            stop_compressed_output_l(out);
+
         pthread_mutex_lock(&adev->lock);
         out->standby = true;
         if (!is_offload_usecase(out->usecase)) {
@@ -2194,7 +2197,6 @@
             }
         } else {
             ALOGD("copl(%p):standby", out);
-            stop_compressed_output_l(out);
             out->send_next_track_params = false;
             out->is_compr_metadata_avail = false;
             out->gapless_mdata.encoder_delay = 0;