mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08:00
Avoid expensive equality checks in DefaultTrackOutput.
If the media format changes from one Format object to another one that's is equal (but not the same object), readData would end up performing an expensive equality evaluation on every invocation. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121362300
This commit is contained in:
parent
c2bd01a756
commit
6b9c43e578
@ -225,8 +225,8 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||
* @return The result, which can be {@link TrackStream#NOTHING_READ},
|
||||
* {@link TrackStream#FORMAT_READ} or {@link TrackStream#BUFFER_READ}.
|
||||
*/
|
||||
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,
|
||||
boolean loadingFinished, long decodeOnlyUntilUs) {
|
||||
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean loadingFinished,
|
||||
long decodeOnlyUntilUs) {
|
||||
switch (infoQueue.readData(formatHolder, buffer, downstreamFormat, extrasHolder)) {
|
||||
case TrackStream.NOTHING_READ:
|
||||
if (loadingFinished) {
|
||||
@ -643,14 +643,14 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||
public synchronized int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,
|
||||
Format downstreamFormat, BufferExtrasHolder extrasHolder) {
|
||||
if (queueSize == 0) {
|
||||
if (upstreamFormat != null && !upstreamFormat.equals(downstreamFormat)) {
|
||||
if (upstreamFormat != null && upstreamFormat != downstreamFormat) {
|
||||
formatHolder.format = upstreamFormat;
|
||||
return TrackStream.FORMAT_READ;
|
||||
}
|
||||
return TrackStream.NOTHING_READ;
|
||||
}
|
||||
|
||||
if (!formats[relativeReadIndex].equals(downstreamFormat)) {
|
||||
if (formats[relativeReadIndex] != downstreamFormat) {
|
||||
formatHolder.format = formats[relativeReadIndex];
|
||||
return TrackStream.FORMAT_READ;
|
||||
}
|
||||
@ -741,7 +741,10 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||
// Called by the loading thread.
|
||||
|
||||
public synchronized void format(Format format) {
|
||||
upstreamFormat = format;
|
||||
// We suppress changes between equal formats so we can use referential equality in readData.
|
||||
if (!format.equals(upstreamFormat)) {
|
||||
upstreamFormat = format;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void commitSample(long timeUs, int sampleFlags, long offset, int size,
|
||||
|
Loading…
x
Reference in New Issue
Block a user