-
Notifications
You must be signed in to change notification settings - Fork 543
RTSP H265 Aggregation packet support #2413
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
base: main
Are you sure you want to change the base?
Changes from all commits
8a3e0b3
92b129e
e43ab65
cacbbdb
af67e05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,8 +102,7 @@ public void consume(ParsableByteArray data, long timestamp, int sequenceNumber, | |
if (payloadType >= 0 && payloadType < RTP_PACKET_TYPE_AP) { | ||
processSingleNalUnitPacket(data); | ||
} else if (payloadType == RTP_PACKET_TYPE_AP) { | ||
// TODO: Support AggregationPacket mode. | ||
throw new UnsupportedOperationException("need to implement processAggregationPacket"); | ||
processAggregationPacket(data); | ||
} else if (payloadType == RTP_PACKET_TYPE_FU) { | ||
processFragmentationUnitPacket(data, sequenceNumber); | ||
} else { | ||
|
@@ -167,6 +166,58 @@ private void processSingleNalUnitPacket(ParsableByteArray data) { | |
bufferFlags = getBufferFlagsFromNalType(nalHeaderType); | ||
} | ||
|
||
/** | ||
* Processes Aggregation packet (RFC7798 Section 4.4.2). | ||
* | ||
* <p>Outputs 2 or more NAL Unit (with start code prepended) to {@link #trackOutput}. Sets {@link | ||
* #bufferFlags} and {@link #fragmentedSampleSizeBytes} accordingly. | ||
*/ | ||
@RequiresNonNull("trackOutput") | ||
private void processAggregationPacket(ParsableByteArray data) throws ParserException { | ||
// The structure of an Aggregation Packet. | ||
// 0 1 2 3 | ||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | PayloadHdr (Type=48) | | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | ||
// | | | ||
// | two or more aggregation units | | ||
// | | | ||
// | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | :...OPTIONAL RTP padding | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
// The structure of aggregation unit | ||
// 0 1 2 3 | ||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// : DONL (conditional) | NALU size | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | NALU size | | | ||
// +-+-+-+-+-+-+-+-+ NAL unit | | ||
// | | | ||
// | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | : | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|
||
// Since sprop-max-don-diff != 0 is not supported, DONL won't present in the packet. | ||
|
||
data.setPosition(2); // skipping payload header (2 bytes) | ||
do { | ||
short nalUnitSize = data.readShort(); // 2 bytes of NAL unit size | ||
int nalHeaderType = (data.getData()[data.getPosition()] >> 1) & 0x3F; | ||
if (data.bytesLeft() < nalUnitSize) { | ||
throw ParserException.createForMalformedManifest( | ||
"Malformed Aggregation Packet. NAL unit size exceeds packet size.", /* cause= */ null); | ||
} | ||
|
||
fragmentedSampleSizeBytes += writeStartCode(); | ||
trackOutput.sampleData(data, nalUnitSize); | ||
fragmentedSampleSizeBytes += nalUnitSize; | ||
bufferFlags = getBufferFlagsFromNalType(nalHeaderType); | ||
} while (data.bytesLeft() > 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also make this a while loop such that while(data.bytesLeft() >= 3) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is correct, however in this case we may miss "invalid" packet with 1-2 bytes "extra" |
||
} | ||
|
||
/** | ||
* Processes Fragmentation Unit packet (RFC7798 Section 4.4.3). | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the data.getData()[data.getPosition()] would be data.peekUnsignedByte().
Or the whole line as NalUnitUtil.getH265NalUnitType(data.getData(), -3).