From 9cb243647f4f83c0ab0c97958def3673f410f231 Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Date: Fri, 28 Jan 2022 11:22:59 +0530 Subject: [PATCH] Clean up RtpH265Reader --- .../media3/exoplayer/rtsp/RtspMediaTrack.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspMediaTrack.java b/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspMediaTrack.java index 8e2d42135f..d7bb6d432a 100644 --- a/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspMediaTrack.java +++ b/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/RtspMediaTrack.java @@ -44,10 +44,10 @@ import com.google.common.collect.ImmutableMap; // Format specific parameter names. 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 H265_SPS = "sprop-sps"; - private static final String H265_PPS = "sprop-pps"; - private static final String H265_VPS = "sprop-vps"; - private static final String H265_MAX_DON_DIFF = "sprop-max-don-diff"; + private static final String PARAMETER_SPROP_H265_SPS = "sprop-sps"; + private static final String PARAMETER_SPROP_H265_PPS = "sprop-pps"; + private static final String PARAMETER_SPROP_H265_VPS = "sprop-vps"; + private static final String PARAMETER_SPROP_H265_MAX_DON_DIFF = "sprop-max-don-diff"; /** Prefix for the RFC6381 codecs string for AAC formats. */ private static final String AAC_CODECS_PREFIX = "mp4a.40."; @@ -221,31 +221,30 @@ import com.google.common.collect.ImmutableMap; private static void processH265FmtpAttribute( Format.Builder formatBuilder, ImmutableMap fmtpAttributes) { - if (fmtpAttributes.containsKey(H265_MAX_DON_DIFF)) { - checkArgument(Integer.parseInt(checkNotNull(fmtpAttributes.get(H265_MAX_DON_DIFF))) == 0); + if (fmtpAttributes.containsKey(PARAMETER_SPROP_H265_MAX_DON_DIFF)) { + 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)); - String spropSPS = checkNotNull(fmtpAttributes.get(H265_SPS)); - checkArgument(fmtpAttributes.containsKey(H265_PPS)); - String spropPPS = checkNotNull(fmtpAttributes.get(H265_PPS)); - checkArgument(fmtpAttributes.containsKey(H265_VPS)); - String spropVPS = checkNotNull(fmtpAttributes.get(H265_VPS)); - String[] parameterSets = new String[] {spropSPS, spropPPS, spropVPS}; + checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_SPS)); + String spropSPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_SPS)); + checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_PPS)); + String spropPPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_PPS)); + checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_VPS)); + String spropVPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_VPS)); - checkArgument(parameterSets.length == 3); - ImmutableList initializationData = - ImmutableList.of( - getInitializationDataFromParameterSet(parameterSets[0]), - getInitializationDataFromParameterSet(parameterSets[1]), - getInitializationDataFromParameterSet(parameterSets[2])); + byte[] vpsNalData = getInitializationDataFromParameterSet(spropVPS); + byte[] spsNalData = getInitializationDataFromParameterSet(spropSPS); + byte[] ppsNalData = getInitializationDataFromParameterSet(spropPPS); + ImmutableList initializationData = ImmutableList.of(vpsNalData, spsNalData, ppsNalData); formatBuilder.setInitializationData(initializationData); // Process SPS (Sequence Parameter Set). - byte[] spsNalDataWithStartCode = initializationData.get(0); NalUnitUtil.H265SpsData spsData = NalUnitUtil.parseH265SpsNalUnit( - spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length); + spsNalData, NAL_START_CODE.length, spsNalData.length); formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio); formatBuilder.setHeight(spsData.height); formatBuilder.setWidth(spsData.width);