Simplify checking whether a sample can be read

PiperOrigin-RevId: 281763672
This commit is contained in:
olly 2019-11-21 17:15:43 +00:00 committed by Oliver Woodman
parent cc520a670e
commit d82da93ec4

View File

@ -266,20 +266,8 @@ import java.io.IOException;
if (formats[relativeReadIndex] != downstreamFormat) {
// A format can be read.
return true;
} else if (Assertions.checkNotNull(downstreamFormat).drmInitData == null) {
// A sample from a clear section can be read.
return true;
} else if (drmSessionManager == DrmSessionManager.DUMMY
|| Assertions.checkNotNull(currentDrmSession).getState()
== DrmSession.STATE_OPENED_WITH_KEYS) {
// TODO: Remove DUMMY DrmSessionManager check once renderers are migrated [Internal ref:
// b/122519809].
return true;
} else {
// A clear sample in an encrypted section may be read if playClearSamplesWithoutKeys is true.
return (flags[relativeReadIndex] & C.BUFFER_FLAG_ENCRYPTED) == 0
&& Assertions.checkNotNull(currentDrmSession).playClearSamplesWithoutKeys();
}
return mayReadSample(relativeReadIndex);
}
/**
@ -328,20 +316,7 @@ import java.io.IOException;
return C.RESULT_FORMAT_READ;
}
// It's likely that the media source creation has not yet been migrated and the renderer can
// acquire the session for the sample.
// TODO: Remove once renderers are migrated [Internal ref: b/122519809].
boolean skipDrmChecks = drmSessionManager == DrmSessionManager.DUMMY;
boolean isNextSampleEncrypted = (flags[relativeReadIndex] & C.BUFFER_FLAG_ENCRYPTED) != 0;
boolean mayReadSample =
skipDrmChecks
|| Util.castNonNull(downstreamFormat).drmInitData == null
|| (Assertions.checkNotNull(currentDrmSession).playClearSamplesWithoutKeys()
&& !isNextSampleEncrypted)
|| Assertions.checkNotNull(currentDrmSession).getState()
== DrmSession.STATE_OPENED_WITH_KEYS;
if (!mayReadSample) {
if (!mayReadSample(relativeReadIndex)) {
return C.RESULT_NOTHING_READ;
}
@ -630,6 +605,25 @@ import java.io.IOException;
}
}
/**
* Returns whether it's possible to read the next sample.
*
* @param relativeReadIndex The relative read index of the next sample.
* @return Whether it's possible to read the next sample.
*/
private boolean mayReadSample(int relativeReadIndex) {
if (drmSessionManager == DrmSessionManager.DUMMY) {
// TODO: Remove once renderers are migrated [Internal ref: b/122519809].
// For protected content it's likely that the DrmSessionManager is still being injected into
// the renderers. We assume that the renderers will be able to acquire a DrmSession if needed.
return true;
}
return currentDrmSession == null
|| currentDrmSession.getState() == DrmSession.STATE_OPENED_WITH_KEYS
|| ((flags[relativeReadIndex] & C.BUFFER_FLAG_ENCRYPTED) == 0
&& currentDrmSession.playClearSamplesWithoutKeys());
}
/**
* Finds the sample in the specified range that's before or at the specified time. If {@code
* keyframe} is {@code true} then the sample is additionally required to be a keyframe.