Skip to content

Commit

Permalink
Some minor cleanup in RTPMpeg4Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ManishaJajoo committed Feb 9, 2022
1 parent 743437e commit dfef2d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Expand Up @@ -45,7 +45,7 @@
// Format specific parameter names.
private static final String PARAMETER_PROFILE_LEVEL_ID = "profile-level-id";
private static final String PARAMETER_SPROP_PARAMS = "sprop-parameter-sets";
private static final String PARAMETER_CONFIG = "config";
private static final String PARAMETER_MP4V_CONFIG = "config";

/** Prefix for the RFC6381 codecs string for AAC formats. */
private static final String AAC_CODECS_PREFIX = "mp4a.40.";
Expand Down Expand Up @@ -171,7 +171,7 @@ private static void processAacFmtpAttribute(

private static void processMPEG4FmtpAttribute(
Format.Builder formatBuilder, ImmutableMap<String, String> fmtpAttributes) {
@Nullable String configInput = fmtpAttributes.get(PARAMETER_CONFIG);
@Nullable String configInput = fmtpAttributes.get(PARAMETER_MP4V_CONFIG);
if (configInput != null) {
byte[] csd = Util.getBytesFromHexString(configInput);
ImmutableList<byte[]> initializationData = ImmutableList.of(csd);
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;

/**
* Parses an H265 byte stream carried on RTP packets, and extracts H265 Access Units. Refer to
* Parses an MPEG4 byte stream carried on RTP packets, and extracts MPEG4 Access Units. Refer to
* RFC6416 for more details.
*/
/* package */ final class RtpMPEG4Reader implements RtpPayloadReader {
Expand All @@ -44,16 +44,11 @@
private static final int I_VOP = 0;

private final RtpPayloadFormat payloadFormat;

private @MonotonicNonNull TrackOutput trackOutput;
@C.BufferFlags private int bufferFlags;

private long firstReceivedTimestamp;

private int previousSequenceNumber;

private long startTimeOffsetUs;

private int sampleLength;

/** Creates an instance. */
Expand All @@ -64,15 +59,6 @@ public RtpMPEG4Reader(RtpPayloadFormat payloadFormat) {
sampleLength = 0;
}

private static long toSampleUs(
long startTimeOffsetUs, long rtpTimestamp, long firstReceivedRtpTimestamp) {
return startTimeOffsetUs
+ Util.scaleLargeTimestamp(
(rtpTimestamp - firstReceivedRtpTimestamp),
/* multiplier= */ C.MICROS_PER_SECOND,
/* divisor= */ MEDIA_CLOCK_FREQUENCY);
}

@Override
public void createTracks(ExtractorOutput extractorOutput, int trackId) {
trackOutput = extractorOutput.track(trackId, C.TRACK_TYPE_VIDEO);
Expand Down Expand Up @@ -113,6 +99,15 @@ public void consume(ParsableByteArray data, long timestamp, int sequenceNumber,
previousSequenceNumber = sequenceNumber;
}

@Override
public void seek(long nextRtpTimestamp, long timeUs) {
firstReceivedTimestamp = nextRtpTimestamp;
startTimeOffsetUs = timeUs;
sampleLength = 0;
}

// Internal methods.

/**
* Parses VOP Coding type
*
Expand All @@ -130,15 +125,17 @@ private void parseVopType(ParsableByteArray data) {
}
}

private static long toSampleUs(
long startTimeOffsetUs, long rtpTimestamp, long firstReceivedRtpTimestamp) {
return startTimeOffsetUs
+ Util.scaleLargeTimestamp(
(rtpTimestamp - firstReceivedRtpTimestamp),
/* multiplier= */ C.MICROS_PER_SECOND,
/* divisor= */ MEDIA_CLOCK_FREQUENCY);
}

@C.BufferFlags
private static int getBufferFlagsFromVopType(int vopType) {
return vopType == I_VOP ? C.BUFFER_FLAG_KEY_FRAME : 0;
}

@Override
public void seek(long nextRtpTimestamp, long timeUs) {
firstReceivedTimestamp = nextRtpTimestamp;
startTimeOffsetUs = timeUs;
sampleLength = 0;
}
}

0 comments on commit dfef2d1

Please sign in to comment.