Fix review comment in mp4a-latm Reader

Change-Id: I004f4a9ed9bd7cc48708d82a01c945789d1e9e5e
This commit is contained in:
Rakesh Kumar 2022-10-03 17:38:22 +05:30
parent 9f8d69929d
commit 0ac84fe16f
2 changed files with 17 additions and 24 deletions

View File

@ -55,7 +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"; private static final String PARAMETER_MP4A_C_PRESENT = "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.";
@ -212,13 +212,13 @@ 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)) {
boolean isCPresent = true; boolean isConfigPresent = true;
if (fmtpParameters.get(PARAMETER_MP4A_CPRESENT) != null && fmtpParameters.get( if (fmtpParameters.get(PARAMETER_MP4A_C_PRESENT) != null && fmtpParameters.get(
PARAMETER_MP4A_CPRESENT).equals("0")) { PARAMETER_MP4A_C_PRESENT).equals("0")) {
isCPresent = false; isConfigPresent = false;
} }
@Nullable String configInput = fmtpParameters.get(PARAMETER_MP4V_CONFIG); @Nullable String configInput = fmtpParameters.get(PARAMETER_MP4V_CONFIG);
if (!isCPresent && configInput != null && configInput.length() % 2 == 0) { if (!isConfigPresent && configInput != null && configInput.length() % 2 == 0) {
Pair<Integer, Integer> configParameters = getSampleRateAndChannelCount(configInput); Pair<Integer, Integer> configParameters = getSampleRateAndChannelCount(configInput);
channelCount = configParameters.first; channelCount = configParameters.first;
clockRate = configParameters.second; clockRate = configParameters.second;
@ -326,25 +326,22 @@ import com.google.common.collect.ImmutableMap;
* configuration (ISO/IEC14496-3, Chapter 1.7.3). * configuration (ISO/IEC14496-3, Chapter 1.7.3).
*/ */
private static Pair<Integer, Integer> getSampleRateAndChannelCount(String configInput) { private static Pair<Integer, Integer> getSampleRateAndChannelCount(String configInput) {
int channelCount = 0, sampleRate = 0; ParsableBitArray config = new ParsableBitArray(Util.getBytesFromHexString(configInput));
byte[] configBuffer = Util.getBytesFromHexString(configInput); int audioMuxVersion = config .readBits(1);
ParsableBitArray scratchBits = new ParsableBitArray(configBuffer);
int audioMuxVersion = scratchBits.readBits(1);
if (audioMuxVersion == 0) { if (audioMuxVersion == 0) {
checkArgument(scratchBits.readBits(1) == 1, "Invalid allStreamsSameTimeFraming."); checkArgument(config .readBits(1) == 1, "Only supports one allStreamsSameTimeFraming.");
scratchBits.readBits(6); config .readBits(6);
checkArgument(scratchBits.readBits(4) == 0, "Invalid numProgram."); checkArgument(config .readBits(4) == 0, "Only supports one program.");
checkArgument(scratchBits.readBits(3) == 0, "Invalid numLayer."); checkArgument(config .readBits(3) == 0, "Only supports one numLayer.");
@Nullable AacUtil.Config aacConfig = null; @Nullable AacUtil.Config aacConfig = null;
try { try {
aacConfig = AacUtil.parseAudioSpecificConfig(scratchBits, false); aacConfig = AacUtil.parseAudioSpecificConfig(config , false);
} catch (ParserException e) { } catch (ParserException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
sampleRate = aacConfig.sampleRateHz; return Pair.create(aacConfig.channelCount, aacConfig.sampleRateHz);
channelCount = aacConfig.channelCount;
} }
return Pair.create(channelCount, sampleRate); throw new IllegalArgumentException ("Only support audio mux version 0");
} }
private static void processMPEG4FmtpAttribute( private static void processMPEG4FmtpAttribute(

View File

@ -104,18 +104,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* Each subframe starts with a variable length encoding. * Each subframe starts with a variable length encoding.
*/ */
for (; audioPayloadOffset < data.bytesLeft(); audioPayloadOffset++) { for (; audioPayloadOffset < data.bytesLeft(); audioPayloadOffset++) {
int payloadMuxLength = data.peekUnsignedByte(); int payloadMuxLength = data.readUnsignedByte();
sampleLength += payloadMuxLength; sampleLength += payloadMuxLength;
if (payloadMuxLength != 0xff) { if (payloadMuxLength != 0xff) {
break; break;
} else {
data.setPosition(audioPayloadOffset + 1);
} }
} }
audioPayloadOffset++;
data.setPosition(audioPayloadOffset);
/* Write the audio sample */ // Write the audio sample
trackOutput.sampleData(data, sampleLength); trackOutput.sampleData(data, sampleLength);
audioPayloadOffset+= sampleLength; audioPayloadOffset+= sampleLength;
fragmentedSampleSizeBytes += sampleLength; fragmentedSampleSizeBytes += sampleLength;