Commit 4880057f by Rakesh Kumar

Fix some more review comment in RTP Mp4a-Latm Reader

Change-Id: I9033d0bd93c6129c64c41ce70fef26bf8a6e4b6e
parent 97afe69e
...@@ -54,7 +54,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -54,7 +54,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private int fragmentedSampleSizeBytes; private int fragmentedSampleSizeBytes;
private long startTimeOffsetUs; private long startTimeOffsetUs;
private long sampleTimeUsOfFragmentedSample; private long sampleTimeUsOfFragmentedSample;
private int numSubFrames; private int numberOfSubframes;
/** Creates an instance. */ /** Creates an instance. */
public RtpMp4aReader(RtpPayloadFormat payloadFormat) { public RtpMp4aReader(RtpPayloadFormat payloadFormat) {
...@@ -78,9 +78,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -78,9 +78,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
checkState(firstReceivedTimestamp == C.TIME_UNSET); checkState(firstReceivedTimestamp == C.TIME_UNSET);
firstReceivedTimestamp = timestamp; firstReceivedTimestamp = timestamp;
try { try {
numSubFrames = getNumOfSubframesFromMpeg4AudioConfig(payloadFormat.fmtpParameters); numberOfSubframes = getNumOfSubframesFromMpeg4AudioConfig(payloadFormat.fmtpParameters);
} catch (ParserException e) { } catch (ParserException e) {
e.printStackTrace(); throw new IllegalArgumentException(e);
} }
} }
...@@ -94,23 +94,30 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -94,23 +94,30 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if(fragmentedSampleSizeBytes > 0 && expectedSequenceNumber < sequenceNumber) { if(fragmentedSampleSizeBytes > 0 && expectedSequenceNumber < sequenceNumber) {
outputSampleMetadataForFragmentedPackets(); outputSampleMetadataForFragmentedPackets();
} }
int sampleOffset = 0; int audioPayloadOffset = 0;
for (int subFrame = 0; subFrame <= numSubFrames; subFrame++) { for (int subFrame = 0; subFrame < numberOfSubframes; subFrame++) {
int sampleLength = 0; int sampleLength = 0;
/* Each subframe starts with a variable length encoding */ /**
for (; sampleOffset < data.bytesLeft(); sampleOffset++) { * This implements PayloadLengthInfo() in Chapter 1.7.3.1, it's only support one program and
sampleLength += data.getData()[sampleOffset] & 0xff; * one layer.
if ((data.getData()[sampleOffset] & 0xff) != 0xff) { * Each subframe starts with a variable length encoding.
*/
for (; audioPayloadOffset < data.bytesLeft(); audioPayloadOffset++) {
int payloadMuxLength = data.peekUnsignedByte();
sampleLength += payloadMuxLength;
if (payloadMuxLength != 0xff) {
break; break;
} else {
data.setPosition(audioPayloadOffset + 1);
} }
} }
sampleOffset++; audioPayloadOffset++;
data.setPosition(sampleOffset); data.setPosition(audioPayloadOffset);
// Write the audio sample /* Write the audio sample */
trackOutput.sampleData(data, sampleLength); trackOutput.sampleData(data, sampleLength);
sampleOffset += sampleLength; audioPayloadOffset+= sampleLength;
fragmentedSampleSizeBytes += sampleLength; fragmentedSampleSizeBytes += sampleLength;
} }
sampleTimeUsOfFragmentedSample = toSampleTimeUs(startTimeOffsetUs, timestamp, sampleTimeUsOfFragmentedSample = toSampleTimeUs(startTimeOffsetUs, timestamp,
...@@ -140,17 +147,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -140,17 +147,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* @throws ParserException If the MPEG-4 Audio Stream Mux configuration cannot be parsed due to * @throws ParserException If the MPEG-4 Audio Stream Mux configuration cannot be parsed due to
* unsupported audioMuxVersion. * unsupported audioMuxVersion.
*/ */
private static Integer getNumOfSubframesFromMpeg4AudioConfig( private static int getNumOfSubframesFromMpeg4AudioConfig(
ImmutableMap<String, String> fmtpAttributes) throws ParserException { ImmutableMap<String, String> fmtpAttributes) throws ParserException {
@Nullable String configInput = fmtpAttributes.get(PARAMETER_MP4A_CONFIG); @Nullable String configInput = fmtpAttributes.get(PARAMETER_MP4A_CONFIG);
int numSubFrames = 0; int numberOfSubframes = 0;
if (configInput != null && configInput.length() % 2 == 0) { if (configInput != null && configInput.length() % 2 == 0) {
byte[] configBuffer = Util.getBytesFromHexString(configInput); byte[] configBuffer = Util.getBytesFromHexString(configInput);
ParsableBitArray scratchBits = new ParsableBitArray(configBuffer); ParsableBitArray scratchBits = new ParsableBitArray(configBuffer);
int audioMuxVersion = scratchBits.readBits(1); int audioMuxVersion = scratchBits.readBits(1);
if (audioMuxVersion == 0) { if (audioMuxVersion == 0) {
checkArgument(scratchBits.readBits(1) == 1, "Invalid allStreamsSameTimeFraming."); checkArgument(scratchBits.readBits(1) == 1, "Invalid allStreamsSameTimeFraming.");
numSubFrames = scratchBits.readBits(6); numberOfSubframes = scratchBits.readBits(6);
checkArgument(scratchBits.readBits(4) == 0, "Invalid numProgram."); checkArgument(scratchBits.readBits(4) == 0, "Invalid numProgram.");
checkArgument(scratchBits.readBits(3) == 0, "Invalid numLayer."); checkArgument(scratchBits.readBits(3) == 0, "Invalid numLayer.");
} else { } else {
...@@ -158,7 +165,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -158,7 +165,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
"unsupported audio mux version: " + audioMuxVersion, null); "unsupported audio mux version: " + audioMuxVersion, null);
} }
} }
return numSubFrames; return numberOfSubframes + 1;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment