audio: Add StreamDescriptor.frameSizeBytes

This field indicates the frame size and is filled by
the HAL module, so that the client does not have
to calculate it.

As a side effect, in the VTS code, a StreamContext can
now be created solely from a StreamDescriptor.

Added unit tests for the functions from Utils.

Bug: 205884982
Test: atest libaudioaidlcommon_test
Test: atest VtsHalAudioCoreTargetTest
Merged-In: Ief836b8b2d35bacb1f9778e2462d540554149d7f
Change-Id: Ief836b8b2d35bacb1f9778e2462d540554149d7f
(cherry picked from commit 5862c1e3bca8d66b11ef7f0d041171bce79a3104)
diff --git a/audio/aidl/common/include/Utils.h b/audio/aidl/common/include/Utils.h
index 1a87882..74549d4 100644
--- a/audio/aidl/common/include/Utils.h
+++ b/audio/aidl/common/include/Utils.h
@@ -62,12 +62,20 @@
 constexpr size_t getFrameSizeInBytes(
         const ::aidl::android::media::audio::common::AudioFormatDescription& format,
         const ::aidl::android::media::audio::common::AudioChannelLayout& layout) {
+    if (format == ::aidl::android::media::audio::common::AudioFormatDescription{}) {
+        // Unspecified format.
+        return 0;
+    }
     using ::aidl::android::media::audio::common::AudioFormatType;
     if (format.type == AudioFormatType::PCM) {
         return getPcmSampleSizeInBytes(format.pcm) * getChannelCount(layout);
+    } else if (format.type == AudioFormatType::NON_PCM) {
+        // For non-PCM formats always use the underlying PCM size. The default value for
+        // PCM is "UINT_8_BIT", thus non-encapsulated streams have the frame size of 1.
+        return getPcmSampleSizeInBytes(format.pcm);
     }
-    // For non-PCM formats always use frame size of 1.
-    return 1;
+    // Something unexpected.
+    return 0;
 }
 
 }  // namespace android::hardware::audio::common