mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Release Extractors when ExtractorSampleSource is released.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=126691912
This commit is contained in:
parent
660b26e3ad
commit
f4239eb571
2 changed files with 42 additions and 3 deletions
|
|
@ -111,8 +111,8 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
||||||
private final EventListener eventListener;
|
private final EventListener eventListener;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final ConditionVariable loadCondition;
|
private final ConditionVariable loadCondition;
|
||||||
private final Loader loader;
|
|
||||||
private final ExtractorHolder extractorHolder;
|
private final ExtractorHolder extractorHolder;
|
||||||
|
private final Loader loader;
|
||||||
|
|
||||||
private Callback callback;
|
private Callback callback;
|
||||||
private Allocator allocator;
|
private Allocator allocator;
|
||||||
|
|
@ -171,8 +171,8 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
||||||
this.eventHandler = eventHandler;
|
this.eventHandler = eventHandler;
|
||||||
dataSource = dataSourceFactory.createDataSource(bandwidthMeter);
|
dataSource = dataSourceFactory.createDataSource(bandwidthMeter);
|
||||||
loadCondition = new ConditionVariable();
|
loadCondition = new ConditionVariable();
|
||||||
loader = new Loader("Loader:ExtractorSampleSource");
|
|
||||||
extractorHolder = new ExtractorHolder(extractorsFactory.createExtractors(), this);
|
extractorHolder = new ExtractorHolder(extractorsFactory.createExtractors(), this);
|
||||||
|
loader = new Loader("Loader:ExtractorSampleSource", extractorHolder);
|
||||||
pendingResetPositionUs = C.UNSET_TIME_US;
|
pendingResetPositionUs = C.UNSET_TIME_US;
|
||||||
sampleQueues = new DefaultTrackOutput[0];
|
sampleQueues = new DefaultTrackOutput[0];
|
||||||
length = C.LENGTH_UNBOUNDED;
|
length = C.LENGTH_UNBOUNDED;
|
||||||
|
|
@ -640,7 +640,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
||||||
/**
|
/**
|
||||||
* Stores a list of extractors and a selected extractor when the format has been detected.
|
* Stores a list of extractors and a selected extractor when the format has been detected.
|
||||||
*/
|
*/
|
||||||
private static final class ExtractorHolder {
|
private static final class ExtractorHolder implements Loader.Releasable {
|
||||||
|
|
||||||
private final Extractor[] extractors;
|
private final Extractor[] extractors;
|
||||||
private final ExtractorOutput extractorOutput;
|
private final ExtractorOutput extractorOutput;
|
||||||
|
|
@ -691,6 +691,14 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
||||||
return extractor;
|
return extractor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release() {
|
||||||
|
if (extractor != null) {
|
||||||
|
extractor.release();
|
||||||
|
extractor = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,18 @@ public final class Loader {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object that can be released on the loading thread when {@link Loader#release()} is called.
|
||||||
|
*/
|
||||||
|
public interface Releasable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases any resources associated with the instance.
|
||||||
|
*/
|
||||||
|
void release();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A callback to be notified of {@link Loader} events.
|
* A callback to be notified of {@link Loader} events.
|
||||||
*/
|
*/
|
||||||
|
|
@ -135,6 +147,7 @@ public final class Loader {
|
||||||
private static final int MSG_FATAL_ERROR = 4;
|
private static final int MSG_FATAL_ERROR = 4;
|
||||||
|
|
||||||
private final ExecutorService downloadExecutorService;
|
private final ExecutorService downloadExecutorService;
|
||||||
|
private final Releasable releasable;
|
||||||
|
|
||||||
private LoadTask<? extends Loadable> currentTask;
|
private LoadTask<? extends Loadable> currentTask;
|
||||||
private IOException fatalError;
|
private IOException fatalError;
|
||||||
|
|
@ -143,7 +156,17 @@ public final class Loader {
|
||||||
* @param threadName A name for the loader's thread.
|
* @param threadName A name for the loader's thread.
|
||||||
*/
|
*/
|
||||||
public Loader(String threadName) {
|
public Loader(String threadName) {
|
||||||
|
this(threadName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param threadName A name for the loader's thread.
|
||||||
|
* @param releasable An object to release on the loader's thread when {@link Loader#release()} is
|
||||||
|
* called.
|
||||||
|
*/
|
||||||
|
public Loader(String threadName, Releasable releasable) {
|
||||||
this.downloadExecutorService = Util.newSingleThreadExecutor(threadName);
|
this.downloadExecutorService = Util.newSingleThreadExecutor(threadName);
|
||||||
|
this.releasable = releasable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -223,6 +246,14 @@ public final class Loader {
|
||||||
if (currentTask != null) {
|
if (currentTask != null) {
|
||||||
currentTask.cancel(true);
|
currentTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
if (releasable != null) {
|
||||||
|
downloadExecutorService.submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
releasable.release();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
downloadExecutorService.shutdown();
|
downloadExecutorService.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue