mirror of
https://github.com/androidx/media.git
synced 2025-05-08 16:10:38 +08:00
Suppress noop format changes
For self-initializing segments, DefaultTrackOutput receives a null format and then the actual format. This broke the deduplication logic in InfoQueue.format, since there were two transitions: FormatX->Null and Null->FormatX. This CL allows deduplication to succeed in this case. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=129081583
This commit is contained in:
parent
5345702ec5
commit
1bea48f249
@ -449,8 +449,8 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||||||
@Override
|
@Override
|
||||||
public void format(Format format) {
|
public void format(Format format) {
|
||||||
Format adjustedFormat = getAdjustedSampleFormat(format, sampleOffsetUs);
|
Format adjustedFormat = getAdjustedSampleFormat(format, sampleOffsetUs);
|
||||||
infoQueue.format(adjustedFormat);
|
boolean formatChanged = infoQueue.format(adjustedFormat);
|
||||||
if (upstreamFormatChangeListener != null) {
|
if (upstreamFormatChangeListener != null && formatChanged) {
|
||||||
upstreamFormatChangeListener.onUpstreamFormatChanged(adjustedFormat);
|
upstreamFormatChangeListener.onUpstreamFormatChanged(adjustedFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,6 +608,7 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||||||
|
|
||||||
private long largestDequeuedTimestampUs;
|
private long largestDequeuedTimestampUs;
|
||||||
private long largestQueuedTimestampUs;
|
private long largestQueuedTimestampUs;
|
||||||
|
private boolean upstreamFormatRequired;
|
||||||
private Format upstreamFormat;
|
private Format upstreamFormat;
|
||||||
private int upstreamSourceId;
|
private int upstreamSourceId;
|
||||||
|
|
||||||
@ -622,6 +623,7 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||||||
formats = new Format[capacity];
|
formats = new Format[capacity];
|
||||||
largestDequeuedTimestampUs = Long.MIN_VALUE;
|
largestDequeuedTimestampUs = Long.MIN_VALUE;
|
||||||
largestQueuedTimestampUs = Long.MIN_VALUE;
|
largestQueuedTimestampUs = Long.MIN_VALUE;
|
||||||
|
upstreamFormatRequired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearSampleData() {
|
public void clearSampleData() {
|
||||||
@ -711,7 +713,7 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||||||
* Returns the upstream {@link Format} in which samples are being queued.
|
* Returns the upstream {@link Format} in which samples are being queued.
|
||||||
*/
|
*/
|
||||||
public synchronized Format getUpstreamFormat() {
|
public synchronized Format getUpstreamFormat() {
|
||||||
return upstreamFormat;
|
return upstreamFormatRequired ? null : upstreamFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -826,15 +828,24 @@ public final class DefaultTrackOutput implements TrackOutput {
|
|||||||
|
|
||||||
// Called by the loading thread.
|
// Called by the loading thread.
|
||||||
|
|
||||||
public synchronized void format(Format format) {
|
public synchronized boolean format(Format format) {
|
||||||
// We suppress changes between equal formats so we can use referential equality in readData.
|
if (format == null) {
|
||||||
if (!Util.areEqual(format, upstreamFormat)) {
|
upstreamFormatRequired = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
upstreamFormatRequired = false;
|
||||||
|
if (Util.areEqual(format, upstreamFormat)) {
|
||||||
|
// Suppress changes between equal formats so we can use referential equality in readData.
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
upstreamFormat = format;
|
upstreamFormat = format;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void commitSample(long timeUs, int sampleFlags, long offset, int size,
|
public synchronized void commitSample(long timeUs, int sampleFlags, long offset, int size,
|
||||||
byte[] encryptionKey) {
|
byte[] encryptionKey) {
|
||||||
|
Assertions.checkState(!upstreamFormatRequired);
|
||||||
commitSampleTimestamp(timeUs);
|
commitSampleTimestamp(timeUs);
|
||||||
timesUs[relativeWriteIndex] = timeUs;
|
timesUs[relativeWriteIndex] = timeUs;
|
||||||
offsets[relativeWriteIndex] = offset;
|
offsets[relativeWriteIndex] = offset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user