mirror of
https://github.com/androidx/media.git
synced 2025-05-07 15:40:37 +08:00
Implement handlesTrack using MediaCodecUtil.
This commit is contained in:
parent
8022d28e04
commit
cf27b83e8a
@ -217,9 +217,11 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean handlesTrack(MediaFormat mediaFormat) {
|
protected boolean handlesTrack(MediaFormat mediaFormat) throws DecoderQueryException {
|
||||||
// TODO: Check the mime type against the available decoders (b/22996976).
|
// TODO: Use MediaCodecList.findDecoderForFormat on API 23.
|
||||||
return MimeTypes.isAudio(mediaFormat.mimeType);
|
String mimeType = mediaFormat.mimeType;
|
||||||
|
return MimeTypes.isAudio(mimeType) && (MimeTypes.AUDIO_UNKNOWN.equals(mimeType)
|
||||||
|
|| allowPassthrough(mimeType) || MediaCodecUtil.getDecoderInfo(mimeType, false) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -256,6 +256,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
|||||||
* @param requiresSecureDecoder Whether a secure decoder is needed for decoding {@code mimeType}.
|
* @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
|
* @return {@link DecoderInfo} for decoding media in the specified MIME type, or {@code null} if
|
||||||
* no suitable decoder is available.
|
* no suitable decoder is available.
|
||||||
|
* @throws DecoderQueryException Thrown if there was an error querying decoders.
|
||||||
*/
|
*/
|
||||||
protected DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder)
|
protected DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder)
|
||||||
throws DecoderQueryException {
|
throws DecoderQueryException {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer;
|
package com.google.android.exoplayer;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer.MediaCodecUtil.DecoderQueryException;
|
||||||
import com.google.android.exoplayer.drm.DrmSessionManager;
|
import com.google.android.exoplayer.drm.DrmSessionManager;
|
||||||
import com.google.android.exoplayer.util.MimeTypes;
|
import com.google.android.exoplayer.util.MimeTypes;
|
||||||
import com.google.android.exoplayer.util.TraceUtil;
|
import com.google.android.exoplayer.util.TraceUtil;
|
||||||
@ -268,9 +269,11 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean handlesTrack(MediaFormat mediaFormat) {
|
protected boolean handlesTrack(MediaFormat mediaFormat) throws DecoderQueryException {
|
||||||
// TODO: Check the mime type against the available decoders (b/22996976).
|
// TODO: Use MediaCodecList.findDecoderForFormat on API 23.
|
||||||
return MimeTypes.isVideo(mediaFormat.mimeType);
|
String mimeType = mediaFormat.mimeType;
|
||||||
|
return MimeTypes.isVideo(mimeType) && (MimeTypes.VIDEO_UNKNOWN.equals(mimeType)
|
||||||
|
|| MediaCodecUtil.getDecoderInfo(mimeType, false) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer;
|
package com.google.android.exoplayer;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer.MediaCodecUtil.DecoderQueryException;
|
||||||
import com.google.android.exoplayer.SampleSource.SampleSourceReader;
|
import com.google.android.exoplayer.SampleSource.SampleSourceReader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -70,7 +71,13 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
|
|||||||
int sourceTrackCount = source.getTrackCount();
|
int sourceTrackCount = source.getTrackCount();
|
||||||
for (int trackIndex = 0; trackIndex < sourceTrackCount; trackIndex++) {
|
for (int trackIndex = 0; trackIndex < sourceTrackCount; trackIndex++) {
|
||||||
MediaFormat format = source.getFormat(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;
|
handledSourceIndices[handledTrackCount] = sourceIndex;
|
||||||
handledTrackIndices[handledTrackCount] = trackIndex;
|
handledTrackIndices[handledTrackCount] = trackIndex;
|
||||||
handledTrackCount++;
|
handledTrackCount++;
|
||||||
@ -101,8 +108,9 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
|
|||||||
*
|
*
|
||||||
* @param mediaFormat The format of the track.
|
* @param mediaFormat The format of the track.
|
||||||
* @return True if the renderer can handle the track, false otherwise.
|
* @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
|
@Override
|
||||||
protected void onEnabled(int track, long positionUs, boolean joining)
|
protected void onEnabled(int track, long positionUs, boolean joining)
|
||||||
|
@ -50,7 +50,7 @@ public final class VideoFormatSelectorUtil {
|
|||||||
* mime types.
|
* mime types.
|
||||||
* @param filterHdFormats True to filter HD formats. False otherwise.
|
* @param filterHdFormats True to filter HD formats. False otherwise.
|
||||||
* @return An array holding the indices of the selected formats.
|
* @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,
|
public static int[] selectVideoFormatsForDefaultDisplay(Context context,
|
||||||
List<? extends FormatWrapper> formatWrappers, String[] allowedContainerMimeTypes,
|
List<? extends FormatWrapper> formatWrappers, String[] allowedContainerMimeTypes,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user