Skip to content

Commit 6970af4

Browse files
Samrobbocopybara-github
authored andcommitted
Add thread-safe information & annotations to necessary fields.
This change is a small incremental step towards better thread-safety. PiperOrigin-RevId: 598852158
1 parent 6b94b72 commit 6970af4

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

library/transformer/src/main/java/com/google/android/exoplayer2/transformer/SequenceAssetLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
private boolean decodeVideo;
9898
private int sequenceLoopCount;
9999
private int processedInputsSize;
100-
private boolean released;
100+
101+
// Accessed when switching asset loader.
102+
private volatile boolean released;
101103

102104
private volatile long currentAssetDurationUs;
103105
private volatile long maxSequenceDurationUs;

library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,34 @@ void onError(
129129
private final AssetLoaderInputTracker assetLoaderInputTracker;
130130

131131
private final List<SampleExporter> sampleExporters;
132-
private final Object setMaxSequenceDurationUsLock;
133132
private final MuxerWrapper muxerWrapper;
134133
private final ConditionVariable transformerConditionVariable;
134+
private final Object setMaxSequenceDurationUsLock;
135135

136136
private boolean isDrainingExporters;
137+
138+
@GuardedBy("setMaxSequenceDurationUsLock")
137139
private long currentMaxSequenceDurationUs;
140+
141+
@GuardedBy("setMaxSequenceDurationUsLock")
138142
private int nonLoopingSequencesWithNonFinalDuration;
139-
private @Transformer.ProgressState int progressState;
143+
140144
private @MonotonicNonNull RuntimeException cancelException;
141145

146+
/**
147+
* The current {@link Transformer.ProgressState}.
148+
*
149+
* <p>Modified on the internal thread. Accessed on the application thread (in {@link
150+
* #getProgress}).
151+
*/
152+
private volatile @Transformer.ProgressState int progressState;
153+
154+
/**
155+
* The boolean tracking if this component has been released.
156+
*
157+
* <p>Modified on the internal thread. Accessed on the application thread (in {@link #getProgress}
158+
* and {@link #cancel()}).
159+
*/
142160
private volatile boolean released;
143161

144162
public TransformerInternal(
@@ -197,8 +215,8 @@ public TransformerInternal(
197215
}
198216
compositionHasLoopingSequence =
199217
nonLoopingSequencesWithNonFinalDuration != composition.sequences.size();
200-
sampleExporters = new ArrayList<>();
201218
setMaxSequenceDurationUsLock = new Object();
219+
sampleExporters = new ArrayList<>();
202220
transformerConditionVariable = new ConditionVariable();
203221
// It's safe to use "this" because we don't send a message before exiting the constructor.
204222
@SuppressWarnings("nullness:methodref.receiver.bound")

0 commit comments

Comments
 (0)