[go: nahoru, domu]

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 h263 test and fix #119

Merged
merged 6 commits into from
Aug 8, 2022
Merged
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
Next Next commit
Update H263 Reader to handle missing frames/fragments.
Change-Id: I43dfbabcbe686c31cb54e6b95688af1fa35a3d24
  • Loading branch information
ManishaJajoo committed Jul 13, 2022
commit a38059d1098535a0c558346c5453626011b430e4
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package androidx.media3.exoplayer.rtsp.reader;

import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull;

import androidx.media3.common.C;
Expand Down Expand Up @@ -61,12 +62,22 @@
private boolean isKeyFrame;
private boolean isOutputFormatSet;
private long startTimeOffsetUs;
private long sampleTimeUsOfFragmentedSample;
/**
* Whether the first packet of a H263 frame is received, it mark the start of a H263 partition. A
* H263 frame can be split into multiple RTP packets.
*/
private boolean gotFirstPacketOfH263Frame;

/** Creates an instance. */
public RtpH263Reader(RtpPayloadFormat payloadFormat) {
this.payloadFormat = payloadFormat;
firstReceivedTimestamp = C.TIME_UNSET;
previousSequenceNumber = C.INDEX_UNSET;
isKeyFrame = false;
fragmentedSampleSizeBytes = 0;
sampleTimeUsOfFragmentedSample = C.TIME_UNSET;
gotFirstPacketOfH263Frame = false;
}

@Override
Expand All @@ -76,7 +87,10 @@ public void createTracks(ExtractorOutput extractorOutput, int trackId) {
}

@Override
public void onReceivingFirstPacket(long timestamp, int sequenceNumber) {}
public void onReceivingFirstPacket(long timestamp, int sequenceNumber) {
checkState(firstReceivedTimestamp == C.TIME_UNSET);
firstReceivedTimestamp = timestamp;
}

@Override
public void consume(
Expand All @@ -103,6 +117,12 @@ public void consume(
}

if (pBitIsSet) {
if (gotFirstPacketOfH263Frame && fragmentedSampleSizeBytes > 0) {
// Received new H263 fragment, output data of previous fragment to decoder.
outputSampleMetadataForFragmentedPackets();
}
gotFirstPacketOfH263Frame = true;

int payloadStartCode = data.peekUnsignedByte() & 0xFC;
// Packets that begin with a Picture Start Code(100000). Refer RFC4629 Section 6.1.
if (payloadStartCode < PICTURE_START_CODE) {
Expand All @@ -113,10 +133,10 @@ public void consume(
data.getData()[currentPosition] = 0;
data.getData()[currentPosition + 1] = 0;
data.setPosition(currentPosition);
} else {
} else if (gotFirstPacketOfH263Frame) {
// Check that this packet is in the sequence of the previous packet.
int expectedSequenceNumber = RtpPacket.getNextSequenceNumber(previousSequenceNumber);
if (sequenceNumber != expectedSequenceNumber) {
if (sequenceNumber < expectedSequenceNumber) {
Log.w(
TAG,
Util.formatInvariant(
Expand All @@ -125,6 +145,12 @@ public void consume(
expectedSequenceNumber, sequenceNumber));
return;
}
} else {
Log.w(
TAG,
"First payload octet of the H263 packet is not the beginning of a new H263 partition,"
+ " Dropping current packet.");
return;
}

if (fragmentedSampleSizeBytes == 0) {
Expand All @@ -141,20 +167,11 @@ public void consume(
// Write the video sample.
trackOutput.sampleData(data, fragmentSize);
fragmentedSampleSizeBytes += fragmentSize;
sampleTimeUsOfFragmentedSample =
toSampleUs(startTimeOffsetUs, timestamp, firstReceivedTimestamp);

if (rtpMarker) {
if (firstReceivedTimestamp == C.TIME_UNSET) {
firstReceivedTimestamp = timestamp;
}
long timeUs = toSampleUs(startTimeOffsetUs, timestamp, firstReceivedTimestamp);
trackOutput.sampleMetadata(
timeUs,
isKeyFrame ? C.BUFFER_FLAG_KEY_FRAME : 0,
fragmentedSampleSizeBytes,
/* offset= */ 0,
/* cryptoData= */ null);
fragmentedSampleSizeBytes = 0;
isKeyFrame = false;
outputSampleMetadataForFragmentedPackets();
}
previousSequenceNumber = sequenceNumber;
}
Expand Down Expand Up @@ -211,6 +228,24 @@ private void parseVopHeader(ParsableByteArray data, boolean gotResolution) {
isKeyFrame = false;
}

/**
* Outputs sample metadata.
*
* <p>Call this method only when receiving a end of VP8 partition
*/
private void outputSampleMetadataForFragmentedPackets() {
trackOutput.sampleMetadata(
sampleTimeUsOfFragmentedSample,
isKeyFrame ? C.BUFFER_FLAG_KEY_FRAME : 0,
fragmentedSampleSizeBytes,
/* offset= */ 0,
/* cryptoData= */ null);
fragmentedSampleSizeBytes = 0;
sampleTimeUsOfFragmentedSample = C.TIME_UNSET;
isKeyFrame = false;
gotFirstPacketOfH263Frame = false;
}

private static long toSampleUs(
long startTimeOffsetUs, long rtpTimestamp, long firstReceivedRtpTimestamp) {
return startTimeOffsetUs
Expand Down