Songyue Han | 130053e | 2024-04-25 22:04:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2024 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 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "CodecCapabilitiesTest" |
| 19 | |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include <memory> |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | #include <binder/Parcel.h> |
| 27 | |
| 28 | #include <media/CodecCapabilities.h> |
| 29 | #include <media/CodecCapabilitiesUtils.h> |
| 30 | #include <media/MediaCodecInfo.h> |
| 31 | |
| 32 | #include <media/stagefright/MediaCodecConstants.h> |
| 33 | #include <media/stagefright/MediaCodecList.h> |
| 34 | #include <media/stagefright/foundation/ABuffer.h> |
| 35 | #include <media/stagefright/foundation/AString.h> |
| 36 | |
Songyue Han | 73d6d11 | 2024-06-05 17:39:06 +0000 | [diff] [blame] | 37 | using namespace android; |
| 38 | |
| 39 | class AudioCapsAacTest : public testing::Test { |
| 40 | protected: |
| 41 | AudioCapsAacTest() { |
| 42 | std::string mediaType = MIMETYPE_AUDIO_AAC; |
| 43 | |
| 44 | sp<AMessage> details = new AMessage; |
| 45 | details->setString("bitrate-range", "8000-960000"); |
| 46 | details->setString("max-channel-count", "8"); |
| 47 | details->setString("sample-rate-ranges", |
| 48 | "7350,8000,11025,12000,16000,22050,24000,32000,44100,48000"); |
| 49 | |
| 50 | std::vector<ProfileLevel> profileLevel{ |
| 51 | ProfileLevel(2, 0), |
| 52 | ProfileLevel(5, 0), |
| 53 | ProfileLevel(29, 0), |
| 54 | ProfileLevel(23, 0), |
| 55 | ProfileLevel(39, 0), |
| 56 | ProfileLevel(20, 0), |
| 57 | ProfileLevel(42, 0), |
| 58 | }; |
| 59 | |
| 60 | audioCaps = AudioCapabilities::Create(mediaType, profileLevel, details); |
| 61 | } |
| 62 | |
| 63 | std::shared_ptr<AudioCapabilities> audioCaps; |
| 64 | }; |
| 65 | |
| 66 | TEST_F(AudioCapsAacTest, AudioCaps_Aac_Bitrate) { |
| 67 | const Range<int>& bitrateRange = audioCaps->getBitrateRange(); |
| 68 | EXPECT_EQ(bitrateRange.lower(), 8000) << "bitrate range1 does not match. lower: " |
| 69 | << bitrateRange.lower(); |
| 70 | EXPECT_EQ(bitrateRange.upper(), 510000) << "bitrate range1 does not match. upper: " |
| 71 | << bitrateRange.upper(); |
| 72 | } |
| 73 | |
| 74 | TEST_F(AudioCapsAacTest, AudioCaps_Aac_InputChannelCount) { |
| 75 | int maxInputChannelCount = audioCaps->getMaxInputChannelCount(); |
| 76 | EXPECT_EQ(maxInputChannelCount, 8); |
| 77 | int minInputChannelCount = audioCaps->getMinInputChannelCount(); |
| 78 | EXPECT_EQ(minInputChannelCount, 1); |
| 79 | } |
| 80 | |
| 81 | TEST_F(AudioCapsAacTest, AudioCaps_Aac_SupportedSampleRates) { |
| 82 | const std::vector<int>& sampleRates = audioCaps->getSupportedSampleRates(); |
| 83 | EXPECT_EQ(sampleRates, std::vector<int>({7350, 8000, 11025, 12000, 16000, 22050, |
| 84 | 24000, 32000, 44100, 48000})); |
| 85 | |
| 86 | EXPECT_FALSE(audioCaps->isSampleRateSupported(6000)) |
| 87 | << "isSampleRateSupported returned true for unsupported sample rate"; |
| 88 | EXPECT_TRUE(audioCaps->isSampleRateSupported(8000)) |
| 89 | << "isSampleRateSupported returned false for supported sample rate"; |
| 90 | EXPECT_TRUE(audioCaps->isSampleRateSupported(12000)) |
| 91 | << "isSampleRateSupported returned false for supported sample rate"; |
| 92 | EXPECT_FALSE(audioCaps->isSampleRateSupported(44000)) |
| 93 | << "isSampleRateSupported returned true for unsupported sample rate"; |
| 94 | EXPECT_TRUE(audioCaps->isSampleRateSupported(48000)) |
| 95 | << "isSampleRateSupported returned true for unsupported sample rate"; |
| 96 | } |
| 97 | |
| 98 | class AudioCapsRawTest : public testing::Test { |
| 99 | protected: |
| 100 | AudioCapsRawTest() { |
| 101 | std::string mediaType = MIMETYPE_AUDIO_RAW; |
| 102 | |
| 103 | sp<AMessage> details = new AMessage; |
| 104 | details->setString("bitrate-range", "1-10000000"); |
| 105 | details->setString("channel-ranges", "1,2,3,4,5,6,7,8,9,10,11,12"); |
| 106 | details->setString("sample-rate-ranges", "8000-192000"); |
| 107 | |
| 108 | std::vector<ProfileLevel> profileLevel; |
| 109 | |
| 110 | audioCaps = AudioCapabilities::Create(mediaType, profileLevel, details); |
| 111 | } |
| 112 | |
| 113 | std::shared_ptr<AudioCapabilities> audioCaps; |
| 114 | }; |
| 115 | |
| 116 | TEST_F(AudioCapsRawTest, AudioCaps_Raw_Bitrate) { |
| 117 | const Range<int>& bitrateRange = audioCaps->getBitrateRange(); |
| 118 | EXPECT_EQ(bitrateRange.lower(), 1); |
| 119 | EXPECT_EQ(bitrateRange.upper(), 10000000); |
| 120 | } |
| 121 | |
| 122 | TEST_F(AudioCapsRawTest, AudioCaps_Raw_InputChannelCount) { |
| 123 | int maxInputChannelCount = audioCaps->getMaxInputChannelCount(); |
| 124 | EXPECT_EQ(maxInputChannelCount, 12); |
| 125 | int minInputChannelCount = audioCaps->getMinInputChannelCount(); |
| 126 | EXPECT_EQ(minInputChannelCount, 1); |
| 127 | } |
| 128 | |
| 129 | TEST_F(AudioCapsRawTest, AudioCaps_Raw_InputChannelCountRanges) { |
| 130 | const std::vector<Range<int>>& inputChannelCountRanges |
| 131 | = audioCaps->getInputChannelCountRanges(); |
| 132 | std::vector<Range<int>> expectedOutput({{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, |
| 133 | {6,6}, {7,7}, {8,8}, {9,9}, {10,10}, {11,11}, {12,12}}); |
| 134 | ASSERT_EQ(inputChannelCountRanges.size(), expectedOutput.size()); |
| 135 | for (int i = 0; i < inputChannelCountRanges.size(); i++) { |
| 136 | EXPECT_EQ(inputChannelCountRanges.at(i).lower(), expectedOutput.at(i).lower()); |
| 137 | EXPECT_EQ(inputChannelCountRanges.at(i).upper(), expectedOutput.at(i).upper()); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | TEST_F(AudioCapsRawTest, AudioCaps_Raw_SupportedSampleRates) { |
| 142 | const std::vector<Range<int>>& sampleRateRanges = audioCaps->getSupportedSampleRateRanges(); |
| 143 | EXPECT_EQ(sampleRateRanges.size(), 1); |
| 144 | EXPECT_EQ(sampleRateRanges.at(0).lower(), 8000); |
| 145 | EXPECT_EQ(sampleRateRanges.at(0).upper(), 192000); |
| 146 | |
| 147 | EXPECT_EQ(audioCaps->isSampleRateSupported(7000), false); |
| 148 | EXPECT_EQ(audioCaps->isSampleRateSupported(10000), true); |
| 149 | EXPECT_EQ(audioCaps->isSampleRateSupported(193000), false); |
| 150 | } |