systemaudio_tests.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <gtest/gtest.h>
  17. #define LOG_TAG "SysAudio_Test"
  18. #include <log/log.h>
  19. #include <media/PatchBuilder.h>
  20. #include <system/audio.h>
  21. using namespace android;
  22. TEST(SystemAudioTest, PatchInvalid) {
  23. audio_patch patch{};
  24. ASSERT_FALSE(audio_patch_is_valid(&patch));
  25. patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1;
  26. patch.num_sinks = 1;
  27. ASSERT_FALSE(audio_patch_is_valid(&patch));
  28. patch.num_sources = 1;
  29. patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1;
  30. ASSERT_FALSE(audio_patch_is_valid(&patch));
  31. patch.num_sources = 0;
  32. patch.num_sinks = 1;
  33. ASSERT_FALSE(audio_patch_is_valid(&patch));
  34. }
  35. TEST(SystemAudioTest, PatchValid) {
  36. const audio_port_config src = {
  37. .id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_DEVICE };
  38. // It's OK not to have sinks.
  39. ASSERT_TRUE(audio_patch_is_valid((PatchBuilder{}).addSource(src).patch()));
  40. const audio_port_config sink = {
  41. .id = 2, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_DEVICE };
  42. ASSERT_TRUE(audio_patch_is_valid((PatchBuilder{}).addSource(src).addSink(sink).patch()));
  43. ASSERT_TRUE(audio_patch_is_valid(
  44. (PatchBuilder{}).addSource(src).addSource(src).addSink(sink).patch()));
  45. ASSERT_TRUE(audio_patch_is_valid(
  46. (PatchBuilder{}).addSource(src).addSink(sink).addSink(sink).patch()));
  47. ASSERT_TRUE(audio_patch_is_valid(
  48. (PatchBuilder{}).addSource(src).addSource(src).
  49. addSink(sink).addSink(sink).patch()));
  50. }
  51. TEST(SystemAudioTest, PatchHwAvSync) {
  52. audio_port_config device_src_cfg = {
  53. .id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_DEVICE };
  54. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_src_cfg));
  55. device_src_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
  56. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_src_cfg));
  57. device_src_cfg.flags.input = AUDIO_INPUT_FLAG_HW_AV_SYNC;
  58. ASSERT_TRUE(audio_port_config_has_hw_av_sync(&device_src_cfg));
  59. audio_port_config device_sink_cfg = {
  60. .id = 1, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_DEVICE };
  61. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_sink_cfg));
  62. device_sink_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
  63. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_sink_cfg));
  64. device_sink_cfg.flags.output = AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
  65. ASSERT_TRUE(audio_port_config_has_hw_av_sync(&device_sink_cfg));
  66. audio_port_config mix_sink_cfg = {
  67. .id = 1, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_MIX };
  68. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_sink_cfg));
  69. mix_sink_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
  70. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_sink_cfg));
  71. mix_sink_cfg.flags.input = AUDIO_INPUT_FLAG_HW_AV_SYNC;
  72. ASSERT_TRUE(audio_port_config_has_hw_av_sync(&mix_sink_cfg));
  73. audio_port_config mix_src_cfg = {
  74. .id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_MIX };
  75. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_src_cfg));
  76. mix_src_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
  77. ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_src_cfg));
  78. mix_src_cfg.flags.output = AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
  79. ASSERT_TRUE(audio_port_config_has_hw_av_sync(&mix_src_cfg));
  80. }
  81. TEST(SystemAudioTest, PatchEqual) {
  82. const audio_patch patch1{}, patch2{};
  83. // Invalid patches are not equal.
  84. ASSERT_FALSE(audio_patches_are_equal(&patch1, &patch2));
  85. const audio_port_config src = {
  86. .id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_DEVICE };
  87. const audio_port_config sink = {
  88. .id = 2, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_DEVICE };
  89. ASSERT_FALSE(audio_patches_are_equal(
  90. (PatchBuilder{}).addSource(src).patch(),
  91. (PatchBuilder{}).addSource(src).addSink(sink).patch()));
  92. ASSERT_TRUE(audio_patches_are_equal(
  93. (PatchBuilder{}).addSource(src).addSink(sink).patch(),
  94. (PatchBuilder{}).addSource(src).addSink(sink).patch()));
  95. ASSERT_FALSE(audio_patches_are_equal(
  96. (PatchBuilder{}).addSource(src).addSink(sink).patch(),
  97. (PatchBuilder{}).addSource(src).addSource(src).addSink(sink).patch()));
  98. audio_port_config sink_hw_av_sync = sink;
  99. sink_hw_av_sync.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
  100. sink_hw_av_sync.flags.output = AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
  101. ASSERT_FALSE(audio_patches_are_equal(
  102. (PatchBuilder{}).addSource(src).addSink(sink).patch(),
  103. (PatchBuilder{}).addSource(src).addSink(sink_hw_av_sync).patch()));
  104. ASSERT_TRUE(audio_patches_are_equal(
  105. (PatchBuilder{}).addSource(src).addSink(sink_hw_av_sync).patch(),
  106. (PatchBuilder{}).addSource(src).addSink(sink_hw_av_sync).patch()));
  107. }