Return format and adaptation support from single method.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=114963314
This commit is contained in:
olly 2016-02-18 07:49:42 -08:00 committed by Oliver Woodman
parent 0e60335064
commit 39a924451a
5 changed files with 82 additions and 73 deletions

View file

@ -332,7 +332,8 @@ import java.util.concurrent.atomic.AtomicInteger;
Format[] adaptiveTrackFormats = new Format[trackGroup.length];
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
Format trackFormat = source.getTrackGroup(groupIndex).getFormat(trackIndex);
if (renderer.supportsFormat(trackFormat) == TrackRenderer.FORMAT_HANDLED) {
if ((renderer.supportsFormat(trackFormat) & TrackRenderer.FORMAT_SUPPORT_MASK)
== TrackRenderer.FORMAT_HANDLED) {
adaptiveTrackIndices[adaptiveTrackIndexCount] = trackIndex;
adaptiveTrackFormats[adaptiveTrackIndexCount++] = trackFormat;
}
@ -350,7 +351,8 @@ import java.util.concurrent.atomic.AtomicInteger;
}
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
Format trackFormat = source.getTrackGroup(groupIndex).getFormat(trackIndex);
if (renderer.supportsFormat(trackFormat) == TrackRenderer.FORMAT_HANDLED) {
if ((renderer.supportsFormat(trackFormat) & TrackRenderer.FORMAT_SUPPORT_MASK)
== TrackRenderer.FORMAT_HANDLED) {
rendererTrackGroups[rendererTrackCount] = groupIndex;
rendererTrackIndices[rendererTrackCount] = new int[] {trackIndex};
rendererTrackFormats[rendererTrackCount] = new Format[] {trackFormat};

View file

@ -186,30 +186,26 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
throws DecoderQueryException {
String mimeType = format.sampleMimeType;
if (!MimeTypes.isAudio(mimeType)) {
return TrackRenderer.FORMAT_UNSUPPORTED_TYPE;
return FORMAT_UNSUPPORTED_TYPE;
}
if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderName() != null) {
return TrackRenderer.FORMAT_HANDLED;
return ADAPTIVE_NOT_SEAMLESS | FORMAT_HANDLED;
}
// TODO[REFACTOR]: If requiresSecureDecryption then we should probably also check that the
// drmSession is able to make use of a secure decoder.
DecoderInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType,
format.requiresSecureDecryption);
if (decoderInfo == null) {
return TrackRenderer.FORMAT_UNSUPPORTED_TYPE;
return FORMAT_UNSUPPORTED_TYPE;
}
if (Util.SDK_INT >= 21) {
// Note: We assume support in the case that the sampleRate or channelCount is unknown.
if (format.sampleRate != Format.NO_VALUE
&& !decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate)) {
return TrackRenderer.FORMAT_EXCEEDS_CAPABILITIES;
}
if (format.channelCount != Format.NO_VALUE
&& !decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)) {
return TrackRenderer.FORMAT_EXCEEDS_CAPABILITIES;
}
}
return TrackRenderer.FORMAT_HANDLED;
// Note: We assume support for unknown sampleRate and channelCount.
boolean decoderCapable = Util.SDK_INT < 21
|| ((format.sampleRate == Format.NO_VALUE
|| decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate))
&& (format.channelCount == Format.NO_VALUE
|| decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)));
int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
return ADAPTIVE_NOT_SEAMLESS | formatSupport;
}
@Override

View file

@ -263,18 +263,8 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
@Override
protected final int supportsAdaptive(String mimeType) throws ExoPlaybackException {
if (mimeType == null) {
return TrackRenderer.ADAPTIVE_NOT_SEAMLESS;
}
try {
// TODO[REFACTOR]: Propagate requiresSecureDecoder to this point.
DecoderInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType, false);
return decoderInfo != null && decoderInfo.adaptive ? TrackRenderer.ADAPTIVE_SEAMLESS
: TrackRenderer.ADAPTIVE_NOT_SEAMLESS;
} catch (DecoderQueryException e) {
throw ExoPlaybackException.createForRenderer(e, getIndex());
}
protected final int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
return ADAPTIVE_NOT_SEAMLESS;
}
@Override
@ -287,13 +277,12 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
/**
* Returns the extent to which the renderer is capable of rendering a given format.
* Returns the extent to which the renderer is capable of supporting a given format.
*
* @param mediaCodecSelector The decoder selector.
* @param format The format.
* @return The extent to which the renderer is capable of rendering the given format. One of
* {@link #FORMAT_HANDLED}, {@link #FORMAT_EXCEEDS_CAPABILITIES} and
* {@link #FORMAT_UNSUPPORTED_TYPE}.
* @return The extent to which the renderer is capable of supporting the given format. See
* {@link #supportsFormat(Format)} for more detail.
* @throws DecoderQueryException If there was an error querying decoders.
*/
protected abstract int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)

