Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ private static long nowMs() {
return System.nanoTime() / 1_000_000;
}

/** Decoders are set up one after another, at least CREATE_GAP_MS apart (#76). */
private static final Object CREATE_LOCK = new Object();
static final long CREATE_GAP_MS = 250;
private static long lastCreateMs;

void createDecoder(boolean codecH265) {
final int gen;
synchronized (decoderLock) {
Expand Down Expand Up @@ -290,17 +295,30 @@ void createDecoder(boolean codecH265) {

MediaCodec local;
try {
Log.i(TAG, "Start video decoder (" + type + ")");
local = MediaCodec.createDecoderByType(type);
learnLimits(local, type);
try {
local.configure(format, s, null, 0);
local.start();
if (listener != null) listener.onDecoderStarted();
} catch (Exception e) {
local.release();
throw e;
// One decoder set up at a time, with a gap: the 3x3 grid used to start up to nine
// at once, and on the AG-216 that stalled SurfaceFlinger for tens of seconds (#76)
synchronized (CREATE_LOCK) {
long wait = lastCreateMs + CREATE_GAP_MS - nowMs();
if (wait > 0) Thread.sleep(wait);
Log.i(TAG, "Start video decoder (" + type + ")");
local = MediaCodec.createDecoderByType(type);
learnLimits(local, type);
try {
local.configure(format, s, null, 0);
local.start();
} catch (Exception e) {
local.release();
throw e;
} finally {
lastCreateMs = nowMs();
}
}
if (listener != null) listener.onDecoderStarted();
} catch (InterruptedException e) {
// The cell stopped while waiting for its turn: nothing was created
Thread.currentThread().interrupt();
InstanceBudget.release(type);
return;
} catch (Exception e) {
InstanceBudget.release(type);
synchronized (decoderLock) {
Expand Down
Loading