mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Changes based on internal comments
This commit is contained in:
parent
ae77333d0f
commit
6811b8394b
2 changed files with 80 additions and 98 deletions
|
|
@ -17,7 +17,6 @@ package androidx.media3.common.util;
|
|||
|
||||
import static java.lang.Math.min;
|
||||
|
||||
import androidx.media3.common.C;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.errorprone.annotations.CheckReturnValue;
|
||||
import java.nio.charset.Charset;
|
||||
|
|
@ -249,16 +248,6 @@ public final class ParsableBitArray {
|
|||
assertValidOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the position is byte-aligned. A bit position is considered byte-aligned if the number
|
||||
* of bits left in the current position is a multiple of {@link C#BITS_PER_BYTE}.
|
||||
*
|
||||
* @return {@code true} if the position is byte-aligned, {@code false} otherwise.
|
||||
*/
|
||||
public boolean isByteAligned() {
|
||||
return bitsLeft() % C.BITS_PER_BYTE == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next {@code length} bytes into {@code buffer}. Must only be called when the position
|
||||
* is byte aligned.
|
||||
|
|
|
|||
|
|
@ -41,10 +41,8 @@ public final class MpeghUtil {
|
|||
public static final int MAX_MHAS_PACKET_HEADER_SIZE = 15;
|
||||
|
||||
/**
|
||||
* Returns whether a given integer matches an MHAS sync word. See ISO_IEC_23008-3;2022, 14.4.4.
|
||||
*
|
||||
* @param word An integer.
|
||||
* @return Whether a given integer matches an MHAS sync word.
|
||||
* Returns whether the lower 3 bytes of the given integer matches an MHAS sync word. See
|
||||
* ISO_IEC_23008-3;2022, 14.4.4.
|
||||
*/
|
||||
public static boolean isSyncWord(int word) {
|
||||
return (word & 0xFFFFFF) == MHAS_SYNC_WORD;
|
||||
|
|
@ -92,82 +90,6 @@ public final class MpeghUtil {
|
|||
return new MhasPacketHeader(packetType, packetLabel, packetLength, headerLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the sampling rate of the current MPEG-H frame. See ISO_IEC_23003-3;2020, 5.2, Table 7.
|
||||
* The reading position of {@code data} will be modified.
|
||||
*
|
||||
* @param data The data to parse, positioned at the start of the fields to obtain the sampling
|
||||
* rate from.
|
||||
* @return The sampling frequency.
|
||||
* @throws ParserException if sampling frequency could not be obtained.
|
||||
*/
|
||||
private static int getSamplingFrequency(ParsableBitArray data) throws ParserException {
|
||||
int samplingFrequencyIndex = data.readBits(5);
|
||||
|
||||
if (samplingFrequencyIndex == 0x1F) {
|
||||
return data.readBits(24);
|
||||
}
|
||||
|
||||
// See ISO_IEC_23003-3;2020, 6.1.1.1, Table 72.
|
||||
switch (samplingFrequencyIndex) {
|
||||
case 0:
|
||||
return 96_000;
|
||||
case 1:
|
||||
return 88_200;
|
||||
case 2:
|
||||
return 64_000;
|
||||
case 3:
|
||||
return 48_000;
|
||||
case 4:
|
||||
return 44_100;
|
||||
case 5:
|
||||
return 32_000;
|
||||
case 6:
|
||||
return 24_000;
|
||||
case 7:
|
||||
return 22_050;
|
||||
case 8:
|
||||
return 16_000;
|
||||
case 9:
|
||||
return 12_000;
|
||||
case 10:
|
||||
return 11_025;
|
||||
case 11:
|
||||
return 8_000;
|
||||
case 12:
|
||||
return 7350;
|
||||
case 15:
|
||||
return 57_600;
|
||||
case 16:
|
||||
return 51_200;
|
||||
case 17:
|
||||
return 40_000;
|
||||
case 18:
|
||||
return 38_400;
|
||||
case 19:
|
||||
return 34_150;
|
||||
case 20:
|
||||
return 28_800;
|
||||
case 21:
|
||||
return 25_600;
|
||||
case 22:
|
||||
return 20_000;
|
||||
case 23:
|
||||
return 19_200;
|
||||
case 24:
|
||||
return 17_075;
|
||||
case 25:
|
||||
return 14_400;
|
||||
case 26:
|
||||
return 12_800;
|
||||
case 27:
|
||||
return 9_600;
|
||||
default:
|
||||
throw ParserException.createForUnsupportedContainerFeature(
|
||||
"Unsupported sampling rate index " + samplingFrequencyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the output frame length of the current MPEG-H frame. See ISO_IEC_23003-3;2020, 6.1.1.1,
|
||||
* Table 75.
|
||||
|
|
@ -289,14 +211,9 @@ public final class MpeghUtil {
|
|||
int profileLevelIndication = data.readBits(8);
|
||||
|
||||
int usacSamplingFrequency = getSamplingFrequency(data);
|
||||
if (usacSamplingFrequency <= 0) {
|
||||
throw ParserException.createForUnsupportedContainerFeature(
|
||||
"Unsupported sampling frequency " + usacSamplingFrequency);
|
||||
}
|
||||
|
||||
int coreSbrFrameLengthIndex = data.readBits(3);
|
||||
int outputFrameLength = getOutputFrameLength(/* index= */ coreSbrFrameLengthIndex);
|
||||
int sbrRatioIndex = getSbrRatioIndex(/* index= */ coreSbrFrameLengthIndex);
|
||||
int outputFrameLength = getOutputFrameLength(coreSbrFrameLengthIndex);
|
||||
int sbrRatioIndex = getSbrRatioIndex(coreSbrFrameLengthIndex);
|
||||
|
||||
data.skipBits(2); // cfg_reserved(1), receiverDelayCompensation(1)
|
||||
|
||||
|
|
@ -334,6 +251,82 @@ public final class MpeghUtil {
|
|||
profileLevelIndication, samplingFrequency, standardFrameSamples, compatibleProfileLevelSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the sampling rate of the current MPEG-H frame. See ISO_IEC_23003-3;2020, 5.2, Table 7.
|
||||
* The reading position of {@code data} will be modified.
|
||||
*
|
||||
* @param data The data to parse, positioned at the start of the fields to obtain the sampling
|
||||
* rate from.
|
||||
* @return The sampling frequency.
|
||||
* @throws ParserException if sampling frequency could not be obtained.
|
||||
*/
|
||||
private static int getSamplingFrequency(ParsableBitArray data) throws ParserException {
|
||||
int samplingFrequencyIndex = data.readBits(5);
|
||||
|
||||
if (samplingFrequencyIndex == 0x1F) {
|
||||
return data.readBits(24);
|
||||
}
|
||||
|
||||
// See ISO_IEC_23003-3;2020, 6.1.1.1, Table 72.
|
||||
switch (samplingFrequencyIndex) {
|
||||
case 0:
|
||||
return 96_000;
|
||||
case 1:
|
||||
return 88_200;
|
||||
case 2:
|
||||
return 64_000;
|
||||
case 3:
|
||||
return 48_000;
|
||||
case 4:
|
||||
return 44_100;
|
||||
case 5:
|
||||
return 32_000;
|
||||
case 6:
|
||||
return 24_000;
|
||||
case 7:
|
||||
return 22_050;
|
||||
case 8:
|
||||
return 16_000;
|
||||
case 9:
|
||||
return 12_000;
|
||||
case 10:
|
||||
return 11_025;
|
||||
case 11:
|
||||
return 8_000;
|
||||
case 12:
|
||||
return 7350;
|
||||
case 15:
|
||||
return 57_600;
|
||||
case 16:
|
||||
return 51_200;
|
||||
case 17:
|
||||
return 40_000;
|
||||
case 18:
|
||||
return 38_400;
|
||||
case 19:
|
||||
return 34_150;
|
||||
case 20:
|
||||
return 28_800;
|
||||
case 21:
|
||||
return 25_600;
|
||||
case 22:
|
||||
return 20_000;
|
||||
case 23:
|
||||
return 19_200;
|
||||
case 24:
|
||||
return 17_075;
|
||||
case 25:
|
||||
return 14_400;
|
||||
case 26:
|
||||
return 12_800;
|
||||
case 27:
|
||||
return 9_600;
|
||||
default:
|
||||
throw ParserException.createForUnsupportedContainerFeature(
|
||||
"Unsupported sampling rate index " + samplingFrequencyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the number of truncated samples of the AudioTruncationInfo from an MPEG-H bit stream.
|
||||
* See ISO_IEC_23008-3;2022, 14.2.2, Table 225. The reading position of {@code data} will be
|
||||
|
|
|
|||
Loading…
Reference in a new issue