Commit 63604493 by aquilescanta Committed by Oliver Woodman

Fix memory leak in HlsMediaChunk's

Issue:#2319

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145089668
parent 26b303a4
...@@ -79,8 +79,10 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -79,8 +79,10 @@ import java.util.concurrent.atomic.AtomicInteger;
private final boolean isEncrypted; private final boolean isEncrypted;
private final boolean isMasterTimestampSource; private final boolean isMasterTimestampSource;
private final TimestampAdjuster timestampAdjuster; private final TimestampAdjuster timestampAdjuster;
private final HlsMediaChunk previousChunk;
private final String lastPathSegment; private final String lastPathSegment;
private final Extractor previousExtractor;
private final boolean shouldSpliceIn;
private final boolean needNewExtractor;
private final boolean isPackedAudio; private final boolean isPackedAudio;
private final Id3Decoder id3Decoder; private final Id3Decoder id3Decoder;
...@@ -123,7 +125,6 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -123,7 +125,6 @@ import java.util.concurrent.atomic.AtomicInteger;
this.isMasterTimestampSource = isMasterTimestampSource; this.isMasterTimestampSource = isMasterTimestampSource;
this.timestampAdjuster = timestampAdjuster; this.timestampAdjuster = timestampAdjuster;
this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.discontinuitySequenceNumber = discontinuitySequenceNumber;
this.previousChunk = previousChunk;
// Note: this.dataSource and dataSource may be different. // Note: this.dataSource and dataSource may be different.
this.isEncrypted = this.dataSource instanceof Aes128DataSource; this.isEncrypted = this.dataSource instanceof Aes128DataSource;
lastPathSegment = dataSpec.uri.getLastPathSegment(); lastPathSegment = dataSpec.uri.getLastPathSegment();
...@@ -131,13 +132,19 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -131,13 +132,19 @@ import java.util.concurrent.atomic.AtomicInteger;
|| lastPathSegment.endsWith(AC3_FILE_EXTENSION) || lastPathSegment.endsWith(AC3_FILE_EXTENSION)
|| lastPathSegment.endsWith(EC3_FILE_EXTENSION) || lastPathSegment.endsWith(EC3_FILE_EXTENSION)
|| lastPathSegment.endsWith(MP3_FILE_EXTENSION); || lastPathSegment.endsWith(MP3_FILE_EXTENSION);
if (isPackedAudio) { if (previousChunk != null) {
id3Decoder = previousChunk != null ? previousChunk.id3Decoder : new Id3Decoder(); id3Decoder = previousChunk.id3Decoder;
id3Data = previousChunk != null ? previousChunk.id3Data id3Data = previousChunk.id3Data;
: new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH); previousExtractor = previousChunk.extractor;
shouldSpliceIn = previousChunk.hlsUrl != hlsUrl;
needNewExtractor = previousChunk.discontinuitySequenceNumber != discontinuitySequenceNumber
|| shouldSpliceIn;
} else { } else {
id3Decoder = null; id3Decoder = isPackedAudio ? new Id3Decoder() : null;
id3Data = null; id3Data = isPackedAudio ? new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH) : null;
previousExtractor = null;
shouldSpliceIn = false;
needNewExtractor = true;
} }
initDataSource = dataSource; initDataSource = dataSource;
uid = UID_SOURCE.getAndIncrement(); uid = UID_SOURCE.getAndIncrement();
...@@ -151,7 +158,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -151,7 +158,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/ */
public void init(HlsSampleStreamWrapper output) { public void init(HlsSampleStreamWrapper output) {
extractorOutput = output; extractorOutput = output;
output.init(uid, previousChunk != null && previousChunk.hlsUrl != hlsUrl); output.init(uid, shouldSpliceIn);
} }
@Override @Override
...@@ -191,8 +198,8 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -191,8 +198,8 @@ import java.util.concurrent.atomic.AtomicInteger;
// Internal loading methods. // Internal loading methods.
private void maybeLoadInitData() throws IOException, InterruptedException { private void maybeLoadInitData() throws IOException, InterruptedException {
if ((previousChunk != null && previousChunk.extractor == extractor) || initLoadCompleted if (previousExtractor == extractor || initLoadCompleted || initDataSpec == null) {
|| initDataSpec == null) { // According to spec, for packed audio, initDataSpec is expected to be null.
return; return;
} }
DataSpec initSegmentDataSpec = Util.getRemainderDataSpec(initDataSpec, initSegmentBytesLoaded); DataSpec initSegmentDataSpec = Util.getRemainderDataSpec(initDataSpec, initSegmentBytesLoaded);
...@@ -325,9 +332,6 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -325,9 +332,6 @@ import java.util.concurrent.atomic.AtomicInteger;
private Extractor buildExtractorByExtension() { private Extractor buildExtractorByExtension() {
// Set the extractor that will read the chunk. // Set the extractor that will read the chunk.
Extractor extractor; Extractor extractor;
boolean needNewExtractor = previousChunk == null
|| previousChunk.discontinuitySequenceNumber != discontinuitySequenceNumber
|| trackFormat != previousChunk.trackFormat;
boolean usingNewExtractor = true; boolean usingNewExtractor = true;
if (lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION) if (lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION)
|| lastPathSegment.endsWith(VTT_FILE_EXTENSION)) { || lastPathSegment.endsWith(VTT_FILE_EXTENSION)) {
...@@ -335,7 +339,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -335,7 +339,7 @@ import java.util.concurrent.atomic.AtomicInteger;
} else if (!needNewExtractor) { } else if (!needNewExtractor) {
// Only reuse TS and fMP4 extractors. // Only reuse TS and fMP4 extractors.
usingNewExtractor = false; usingNewExtractor = false;
extractor = previousChunk.extractor; extractor = previousExtractor;
} else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION)) { } else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION)) {
extractor = new FragmentedMp4Extractor(0, timestampAdjuster); extractor = new FragmentedMp4Extractor(0, timestampAdjuster);
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment