Skip to content

Commit 281a0e7

Browse files
ychaparovcopybara-github
authored andcommitted
Populate HevcConfig with number of temporal layers
The number of temporal sub-layers is required for H.265 non-reference frame identification as only frames from the highest temporal sub-layer can be discarded. PiperOrigin-RevId: 713242894
1 parent b3e1872 commit 281a0e7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libraries/extractor/src/main/java/androidx/media3/extractor/HevcConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private static HevcConfig parseImpl(
9595
// Concatenate the codec-specific data into a single buffer.
9696
data.setPosition(csdStartPosition);
9797
byte[] buffer = new byte[csdLength];
98+
int maxSubLayers = Format.NO_VALUE;
9899
int bufferPosition = 0;
99100
int width = Format.NO_VALUE;
100101
int height = Format.NO_VALUE;
@@ -131,6 +132,7 @@ private static HevcConfig parseImpl(
131132
NalUnitUtil.H265SpsData spsData =
132133
NalUnitUtil.parseH265SpsNalUnit(
133134
buffer, bufferPosition, bufferPosition + nalUnitLength, currentVpsData);
135+
maxSubLayers = spsData.maxSubLayersMinus1 + 1;
134136
width = spsData.width;
135137
height = spsData.height;
136138
bitdepthLuma = spsData.bitDepthLumaMinus8 + 8;
@@ -172,6 +174,7 @@ private static HevcConfig parseImpl(
172174
return new HevcConfig(
173175
initializationData,
174176
lengthSizeMinusOne + 1,
177+
maxSubLayers,
175178
width,
176179
height,
177180
bitdepthLuma,
@@ -200,6 +203,9 @@ private static HevcConfig parseImpl(
200203
/** The length of the NAL unit length field in the bitstream's container, in bytes. */
201204
public final int nalUnitLengthFieldLength;
202205

206+
/** The {@code sps_max_sub_layers_minus1 + 1} value: the number of temporal sub-layers. */
207+
public final int maxSubLayers;
208+
203209
/** The width of each decoded frame, or {@link Format#NO_VALUE} if unknown. */
204210
public final int width;
205211

@@ -258,6 +264,7 @@ private static HevcConfig parseImpl(
258264
private HevcConfig(
259265
List<byte[]> initializationData,
260266
int nalUnitLengthFieldLength,
267+
int maxSubLayers,
261268
int width,
262269
int height,
263270
int bitdepthLuma,
@@ -272,6 +279,7 @@ private HevcConfig(
272279
@Nullable NalUnitUtil.H265VpsData vpsData) {
273280
this.initializationData = initializationData;
274281
this.nalUnitLengthFieldLength = nalUnitLengthFieldLength;
282+
this.maxSubLayers = maxSubLayers;
275283
this.width = width;
276284
this.height = height;
277285
this.bitdepthLuma = bitdepthLuma;

libraries/extractor/src/test/java/androidx/media3/extractor/HevcConfigTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ public void parseHevcDecoderConfigurationRecord() throws Exception {
477477
ParsableByteArray data = new ParsableByteArray(HVCC_BOX_PAYLOAD);
478478
HevcConfig hevcConfig = HevcConfig.parse(data);
479479

480+
assertThat(hevcConfig.maxSubLayers).isEqualTo(1);
480481
assertThat(hevcConfig.codecs).isEqualTo("hvc1.1.6.L153.B0");
481482
assertThat(hevcConfig.nalUnitLengthFieldLength).isEqualTo(4);
482483
}
@@ -487,6 +488,7 @@ public void parseHevcDecoderConfigurationRecord_ignoresReservedBit() throws Exce
487488
ParsableByteArray data = new ParsableByteArray(HVCC_BOX_PAYLOAD_WITH_SET_RESERVED_BIT);
488489
HevcConfig hevcConfig = HevcConfig.parse(data);
489490

491+
assertThat(hevcConfig.maxSubLayers).isEqualTo(1);
490492
assertThat(hevcConfig.codecs).isEqualTo("hvc1.1.6.L153.B0");
491493
assertThat(hevcConfig.nalUnitLengthFieldLength).isEqualTo(4);
492494
}
@@ -496,12 +498,14 @@ public void parseLhevcDecoderConfigurationRecord() throws Exception {
496498
ParsableByteArray hevcData = new ParsableByteArray(HVCC_BOX_PAYLOAD_MV_HEVC);
497499
HevcConfig hevcConfig = HevcConfig.parse(hevcData);
498500

501+
assertThat(hevcConfig.maxSubLayers).isEqualTo(1);
499502
assertThat(hevcConfig.codecs).isEqualTo("hvc1.1.6.L120.B0");
500503
assertThat(hevcConfig.nalUnitLengthFieldLength).isEqualTo(4);
501504

502505
ParsableByteArray lhevcData = new ParsableByteArray(LHVC_BOX_PAYLOAD_MV_HEVC);
503506
HevcConfig lhevcConfig = HevcConfig.parseLayered(lhevcData, hevcConfig.vpsData);
504507

508+
assertThat(lhevcConfig.maxSubLayers).isEqualTo(8);
505509
assertThat(lhevcConfig.codecs).isEqualTo("hvc1.6.40.L120.BF.80");
506510
assertThat(lhevcConfig.nalUnitLengthFieldLength).isEqualTo(4);
507511
}

0 commit comments

Comments
 (0)