Make ExoPlayer systrace consistent.

Plus remove some unused util methods + make a few
warnings go away.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123888046
This commit is contained in:
olly 2016-06-02 11:23:06 -07:00 committed by Oliver Woodman
parent 5cde3aa314
commit 14cb76a112
6 changed files with 17 additions and 52 deletions

View File

@ -27,6 +27,7 @@ import com.google.android.exoplayer.TrackStream;
import com.google.android.exoplayer.VideoTrackRendererEventListener; import com.google.android.exoplayer.VideoTrackRendererEventListener;
import com.google.android.exoplayer.VideoTrackRendererEventListener.EventDispatcher; import com.google.android.exoplayer.VideoTrackRendererEventListener.EventDispatcher;
import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.TraceUtil;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -152,15 +153,19 @@ public final class LibvpxVideoTrackRenderer extends TrackRenderer {
if (decoder == null) { if (decoder == null) {
// If we don't have a decoder yet, we need to instantiate one. // If we don't have a decoder yet, we need to instantiate one.
long codecInitializingTimestamp = SystemClock.elapsedRealtime(); long codecInitializingTimestamp = SystemClock.elapsedRealtime();
TraceUtil.beginSection("createVpxDecoder");
decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE); decoder = new VpxDecoder(NUM_BUFFERS, NUM_BUFFERS, INITIAL_INPUT_BUFFER_SIZE);
decoder.setOutputMode(outputMode); decoder.setOutputMode(outputMode);
TraceUtil.endSection();
long codecInitializedTimestamp = SystemClock.elapsedRealtime(); long codecInitializedTimestamp = SystemClock.elapsedRealtime();
eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp, eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
codecInitializedTimestamp - codecInitializingTimestamp); codecInitializedTimestamp - codecInitializingTimestamp);
codecCounters.codecInitCount++; codecCounters.codecInitCount++;
} }
TraceUtil.beginSection("drainAndFeed");
while (drainOutputBuffer(positionUs)) {} while (drainOutputBuffer(positionUs)) {}
while (feedInputBuffer()) {} while (feedInputBuffer()) {}
TraceUtil.endSection();
} catch (VpxDecoderException e) { } catch (VpxDecoderException e) {
throw ExoPlaybackException.createForRenderer(e, getIndex()); throw ExoPlaybackException.createForRenderer(e, getIndex());
} }

View File

