audiovideo_CRASFormatConversion - Ensures the playing order of the two test tones.

Ensure the following order in the loopback test:

1. Play the first sine tone
2. Play the second sine tone
3. Start recording

Also reduce the time needed for this test by

1. Generate the noise profile once.
2. Loopback only once and analyze the recorded audio for both channels

BUG=None
TEST=Run the test on parrot

Change-Id: I8e61c07141f5d6e6ae4c4c0cfb8926bcf7e2a2fe
Reviewed-on: https://chromium-review.googlesource.com/178392
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Owen Lin <owenlin@chromium.org>
Tested-by: Owen Lin <owenlin@chromium.org>
diff --git a/client/cros/audio/cras_utils.py b/client/cros/audio/cras_utils.py
index 74422de..dd8b263 100644
--- a/client/cros/audio/cras_utils.py
+++ b/client/cros/audio/cras_utils.py
@@ -12,6 +12,7 @@
 _CRAS_TEST_CLIENT = '/usr/bin/cras_test_client'
 _RE_SELECTED_OUTPUT_NODE = re.compile('Selected Output Node: (.*)')
 _RE_SELECTED_INPUT_NODE = re.compile('Selected Input Node: (.*)')
+_RE_NUM_ACTIVE_STREAM = re.compile('Num active streams: (.*)')
 
 def playback(*args, **kargs):
     """A helper function to execute the playback_cmd."""
@@ -97,3 +98,12 @@
         raise RuntimeError('No match for the pattern')
 
     return (output_match.group(1).strip(), input_match.group(1).strip())
+
+def get_active_stream_count():
+    """Gets the number of active streams."""
+    server_info = dump_server_info()
+    match = _RE_NUM_ACTIVE_STREAM.search(server_info)
+    if not match:
+        logging.error(server_info)
+        raise RuntimeException('Cannot find matched pattern')
+    return int(match.group(1))