@@ -159,7 +159,7 @@ protected void onPositionReset(long positionUs, boolean joining) {
159159 replaceDecoder ();
160160 } else {
161161 releaseBuffers ();
162- decoder .flush ();
162+ Assertions . checkNotNull ( decoder ) .flush ();
163163 }
164164 }
165165
@@ -170,9 +170,9 @@ public void render(long positionUs, long elapsedRealtimeUs) {
170170 }
171171
172172 if (nextSubtitle == null ) {
173- decoder .setPositionUs (positionUs );
173+ Assertions . checkNotNull ( decoder ) .setPositionUs (positionUs );
174174 try {
175- nextSubtitle = decoder .dequeueOutputBuffer ();
175+ nextSubtitle = Assertions . checkNotNull ( decoder ) .dequeueOutputBuffer ();
176176 } catch (SubtitleDecoderException e ) {
177177 handleDecoderError (e );
178178 return ;
@@ -194,8 +194,8 @@ public void render(long positionUs, long elapsedRealtimeUs) {
194194 textRendererNeedsUpdate = true ;
195195 }
196196 }
197-
198197 if (nextSubtitle != null ) {
198+ SubtitleOutputBuffer nextSubtitle = this .nextSubtitle ;
199199 if (nextSubtitle .isEndOfStream ()) {
200200 if (!textRendererNeedsUpdate && getNextEventTime () == Long .MAX_VALUE ) {
201201 if (decoderReplacementState == REPLACEMENT_STATE_WAIT_END_OF_STREAM ) {
@@ -210,14 +210,16 @@ public void render(long positionUs, long elapsedRealtimeUs) {
210210 if (subtitle != null ) {
211211 subtitle .release ();
212212 }
213+ nextSubtitleEventIndex = nextSubtitle .getNextEventTimeIndex (positionUs );
213214 subtitle = nextSubtitle ;
214- nextSubtitle = null ;
215- nextSubtitleEventIndex = subtitle .getNextEventTimeIndex (positionUs );
215+ this .nextSubtitle = null ;
216216 textRendererNeedsUpdate = true ;
217217 }
218218 }
219219
220220 if (textRendererNeedsUpdate ) {
221+ // If textRendererNeedsUpdate then subtitle must be non-null.
222+ Assertions .checkNotNull (subtitle );
221223 // textRendererNeedsUpdate is set and we're playing. Update the renderer.
222224 updateOutput (subtitle .getCues (positionUs ));
223225 }
@@ -227,17 +229,18 @@ public void render(long positionUs, long elapsedRealtimeUs) {
227229 }
228230
229231 try {
232+ @ Nullable SubtitleInputBuffer nextInputBuffer = this .nextInputBuffer ;
230233 while (!inputStreamEnded ) {
231234 if (nextInputBuffer == null ) {
232- nextInputBuffer = decoder .dequeueInputBuffer ();
235+ nextInputBuffer = Assertions . checkNotNull ( decoder ) .dequeueInputBuffer ();
233236 if (nextInputBuffer == null ) {
234237 return ;
235238 }
236239 }
237240 if (decoderReplacementState == REPLACEMENT_STATE_SIGNAL_END_OF_STREAM ) {
238241 nextInputBuffer .setFlags (C .BUFFER_FLAG_END_OF_STREAM );
239- decoder .queueInputBuffer (nextInputBuffer );
240- nextInputBuffer = null ;
242+ Assertions . checkNotNull ( decoder ) .queueInputBuffer (nextInputBuffer );
243+ this . nextInputBuffer = null ;
241244 decoderReplacementState = REPLACEMENT_STATE_WAIT_END_OF_STREAM ;
242245 return ;
243246 }
@@ -248,13 +251,18 @@ public void render(long positionUs, long elapsedRealtimeUs) {
248251 inputStreamEnded = true ;
249252 waitingForKeyFrame = false ;
250253 } else {
251- nextInputBuffer .subsampleOffsetUs = formatHolder .format .subsampleOffsetUs ;
254+ @ Nullable Format format = formatHolder .format ;
255+ if (format == null ) {
256+ // We haven't received a format yet.
257+ return ;
258+ }
259+ nextInputBuffer .subsampleOffsetUs = format .subsampleOffsetUs ;
252260 nextInputBuffer .flip ();
253261 waitingForKeyFrame &= !nextInputBuffer .isKeyFrame ();
254262 }
255263 if (!waitingForKeyFrame ) {
256- decoder .queueInputBuffer (nextInputBuffer );
257- nextInputBuffer = null ;
264+ Assertions . checkNotNull ( decoder ) .queueInputBuffer (nextInputBuffer );
265+ this . nextInputBuffer = null ;
258266 }
259267 } else if (result == C .RESULT_NOTHING_READ ) {
260268 return ;
@@ -300,14 +308,14 @@ private void releaseBuffers() {
300308
301309 private void releaseDecoder () {
302310 releaseBuffers ();
303- decoder .release ();
311+ Assertions . checkNotNull ( decoder ) .release ();
304312 decoder = null ;
305313 decoderReplacementState = REPLACEMENT_STATE_NONE ;
306314 }
307315
308316 private void initDecoder () {
309317 waitingForKeyFrame = true ;
310- decoder = decoderFactory .createDecoder (streamFormat );
318+ decoder = decoderFactory .createDecoder (Assertions . checkNotNull ( streamFormat ) );
311319 }
312320
313321 private void replaceDecoder () {
@@ -316,6 +324,7 @@ private void replaceDecoder() {
316324 }
317325
318326 private long getNextEventTime () {
327+ Assertions .checkNotNull (subtitle );
319328 return nextSubtitleEventIndex == C .INDEX_UNSET
320329 || nextSubtitleEventIndex >= subtitle .getEventTimeCount ()
321330 ? Long .MAX_VALUE : subtitle .getEventTime (nextSubtitleEventIndex );
0 commit comments