Send H.265 parameter sets in TSs to the decoder.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=122730598
This commit is contained in:
parent
7d9541848e
commit
fb3fdb34c7
@ -150,14 +150,15 @@ import java.util.Collections;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
private void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
||||||
if (!hasOutputFormat) {
|
if (hasOutputFormat) {
|
||||||
|
sampleReader.startNalUnit(position, offset, nalUnitType, pesTimeUs);
|
||||||
|
} else {
|
||||||
vps.startNalUnit(nalUnitType);
|
vps.startNalUnit(nalUnitType);
|
||||||
sps.startNalUnit(nalUnitType);
|
sps.startNalUnit(nalUnitType);
|
||||||
pps.startNalUnit(nalUnitType);
|
pps.startNalUnit(nalUnitType);
|
||||||
}
|
}
|
||||||
prefixSei.startNalUnit(nalUnitType);
|
prefixSei.startNalUnit(nalUnitType);
|
||||||
suffixSei.startNalUnit(nalUnitType);
|
suffixSei.startNalUnit(nalUnitType);
|
||||||
sampleReader.startNalUnit(position, offset, nalUnitType, pesTimeUs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nalUnitData(byte[] dataArray, int offset, int limit) {
|
private void nalUnitData(byte[] dataArray, int offset, int limit) {
|
||||||
@ -392,10 +393,12 @@ import java.util.Collections;
|
|||||||
private int nalUnitBytesRead;
|
private int nalUnitBytesRead;
|
||||||
private long nalUnitTimeUs;
|
private long nalUnitTimeUs;
|
||||||
private boolean lookingForFirstSliceFlag;
|
private boolean lookingForFirstSliceFlag;
|
||||||
private boolean firstSliceFlag;
|
private boolean isFirstSlice;
|
||||||
|
private boolean isFirstParameterSet;
|
||||||
|
|
||||||
// Per sample state that gets reset at the start of each sample.
|
// Per sample state that gets reset at the start of each sample.
|
||||||
private boolean readingSample;
|
private boolean readingSample;
|
||||||
|
private boolean writingParameterSets;
|
||||||
private long samplePosition;
|
private long samplePosition;
|
||||||
private long sampleTimeUs;
|
private long sampleTimeUs;
|
||||||
private boolean sampleIsKeyframe;
|
private boolean sampleIsKeyframe;
|
||||||
@ -406,20 +409,32 @@ import java.util.Collections;
|
|||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
lookingForFirstSliceFlag = false;
|
lookingForFirstSliceFlag = false;
|
||||||
firstSliceFlag = false;
|
isFirstSlice = false;
|
||||||
|
isFirstParameterSet = false;
|
||||||
readingSample = false;
|
readingSample = 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) {
|
||||||
firstSliceFlag = false;
|
isFirstSlice = false;
|
||||||
|
isFirstParameterSet = false;
|
||||||
nalUnitTimeUs = pesTimeUs;
|
nalUnitTimeUs = pesTimeUs;
|
||||||
nalUnitBytesRead = 0;
|
nalUnitBytesRead = 0;
|
||||||
nalUnitStartPosition = position;
|
nalUnitStartPosition = position;
|
||||||
// Flush the previous sample when reading a non-VCL NAL unit.
|
|
||||||
if (nalUnitType >= VPS_NUT && readingSample) {
|
if (nalUnitType >= VPS_NUT) {
|
||||||
outputSample(offset);
|
if (!writingParameterSets && readingSample) {
|
||||||
readingSample = false;
|
// 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.
|
// Look for the flag if this NAL unit contains a slice_segment_layer_rbsp.
|
||||||
nalUnitHasKeyframeData = (nalUnitType >= BLA_W_LP && nalUnitType <= CRA_NUT);
|
nalUnitHasKeyframeData = (nalUnitType >= BLA_W_LP && nalUnitType <= CRA_NUT);
|
||||||
lookingForFirstSliceFlag = nalUnitHasKeyframeData || nalUnitType <= RASL_R;
|
lookingForFirstSliceFlag = nalUnitHasKeyframeData || nalUnitType <= RASL_R;
|
||||||
@ -429,7 +444,7 @@ import java.util.Collections;
|
|||||||
if (lookingForFirstSliceFlag) {
|
if (lookingForFirstSliceFlag) {
|
||||||
int headerOffset = offset + FIRST_SLICE_FLAG_OFFSET - nalUnitBytesRead;
|
int headerOffset = offset + FIRST_SLICE_FLAG_OFFSET - nalUnitBytesRead;
|
||||||
if (headerOffset < limit) {
|
if (headerOffset < limit) {
|
||||||
firstSliceFlag = (data[headerOffset] & 0x80) != 0;
|
isFirstSlice = (data[headerOffset] & 0x80) != 0;
|
||||||
lookingForFirstSliceFlag = false;
|
lookingForFirstSliceFlag = false;
|
||||||
} else {
|
} else {
|
||||||
nalUnitBytesRead += limit - offset;
|
nalUnitBytesRead += limit - offset;
|
||||||
@ -438,9 +453,14 @@ import java.util.Collections;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void endNalUnit(long position, int offset) {
|
public void endNalUnit(long position, int offset) {
|
||||||
if (firstSliceFlag) {
|
if (writingParameterSets && isFirstSlice) {
|
||||||
// If the NAL unit ending is the start of a new sample, output the previous one.
|
// This sample has parameter sets. Reset the key-frame flag based on the first slice.
|
||||||
|
sampleIsKeyframe = nalUnitHasKeyframeData;
|
||||||
|
writingParameterSets = false;
|
||||||
|
} else if (isFirstParameterSet || isFirstSlice) {
|
||||||
|
// This NAL unit is at the start of a new sample (access unit).
|
||||||
if (readingSample) {
|
if (readingSample) {
|
||||||
|
// 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…
x
Reference in New Issue
Block a user