private static String getMediaMimeType(Format format) { String formatMimeType = format.mimeType; if (MimeTypes.isAudio(formatMimeType)) { return MimeTypes.getAudioMediaMimeType(format.codecs); } else if (MimeTypes.isVideo(formatMimeType)) { return MimeTypes.getVideoMediaMimeType(format.codecs); } else if (mimeTypeIsRawText(formatMimeType)) { return formatMimeType; } else if (MimeTypes.APPLICATION_MP4.equals(formatMimeType)) { if ("stpp".equals(format.codecs)) { return MimeTypes.APPLICATION_TTML; } if ("wvtt".equals(format.codecs)) { return MimeTypes.APPLICATION_MP4VTT; } } return null; }
@Override public void adaptiveTrack(HlsMasterPlaylist playlist, Variant[] variants) { Arrays.sort(variants, new Comparator<Variant>() { private final Comparator<Format> formatComparator = new Format.DecreasingBandwidthComparator(); @Override public int compare(Variant first, Variant second) { return formatComparator.compare(first.format, second.format); } }); int defaultVariantIndex = computeDefaultVariantIndex(playlist, variants, bandwidthMeter); int maxWidth = -1; int maxHeight = -1; for (int i = 0; i < variants.length; i++) { Format variantFormat = variants[i].format; maxWidth = Math.max(variantFormat.width, maxWidth); maxHeight = Math.max(variantFormat.height, maxHeight); } // TODO: We should allow the default values to be passed through the constructor. // TODO: Print a warning if resolution tags are omitted. maxWidth = maxWidth > 0 ? maxWidth : 1920; maxHeight = maxHeight > 0 ? maxHeight : 1080; tracks.add(new ExposedTrack(variants, defaultVariantIndex, maxWidth, maxHeight)); }
@Override public void onDownstreamFormatChanged(int sourceId, Format format, int trigger, long mediaTimeMs) { if (infoListener == null) { return; } if (sourceId == TYPE_VIDEO) { videoFormat = format; infoListener.onVideoFormatEnabled(format, trigger, mediaTimeMs); } else if (sourceId == TYPE_AUDIO) { infoListener.onAudioFormatEnabled(format, trigger, mediaTimeMs); } }
@Override public void onLoadStarted(int sourceId, long length, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs) { if (infoListener != null) { infoListener.onLoadStarted(sourceId, length, type, trigger, format, mediaStartTimeMs, mediaEndTimeMs); } }
@Override public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) { if (infoListener != null) { infoListener .onLoadCompleted(sourceId, bytesLoaded, type, trigger, format, mediaStartTimeMs, mediaEndTimeMs, elapsedRealtimeMs, loadDurationMs); } }
@Override public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) { if (infoListener != null) { infoListener.onLoadCompleted(sourceId, bytesLoaded, type, trigger, format, mediaStartTimeMs, mediaEndTimeMs, elapsedRealtimeMs, loadDurationMs); } }
@Override public void onLoadStarted(int sourceId, long length, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs) { loadStartTimeMs[sourceId] = SystemClock.elapsedRealtime(); if (VerboseLogUtil.isTagEnabled(TAG)) { Log.v(TAG, "loadStart [" + getSessionTimeString() + ", " + sourceId + ", " + type + ", " + mediaStartTimeMs + ", " + mediaEndTimeMs + "]"); } }
@Override public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) { if (VerboseLogUtil.isTagEnabled(TAG)) { long downloadTime = SystemClock.elapsedRealtime() - loadStartTimeMs[sourceId]; Log.v(TAG, "loadEnd [" + getSessionTimeString() + ", " + sourceId + ", " + downloadTime + "]"); } }
@Override public void onLoadStarted(int sourceId, long length, int type, int trigger, Format format, int mediaStartTimeMs, int mediaEndTimeMs) { loadStartTimeMs[sourceId] = SystemClock.elapsedRealtime(); if (VerboseLogUtil.isTagEnabled(TAG)) { Log.v(TAG, "loadStart [" + getSessionTimeString() + ", " + sourceId + ", " + type + ", " + mediaStartTimeMs + ", " + mediaEndTimeMs + "]"); } }
@Override public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format, int mediaStartTimeMs, int mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) { if (infoListener != null) { infoListener.onLoadCompleted(sourceId, bytesLoaded, type, trigger, format, mediaStartTimeMs, mediaEndTimeMs, elapsedRealtimeMs, loadDurationMs); } }
public ExposedTrack(MediaFormat trackFormat, int elementIndex, Format[] adaptiveFormats, int adaptiveMaxWidth, int adaptiveMaxHeight) { this.trackFormat = trackFormat; this.elementIndex = elementIndex; this.adaptiveFormats = adaptiveFormats; this.adaptiveMaxWidth = adaptiveMaxWidth; this.adaptiveMaxHeight = adaptiveMaxHeight; this.fixedFormat = null; }
@Override public void onLoadStarted(int sourceId, long length, int type, int trigger, Format format, int mediaStartTimeMs, int mediaEndTimeMs) { if (infoListener != null) { infoListener.onLoadStarted(sourceId, length, type, trigger, format, mediaStartTimeMs, mediaEndTimeMs); } }
@Override public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format, int mediaStartTimeMs, int mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) { if (VerboseLogUtil.isTagEnabled(TAG)) { long downloadTime = SystemClock.elapsedRealtime() - loadStartTimeMs[sourceId]; Log.v(TAG, "loadEnd [" + getSessionTimeString() + ", " + sourceId + ", " + downloadTime + "]"); } }