Commit 5c571e6e by andrewlewis Committed by Oliver Woodman

Handle H.265/HEVC SEI NAL units in FragmentedMp4Extractor.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=147609330
parent fd6012a7
...@@ -1087,7 +1087,7 @@ public final class FragmentedMp4Extractor implements Extractor { ...@@ -1087,7 +1087,7 @@ public final class FragmentedMp4Extractor implements Extractor {
// Write the NAL unit type byte. // Write the NAL unit type byte.
output.sampleData(nalPrefix, 1); output.sampleData(nalPrefix, 1);
processSeiNalUnitPayload = cea608TrackOutput != null processSeiNalUnitPayload = cea608TrackOutput != null
&& NalUnitUtil.isNalUnitSei(nalPrefixData[4]); && NalUnitUtil.isNalUnitSei(track.format.sampleMimeType, nalPrefixData[4]);
sampleBytesWritten += 5; sampleBytesWritten += 5;
sampleSize += nalUnitLengthFieldLengthDiff; sampleSize += nalUnitLengthFieldLengthDiff;
} else { } else {
...@@ -1100,7 +1100,9 @@ public final class FragmentedMp4Extractor implements Extractor { ...@@ -1100,7 +1100,9 @@ public final class FragmentedMp4Extractor implements Extractor {
writtenBytes = sampleCurrentNalBytesRemaining; writtenBytes = sampleCurrentNalBytesRemaining;
// Unescape and process the SEI NAL unit. // Unescape and process the SEI NAL unit.
int unescapedLength = NalUnitUtil.unescapeStream(nalBuffer.data, nalBuffer.limit()); int unescapedLength = NalUnitUtil.unescapeStream(nalBuffer.data, nalBuffer.limit());
nalBuffer.reset(unescapedLength); // If the format is H.265/HEVC the NAL unit header has two bytes so skip one more byte.
nalBuffer.setPosition(MimeTypes.VIDEO_H265.equals(track.format.sampleMimeType) ? 1 : 0);
nalBuffer.setLimit(unescapedLength);
CeaUtil.consume(fragment.getSamplePresentationTime(sampleIndex) * 1000L, nalBuffer, CeaUtil.consume(fragment.getSamplePresentationTime(sampleIndex) * 1000L, nalBuffer,
cea608TrackOutput); cea608TrackOutput);
} else { } else {
......
...@@ -103,8 +103,9 @@ public final class NalUnitUtil { ...@@ -103,8 +103,9 @@ public final class NalUnitUtil {
2f 2f
}; };
private static final int NAL_UNIT_TYPE_SEI = 6; // Supplemental enhancement information private static final int H264_NAL_UNIT_TYPE_SEI = 6; // Supplemental enhancement information
private static final int NAL_UNIT_TYPE_SPS = 7; // Sequence parameter set private static final int H264_NAL_UNIT_TYPE_SPS = 7; // Sequence parameter set
private static final int H265_NAL_UNIT_TYPE_PREFIX_SEI = 39;
private static final Object scratchEscapePositionsLock = new Object(); private static final Object scratchEscapePositionsLock = new Object();
...@@ -177,7 +178,7 @@ public final class NalUnitUtil { ...@@ -177,7 +178,7 @@ public final class NalUnitUtil {
while (offset + 1 < length) { while (offset + 1 < length) {
int value = data.get(offset) & 0xFF; int value = data.get(offset) & 0xFF;
if (consecutiveZeros == 3) { if (consecutiveZeros == 3) {
if (value == 1 && (data.get(offset + 1) & 0x1F) == NAL_UNIT_TYPE_SPS) { if (value == 1 && (data.get(offset + 1) & 0x1F) == H264_NAL_UNIT_TYPE_SPS) {
// Copy from this NAL unit onwards to the start of the buffer. // Copy from this NAL unit onwards to the start of the buffer.
ByteBuffer offsetData = data.duplicate(); ByteBuffer offsetData = data.duplicate();
offsetData.position(offset - 3); offsetData.position(offset - 3);
...@@ -202,11 +203,15 @@ public final class NalUnitUtil { ...@@ -202,11 +203,15 @@ public final class NalUnitUtil {
* Returns whether the NAL unit with the specified header contains supplemental enhancement * Returns whether the NAL unit with the specified header contains supplemental enhancement
* information. * information.
* *
* @param nalUnitHeader The header of the NAL unit (first byte of nal_unit()). * @param mimeType The sample MIME type.
* @param nalUnitHeaderFirstByte The first byte of nal_unit().
* @return Whether the NAL unit with the specified header is an SEI NAL unit. * @return Whether the NAL unit with the specified header is an SEI NAL unit.
*/ */
public static boolean isNalUnitSei(byte nalUnitHeader) { public static boolean isNalUnitSei(String mimeType, byte nalUnitHeaderFirstByte) {
return (nalUnitHeader & 0x1F) == NAL_UNIT_TYPE_SEI; return (MimeTypes.VIDEO_H264.equals(mimeType)
&& (nalUnitHeaderFirstByte & 0x1F) == H264_NAL_UNIT_TYPE_SEI)
|| (MimeTypes.VIDEO_H265.equals(mimeType)
&& ((nalUnitHeaderFirstByte & 0x7E) >> 1) == H265_NAL_UNIT_TYPE_PREFIX_SEI);
} }
/** /**
......
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