|
| 1 | +/* |
| 2 | + * Copyright 2022 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 | +package androidx.media3.extractor; |
| 17 | + |
| 18 | +import static com.google.common.truth.Truth.assertThat; |
| 19 | +import static org.junit.Assert.assertThrows; |
| 20 | + |
| 21 | +import androidx.media3.common.ParserException; |
| 22 | +import androidx.media3.common.util.Util; |
| 23 | +import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | + |
| 27 | +/** Unit tests for {@link AacUtil}. */ |
| 28 | +@RunWith(AndroidJUnit4.class) |
| 29 | +public final class AacUtilTest { |
| 30 | + private static final byte[] AAC_48K_2CH_HEADER = Util.getBytesFromHexString("1190"); |
| 31 | + |
| 32 | + private static final byte[] NOT_ENOUGH_ARBITRARY_SAMPLING_FREQ_BITS_HEADER = |
| 33 | + Util.getBytesFromHexString("1790"); |
| 34 | + |
| 35 | + private static final byte[] ARBITRARY_SAMPLING_FREQ_BITS_HEADER = |
| 36 | + Util.getBytesFromHexString("1780000790"); |
| 37 | + |
| 38 | + @Test |
| 39 | + public void parseAudioSpecificConfig_twoCh48kAac_parsedCorrectly() throws Exception { |
| 40 | + AacUtil.Config aac = AacUtil.parseAudioSpecificConfig(AAC_48K_2CH_HEADER); |
| 41 | + |
| 42 | + assertThat(aac.channelCount).isEqualTo(2); |
| 43 | + assertThat(aac.sampleRateHz).isEqualTo(48000); |
| 44 | + assertThat(aac.codecs).isEqualTo("mp4a.40.2"); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void parseAudioSpecificConfig_arbitrarySamplingFreqHeader_parsedCorrectly() |
| 49 | + throws Exception { |
| 50 | + AacUtil.Config aac = AacUtil.parseAudioSpecificConfig(ARBITRARY_SAMPLING_FREQ_BITS_HEADER); |
| 51 | + assertThat(aac.channelCount).isEqualTo(2); |
| 52 | + assertThat(aac.sampleRateHz).isEqualTo(15); |
| 53 | + assertThat(aac.codecs).isEqualTo("mp4a.40.2"); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void |
| 58 | + parseAudioSpecificConfig_arbitrarySamplingFreqHeaderNotEnoughBits_throwsParserException() { |
| 59 | + // ISO 14496-3 1.6.2.1 allows for setting of arbitrary sampling frequency, but if the extra |
| 60 | + // frequency bits are missing, make sure the code will throw an exception. |
| 61 | + assertThrows( |
| 62 | + ParserException.class, |
| 63 | + () -> AacUtil.parseAudioSpecificConfig(NOT_ENOUGH_ARBITRARY_SAMPLING_FREQ_BITS_HEADER)); |
| 64 | + } |
| 65 | +} |
0 commit comments