Fix review comment in CSD parsing of Mp4a-Latm Reader

Change-Id: I6fc07d88a7dbc52fc2fbe0e5ad45a53f8f25c4fd
This commit is contained in:
Rakesh Kumar 2022-09-30 14:07:27 +05:30
parent 4880057f92
commit 9f8d69929d

View File

@ -55,6 +55,7 @@ import com.google.common.collect.ImmutableMap;
private static final String PARAMETER_H265_SPROP_VPS = "sprop-vps"; private static final String PARAMETER_H265_SPROP_VPS = "sprop-vps";
private static final String PARAMETER_H265_SPROP_MAX_DON_DIFF = "sprop-max-don-diff"; private static final String PARAMETER_H265_SPROP_MAX_DON_DIFF = "sprop-max-don-diff";
private static final String PARAMETER_MP4V_CONFIG = "config"; private static final String PARAMETER_MP4V_CONFIG = "config";
private static final String PARAMETER_MP4A_CPRESENT = "cpresent";
/** Prefix for the RFC6381 codecs string for AAC formats. */ /** Prefix for the RFC6381 codecs string for AAC formats. */
private static final String AAC_CODECS_PREFIX = "mp4a.40."; private static final String AAC_CODECS_PREFIX = "mp4a.40.";
@ -211,11 +212,18 @@ import com.google.common.collect.ImmutableMap;
checkArgument(channelCount != C.INDEX_UNSET); checkArgument(channelCount != C.INDEX_UNSET);
checkArgument(!fmtpParameters.isEmpty()); checkArgument(!fmtpParameters.isEmpty());
if(mediaEncoding.equals(RtpPayloadFormat.RTP_MEDIA_MPEG4_AUDIO)) { if(mediaEncoding.equals(RtpPayloadFormat.RTP_MEDIA_MPEG4_AUDIO)) {
Pair<Integer, Integer> cfgOpts = getSampleRateAndChannelCountFromAudioConfig( boolean isCPresent = true;
fmtpParameters, channelCount, clockRate); if (fmtpParameters.get(PARAMETER_MP4A_CPRESENT) != null && fmtpParameters.get(
channelCount = cfgOpts.first; PARAMETER_MP4A_CPRESENT).equals("0")) {
clockRate = cfgOpts.second; isCPresent = false;
formatBuilder.setSampleRate(clockRate).setChannelCount(channelCount); }
@Nullable String configInput = fmtpParameters.get(PARAMETER_MP4V_CONFIG);
if (!isCPresent && configInput != null && configInput.length() % 2 == 0) {
Pair<Integer, Integer> configParameters = getSampleRateAndChannelCount(configInput);
channelCount = configParameters.first;
clockRate = configParameters.second;
formatBuilder.setSampleRate(clockRate).setChannelCount(channelCount);
}
} }
processAacFmtpAttribute(formatBuilder, fmtpParameters, channelCount, clockRate); processAacFmtpAttribute(formatBuilder, fmtpParameters, channelCount, clockRate);
break; break;
@ -311,33 +319,30 @@ import com.google.common.collect.ImmutableMap;
} }
/** /**
* Parses an MPEG-4 Audio Stream Mux configuration, as defined in ISO/IEC14496-3. FMTP attribute * Returns a {@link Pair} of sample rate and channel count, by parsing the
* contains config which is a byte array containing the MPEG-4 Audio Stream Mux configuration to * MPEG4 Audio Stream Mux configuration.
* parse. *
* <p>fmtp attribute {@code config} includes the MPEG4 Audio Stream Mux
* configuration (ISO/IEC14496-3, Chapter 1.7.3).
*/ */
private static Pair<Integer, Integer> getSampleRateAndChannelCountFromAudioConfig( private static Pair<Integer, Integer> getSampleRateAndChannelCount(String configInput) {
ImmutableMap<String, String> fmtpAttributes, int channelCount = 0, sampleRate = 0;
int channelCount, byte[] configBuffer = Util.getBytesFromHexString(configInput);
int sampleRate) { ParsableBitArray scratchBits = new ParsableBitArray(configBuffer);
@Nullable String configInput = fmtpAttributes.get(PARAMETER_MP4V_CONFIG); int audioMuxVersion = scratchBits.readBits(1);
if (configInput != null && configInput.length() % 2 == 0) { if (audioMuxVersion == 0) {
byte[] configBuffer = Util.getBytesFromHexString(configInput); checkArgument(scratchBits.readBits(1) == 1, "Invalid allStreamsSameTimeFraming.");
ParsableBitArray scratchBits = new ParsableBitArray(configBuffer); scratchBits.readBits(6);
int audioMuxVersion = scratchBits.readBits(1); checkArgument(scratchBits.readBits(4) == 0, "Invalid numProgram.");
if (audioMuxVersion == 0) { checkArgument(scratchBits.readBits(3) == 0, "Invalid numLayer.");
checkArgument(scratchBits.readBits(1) == 1, "Invalid allStreamsSameTimeFraming."); @Nullable AacUtil.Config aacConfig = null;
scratchBits.readBits(6); try {
checkArgument(scratchBits.readBits(4) == 0, "Invalid numProgram."); aacConfig = AacUtil.parseAudioSpecificConfig(scratchBits, false);
checkArgument(scratchBits.readBits(3) == 0, "Invalid numLayer."); } catch (ParserException e) {
AacUtil.Config aacConfig = null; throw new IllegalArgumentException(e);
try {
aacConfig = AacUtil.parseAudioSpecificConfig(scratchBits, false);
} catch (ParserException e) {
throw new IllegalArgumentException(e);
}
sampleRate = aacConfig.sampleRateHz;
channelCount = aacConfig.channelCount;
} }
sampleRate = aacConfig.sampleRateHz;
channelCount = aacConfig.channelCount;
} }
return Pair.create(channelCount, sampleRate); return Pair.create(channelCount, sampleRate);
} }