View file

@ -224,33 +224,38 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
throws DecoderQueryException {
String mimeType = format.sampleMimeType;
if (!MimeTypes.isVideo(mimeType)) {
return TrackRenderer.FORMAT_UNSUPPORTED_TYPE;
return FORMAT_UNSUPPORTED_TYPE;
}
// TODO[REFACTOR]: If requiresSecureDecryption then we should probably also check that the
// drmSession is able to make use of a secure decoder.
DecoderInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType,
format.requiresSecureDecryption);
if (decoderInfo == null) {
return TrackRenderer.FORMAT_UNSUPPORTED_TYPE;
return FORMAT_UNSUPPORTED_TYPE;
}
boolean decoderCapable;
if (format.width > 0 && format.height > 0) {
if (Util.SDK_INT >= 21) {
if (format.frameRate > 0) {
return decoderInfo.isVideoSizeAndRateSupportedV21(format.width, format.height,
format.frameRate) ? TrackRenderer.FORMAT_HANDLED
: TrackRenderer.FORMAT_EXCEEDS_CAPABILITIES;
decoderCapable = decoderInfo.isVideoSizeAndRateSupportedV21(format.width, format.height,
format.frameRate);
} else {
return decoderInfo.isVideoSizeSupportedV21(format.width, format.height)
? TrackRenderer.FORMAT_HANDLED : TrackRenderer.FORMAT_EXCEEDS_CAPABILITIES;
decoderCapable = decoderInfo.isVideoSizeSupportedV21(format.width, format.height);
}
} else {
// TODO[REFACTOR]: We should probably assume that we can decode at least the resolution of
// the display, or the camera, as a sanity check?
decoderCapable = format.width * format.height > MediaCodecUtil.maxH264DecodableFrameSize();
}
// TODO[REFACTOR]: We should probably assume that we can decode at least the resolution of
// the display, or the camera, as a sanity check?
if (format.width * format.height > MediaCodecUtil.maxH264DecodableFrameSize()) {
return TrackRenderer.FORMAT_EXCEEDS_CAPABILITIES;
}
} else {
// We don't know any better, so assume true.
decoderCapable = true;
}
return TrackRenderer.FORMAT_HANDLED;
int adaptiveSupport = decoderInfo.adaptive ? ADAPTIVE_SEAMLESS : ADAPTIVE_NOT_SEAMLESS;
int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
return adaptiveSupport | formatSupport;
}
@Override

View file

