• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
17 #include <gtest/gtest.h>
18 
19 #include <media/AudioContainers.h>
20 
21 namespace android {
22 
23 const static AudioProfileAttributesMultimap AUDIO_PROFILE_ATTRIBUTES = {
24         {AUDIO_FORMAT_PCM_16_BIT, {{44100, 48000},
25                                    {AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1}}},
26         {AUDIO_FORMAT_PCM_16_BIT, {{96000},
27                                    {AUDIO_CHANNEL_OUT_STEREO}}},
28         {AUDIO_FORMAT_PCM_8_24_BIT, {{48000},
29                                      {AUDIO_CHANNEL_OUT_STEREO}}}
30 };
31 
TEST(PopulateAudioProfilesTest,AllAttributesMatches)32 TEST(PopulateAudioProfilesTest, AllAttributesMatches) {
33     const AudioProfileAttributesMultimap expected = {
34             {AUDIO_FORMAT_PCM_16_BIT, {{44100, 48000},
35                                        {AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1}}},
36             {AUDIO_FORMAT_PCM_16_BIT, {{96000},
37                                        {AUDIO_CHANNEL_OUT_STEREO}}}
38     };
39     const audio_format_t format = AUDIO_FORMAT_PCM_16_BIT;
40     const SampleRateSet allSampleRates = {44100, 48000, 96000};
41     const ChannelMaskSet allChannelMasks = {AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1};
42 
43     audio_profile profiles[AUDIO_PORT_MAX_AUDIO_PROFILES];
44     uint32_t numProfiles = 0;
45     populateAudioProfiles(AUDIO_PROFILE_ATTRIBUTES, format, allChannelMasks, allSampleRates,
46                           profiles, &numProfiles);
47     ASSERT_EQ(expected, createAudioProfilesAttrMap(profiles, 0, numProfiles));
48 }
49 
TEST(PopulateAudioProfilesTest,AttributesNotInAllValues)50 TEST(PopulateAudioProfilesTest, AttributesNotInAllValues) {
51     const AudioProfileAttributesMultimap expected = {
52             {AUDIO_FORMAT_PCM_16_BIT, {{48000},
53                                        {AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1}}},
54             {AUDIO_FORMAT_PCM_16_BIT, {{96000},
55                                        {AUDIO_CHANNEL_OUT_STEREO}}}
56     };
57     const audio_format_t format = AUDIO_FORMAT_PCM_16_BIT;
58     const SampleRateSet allSampleRates = {48000, 96000};
59     const ChannelMaskSet allChannelMasks = {AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1};
60 
61     audio_profile profiles[AUDIO_PORT_MAX_AUDIO_PROFILES];
62     uint32_t numProfiles = 0;
63     populateAudioProfiles(AUDIO_PROFILE_ATTRIBUTES, format, allChannelMasks, allSampleRates,
64             profiles, &numProfiles);
65     ASSERT_EQ(expected, createAudioProfilesAttrMap(profiles, 0, numProfiles));
66 }
67 
TEST(PopulateAudioProfilesTest,AllValuesNotInAttributes)68 TEST(PopulateAudioProfilesTest, AllValuesNotInAttributes) {
69     const AudioProfileAttributesMultimap expected = {
70             {AUDIO_FORMAT_PCM_16_BIT, {{48000},
71                                        {AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1}}},
72             {AUDIO_FORMAT_PCM_16_BIT, {{96000},
73                                        {AUDIO_CHANNEL_OUT_STEREO}}},
74             {AUDIO_FORMAT_PCM_16_BIT, {{88200},
75                                        {AUDIO_CHANNEL_OUT_MONO, AUDIO_CHANNEL_OUT_STEREO,
76                                         AUDIO_CHANNEL_OUT_7POINT1}}},
77             {AUDIO_FORMAT_PCM_16_BIT, {{48000, 88200, 96000},
78                                        {AUDIO_CHANNEL_OUT_MONO}}}
79     };
80     const audio_format_t format = AUDIO_FORMAT_PCM_16_BIT;
81     const SampleRateSet allSampleRates = {48000, 88200, 96000};
82     const ChannelMaskSet allChannelMasks =
83             {AUDIO_CHANNEL_OUT_MONO, AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1};
84 
85     audio_profile profiles[AUDIO_PORT_MAX_AUDIO_PROFILES];
86     uint32_t numProfiles = 0;
87     populateAudioProfiles(AUDIO_PROFILE_ATTRIBUTES, format, allChannelMasks, allSampleRates,
88             profiles, &numProfiles);
89     ASSERT_EQ(expected, createAudioProfilesAttrMap(profiles, 0, numProfiles));
90 }
91 
TEST(PopulateAudioProfilesTest,NoOverflow)92 TEST(PopulateAudioProfilesTest, NoOverflow) {
93     const audio_format_t format = AUDIO_FORMAT_PCM_16_BIT;
94     const SampleRateSet allSampleRates = {48000, 88200, 96000};
95     const ChannelMaskSet allChannelMasks =
96             {AUDIO_CHANNEL_OUT_MONO, AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_7POINT1};
97 
98     audio_profile profiles[AUDIO_PORT_MAX_AUDIO_PROFILES];
99     const uint32_t expectedNumProfiles = 4;
100     for (uint32_t i = 0; i <= AUDIO_PORT_MAX_AUDIO_PROFILES; ++i) {
101         uint32_t numProfiles = 0;
102         populateAudioProfiles(AUDIO_PROFILE_ATTRIBUTES, format, allChannelMasks, allSampleRates,
103                               profiles, &numProfiles, i);
104         ASSERT_EQ(std::min(i, expectedNumProfiles), numProfiles);
105     }
106 }
107 
108 } // namespace android
109