Clean up RtpH265Reader

This commit is contained in:
Rakesh Kumar 2022-01-28 11:22:59 +05:30
parent 4b99db938a
commit 9cb243647f

View File

@ -44,10 +44,10 @@ import com.google.common.collect.ImmutableMap;
// Format specific parameter names. // Format specific parameter names.
private static final String PARAMETER_PROFILE_LEVEL_ID = "profile-level-id"; private static final String PARAMETER_PROFILE_LEVEL_ID = "profile-level-id";
private static final String PARAMETER_SPROP_PARAMS = "sprop-parameter-sets"; private static final String PARAMETER_SPROP_PARAMS = "sprop-parameter-sets";
private static final String H265_SPS = "sprop-sps"; private static final String PARAMETER_SPROP_H265_SPS = "sprop-sps";
private static final String H265_PPS = "sprop-pps"; private static final String PARAMETER_SPROP_H265_PPS = "sprop-pps";
private static final String H265_VPS = "sprop-vps"; private static final String PARAMETER_SPROP_H265_VPS = "sprop-vps";
private static final String H265_MAX_DON_DIFF = "sprop-max-don-diff"; private static final String PARAMETER_SPROP_H265_MAX_DON_DIFF = "sprop-max-don-diff";
/** Prefix for the RFC6381 codecs string for AAC formats. */ /** Prefix for the RFC6381 codecs string for AAC formats. */
private static final String AAC_CODECS_PREFIX = "mp4a.40."; private static final String AAC_CODECS_PREFIX = "mp4a.40.";
@ -221,31 +221,30 @@ import com.google.common.collect.ImmutableMap;
private static void processH265FmtpAttribute( private static void processH265FmtpAttribute(
Format.Builder formatBuilder, ImmutableMap<String, String> fmtpAttributes) { Format.Builder formatBuilder, ImmutableMap<String, String> fmtpAttributes) {
if (fmtpAttributes.containsKey(H265_MAX_DON_DIFF)) { if (fmtpAttributes.containsKey(PARAMETER_SPROP_H265_MAX_DON_DIFF)) {
checkArgument(Integer.parseInt(checkNotNull(fmtpAttributes.get(H265_MAX_DON_DIFF))) == 0); checkArgument(
Integer.parseInt(checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_MAX_DON_DIFF)))
== 0,
"non-zero sprop-max-don-diff is not supported");
} }
checkArgument(fmtpAttributes.containsKey(H265_SPS)); checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_SPS));
String spropSPS = checkNotNull(fmtpAttributes.get(H265_SPS)); String spropSPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_SPS));
checkArgument(fmtpAttributes.containsKey(H265_PPS)); checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_PPS));
String spropPPS = checkNotNull(fmtpAttributes.get(H265_PPS)); String spropPPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_PPS));
checkArgument(fmtpAttributes.containsKey(H265_VPS)); checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_VPS));
String spropVPS = checkNotNull(fmtpAttributes.get(H265_VPS)); String spropVPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_VPS));
String[] parameterSets = new String[] {spropSPS, spropPPS, spropVPS};
checkArgument(parameterSets.length == 3); byte[] vpsNalData = getInitializationDataFromParameterSet(spropVPS);
ImmutableList<byte[]> initializationData = byte[] spsNalData = getInitializationDataFromParameterSet(spropSPS);
ImmutableList.of( byte[] ppsNalData = getInitializationDataFromParameterSet(spropPPS);
getInitializationDataFromParameterSet(parameterSets[0]), ImmutableList<byte[]> initializationData = ImmutableList.of(vpsNalData, spsNalData, ppsNalData);
getInitializationDataFromParameterSet(parameterSets[1]),
getInitializationDataFromParameterSet(parameterSets[2]));
formatBuilder.setInitializationData(initializationData); formatBuilder.setInitializationData(initializationData);
// Process SPS (Sequence Parameter Set). // Process SPS (Sequence Parameter Set).
byte[] spsNalDataWithStartCode = initializationData.get(0);
NalUnitUtil.H265SpsData spsData = NalUnitUtil.H265SpsData spsData =
NalUnitUtil.parseH265SpsNalUnit( NalUnitUtil.parseH265SpsNalUnit(
spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length); spsNalData, NAL_START_CODE.length, spsNalData.length);
formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio); formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio);
formatBuilder.setHeight(spsData.height); formatBuilder.setHeight(spsData.height);
formatBuilder.setWidth(spsData.width); formatBuilder.setWidth(spsData.width);