From ca1c1c26d5e8828e2bcc726525c66c961928ecc0 Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Date: Tue, 15 Feb 2022 22:32:06 +0530 Subject: [PATCH] Fix some minor review comments in RtpH265Reader --- .../media3/exoplayer/rtsp/RtspMediaTrack.java | 27 +++++++++---------- .../exoplayer/rtsp/reader/RtpH265Reader.java | 20 +++++--------- 2 files changed, 20 insertions(+), 27 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 afa3327efb..5ca99fdeda 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 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"; + private static final String PARAMETER_H265_SPROP_SPS = "sprop-sps"; + private static final String PARAMETER_H265_SPROP_PPS = "sprop-pps"; + private static final String PARAMETER_H265_SPROP_VPS = "sprop-vps"; + private static final String PARAMETER_H265_SPROP_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."; @@ -222,19 +222,19 @@ import com.google.common.collect.ImmutableMap; private static void processH265FmtpAttribute( Format.Builder formatBuilder, ImmutableMap fmtpAttributes) { - if (fmtpAttributes.containsKey(PARAMETER_SPROP_H265_MAX_DON_DIFF)) { + if (fmtpAttributes.containsKey(PARAMETER_H265_SPROP_MAX_DON_DIFF)) { checkArgument( - Integer.parseInt(checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_MAX_DON_DIFF))) + Integer.parseInt(checkNotNull(fmtpAttributes.get(PARAMETER_H265_SPROP_MAX_DON_DIFF))) == 0, "non-zero sprop-max-don-diff is not supported"); } - checkArgument(fmtpAttributes.containsKey(PARAMETER_SPROP_H265_VPS)); - String spropVPS = checkNotNull(fmtpAttributes.get(PARAMETER_SPROP_H265_VPS)); - 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_H265_SPROP_VPS)); + String spropVPS = checkNotNull(fmtpAttributes.get(PARAMETER_H265_SPROP_VPS)); + checkArgument(fmtpAttributes.containsKey(PARAMETER_H265_SPROP_SPS)); + String spropSPS = checkNotNull(fmtpAttributes.get(PARAMETER_H265_SPROP_SPS)); + checkArgument(fmtpAttributes.containsKey(PARAMETER_H265_SPROP_PPS)); + String spropPPS = checkNotNull(fmtpAttributes.get(PARAMETER_H265_SPROP_PPS)); ImmutableList initializationData = ImmutableList.of( getInitializationDataFromParameterSet(spropVPS), @@ -248,8 +248,7 @@ import com.google.common.collect.ImmutableMap; NalUnitUtil.parseH265SpsNalUnit( spsNalDataWithStartCode, NAL_START_CODE.length, spsNalDataWithStartCode.length); formatBuilder.setPixelWidthHeightRatio(spsData.pixelWidthHeightRatio); - formatBuilder.setHeight(spsData.height); - formatBuilder.setWidth(spsData.width); + formatBuilder.setHeight(spsData.height).setWidth(spsData.width); formatBuilder.setCodecs( CodecSpecificDataUtil.buildHevcCodecString( diff --git a/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/reader/RtpH265Reader.java b/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/reader/RtpH265Reader.java index 28d5c7a33a..f8159dc529 100644 --- a/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/reader/RtpH265Reader.java +++ b/libraries/exoplayer_rtsp/src/main/java/androidx/media3/exoplayer/rtsp/reader/RtpH265Reader.java @@ -68,10 +68,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; /** Scratch for Fragmentation Unit RTP packets. */ private final ParsableByteArray fuScratchBuffer; - - private final ParsableByteArray nalStartCodeArray = - new ParsableByteArray(NalUnitUtil.NAL_START_CODE); - + private final ParsableByteArray nalStartCodeArray; private final RtpPayloadFormat payloadFormat; private @MonotonicNonNull TrackOutput trackOutput; @@ -84,8 +81,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; /** Creates an instance. */ public RtpH265Reader(RtpPayloadFormat payloadFormat) { - this.payloadFormat = payloadFormat; fuScratchBuffer = new ParsableByteArray(); + nalStartCodeArray = new ParsableByteArray(NalUnitUtil.NAL_START_CODE); + this.payloadFormat = payloadFormat; firstReceivedTimestamp = C.TIME_UNSET; previousSequenceNumber = C.INDEX_UNSET; } @@ -235,11 +233,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; (data.getData()[1] & 0x7); // last 3 bits in byte 1 of payload header, RFC7798 Section 1.1.4 int fuHeader = data.getData()[2]; int nalUnitType = fuHeader & 0x3F; - byte nalHeader[] = new byte[2]; - nalHeader[0] = (byte) (nalUnitType << 1); // RFC7798 Section 1.1.4 - // layerId must be zero according to RFC7798 Section 1.1.4, so copying the tid only - nalHeader[1] = (byte) tid; boolean isFirstFuPacket = (fuHeader & 0x80) > 0; boolean isLastFuPacket = (fuHeader & 0x40) > 0; @@ -249,12 +243,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; // Overwrite a few bytes in Rtp buffer to get HEVC NAL Unit // Rtp Byte 0 -> Ignore - // Rtp Byte 1 -> Byte 0 of HEVC NAL Header - // Rtp Byte 2 -> Byte 1 of HEVC NAL Header + // Rtp Byte 1 -> nal_unit_type, RFC7798 Section 1.1.4 + // Rtp Byte 2 -> layerId required to be zero so copying only tid, RFC7798 Section 1.1.4 // Rtp Payload -> HEVC NAL bytes, so leave them unchanged // Set data position from byte 1 as byte 0 was ignored - data.getData()[1] = (byte) nalHeader[0]; - data.getData()[2] = (byte) nalHeader[1]; + data.getData()[1] = (byte) (nalUnitType << 1); + data.getData()[2] = (byte) tid; fuScratchBuffer.reset(data.getData()); fuScratchBuffer.setPosition(1); } else {