Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AUD in hevc ts when available #7115

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class H265Reader implements ElementaryStreamReader {
private static final int VPS_NUT = 32;
private static final int SPS_NUT = 33;
private static final int PPS_NUT = 34;
private static final int AUD_NUT = 35;
private static final int PREFIX_SEI_NUT = 39;
private static final int SUFFIX_SEI_NUT = 40;

Expand Down Expand Up @@ -434,7 +435,7 @@ private static final class SampleReader {
private boolean lookingForFirstSliceFlag;
private boolean isFirstSlice;
private boolean isFirstParameterSet;

private boolean AUD_Detected;
// Per sample state that gets reset at the start of each sample.
private boolean readingSample;
private boolean writingParameterSets;
Expand All @@ -452,31 +453,65 @@ public void reset() {
isFirstParameterSet = false;
readingSample = false;
writingParameterSets = false;
AUD_Detected = false;
}

public void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
isFirstSlice = false;
isFirstParameterSet = false;
nalUnitTimeUs = pesTimeUs;
nalUnitBytesRead = 0;
nalUnitStartPosition = position;

if (nalUnitType >= VPS_NUT) {
if (!writingParameterSets && readingSample) {
// This is a non-VCL NAL unit, so flush the previous sample.
if (nalUnitType == AUD_NUT) {
//
// AUD based operation, if the stream has AUD's look for these and
// create the sample based on the AUD positions
//

// check if an AUD was detected before, if so flush it to the output
if (AUD_Detected) {
samplePosition = nalUnitStartPosition;
sampleTimeUs = nalUnitTimeUs;
nalUnitStartPosition = position;
nalUnitTimeUs = pesTimeUs;
outputSample(offset);
readingSample = false;
}
if (nalUnitType <= PPS_NUT) {
// This sample will have parameter sets at the start.
isFirstParameterSet = !writingParameterSets;
writingParameterSets = true;
} else {
nalUnitStartPosition = position;
nalUnitTimeUs = pesTimeUs;
}

nalUnitBytesRead = 0;

// disable none AUD logic in the other method Read/End methods
lookingForFirstSliceFlag = false;
isFirstSlice = false;
isFirstParameterSet = false;
readingSample = false;
writingParameterSets = false;

AUD_Detected = true;
}

// Look for the flag if this NAL unit contains a slice_segment_layer_rbsp.
nalUnitHasKeyframeData = (nalUnitType >= BLA_W_LP && nalUnitType <= CRA_NUT);
lookingForFirstSliceFlag = nalUnitHasKeyframeData || nalUnitType <= RASL_R;
// fall back to alternate approach in case stream has no AUD
if (!AUD_Detected) {
isFirstSlice = false;
isFirstParameterSet = false;
nalUnitTimeUs = pesTimeUs;
nalUnitBytesRead = 0;
nalUnitStartPosition = position;

if (nalUnitType >= VPS_NUT) {
if (!writingParameterSets && readingSample) {
// This is a non-VCL NAL unit, so flush the previous sample.
outputSample(offset);
readingSample = false;
}
if (nalUnitType <= PPS_NUT) {
// This sample will have parameter sets at the start.
isFirstParameterSet = !writingParameterSets;
writingParameterSets = true;
}
}

// Look for the flag if this NAL unit contains a slice_segment_layer_rbsp.
nalUnitHasKeyframeData = (nalUnitType >= BLA_W_LP && nalUnitType <= CRA_NUT);
lookingForFirstSliceFlag = nalUnitHasKeyframeData || nalUnitType <= RASL_R;
}
}

public void readNalUnitData(byte[] data, int offset, int limit) {
Expand Down