mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Keep the existing parseSpsNalUnit (and similar) methods to avoid breaking changes
This commit is contained in:
parent
296074fbea
commit
dbc7088716
@ -292,11 +292,24 @@ public final class NalUnitUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a SPS NAL unit payload using the syntax defined in ITU-T Recommendation H.264 (2013)
|
* Parses a SPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection
|
||||||
|
* 7.3.2.1.1.
|
||||||
|
*
|
||||||
|
* @param nalData A buffer containing escaped SPS data.
|
||||||
|
* @param nalOffset The offset of the NAL unit header in {@code nalData}.
|
||||||
|
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
||||||
|
* @return A parsed representation of the SPS data.
|
||||||
|
*/
|
||||||
|
public static SpsData parseSpsNalUnit(byte[] nalData, int nalOffset, int nalLimit) {
|
||||||
|
return parseSpsNalUnitPayload(nalData, nalOffset + 1, nalLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a SPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.264 (2013)
|
||||||
* subsection 7.3.2.1.1.
|
* subsection 7.3.2.1.1.
|
||||||
*
|
*
|
||||||
* @param nalData A buffer containing escaped SPS data.
|
* @param nalData A buffer containing escaped SPS data.
|
||||||
* @param nalOffset The offset of the NAL unit in {@code nalData}.
|
* @param nalOffset The offset of the NAL unit payload in {@code nalData}.
|
||||||
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
||||||
* @return A parsed representation of the SPS data.
|
* @return A parsed representation of the SPS data.
|
||||||
*/
|
*/
|
||||||
@ -426,11 +439,24 @@ public final class NalUnitUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a H.265 SPS NAL unit payload using the syntax defined in ITU-T Recommendation H.265 (2019)
|
* Parses a H.265 SPS NAL unit using the syntax defined in ITU-T Recommendation H.265 (2019)
|
||||||
* subsection 7.3.2.2.1.
|
* subsection 7.3.2.2.1.
|
||||||
*
|
*
|
||||||
* @param nalData A buffer containing escaped SPS data.
|
* @param nalData A buffer containing escaped SPS data.
|
||||||
* @param nalOffset The offset of the NAL unit in {@code nalData}.
|
* @param nalOffset The offset of the NAL unit header in {@code nalData}.
|
||||||
|
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
||||||
|
* @return A parsed representation of the SPS data.
|
||||||
|
*/
|
||||||
|
public static H265SpsData parseH265SpsNalUnit(byte[] nalData, int nalOffset, int nalLimit) {
|
||||||
|
return parseH265SpsNalUnitPayload(nalData, nalOffset + 1, nalLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a H.265 SPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.265 (2019)
|
||||||
|
* subsection 7.3.2.2.1.
|
||||||
|
*
|
||||||
|
* @param nalData A buffer containing escaped SPS data.
|
||||||
|
* @param nalOffset The offset of the NAL unit payload in {@code nalData}.
|
||||||
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
||||||
* @return A parsed representation of the SPS data.
|
* @return A parsed representation of the SPS data.
|
||||||
*/
|
*/
|
||||||
@ -576,11 +602,24 @@ public final class NalUnitUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a PPS NAL unit payload using the syntax defined in ITU-T Recommendation H.264 (2013)
|
* Parses a PPS NAL unit using the syntax defined in ITU-T Recommendation H.264 (2013) subsection
|
||||||
|
* 7.3.2.2.
|
||||||
|
*
|
||||||
|
* @param nalData A buffer containing escaped PPS data.
|
||||||
|
* @param nalOffset The offset of the NAL unit header in {@code nalData}.
|
||||||
|
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
||||||
|
* @return A parsed representation of the PPS data.
|
||||||
|
*/
|
||||||
|
public static PpsData parsePpsNalUnit(byte[] nalData, int nalOffset, int nalLimit) {
|
||||||
|
return parsePpsNalUnitPayload(nalData, nalOffset + 1, nalLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a PPS NAL unit payload (excluding the NAL unit header) using the syntax defined in ITU-T Recommendation H.264 (2013)
|
||||||
* subsection 7.3.2.2.
|
* subsection 7.3.2.2.
|
||||||
*
|
*
|
||||||
* @param nalData A buffer containing escaped PPS data.
|
* @param nalData A buffer containing escaped PPS data.
|
||||||
* @param nalOffset The offset of the NAL unit in {@code nalData}.
|
* @param nalOffset The offset of the NAL unit payload in {@code nalData}.
|
||||||
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
* @param nalLimit The limit of the NAL unit in {@code nalData}.
|
||||||
* @return A parsed representation of the PPS data.
|
* @return A parsed representation of the PPS data.
|
||||||
*/
|
*/
|
||||||
|
@ -33,7 +33,7 @@ public final class NalUnitUtilTest {
|
|||||||
createByteArray(
|
createByteArray(
|
||||||
0x00, 0x00, 0x01, 0x67, 0x4D, 0x40, 0x16, 0xEC, 0xA0, 0x50, 0x17, 0xFC, 0xB8, 0x08, 0x80,
|
0x00, 0x00, 0x01, 0x67, 0x4D, 0x40, 0x16, 0xEC, 0xA0, 0x50, 0x17, 0xFC, 0xB8, 0x08, 0x80,
|
||||||
0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x0F, 0x47, 0x8B, 0x16, 0xCB);
|
0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x0F, 0x47, 0x8B, 0x16, 0xCB);
|
||||||
private static final int SPS_TEST_DATA_OFFSET = 4;
|
private static final int SPS_TEST_DATA_OFFSET = 3;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findNalUnit() {
|
public void findNalUnit() {
|
||||||
@ -121,10 +121,9 @@ public final class NalUnitUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseSpsNalUnitPayload() {
|
public void parseSpsNalUnit() {
|
||||||
NalUnitUtil.SpsData data =
|
NalUnitUtil.SpsData data =
|
||||||
NalUnitUtil.parseSpsNalUnitPayload(
|
NalUnitUtil.parseSpsNalUnit(SPS_TEST_DATA, SPS_TEST_DATA_OFFSET, SPS_TEST_DATA.length);
|
||||||
SPS_TEST_DATA, SPS_TEST_DATA_OFFSET, SPS_TEST_DATA.length);
|
|
||||||
assertThat(data.width).isEqualTo(640);
|
assertThat(data.width).isEqualTo(640);
|
||||||
assertThat(data.height).isEqualTo(360);
|
assertThat(data.height).isEqualTo(360);
|
||||||
assertThat(data.deltaPicOrderAlwaysZeroFlag).isFalse();
|
assertThat(data.deltaPicOrderAlwaysZeroFlag).isFalse();
|
||||||
|
@ -200,8 +200,8 @@ public final class H264Reader implements ElementaryStreamReader {
|
|||||||
List<byte[]> initializationData = new ArrayList<>();
|
List<byte[]> initializationData = new ArrayList<>();
|
||||||
initializationData.add(Arrays.copyOf(sps.nalData, sps.nalLength));
|
initializationData.add(Arrays.copyOf(sps.nalData, sps.nalLength));
|
||||||
initializationData.add(Arrays.copyOf(pps.nalData, pps.nalLength));
|
initializationData.add(Arrays.copyOf(pps.nalData, pps.nalLength));
|
||||||
NalUnitUtil.SpsData spsData = NalUnitUtil.parseSpsNalUnitPayload(sps.nalData, 4, sps.nalLength);
|
NalUnitUtil.SpsData spsData = NalUnitUtil.parseSpsNalUnit(sps.nalData, 3, sps.nalLength);
|
||||||
NalUnitUtil.PpsData ppsData = NalUnitUtil.parsePpsNalUnitPayload(pps.nalData, 4, pps.nalLength);
|
NalUnitUtil.PpsData ppsData = NalUnitUtil.parsePpsNalUnit(pps.nalData, 3, pps.nalLength);
|
||||||
String codecs =
|
String codecs =
|
||||||
CodecSpecificDataUtil.buildAvcCodecString(
|
CodecSpecificDataUtil.buildAvcCodecString(
|
||||||
spsData.profileIdc,
|
spsData.profileIdc,
|
||||||
@ -224,11 +224,11 @@ public final class H264Reader implements ElementaryStreamReader {
|
|||||||
pps.reset();
|
pps.reset();
|
||||||
}
|
}
|
||||||
} else if (sps.isCompleted()) {
|
} else if (sps.isCompleted()) {
|
||||||
NalUnitUtil.SpsData spsData = NalUnitUtil.parseSpsNalUnitPayload(sps.nalData, 4, sps.nalLength);
|
NalUnitUtil.SpsData spsData = NalUnitUtil.parseSpsNalUnit(sps.nalData, 3, sps.nalLength);
|
||||||
sampleReader.putSps(spsData);
|
sampleReader.putSps(spsData);
|
||||||
sps.reset();
|
sps.reset();
|
||||||
} else if (pps.isCompleted()) {
|
} else if (pps.isCompleted()) {
|
||||||
NalUnitUtil.PpsData ppsData = NalUnitUtil.parsePpsNalUnitPayload(pps.nalData, 4, pps.nalLength);
|
NalUnitUtil.PpsData ppsData = NalUnitUtil.parsePpsNalUnit(pps.nalData, 3, pps.nalLength);
|
||||||
sampleReader.putPps(ppsData);
|
sampleReader.putPps(ppsData);
|
||||||
pps.reset();
|
pps.reset();
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,9 @@ public final class AvcConfig {
|
|||||||
@Nullable String codecs = null;
|
@Nullable String codecs = null;
|
||||||
if (numSequenceParameterSets > 0) {
|
if (numSequenceParameterSets > 0) {
|
||||||
byte[] sps = initializationData.get(0);
|
byte[] sps = initializationData.get(0);
|
||||||
SpsData spsData = NalUnitUtil.parseSpsNalUnitPayload(sps,
|
SpsData spsData =
|
||||||
nalUnitLengthFieldLength + 1, sps.length);
|
NalUnitUtil.parseSpsNalUnit(
|
||||||
|
initializationData.get(0), nalUnitLengthFieldLength, sps.length);
|
||||||
width = spsData.width;
|
width = spsData.width;
|
||||||
height = spsData.height;
|
height = spsData.height;
|
||||||
pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
|
pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
|
||||||
|
@ -78,8 +78,8 @@ public final class HevcConfig {
|
|||||||
data.getData(), data.getPosition(), buffer, bufferPosition, nalUnitLength);
|
data.getData(), data.getPosition(), buffer, bufferPosition, nalUnitLength);
|
||||||
if (nalUnitType == SPS_NAL_UNIT_TYPE && j == 0) {
|
if (nalUnitType == SPS_NAL_UNIT_TYPE && j == 0) {
|
||||||
NalUnitUtil.H265SpsData spsData =
|
NalUnitUtil.H265SpsData spsData =
|
||||||
NalUnitUtil.parseH265SpsNalUnitPayload(
|
NalUnitUtil.parseH265SpsNalUnit(
|
||||||
buffer, bufferPosition + 1, bufferPosition + nalUnitLength);
|
buffer, bufferPosition, bufferPosition + nalUnitLength);
|
||||||
width = spsData.picWidthInLumaSamples;
|
width = spsData.picWidthInLumaSamples;
|
||||||
height = spsData.picHeightInLumaSamples;
|
height = spsData.picHeightInLumaSamples;
|
||||||
pixelWidthAspectRatio = spsData.pixelWidthHeightRatio;
|
pixelWidthAspectRatio = spsData.pixelWidthHeightRatio;
|
||||||
|
@ -183,8 +183,8 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
// Process SPS (Sequence Parameter Set).
|
// Process SPS (Sequence Parameter Set).
|
||||||
byte[] spsNalDataWithStartCode = initializationData.get(0);
|
byte[] spsNalDataWithStartCode = initializationData.get(0);
|
||||||
NalUnitUtil.SpsData spsData =
|
NalUnitUtil.SpsData spsData =
|
||||||
NalUnitUtil.parseSpsNalUnitPayload(
|
NalUnitUtil.parseSpsNalUnit(
|
||||||
spsNalDataWithStartCode, NAL_START_CODE.length + 1, spsNalDataWithStartCode.length);
|
spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length);
|
||||||
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthAspectRatio);
|
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthAspectRatio);
|
||||||
formatBuilder.setHeight(spsData.height);
|
formatBuilder.setHeight(spsData.height);
|
||||||
formatBuilder.setWidth(spsData.width);
|
formatBuilder.setWidth(spsData.width);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user