mirror of
https://github.com/samsonjs/media.git
synced 2026-04-26 14:57:47 +00:00
Tweak PassthroughSectionPayloadReader to allow timestamp to change
PiperOrigin-RevId: 305674374
This commit is contained in:
parent
d9a8622bd5
commit
dfd5c512f6
1 changed files with 11 additions and 15 deletions
|
|
@ -33,10 +33,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
*/
|
*/
|
||||||
public final class PassthroughSectionPayloadReader implements SectionPayloadReader {
|
public final class PassthroughSectionPayloadReader implements SectionPayloadReader {
|
||||||
|
|
||||||
private final String mimeType;
|
private Format format;
|
||||||
private @MonotonicNonNull TimestampAdjuster timestampAdjuster;
|
private @MonotonicNonNull TimestampAdjuster timestampAdjuster;
|
||||||
private @MonotonicNonNull TrackOutput output;
|
private @MonotonicNonNull TrackOutput output;
|
||||||
private boolean formatOutputWithTimestampAdjustment;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PassthroughSectionPayloadReader.
|
* Create a new PassthroughSectionPayloadReader.
|
||||||
|
|
@ -44,7 +43,7 @@ public final class PassthroughSectionPayloadReader implements SectionPayloadRead
|
||||||
* @param mimeType The MIME type set as {@link Format#sampleMimeType} on the created output track.
|
* @param mimeType The MIME type set as {@link Format#sampleMimeType} on the created output track.
|
||||||
*/
|
*/
|
||||||
public PassthroughSectionPayloadReader(String mimeType) {
|
public PassthroughSectionPayloadReader(String mimeType) {
|
||||||
this.mimeType = mimeType;
|
this.format = new Format.Builder().setSampleMimeType(mimeType).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -57,23 +56,20 @@ public final class PassthroughSectionPayloadReader implements SectionPayloadRead
|
||||||
output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_METADATA);
|
output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_METADATA);
|
||||||
// Eagerly output an incomplete format (missing timestamp offset) to ensure source preparation
|
// Eagerly output an incomplete format (missing timestamp offset) to ensure source preparation
|
||||||
// is not blocked waiting for potentially sparse metadata.
|
// is not blocked waiting for potentially sparse metadata.
|
||||||
output.format(new Format.Builder().setSampleMimeType(mimeType).build());
|
output.format(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void consume(ParsableByteArray sectionData) {
|
public void consume(ParsableByteArray sectionData) {
|
||||||
assertInitialized();
|
assertInitialized();
|
||||||
if (!formatOutputWithTimestampAdjustment) {
|
long subsampleOffsetUs = timestampAdjuster.getTimestampOffsetUs();
|
||||||
if (timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET) {
|
if (subsampleOffsetUs == C.TIME_UNSET) {
|
||||||
// There is not enough information to initialize the timestamp adjuster.
|
// Don't output samples without a known subsample offset.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
output.format(
|
if (subsampleOffsetUs != format.subsampleOffsetUs) {
|
||||||
new Format.Builder()
|
format = format.buildUpon().setSubsampleOffsetUs(subsampleOffsetUs).build();
|
||||||
.setSampleMimeType(mimeType)
|
output.format(format);
|
||||||
.setSubsampleOffsetUs(timestampAdjuster.getTimestampOffsetUs())
|
|
||||||
.build());
|
|
||||||
formatOutputWithTimestampAdjustment = true;
|
|
||||||
}
|
}
|
||||||
int sampleSize = sectionData.bytesLeft();
|
int sampleSize = sectionData.bytesLeft();
|
||||||
output.sampleData(sectionData, sampleSize);
|
output.sampleData(sectionData, sampleSize);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue