Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rtp mpeg4 #35

Merged
merged 6 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some minor cleanup in RTPMpeg4Reader
  • Loading branch information
ManishaJajoo committed Feb 9, 2022
commit dfef2d13872d7950f54a805a1a18ad83e6c510dd
Original file line number Diff line number Diff line change
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);
ManishaJajoo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
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
ManishaJajoo marked this conversation as resolved.
Show resolved Hide resolved
*
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;
ManishaJajoo marked this conversation as resolved.
Show resolved Hide resolved
}

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