Skip to content

Commit

Permalink
Merge pull request google#147 from jonasl/dev-gc
Browse files Browse the repository at this point in the history
MediaCodecTrackRenderer: Avoid excessive garbage generation
  • Loading branch information
ojw28 committed Nov 19, 2014
2 parents 127bcd1 + 255c3b2 commit d506d76
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -141,7 +142,7 @@ private static String getDiagnosticInfoV21(Throwable cause) {
private final SampleSource source;
private final SampleHolder sampleHolder;
private final MediaFormatHolder formatHolder;
private final HashSet<Long> decodeOnlyPresentationTimestamps;
private final List<Long> decodeOnlyPresentationTimestamps;
private final MediaCodec.BufferInfo outputBufferInfo;
private final EventListener eventListener;
protected final Handler eventHandler;
Expand Down Expand Up @@ -191,7 +192,7 @@ public MediaCodecTrackRenderer(SampleSource source, DrmSessionManager drmSession
codecCounters = new CodecCounters();
sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DISABLED);
formatHolder = new MediaFormatHolder();
decodeOnlyPresentationTimestamps = new HashSet<Long>();
decodeOnlyPresentationTimestamps = new ArrayList<Long>();
outputBufferInfo = new MediaCodec.BufferInfo();
}

Expand Down Expand Up @@ -736,12 +737,11 @@ private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs)
return false;
}

boolean decodeOnly = decodeOnlyPresentationTimestamps.contains(
outputBufferInfo.presentationTimeUs);
int decodeOnlyIdx = getDecodeOnlyIndex(outputBufferInfo.presentationTimeUs);
if (processOutputBuffer(positionUs, elapsedRealtimeUs, codec, outputBuffers[outputIndex],
outputBufferInfo, outputIndex, decodeOnly)) {
if (decodeOnly) {
decodeOnlyPresentationTimestamps.remove(outputBufferInfo.presentationTimeUs);
outputBufferInfo, outputIndex, decodeOnlyIdx >= 0)) {
if (decodeOnlyIdx >= 0) {
decodeOnlyPresentationTimestamps.remove(decodeOnlyIdx);
} else {
currentPositionUs = outputBufferInfo.presentationTimeUs;
}
Expand Down Expand Up @@ -785,4 +785,13 @@ public void run() {
}
}

private int getDecodeOnlyIndex(long presentationTimeUs) {
final int size = decodeOnlyPresentationTimestamps.size();
for (int i = 0; i < size; i++) {
if (decodeOnlyPresentationTimestamps.get(i).longValue() == presentationTimeUs) {
return i;
}
}
return -1;
}
}

0 comments on commit d506d76

Please sign in to comment.