@ -306,13 +306,13 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
codecNeedsMonoChannelCountWorkaround = codecNeedsMonoChannelCountWorkaround(codecName, format); codecNeedsMonoChannelCountWorkaround = codecNeedsMonoChannelCountWorkaround(codecName, format);
try { try {
long codecInitializingTimestamp = SystemClock.elapsedRealtime(); long codecInitializingTimestamp = SystemClock.elapsedRealtime();
TraceUtil.beginSection("createByCodecName(" + codecName + ")"); TraceUtil.beginSection("createCodec:" + codecName);
codec = MediaCodec.createByCodecName(codecName); codec = MediaCodec.createByCodecName(codecName);
TraceUtil.endSection(); TraceUtil.endSection();
TraceUtil.beginSection("configureCodec"); TraceUtil.beginSection("configureCodec");
configureCodec(codec, format, mediaCrypto); configureCodec(codec, format, mediaCrypto);
TraceUtil.endSection(); TraceUtil.endSection();
TraceUtil.beginSection("codec.start()"); TraceUtil.beginSection("startCodec");
codec.start(); codec.start();
TraceUtil.endSection(); TraceUtil.endSection();
long codecInitializedTimestamp = SystemClock.elapsedRealtime(); long codecInitializedTimestamp = SystemClock.elapsedRealtime();

View File

@ -28,6 +28,7 @@ import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.TrackStream; import com.google.android.exoplayer.TrackStream;
import com.google.android.exoplayer.audio.AudioTrack; import com.google.android.exoplayer.audio.AudioTrack;
import com.google.android.exoplayer.util.MimeTypes; import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.TraceUtil;
import android.media.PlaybackParams; import android.media.PlaybackParams;
import android.os.Handler; import android.os.Handler;
@ -98,7 +99,9 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
if (decoder == null) { if (decoder == null) {
try { try {
long codecInitializingTimestamp = SystemClock.elapsedRealtime(); long codecInitializingTimestamp = SystemClock.elapsedRealtime();
TraceUtil.beginSection("createAudioDecoder");
decoder = createDecoder(inputFormat); decoder = createDecoder(inputFormat);
TraceUtil.endSection();
long codecInitializedTimestamp = SystemClock.elapsedRealtime(); long codecInitializedTimestamp = SystemClock.elapsedRealtime();
eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp, eventDispatcher.decoderInitialized(decoder.getName(), codecInitializedTimestamp,
codecInitializedTimestamp - codecInitializingTimestamp); codecInitializedTimestamp - codecInitializingTimestamp);
@ -110,8 +113,10 @@ public abstract class AudioDecoderTrackRenderer extends TrackRenderer implements
// Rendering loop. // Rendering loop.
try { try {
TraceUtil.beginSection("drainAndFeed");
while (drainOutputBuffer()) {} while (drainOutputBuffer()) {}
while (feedInputBuffer()) {} while (feedInputBuffer()) {}
TraceUtil.endSection();
} catch (AudioTrack.InitializationException | AudioTrack.WriteException } catch (AudioTrack.InitializationException | AudioTrack.WriteException
| AudioDecoderException e) { | AudioDecoderException e) {
throw ExoPlaybackException.createForRenderer(e, getIndex()); throw ExoPlaybackException.createForRenderer(e, getIndex());

View File

@ -251,7 +251,7 @@ public final class Loader {
try { try {
executorThread = Thread.currentThread(); executorThread = Thread.currentThread();
if (!loadable.isLoadCanceled()) { if (!loadable.isLoadCanceled()) {
TraceUtil.beginSection(loadable.getClass().getSimpleName() + ".load()"); TraceUtil.beginSection("load:" + loadable.getClass().getSimpleName());
try { try {
loadable.load(); loadable.load();
} finally { } finally {

View File

@ -116,7 +116,7 @@ public final class UriUtil {
return removeDotSegments(uri, baseLimit + refIndices[PATH], baseLimit + refIndices[QUERY]); return removeDotSegments(uri, baseLimit + refIndices[PATH], baseLimit + refIndices[QUERY]);
} }
if (refIndices[PATH] != refIndices[QUERY] && referenceUri.charAt(refIndices[PATH]) == '/') { if (referenceUri.charAt(refIndices[PATH]) == '/') {
// The reference path is rooted. The target is the base scheme and authority (if any), plus // The reference path is rooted. The target is the base scheme and authority (if any), plus
// the reference. // the reference.
uri.append(baseUri, 0, baseIndices[PATH]).append(referenceUri); uri.append(baseUri, 0, baseIndices[PATH]).append(referenceUri);

View File

@ -20,10 +20,8 @@ import com.google.android.exoplayer.ExoPlayerLibraryInfo;
import com.google.android.exoplayer.upstream.DataSource; import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.upstream.DataSpec; import com.google.android.exoplayer.upstream.DataSpec;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -46,7 +44,6 @@ import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -118,17 +115,6 @@ public final class Util {
private Util() {} private Util() {}
/**
* Returns whether the device is an AndroidTV.
*
* @param context A context.
* @return True if the device is an AndroidTV. False otherwise.
*/
@SuppressLint("InlinedApi")
public static boolean isAndroidTv(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
}
/** /**
* Converts microseconds to milliseconds (rounding down). * Converts microseconds to milliseconds (rounding down).
* *
@ -213,21 +199,6 @@ public final class Util {
}); });
} }
/**
* Instantiates a new single threaded scheduled executor whose thread has the specified name.
*
* @param threadName The name of the thread.
* @return The executor.
*/
public static ScheduledExecutorService newSingleThreadScheduledExecutor(final String threadName) {
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, threadName);
}
});
}
/** /**
* Closes a {@link DataSource}, suppressing any {@link IOException} that may occur. * Closes a {@link DataSource}, suppressing any {@link IOException} that may occur.
* *
@ -598,10 +569,10 @@ public final class Util {
unexpectedEndOfInput.setAccessible(true); unexpectedEndOfInput.setAccessible(true);
unexpectedEndOfInput.invoke(inputStream); unexpectedEndOfInput.invoke(inputStream);
} }
} catch (IOException e) {
// The connection didn't ever have an input stream, or it was closed already.
} catch (Exception e) { } catch (Exception e) {
// Something went wrong. The device probably isn't using okhttp. // If an IOException then the connection didn't ever have an input stream, or it was closed
// already. If another type of exception then something went wrong, most likely the device
// isn't using okhttp.
} }
} }
@ -660,22 +631,6 @@ public final class Util {
return ((long) topInteger << 32) | (bottomInteger & 0xFFFFFFFFL); return ((long) topInteger << 32) | (bottomInteger & 0xFFFFFFFFL);
} }
/**
* Returns a hex string representation of the data provided.
*
* @param data The byte array containing the data to be turned into a hex string.
* @param beginIndex The begin index, inclusive.
* @param endIndex The end index, exclusive.
* @return A string containing the hex representation of the data provided.
*/
public static String getHexStringFromBytes(byte[] data, int beginIndex, int endIndex) {
StringBuilder dataStringBuilder = new StringBuilder(endIndex - beginIndex);
for (int i = beginIndex; i < endIndex; i++) {
dataStringBuilder.append(String.format(Locale.US, "%02X", data[i]));
}
return dataStringBuilder.toString();
}
/** /**
* Returns a byte array containing values parsed from the hex string provided. * Returns a byte array containing values parsed from the hex string provided.
* *