bluetooth: a2dp write to raw file

Let the btpeer record the A2DP audio streams to a raw file
directly instead of piping to another process to avoid the
little/big endian issue ocurring during the piping process.

The raw file, compared to a wav file, is easier to divide
into chunks for verification.

In addition, remote copying the chunk file to the DUT is
performed internally inside the btpeer to be more efficient.

BUG=b:169039281
TEST=Conduct both the A2DP test and A2DP long test on DUTs
in the lab.

Change-Id: I1a59ba5181e98a3da6b259f1d29f9d211083650e
Previous-Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2461187
Previous-Reviewed-on: https://chromium-review.googlesource.com/2461187
(cherry picked from commit 76a8edad5fe70a53bab1351bf98bfaea00716b17)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2531212
Reviewed-by: Michael Sun <michaelfsun@google.com>
Tested-by: Shyh-In Hwang <josephsih@chromium.org>
Commit-Queue: Shyh-In Hwang <josephsih@chromium.org>
diff --git a/client/cros/bluetooth/bluetooth_audio_test_data.py b/client/cros/bluetooth/bluetooth_audio_test_data.py
index 8c5496d..219f5ef 100644
--- a/client/cros/bluetooth/bluetooth_audio_test_data.py
+++ b/client/cros/bluetooth/bluetooth_audio_test_data.py
@@ -308,7 +308,7 @@
     'file': os.path.join(AUDIO_TEST_DIR,
                          'binaural_sine_440hz_20000hz_rate48000_%dsecs.raw'),
     'recorded_by_peer': os.path.join(AUDIO_RECORD_DIR,
-                                     'a2dp_recorded_by_peer_%d.wav'),
+                                     'a2dp_recorded_by_peer.raw'),
     'chunk_in_secs': 5,
 }
 a2dp_test_data.update(common_test_data)
@@ -319,7 +319,7 @@
 a2dp_long_test_data = a2dp_test_data.copy()
 a2dp_long_test_data.update({
     'recorded_by_peer': os.path.join(AUDIO_RECORD_DIR,
-                                     'a2dp_long_recorded_by_peer_%d.wav'),
+                                     'a2dp_long_recorded_by_peer.raw'),
     'duration': 0,       # determined at run time
     'chunk_in_secs': 1,
 })
diff --git a/server/cros/bluetooth/bluetooth_adapter_audio_tests.py b/server/cros/bluetooth/bluetooth_adapter_audio_tests.py
index df93633..b3c3311 100644
--- a/server/cros/bluetooth/bluetooth_adapter_audio_tests.py
+++ b/server/cros/bluetooth/bluetooth_adapter_audio_tests.py
@@ -629,14 +629,11 @@
         all_chunks_test_result = True
         for i in range(nchunks):
             logging.info('Handle chunk %d', i)
-            if not device.HandleOneChunk(chunk_in_secs, i, test_profile):
+            recorded_file = device.HandleOneChunk(chunk_in_secs, i,
+                                                  test_profile, self.host.ip)
+            if recorded_file is None:
                 raise error.TestError('Failed to handle chunk %d' % i)
 
-            # Copy the recorded audio file to the DUT for spectrum analysis.
-            logging.debug('Scp recorded file of chunk %d', i)
-            recorded_file = test_data['recorded_by_peer'] % i
-            device.ScpToDut(recorded_file, recorded_file, self.host.ip)
-
             # Check if the audio frames in the recorded file are legitimate.
             if not self._check_audio_frames_legitimacy(
                     test_data, 'recorded_by_peer', recorded_file=recorded_file):