@ -36,23 +36,15 @@ import java.io.IOException;
public abstract class TrackRenderer implements ExoPlayerComponent {
/**
* The {@link TrackRenderer} can seamlessly adapt between formats.
* A mask to apply to the result of {@link #supportsFormat(Format)} to obtain one of
* {@link #FORMAT_HANDLED}, {@link #FORMAT_EXCEEDS_CAPABILITIES} and
* {@link #FORMAT_UNSUPPORTED_TYPE}.
*/
public static final int ADAPTIVE_SEAMLESS = 0;
/**
* The {@link TrackRenderer} can adapt between formats, but may suffer a brief discontinuity
* (~50-100ms) when adaptation occurs.
*/
public static final int ADAPTIVE_NOT_SEAMLESS = 1;
/**
* The {@link TrackRenderer} does not support adaptation between formats.
*/
public static final int ADAPTIVE_NOT_SUPPORTED = 2;
public static final int FORMAT_SUPPORT_MASK = 0b11;
/**
* The {@link TrackRenderer} is capable of rendering the format.
*/
public static final int FORMAT_HANDLED = 0;
public static final int FORMAT_HANDLED = 0b10;
/**
* The {@link TrackRenderer} is capable of rendering formats with the same mimeType, but the
* properties of the format exceed the renderer's capability.
@ -61,7 +53,7 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
* {@link MimeTypes#VIDEO_H264}, but the format's resolution exceeds the maximum limit supported
* by the underlying H264 decoder.
*/
public static final int FORMAT_EXCEEDS_CAPABILITIES = 1;
public static final int FORMAT_EXCEEDS_CAPABILITIES = 0b01;
/**
* The {@link TrackRenderer} is not capable of rendering the format, or any other format with the
* same mimeType.
@ -69,7 +61,26 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
* Example: The {@link TrackRenderer} is only capable of rendering video and the track has an
* audio mimeType.
*/
public static final int FORMAT_UNSUPPORTED_TYPE = 2;
public static final int FORMAT_UNSUPPORTED_TYPE = 0b00;
/**
* A mask to apply to the result of {@link #supportsFormat(Format)} to obtain one of
* {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and {@link #ADAPTIVE_NOT_SUPPORTED}.
*/
public static final int ADAPTIVE_SUPPORT_MASK = 0b1100;
/**
* The {@link TrackRenderer} can seamlessly adapt between formats.
*/
public static final int ADAPTIVE_SEAMLESS = 0b1000;
/**
* The {@link TrackRenderer} can adapt between formats, but may suffer a brief discontinuity
* (~50-100ms) when adaptation occurs.
*/
public static final int ADAPTIVE_NOT_SEAMLESS = 0b0100;
/**
* The {@link TrackRenderer} does not support adaptation between formats.
*/
public static final int ADAPTIVE_NOT_SUPPORTED = 0b0000;
/**
* The renderer is idle.
@ -131,28 +142,34 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
}
/**
* Returns the extent to which the renderer is capable of consuming from a {@link TrackStream}
* that adapts between multiple supported formats of a given mimeType, or of differing mimeTypes
* if {@code mimeType == null} is passed.
* Returns the extent to which the renderer supports adapting between supported formats that have
* different mimeTypes.
*
* @param mimeType The mimeType, or null to query the extent to which the renderer is capable of
* adapting between formats with different mimeTypes.
* @return The extent to which the renderer supports the adaptation. One of
* {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* @return The extent to which the renderer supports adapting between supported formats that have
* different mimeTypes. One of {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* {@link #ADAPTIVE_NOT_SUPPORTED}.
* @throws ExoPlaybackException If an error occurs.
*/
protected int supportsAdaptive(String mimeType) throws ExoPlaybackException {
protected int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
return ADAPTIVE_NOT_SUPPORTED;
}
/**
* Returns the extent to which the renderer is capable of rendering a given format.
* Returns the extent to which the renderer supports a given format.
* <p>
* The returned value is the bitwise OR of two properties:
* <ul>
* <li>The level of support for the format itself. One of {@code}link #FORMAT_HANDLED},
* {@link #FORMAT_EXCEEDS_CAPABILITIES} and {@link #FORMAT_UNSUPPORTED_TYPE}.</li>
* <li>The level of support for adapting from the format to another format of the same mimeType.
* One of {@link #ADAPTIVE_SEAMLESS}, {@link #ADAPTIVE_NOT_SEAMLESS} and
* {@link #ADAPTIVE_NOT_SUPPORTED}.</li>
* </ul>
* The individual properties can be retrieved by performing a bitwise AND with
* {@link #FORMAT_SUPPORT_MASK} and {@link #ADAPTIVE_SUPPORT_MASK} respectively.
*
* @param format The format.
* @return The extent to which the renderer is capable of rendering the given format. One of
* {@link #FORMAT_HANDLED}, {@link #FORMAT_EXCEEDS_CAPABILITIES} and
* {@link #FORMAT_UNSUPPORTED_TYPE}.
* @return The extent to which the renderer is capable of supporting the given format.
* @throws ExoPlaybackException If an error occurs.
*/
protected abstract int supportsFormat(Format format) throws ExoPlaybackException;