Skip to content

Commit

Permalink
Fix review comments on RtpMPEG4Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ManishaJajoo committed Feb 21, 2022
1 parent 706d5ac commit ef9393a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Expand Up @@ -56,7 +56,7 @@
/** Prefix for the RFC6381 codecs string for AVC formats. */
private static final String H264_CODECS_PREFIX = "avc1.";
/** Prefix for the RFC6416 codecs string for MPEG4V-ES formats. */
private static final String MPEG4_CODECS_PREFIX = "mp4v";
private static final String MPEG4_CODECS_PREFIX = "mp4v.";

private static final String GENERIC_CONTROL_ATTR = "*";

Expand Down Expand Up @@ -181,12 +181,14 @@ private static void processMPEG4FmtpAttribute(
Format.Builder formatBuilder, ImmutableMap<String, String> fmtpAttributes) {
@Nullable String configInput = fmtpAttributes.get(PARAMETER_MP4V_CONFIG);
if (configInput != null) {
byte[] csd = Util.getBytesFromHexString(configInput);
formatBuilder.setInitializationData(ImmutableList.of(csd));
byte[] configBuffer = Util.getBytesFromHexString(configInput);
formatBuilder.setInitializationData(ImmutableList.of(configBuffer));
Pair<Integer, Integer> resolution =
CodecSpecificDataUtil.getVideoResolutionFromMpeg4VideoConfig(csd);
formatBuilder.setWidth(resolution.first);
formatBuilder.setHeight(resolution.second);
CodecSpecificDataUtil.getVideoResolutionFromMpeg4VideoConfig(configBuffer);
formatBuilder.setWidth(resolution.first).setHeight(resolution.second);
} else {
// set the default width and height
formatBuilder.setWidth(352).setHeight(288);
}
@Nullable String profileLevel = fmtpAttributes.get(PARAMETER_PROFILE_LEVEL_ID);
formatBuilder.setCodecs(MPEG4_CODECS_PREFIX + (profileLevel == null ? "1" : profileLevel));
Expand Down
Expand Up @@ -88,7 +88,9 @@ public void consume(ParsableByteArray data, long timestamp, int sequenceNumber,
// Parse VOP Type and get the buffer flags
int limit = data.bytesLeft();
trackOutput.sampleData(data, limit);
if (sampleLength == 0) bufferFlags = getBufferFlagsFromVop(data);
if (sampleLength == 0) {
bufferFlags = getBufferFlagsFromVop(data);
}
sampleLength += limit;

// Marker (M) bit: The marker bit is set to 1 to indicate the last RTP
Expand Down Expand Up @@ -122,17 +124,16 @@ public void seek(long nextRtpTimestamp, long timeUs) {
*/
@C.BufferFlags
private static int getBufferFlagsFromVop(ParsableByteArray data) {
int flags = 0;
// search for VOP_START_CODE (00 00 01 B6)
byte[] inputData = data.getData();
byte[] startCode = new byte[] {0x0, 0x0, 0x1, (byte) 0xB6};
int vopStartCodePos = Bytes.indexOf(inputData, startCode);
if (vopStartCodePos != -1) {
data.setPosition(vopStartCodePos + 4);
int vopType = data.peekUnsignedByte() >> 6;
flags = vopType == I_VOP ? C.BUFFER_FLAG_KEY_FRAME : 0;
return (vopType == I_VOP ? C.BUFFER_FLAG_KEY_FRAME : 0);
}
return flags;
return 0;
}

private static long toSampleUs(
Expand Down

0 comments on commit ef9393a

Please sign in to comment.