SampleQueue implements TrackOutput { @CallSuper public void maybeThrowError() throws IOException { if (currentDrmSession != null && currentDrmSession.getState() == DrmSession.STATE_ERROR) { throw Assertions.checkNotNull(currentDrmSession.getError()); } } SampleQueue(Allocator allocator, DrmSessionManager<?> drmSessionManager); @CallSuper void release(); final void reset(); @CallSuper void reset(boolean resetUpstreamFormat); final void sourceId(int sourceId); final void splice(); final int getWriteIndex(); final void discardUpstreamSamples(int discardFromIndex); @CallSuper void preRelease(); @CallSuper void maybeThrowError(); final int getFirstIndex(); final int getReadIndex(); final synchronized int peekSourceId(); final synchronized Format getUpstreamFormat(); final synchronized long getLargestQueuedTimestampUs(); final synchronized boolean isLastSampleQueued(); final synchronized long getFirstTimestampUs(); @SuppressWarnings("ReferenceEquality") // See comments in setUpstreamFormat @CallSuper synchronized boolean isReady(boolean loadingFinished); @CallSuper int read(
      FormatHolder formatHolder,
      DecoderInputBuffer buffer,
      boolean formatRequired,
      boolean loadingFinished,
      long decodeOnlyUntilUs); final synchronized boolean seekTo(int sampleIndex); final synchronized boolean seekTo(long timeUs, boolean allowTimeBeyondBuffer); final synchronized int advanceTo(long timeUs); final synchronized int advanceToEnd(); final void discardTo(long timeUs, boolean toKeyframe, boolean stopAtReadPosition); final void discardToRead(); final void discardToEnd(); final void setSampleOffsetUs(long sampleOffsetUs); final void setUpstreamFormatChangeListener(UpstreamFormatChangedListener listener); @Override final void format(Format unadjustedUpstreamFormat); @Override final int sampleData(ExtractorInput input, int length, boolean allowEndOfInput); @Override final void sampleData(ParsableByteArray buffer, int length); @Override final void sampleMetadata(
      long timeUs,
      @C.BufferFlags int flags,
      int size,
      int offset,
      @Nullable CryptoData cryptoData); synchronized long discardSampleMetadataToRead();  }
@Test public void testReadWithErrorSessionReadsNothingAndThrows() throws IOException { when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED); writeTestDataWithEncryptedSections(); assertReadFormat( false, FORMAT_ENCRYPTED); assertReadNothing( false); sampleQueue.maybeThrowError(); when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_ERROR); when(mockDrmSession.getError()).thenReturn(new DrmSession.DrmSessionException(new Exception())); assertReadNothing( false); try { sampleQueue.maybeThrowError(); Assert.fail(); } catch (IOException e) { } when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS); assertReadEncryptedSample( 0); }