Implement handlesTrack using MediaCodecUtil.

This commit is contained in:
Oliver Woodman 2015-09-18 18:22:40 +01:00
parent 8022d28e04
commit cf27b83e8a
5 changed files with 23 additions and 9 deletions

View File

@ -217,9 +217,11 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
}
@Override
protected boolean handlesTrack(MediaFormat mediaFormat) {
// TODO: Check the mime type against the available decoders (b/22996976).
return MimeTypes.isAudio(mediaFormat.mimeType);
protected boolean handlesTrack(MediaFormat mediaFormat) throws DecoderQueryException {
// TODO: Use MediaCodecList.findDecoderForFormat on API 23.
String mimeType = mediaFormat.mimeType;
return MimeTypes.isAudio(mimeType) && (MimeTypes.AUDIO_UNKNOWN.equals(mimeType)
|| allowPassthrough(mimeType) || MediaCodecUtil.getDecoderInfo(mimeType, false) != null);
}
@Override

View File

@ -256,6 +256,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
* @param requiresSecureDecoder Whether a secure decoder is needed for decoding {@code mimeType}.
* @return {@link DecoderInfo} for decoding media in the specified MIME type, or {@code null} if
* no suitable decoder is available.
* @throws DecoderQueryException Thrown if there was an error querying decoders.
*/
protected DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder)
throws DecoderQueryException {

View File

@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer;
import com.google.android.exoplayer.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer.drm.DrmSessionManager;
import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.TraceUtil;
@ -268,9 +269,11 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
}
@Override
protected boolean handlesTrack(MediaFormat mediaFormat) {
// TODO: Check the mime type against the available decoders (b/22996976).
return MimeTypes.isVideo(mediaFormat.mimeType);
protected boolean handlesTrack(MediaFormat mediaFormat) throws DecoderQueryException {
// TODO: Use MediaCodecList.findDecoderForFormat on API 23.
String mimeType = mediaFormat.mimeType;
return MimeTypes.isVideo(mimeType) && (MimeTypes.VIDEO_UNKNOWN.equals(mimeType)
|| MediaCodecUtil.getDecoderInfo(mimeType, false) != null);
}
@Override

View File

@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer;
import com.google.android.exoplayer.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer.SampleSource.SampleSourceReader;
import java.io.IOException;
@ -70,7 +71,13 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
int sourceTrackCount = source.getTrackCount();
for (int trackIndex = 0; trackIndex < sourceTrackCount; trackIndex++) {
MediaFormat format = source.getFormat(trackIndex);
if (handlesTrack(format)) {
boolean handlesTrack;
try {
handlesTrack = handlesTrack(format);
} catch (DecoderQueryException e) {
throw new ExoPlaybackException(e);
}
if (handlesTrack) {
handledSourceIndices[handledTrackCount] = sourceIndex;
handledTrackIndices[handledTrackCount] = trackIndex;
handledTrackCount++;
@ -101,8 +108,9 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
*
* @param mediaFormat The format of the track.
* @return True if the renderer can handle the track, false otherwise.
* @throws DecoderQueryException Thrown if there was an error querying decoders.
*/
protected abstract boolean handlesTrack(MediaFormat mediaFormat);
protected abstract boolean handlesTrack(MediaFormat mediaFormat) throws DecoderQueryException;
@Override
protected void onEnabled(int track, long positionUs, boolean joining)

View File

@ -50,7 +50,7 @@ public final class VideoFormatSelectorUtil {
* mime types.
* @param filterHdFormats True to filter HD formats. False otherwise.
* @return An array holding the indices of the selected formats.
* @throws DecoderQueryException
* @throws DecoderQueryException Thrown if there was an error querying decoders.
*/
public static int[] selectVideoFormatsForDefaultDisplay(Context context,
List<? extends FormatWrapper> formatWrappers, String[] allowedContainerMimeTypes,