mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix H265Reader
Update H265Reader to output the same samples after a seek to 0. PiperOrigin-RevId: 306675050
This commit is contained in:
parent
48081dd073
commit
f2d2d56109
1 changed files with 13 additions and 13 deletions
|
|
@ -161,9 +161,8 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
private void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
||||||
if (hasOutputFormat) {
|
sampleReader.startNalUnit(position, offset, nalUnitType, pesTimeUs, hasOutputFormat);
|
||||||
sampleReader.startNalUnit(position, offset, nalUnitType, pesTimeUs);
|
if (!hasOutputFormat) {
|
||||||
} else {
|
|
||||||
vps.startNalUnit(nalUnitType);
|
vps.startNalUnit(nalUnitType);
|
||||||
sps.startNalUnit(nalUnitType);
|
sps.startNalUnit(nalUnitType);
|
||||||
pps.startNalUnit(nalUnitType);
|
pps.startNalUnit(nalUnitType);
|
||||||
|
|
@ -173,9 +172,8 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nalUnitData(byte[] dataArray, int offset, int limit) {
|
private void nalUnitData(byte[] dataArray, int offset, int limit) {
|
||||||
if (hasOutputFormat) {
|
sampleReader.readNalUnitData(dataArray, offset, limit);
|
||||||
sampleReader.readNalUnitData(dataArray, offset, limit);
|
if (!hasOutputFormat) {
|
||||||
} else {
|
|
||||||
vps.appendToNalUnit(dataArray, offset, limit);
|
vps.appendToNalUnit(dataArray, offset, limit);
|
||||||
sps.appendToNalUnit(dataArray, offset, limit);
|
sps.appendToNalUnit(dataArray, offset, limit);
|
||||||
pps.appendToNalUnit(dataArray, offset, limit);
|
pps.appendToNalUnit(dataArray, offset, limit);
|
||||||
|
|
@ -185,9 +183,8 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endNalUnit(long position, int offset, int discardPadding, long pesTimeUs) {
|
private void endNalUnit(long position, int offset, int discardPadding, long pesTimeUs) {
|
||||||
if (hasOutputFormat) {
|
sampleReader.endNalUnit(position, offset, hasOutputFormat);
|
||||||
sampleReader.endNalUnit(position, offset);
|
if (!hasOutputFormat) {
|
||||||
} else {
|
|
||||||
vps.endNalUnit(discardPadding);
|
vps.endNalUnit(discardPadding);
|
||||||
sps.endNalUnit(discardPadding);
|
sps.endNalUnit(discardPadding);
|
||||||
pps.endNalUnit(discardPadding);
|
pps.endNalUnit(discardPadding);
|
||||||
|
|
@ -427,7 +424,8 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||||
writingParameterSets = false;
|
writingParameterSets = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
public void startNalUnit(
|
||||||
|
long position, int offset, int nalUnitType, long pesTimeUs, boolean hasOutputFormat) {
|
||||||
isFirstSlice = false;
|
isFirstSlice = false;
|
||||||
isFirstParameterSet = false;
|
isFirstParameterSet = false;
|
||||||
nalUnitTimeUs = pesTimeUs;
|
nalUnitTimeUs = pesTimeUs;
|
||||||
|
|
@ -437,7 +435,9 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||||
if (nalUnitType >= VPS_NUT) {
|
if (nalUnitType >= VPS_NUT) {
|
||||||
if (!writingParameterSets && readingSample) {
|
if (!writingParameterSets && readingSample) {
|
||||||
// This is a non-VCL NAL unit, so flush the previous sample.
|
// This is a non-VCL NAL unit, so flush the previous sample.
|
||||||
outputSample(offset);
|
if (hasOutputFormat) {
|
||||||
|
outputSample(offset);
|
||||||
|
}
|
||||||
readingSample = false;
|
readingSample = false;
|
||||||
}
|
}
|
||||||
if (nalUnitType <= PPS_NUT) {
|
if (nalUnitType <= PPS_NUT) {
|
||||||
|
|
@ -464,14 +464,14 @@ public final class H265Reader implements ElementaryStreamReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endNalUnit(long position, int offset) {
|
public void endNalUnit(long position, int offset, boolean hasOutputFormat) {
|
||||||
if (writingParameterSets && isFirstSlice) {
|
if (writingParameterSets && isFirstSlice) {
|
||||||
// This sample has parameter sets. Reset the key-frame flag based on the first slice.
|
// This sample has parameter sets. Reset the key-frame flag based on the first slice.
|
||||||
sampleIsKeyframe = nalUnitHasKeyframeData;
|
sampleIsKeyframe = nalUnitHasKeyframeData;
|
||||||
writingParameterSets = false;
|
writingParameterSets = false;
|
||||||
} else if (isFirstParameterSet || isFirstSlice) {
|
} else if (isFirstParameterSet || isFirstSlice) {
|
||||||
// This NAL unit is at the start of a new sample (access unit).
|
// This NAL unit is at the start of a new sample (access unit).
|
||||||
if (readingSample) {
|
if (hasOutputFormat && readingSample) {
|
||||||
// Output the sample ending before this NAL unit.
|
// Output the sample ending before this NAL unit.
|
||||||
int nalUnitLength = (int) (position - nalUnitStartPosition);
|
int nalUnitLength = (int) (position - nalUnitStartPosition);
|
||||||
outputSample(offset + nalUnitLength);
|
outputSample(offset + nalUnitLength);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue