Add reset() to SampleQueue. Deprecate reset(boolean) and disable()

The deprecated methods will be removed as soon as HLS is migrated
to use the new ones.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160827936
This commit is contained in:
olly 2017-07-03 07:23:03 -07:00 committed by Oliver Woodman
parent d733bb4101
commit ad3d1e0cf2
4 changed files with 40 additions and 25 deletions

View file

@ -93,10 +93,10 @@ public class SampleQueueTest extends TestCase {
inputBuffer = null; inputBuffer = null;
} }
public void testDisableReleasesAllocations() { public void testResetReleasesAllocations() {
writeTestData(); writeTestData();
assertAllocationCount(10); assertAllocationCount(10);
sampleQueue.disable(); sampleQueue.reset();
assertAllocationCount(0); assertAllocationCount(0);
} }
@ -545,8 +545,8 @@ public class SampleQueueTest extends TestCase {
} }
/** /**
* Asserts {@link SampleQueue#readData} is behaving correctly, given there are no samples * Asserts {@link SampleQueue#read} is behaving correctly, given there are no samples to read and
* to read and the last format to be written to the sample queue is {@code endFormat}. * the last format to be written to the sample queue is {@code endFormat}.
* *
* @param endFormat The last format to be written to the sample queue, or null of no format has * @param endFormat The last format to be written to the sample queue, or null of no format has
* been written. * been written.
@ -573,7 +573,7 @@ public class SampleQueueTest extends TestCase {
} }
/** /**
* Asserts {@link SampleQueue#readData} returns {@link C#RESULT_NOTHING_READ}. * Asserts {@link SampleQueue#read} returns {@link C#RESULT_NOTHING_READ}.
* *
* @param formatRequired The value of {@code formatRequired} passed to readData. * @param formatRequired The value of {@code formatRequired} passed to readData.
*/ */
@ -589,7 +589,7 @@ public class SampleQueueTest extends TestCase {
} }
/** /**
* Asserts {@link SampleQueue#readData} returns {@link C#RESULT_BUFFER_READ} and that the * Asserts {@link SampleQueue#read} returns {@link C#RESULT_BUFFER_READ} and that the
* {@link DecoderInputBuffer#isEndOfStream()} is set. * {@link DecoderInputBuffer#isEndOfStream()} is set.
* *
* @param formatRequired The value of {@code formatRequired} passed to readData. * @param formatRequired The value of {@code formatRequired} passed to readData.
@ -608,8 +608,8 @@ public class SampleQueueTest extends TestCase {
} }
/** /**
* Asserts {@link SampleQueue#readData} returns {@link C#RESULT_FORMAT_READ} and that the * Asserts {@link SampleQueue#read} returns {@link C#RESULT_FORMAT_READ} and that the format
* format holder is filled with a {@link Format} that equals {@code format}. * holder is filled with a {@link Format} that equals {@code format}.
* *
* @param formatRequired The value of {@code formatRequired} passed to readData. * @param formatRequired The value of {@code formatRequired} passed to readData.
* @param format The expected format. * @param format The expected format.
@ -626,8 +626,8 @@ public class SampleQueueTest extends TestCase {
} }
/** /**
* Asserts {@link SampleQueue#readData} returns {@link C#RESULT_BUFFER_READ} and that the * Asserts {@link SampleQueue#read} returns {@link C#RESULT_BUFFER_READ} and that the buffer is
* buffer is filled with the specified sample data. * filled with the specified sample data.
* *
* @param timeUs The expected buffer timestamp. * @param timeUs The expected buffer timestamp.
* @param isKeyframe The expected keyframe flag. * @param isKeyframe The expected keyframe flag.

View file

@ -150,8 +150,8 @@ import java.util.Arrays;
public void release() { public void release() {
boolean releasedSynchronously = loader.release(this); boolean releasedSynchronously = loader.release(this);
if (prepared && !releasedSynchronously) { if (prepared && !releasedSynchronously) {
// Discard as much as we can synchronously. We only do this if we're prepared, since // Discard as much as we can synchronously. We only do this if we're prepared, since otherwise
// otherwise sampleQueues may still be being modified by the loading thread. // sampleQueues may still be being modified by the loading thread.
for (SampleQueue sampleQueue : sampleQueues) { for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.discardToEnd(); sampleQueue.discardToEnd();
} }
@ -164,7 +164,7 @@ import java.util.Arrays;
public void onLoaderReleased() { public void onLoaderReleased() {
extractorHolder.release(); extractorHolder.release();
for (SampleQueue sampleQueue : sampleQueues) { for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.reset(true); sampleQueue.reset();
} }
} }
@ -227,7 +227,15 @@ import java.util.Arrays;
if (enabledTrackCount == 0) { if (enabledTrackCount == 0) {
notifyReset = false; notifyReset = false;
if (loader.isLoading()) { if (loader.isLoading()) {
// Discard as much as we can synchronously.
for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.discardToEnd();
}
loader.cancelLoading(); loader.cancelLoading();
} else {
for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.reset();
}
} }
} else if (seekRequired) { } else if (seekRequired) {
positionUs = seekToUs(positionUs); positionUs = seekToUs(positionUs);
@ -327,7 +335,7 @@ import java.util.Arrays;
loader.cancelLoading(); loader.cancelLoading();
} else { } else {
for (int i = 0; i < trackCount; i++) { for (int i = 0; i < trackCount; i++) {
sampleQueues[i].reset(trackEnabledStates[i]); sampleQueues[i].reset();
} }
} }
} }
@ -388,7 +396,7 @@ import java.util.Arrays;
} }
copyLengthFromLoader(loadable); copyLengthFromLoader(loadable);
for (SampleQueue sampleQueue : sampleQueues) { for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.reset(true); sampleQueue.reset();
} }
if (enabledTrackCount > 0) { if (enabledTrackCount > 0) {
callback.onContinueLoadingRequested(this); callback.onContinueLoadingRequested(this);
@ -526,7 +534,7 @@ import java.util.Arrays;
lastSeekPositionUs = 0; lastSeekPositionUs = 0;
notifyReset = prepared; notifyReset = prepared;
for (SampleQueue sampleQueue : sampleQueues) { for (SampleQueue sampleQueue : sampleQueues) {
sampleQueue.reset(true); sampleQueue.reset();
} }
loadable.setLoadPosition(0, 0); loadable.setLoadPosition(0, 0);
} }

View file

@ -98,9 +98,15 @@ public final class SampleQueue implements TrackOutput {
/** /**
* Resets the output. * Resets the output.
*
* @param enable Whether the output should be enabled. False if it should be disabled.
*/ */
public void reset() {
reset(true);
}
/**
* @deprecated Use {@link #reset()}. Don't disable sample queues.
*/
@Deprecated
public void reset(boolean enable) { public void reset(boolean enable) {
int previousState = state.getAndSet(enable ? STATE_ENABLED : STATE_DISABLED); int previousState = state.getAndSet(enable ? STATE_ENABLED : STATE_DISABLED);
clearSampleData(); clearSampleData();
@ -169,8 +175,9 @@ public final class SampleQueue implements TrackOutput {
// Called by the consuming thread. // Called by the consuming thread.
/** /**
* Disables buffering of sample data and metadata. * @deprecated Don't disable sample queues.
*/ */
@Deprecated
public void disable() { public void disable() {
if (state.getAndSet(STATE_DISABLED) == STATE_ENABLED) { if (state.getAndSet(STATE_DISABLED) == STATE_ENABLED) {
clearSampleData(); clearSampleData();

View file

@ -203,9 +203,9 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
if (loader.isLoading()) { if (loader.isLoading()) {
loader.cancelLoading(); loader.cancelLoading();
} else { } else {
primarySampleQueue.reset(true); primarySampleQueue.reset();
for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.reset(true); embeddedSampleQueue.reset();
} }
} }
} }
@ -229,9 +229,9 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
@Override @Override
public void onLoaderReleased() { public void onLoaderReleased() {
primarySampleQueue.reset(true); primarySampleQueue.reset();
for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.reset(true); embeddedSampleQueue.reset();
} }
} }
@ -295,9 +295,9 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
loadable.startTimeUs, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, loadable.startTimeUs, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs,
loadable.bytesLoaded()); loadable.bytesLoaded());
if (!released) { if (!released) {
primarySampleQueue.reset(true); primarySampleQueue.reset();
for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) { for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.reset(true); embeddedSampleQueue.reset();
} }
callback.onContinueLoadingRequested(this); callback.onContinueLoadingRequested(this);
} }