audio: RT streams cleanup on error

Do proper cleanup for RT streams if start fails on
these streams. Returning error from start_*_stream
does not guarantee stream will be put to standby

Bug: 30388410
Change-Id: Icbb2c6cfff95eaf4de59626b89b1c99f9090b2a3
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 1a77278..a96a509 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1098,10 +1098,16 @@
         in->pcm = NULL;
         goto error_open;
     }
-    register_in_stream(in);
     if (in->realtime) {
         ret = pcm_start(in->pcm);
+        if (ret < 0) {
+            ALOGE("%s: RT pcm_start failed ret %d", __func__, ret);
+            pcm_close(in->pcm);
+            in->pcm = NULL;
+            goto error_open;
+        }
     }
+    register_in_stream(in);
     audio_extn_perf_lock_release();
     ALOGV("%s: exit", __func__);
 
@@ -1503,10 +1509,16 @@
             adev->offload_effects_start_output(out->handle, out->pcm_device_id);
     }
     ret = 0;
-    register_out_stream(out);
     if (out->realtime) {
         ret = pcm_start(out->pcm);
+        if (ret < 0) {
+            ALOGE("%s: RT pcm_start failed ret %d", __func__, ret);
+            pcm_close(out->pcm);
+            out->pcm = NULL;
+            goto error_open;
+        }
     }
+    register_out_stream(out);
     audio_extn_perf_lock_release();
     ALOGV("%s: exit", __func__);
     return ret;