mirror of
https://github.com/samsonjs/media.git
synced 2026-04-19 13:35:47 +00:00
Verify a thread is alive before sending a message to it.
PiperOrigin-RevId: 568515736
This commit is contained in:
parent
69ffac28bb
commit
0b62d37425
1 changed files with 10 additions and 0 deletions
|
|
@ -209,6 +209,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
}
|
||||
|
||||
public void start() {
|
||||
verifyInternalThreadAlive();
|
||||
internalHandler.sendEmptyMessage(MSG_START);
|
||||
}
|
||||
|
||||
|
|
@ -216,6 +217,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
if (released) {
|
||||
return PROGRESS_STATE_NOT_STARTED;
|
||||
}
|
||||
verifyInternalThreadAlive();
|
||||
internalHandler.obtainMessage(MSG_UPDATE_PROGRESS, progressHolder).sendToTarget();
|
||||
// TODO: figure out why calling clock.onThreadBlocked() here makes the tests fail.
|
||||
transformerConditionVariable.blockUninterruptible();
|
||||
|
|
@ -227,6 +229,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
if (released) {
|
||||
return;
|
||||
}
|
||||
verifyInternalThreadAlive();
|
||||
internalHandler
|
||||
.obtainMessage(MSG_END, END_REASON_CANCELLED, /* unused */ 0, /* exportException */ null)
|
||||
.sendToTarget();
|
||||
|
|
@ -239,12 +242,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
}
|
||||
|
||||
public void endWithCompletion() {
|
||||
verifyInternalThreadAlive();
|
||||
internalHandler
|
||||
.obtainMessage(MSG_END, END_REASON_COMPLETED, /* unused */ 0, /* exportException */ null)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
public void endWithException(ExportException exportException) {
|
||||
verifyInternalThreadAlive();
|
||||
internalHandler
|
||||
.obtainMessage(MSG_END, END_REASON_ERROR, /* unused */ 0, exportException)
|
||||
.sendToTarget();
|
||||
|
|
@ -252,6 +257,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
|
||||
// Private methods.
|
||||
|
||||
private void verifyInternalThreadAlive() {
|
||||
checkState(internalHandlerThread.isAlive(), "Internal thread is dead.");
|
||||
}
|
||||
|
||||
private boolean handleMessage(Message msg) {
|
||||
// Some messages cannot be ignored when resources have been released. End messages must be
|
||||
// handled to report release timeouts and to unblock the transformer condition variable in case
|
||||
|
|
@ -540,6 +549,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
// which the AssetLoader are allowed to send data. This way SampleExporter understands all
|
||||
// the inputs are registered when AssetLoader sends data.
|
||||
if (assetLoaderInputTracker.hasAssociatedAllTracksWithGraphInput(trackType)) {
|
||||
verifyInternalThreadAlive();
|
||||
internalHandler
|
||||
.obtainMessage(MSG_REGISTER_SAMPLE_EXPORTER, sampleExporter)
|
||||
.sendToTarget();
|
||||
|
|
|
|||
Loading…
Reference in a new issue