Commit c53495e7 by Andrew Lewis Committed by Oliver Woodman

Check all descriptors for a registration_descriptor.

Issue: #898
parent b64986ce
...@@ -277,38 +277,26 @@ public final class TsExtractor implements Extractor { ...@@ -277,38 +277,26 @@ public final class TsExtractor implements Extractor {
id3Reader = new Id3Reader(output.track(TS_STREAM_TYPE_ID3)); id3Reader = new Id3Reader(output.track(TS_STREAM_TYPE_ID3));
} }
int entriesSize = sectionLength - 9 /* Size of the rest of the fields before descriptors */ int remainingEntriesLength = sectionLength - 9 /* Length of fields before descriptors */
- programInfoLength - 4 /* CRC size */; - programInfoLength - 4 /* CRC length */;
while (entriesSize > 0) { while (remainingEntriesLength > 0) {
data.readBytes(pmtScratch, 5); data.readBytes(pmtScratch, 5);
int streamType = pmtScratch.readBits(8); int streamType = pmtScratch.readBits(8);
pmtScratch.skipBits(3); // reserved pmtScratch.skipBits(3); // reserved
int elementaryPid = pmtScratch.readBits(13); int elementaryPid = pmtScratch.readBits(13);
pmtScratch.skipBits(4); // reserved pmtScratch.skipBits(4); // reserved
int esInfoLength = pmtScratch.readBits(12); int esInfoLength = pmtScratch.readBits(12); // ES_info_length
int descriptorPosition = data.getPosition();
if (streamType == 0x06) { if (streamType == 0x06) {
int descriptorTag = data.readUnsignedByte(); // Read descriptors in PES packets containing private data.
if (descriptorTag == 0x05) { // registration_descriptor streamType = readPrivateDataStreamType(data, esInfoLength);
data.skipBytes(1); // descriptor_length } else {
long formatIdentifier = data.readUnsignedInt(); data.skipBytes(esInfoLength);
if (formatIdentifier == AC3_FORMAT_IDENTIFIER) {
streamType = TS_STREAM_TYPE_ATSC_AC3;
} else if (formatIdentifier == HEVC_FORMAT_IDENTIFIER) {
streamType = TS_STREAM_TYPE_H265;
}
// Ignore additional_identification_info.
}
} }
data.setPosition(descriptorPosition + esInfoLength); remainingEntriesLength -= esInfoLength + 5;
entriesSize -= esInfoLength + 5;
if (streamTypes.get(streamType)) { if (streamTypes.get(streamType)) {
continue; continue;
} }
// TODO: Detect and read DVB AC-3 streams with Ac3Reader.
ElementaryStreamReader pesPayloadReader = null; ElementaryStreamReader pesPayloadReader = null;
switch (streamType) { switch (streamType) {
case TS_STREAM_TYPE_MPA: case TS_STREAM_TYPE_MPA:
...@@ -346,6 +334,36 @@ public final class TsExtractor implements Extractor { ...@@ -346,6 +334,36 @@ public final class TsExtractor implements Extractor {
output.endTracks(); output.endTracks();
} }
/**
* Returns the stream type read from a registration descriptor in private data, or -1 if no
* stream type is present. Sets {@code data}'s position to the end of the descriptors.
*
* @param data A buffer with its position set to the start of the first descriptor.
* @param length The length of descriptors to read from the current position in {@code data}.
* @return The stream type read from a registration descriptor in private data, or -1 if no
* stream type is present.
*/
private int readPrivateDataStreamType(ParsableByteArray data, int length) {
int streamType = -1;
int descriptorsEndPosition = data.getPosition() + length;
while (data.getPosition() < descriptorsEndPosition) {
int descriptorTag = data.readUnsignedByte();
int descriptorLength = data.readUnsignedByte();
if (descriptorTag == 0x05) { // registration_descriptor
long formatIdentifier = data.readUnsignedInt();
if (formatIdentifier == AC3_FORMAT_IDENTIFIER) {
streamType = TS_STREAM_TYPE_ATSC_AC3;
} else if (formatIdentifier == HEVC_FORMAT_IDENTIFIER) {
streamType = TS_STREAM_TYPE_H265;
}
break;
}
data.skipBytes(descriptorLength);
}
data.setPosition(descriptorsEndPosition);
return streamType;
}
} }
/** /**
......
...@@ -31,7 +31,7 @@ public final class Ac3Util { ...@@ -31,7 +31,7 @@ public final class Ac3Util {
224, 256, 320, 384, 448, 512, 576, 640}; 224, 256, 320, 384, 448, 512, 576, 640};
/** 16-bit words per sync frame, indexed by frmsizecod / 2. (See ETSI TS 102 366 table 4.13.) */ /** 16-bit words per sync frame, indexed by frmsizecod / 2. (See ETSI TS 102 366 table 4.13.) */
private static final int[] FRMSIZECOD_TO_FRAME_SIZE_44_1 = new int[] {69, 87, 104, 121, 139, 174, private static final int[] FRMSIZECOD_TO_FRAME_SIZE_44_1 = new int[] {69, 87, 104, 121, 139, 174,
208, 243, 278, 348, 417, 487, 557, 696, 835, 975, 1114, 1253, 1393}; 208, 243, 278, 348, 417, 487, 557, 696, 835, 975, 1114, 1253, 1393};
/** /**
* Returns the AC-3 format given {@code data} containing the AC3SpecificBox according to * Returns the AC-3 format given {@code data} containing the AC3SpecificBox according to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment