Pass component of event to debug trace logEvent as parameter.

PiperOrigin-RevId: 633176557
This commit is contained in:
samrobinson 2024-05-13 05:30:54 -07:00 committed by Copybara-Service
parent 0db23ae904
commit 30624aae6e
11 changed files with 165 additions and 71 deletions

View File

@ -18,6 +18,10 @@ package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkArgument; import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_BITMAP_TEXTURE_MANAGER;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VFP;
import static androidx.media3.effect.DebugTraceUtil.EVENT_BITMAP_TEXTURE_MANAGER_SIGNAL_EOS;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_QUEUE_BITMAP;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import androidx.media3.common.C; import androidx.media3.common.C;
@ -109,7 +113,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (pendingBitmaps.isEmpty()) { if (pendingBitmaps.isEmpty()) {
checkNotNull(gainmapShaderProgram).signalEndOfCurrentInputStream(); checkNotNull(gainmapShaderProgram).signalEndOfCurrentInputStream();
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_BITMAP_TEXTURE_MANAGER_SIGNAL_EOS, C.TIME_END_OF_SOURCE); COMPONENT_BITMAP_TEXTURE_MANAGER,
EVENT_BITMAP_TEXTURE_MANAGER_SIGNAL_EOS,
C.TIME_END_OF_SOURCE);
} else { } else {
currentInputStreamEnded = true; currentInputStreamEnded = true;
} }
@ -156,7 +162,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
.queueInputFrame( .queueInputFrame(
glObjectsProvider, checkNotNull(currentSdrGlTextureInfo), currentPresentationTimeUs); glObjectsProvider, checkNotNull(currentSdrGlTextureInfo), currentPresentationTimeUs);
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_VFP_QUEUE_BITMAP, COMPONENT_VFP,
EVENT_VFP_QUEUE_BITMAP,
currentPresentationTimeUs, currentPresentationTimeUs,
/* extraFormat= */ "%dx%d", /* extraFormat= */ "%dx%d",
/* extraArgs...= */ currentFrameInfo.width, /* extraArgs...= */ currentFrameInfo.width,
@ -170,7 +177,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
// Only signal end of stream after all pending bitmaps are processed. // Only signal end of stream after all pending bitmaps are processed.
checkNotNull(gainmapShaderProgram).signalEndOfCurrentInputStream(); checkNotNull(gainmapShaderProgram).signalEndOfCurrentInputStream();
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_BITMAP_TEXTURE_MANAGER_SIGNAL_EOS, C.TIME_END_OF_SOURCE); COMPONENT_BITMAP_TEXTURE_MANAGER,
EVENT_BITMAP_TEXTURE_MANAGER_SIGNAL_EOS,
C.TIME_END_OF_SOURCE);
currentInputStreamEnded = false; currentInputStreamEnded = false;
} }
} }

View File

@ -22,6 +22,7 @@ import static java.lang.annotation.ElementType.TYPE_USE;
import android.util.JsonWriter; import android.util.JsonWriter;
import androidx.annotation.GuardedBy; import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.annotation.StringDef; import androidx.annotation.StringDef;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.util.SystemClock; import androidx.media3.common.util.SystemClock;
@ -55,6 +56,7 @@ public final class DebugTraceUtil {
public static boolean enableTracing = false; public static boolean enableTracing = false;
/** Events logged by {@link #logEvent}. */ /** Events logged by {@link #logEvent}. */
@Documented
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@StringDef({ @StringDef({
EVENT_VIDEO_INPUT_FORMAT, EVENT_VIDEO_INPUT_FORMAT,
@ -83,9 +85,8 @@ public final class DebugTraceUtil {
EVENT_MUXER_TRACK_ENDED_AUDIO, EVENT_MUXER_TRACK_ENDED_AUDIO,
EVENT_MUXER_TRACK_ENDED_VIDEO EVENT_MUXER_TRACK_ENDED_VIDEO
}) })
@Documented
@Target(TYPE_USE) @Target(TYPE_USE)
public @interface DebugTraceEvent {} public @interface Event {}
public static final String EVENT_VIDEO_INPUT_FORMAT = "VideoInputFormat"; public static final String EVENT_VIDEO_INPUT_FORMAT = "VideoInputFormat";
public static final String EVENT_DECODER_DECODED_FRAME = "Decoder-DecodedFrame"; public static final String EVENT_DECODER_DECODED_FRAME = "Decoder-DecodedFrame";
@ -117,19 +118,37 @@ public final class DebugTraceUtil {
public static final String EVENT_MUXER_TRACK_ENDED_AUDIO = "Muxer-TrackEnded_Audio"; public static final String EVENT_MUXER_TRACK_ENDED_AUDIO = "Muxer-TrackEnded_Audio";
public static final String EVENT_MUXER_TRACK_ENDED_VIDEO = "Muxer-TrackEnded_Video"; public static final String EVENT_MUXER_TRACK_ENDED_VIDEO = "Muxer-TrackEnded_Video";
/** Components logged by {@link #logEvent}. */
@Documented
@Retention(RetentionPolicy.SOURCE)
@StringDef({
COMPONENT_VIDEO,
COMPONENT_DECODER,
COMPONENT_VFP,
COMPONENT_BITMAP_TEXTURE_MANAGER,
COMPONENT_EXTERNAL_TEXTURE_MANAGER,
COMPONENT_TEX_ID_TEXTURE_MANAGER,
COMPONENT_COMPOSITOR,
COMPONENT_ENCODER,
COMPONENT_MUXER
})
@Target(TYPE_USE)
public @interface Component {}
// TODO - b/339639306: Migrate COMPONENT_VIDEO usage to COMPONENT_ASSETLOADER. // TODO - b/339639306: Migrate COMPONENT_VIDEO usage to COMPONENT_ASSETLOADER.
private static final String COMPONENT_VIDEO = "Video"; public static final String COMPONENT_VIDEO = "Video";
private static final String COMPONENT_DECODER = "Decoder"; public static final String COMPONENT_DECODER = "Decoder";
private static final String COMPONENT_VFP = "VFP"; public static final String COMPONENT_VFP = "VFP";
private static final String COMPONENT_EXTERNAL_TEXTURE_MANAGER = "ExternalTextureManager"; public static final String COMPONENT_EXTERNAL_TEXTURE_MANAGER = "ExternalTextureManager";
private static final String COMPONENT_BITMAP_TEXTURE_MANAGER = "BitmapTextureManager"; public static final String COMPONENT_BITMAP_TEXTURE_MANAGER = "BitmapTextureManager";
private static final String COMPONENT_TEX_ID_TEXTURE_MANAGER = "TexIdTextureManager"; public static final String COMPONENT_TEX_ID_TEXTURE_MANAGER = "TexIdTextureManager";
private static final String COMPONENT_COMPOSITOR = "Compositor"; public static final String COMPONENT_COMPOSITOR = "Compositor";
private static final String COMPONENT_ENCODER = "Encoder"; public static final String COMPONENT_ENCODER = "Encoder";
private static final String COMPONENT_MUXER = "Muxer"; public static final String COMPONENT_MUXER = "Muxer";
private static final ImmutableMap<String, List<String>> COMPONENTS_TO_EVENTS = // For a given component, events are in the rough expected order that they occur.
private static final ImmutableMap<@Component String, List<@Event String>> COMPONENTS_TO_EVENTS =
ImmutableMap.of( ImmutableMap.of(
COMPONENT_VIDEO, ImmutableList.of(EVENT_VIDEO_INPUT_FORMAT), COMPONENT_VIDEO, ImmutableList.of(EVENT_VIDEO_INPUT_FORMAT),
COMPONENT_DECODER, COMPONENT_DECODER,
@ -167,28 +186,32 @@ public final class DebugTraceUtil {
private static final int MAX_FIRST_LAST_LOGS = 10; private static final int MAX_FIRST_LAST_LOGS = 10;
@GuardedBy("DebugTraceUtil.class") @GuardedBy("DebugTraceUtil.class")
private static final Map<String, EventLogger> events = new LinkedHashMap<>(); private static final Map<@Component String, Map<@Event String, EventLogger>>
componentsToEventsToLogs = new LinkedHashMap<>();
@GuardedBy("DebugTraceUtil.class") @GuardedBy("DebugTraceUtil.class")
private static long startTimeMs = SystemClock.DEFAULT.elapsedRealtime(); private static long startTimeMs = SystemClock.DEFAULT.elapsedRealtime();
public static synchronized void reset() { public static synchronized void reset() {
events.clear(); componentsToEventsToLogs.clear();
startTimeMs = SystemClock.DEFAULT.elapsedRealtime(); startTimeMs = SystemClock.DEFAULT.elapsedRealtime();
} }
/** /**
* Logs a new event, if debug logging is enabled. * Logs a new event, if debug logging is enabled.
* *
* @param eventName The {@linkplain DebugTraceEvent event name} to log. * @param component The {@link Component} to log.
* @param event The {@link Event} to log.
* @param presentationTimeUs The current presentation time of the media. Use {@link C#TIME_UNSET} * @param presentationTimeUs The current presentation time of the media. Use {@link C#TIME_UNSET}
* if unknown, {@link C#TIME_END_OF_SOURCE} if EOS. * if unknown, {@link C#TIME_END_OF_SOURCE} if EOS.
* @param extraFormat Format string for optional extra information. See {@link * @param extraFormat Format string for optional extra information. See {@link
* Util#formatInvariant(String, Object...)}. * Util#formatInvariant(String, Object...)}.
* @param extraArgs Arguments for optional extra information. * @param extraArgs Arguments for optional extra information.
*/ */
@SuppressWarnings("ComputeIfAbsentContainsKey") // Avoid Java8 for visibility
public static synchronized void logEvent( public static synchronized void logEvent(
@DebugTraceEvent String eventName, @Component String component,
@Event String event,
long presentationTimeUs, long presentationTimeUs,
String extraFormat, String extraFormat,
Object... extraArgs) { Object... extraArgs) {
@ -196,10 +219,15 @@ public final class DebugTraceUtil {
return; return;
} }
long eventTimeMs = SystemClock.DEFAULT.elapsedRealtime() - startTimeMs; long eventTimeMs = SystemClock.DEFAULT.elapsedRealtime() - startTimeMs;
if (!events.containsKey(eventName)) {
events.put(eventName, new EventLogger()); if (!componentsToEventsToLogs.containsKey(component)) {
componentsToEventsToLogs.put(component, new LinkedHashMap<>());
} }
EventLogger logger = events.get(eventName); Map<@Event String, EventLogger> events = componentsToEventsToLogs.get(component);
if (!events.containsKey(event)) {
events.put(event, new EventLogger());
}
EventLogger logger = events.get(event);
String extra = Util.formatInvariant(extraFormat, extraArgs); String extra = Util.formatInvariant(extraFormat, extraArgs);
logger.addLog(new EventLog(presentationTimeUs, eventTimeMs, extra)); logger.addLog(new EventLog(presentationTimeUs, eventTimeMs, extra));
} }
@ -207,13 +235,14 @@ public final class DebugTraceUtil {
/** /**
* Logs a new event, if debug logging is enabled. * Logs a new event, if debug logging is enabled.
* *
* @param eventName The {@linkplain DebugTraceEvent event name} to log. * @param component The {@link Component} to log.
* @param event The {@link Event} to log.
* @param presentationTimeUs The current presentation time of the media. Use {@link C#TIME_UNSET} * @param presentationTimeUs The current presentation time of the media. Use {@link C#TIME_UNSET}
* if unknown, {@link C#TIME_END_OF_SOURCE} if EOS. * if unknown, {@link C#TIME_END_OF_SOURCE} if EOS.
*/ */
public static synchronized void logEvent( public static synchronized void logEvent(
@DebugTraceEvent String eventName, long presentationTimeUs) { @Component String component, @Event String event, long presentationTimeUs) {
logEvent(eventName, presentationTimeUs, /* extraFormat= */ ""); logEvent(component, event, presentationTimeUs, /* extraFormat= */ "");
} }
/** /**
@ -228,14 +257,21 @@ public final class DebugTraceUtil {
JsonWriter jsonWriter = new JsonWriter(stringWriter); JsonWriter jsonWriter = new JsonWriter(stringWriter);
try { try {
jsonWriter.beginObject(); jsonWriter.beginObject();
for (Map.Entry<String, List<String>> componentToEvents : COMPONENTS_TO_EVENTS.entrySet()) { for (Map.Entry<@Component String, List<@Event String>> componentToEvents :
jsonWriter.name(componentToEvents.getKey()).beginObject(); COMPONENTS_TO_EVENTS.entrySet()) {
for (String eventType : componentToEvents.getValue()) { @Component String component = componentToEvents.getKey();
jsonWriter.name(eventType); List<@Event String> componentEvents = componentToEvents.getValue();
if (!events.containsKey(eventType)) {
jsonWriter.value("No events"); jsonWriter.name(component);
@Nullable
Map<@Event String, EventLogger> eventsToLogs = componentsToEventsToLogs.get(component);
jsonWriter.beginObject();
for (@Event String event : componentEvents) {
jsonWriter.name(event);
if (eventsToLogs != null && eventsToLogs.containsKey(event)) {
checkNotNull(eventsToLogs.get(event)).toJson(jsonWriter);
} else { } else {
checkNotNull(events.get(eventType)).toJson(jsonWriter); jsonWriter.value("No events");
} }
} }
jsonWriter.endObject(); jsonWriter.endObject();
@ -249,27 +285,33 @@ public final class DebugTraceUtil {
} }
} }
/** Dumps all the logged events to a tsv file. */ /** Dumps all the logged events to the {@link Writer} as tab separated values (tsv). */
public static synchronized void dumpTsv(Writer writer) throws IOException { public static synchronized void dumpTsv(Writer writer) throws IOException {
if (!enableTracing) { if (!enableTracing) {
writer.write("Tracing disabled"); writer.write("Tracing disabled");
return; return;
} }
writer.write("event\ttimestamp\tpresentation\textra\n"); writer.write("component\tevent\ttimestamp\tpresentation\textra\n");
for (Map.Entry<String, EventLogger> entry : events.entrySet()) { for (Map.Entry<@Component String, Map<@Event String, EventLogger>> componentToEventsToLogs :
ImmutableList<EventLog> eventLogs = entry.getValue().getLogs(); componentsToEventsToLogs.entrySet()) {
for (int i = 0; i < eventLogs.size(); i++) { @Component String component = componentToEventsToLogs.getKey();
EventLog eventLog = eventLogs.get(i); Map<@Event String, EventLogger> eventsToLogs = componentToEventsToLogs.getValue();
for (Map.Entry<@Event String, EventLogger> eventToLogs : eventsToLogs.entrySet()) {
@Event String componentEvent = eventToLogs.getKey();
ImmutableList<EventLog> eventLogs = eventToLogs.getValue().getLogs();
for (EventLog eventLog : eventLogs) {
writer.write( writer.write(
formatInvariant( formatInvariant(
"%s\t%dms\t%s\t%s\n", "%s\t%s\t%dms\t%s\t%s\n",
entry.getKey(), component,
componentEvent,
eventLog.eventTimeMs, eventLog.eventTimeMs,
presentationTimeToString(eventLog.presentationTimeUs), presentationTimeToString(eventLog.presentationTimeUs),
eventLog.extra)); eventLog.extra));
} }
} }
} }
}
private static String presentationTimeToString(long presentationTimeUs) { private static String presentationTimeToString(long presentationTimeUs) {
if (presentationTimeUs == C.TIME_UNSET) { if (presentationTimeUs == C.TIME_UNSET) {

View File

@ -20,10 +20,10 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.common.util.Util.SDK_INT; import static androidx.media3.common.util.Util.SDK_INT;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VFP;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_RECEIVE_END_OF_INPUT; import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_RECEIVE_END_OF_INPUT;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_REGISTER_NEW_INPUT_STREAM; import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_REGISTER_NEW_INPUT_STREAM;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_SIGNAL_ENDED; import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_SIGNAL_ENDED;
import static androidx.media3.effect.DebugTraceUtil.logEvent;
import static com.google.common.collect.Iterables.getFirst; import static com.google.common.collect.Iterables.getFirst;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
@ -427,7 +427,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
() -> { () -> {
if (inputStreamEnded) { if (inputStreamEnded) {
listenerExecutor.execute(listener::onEnded); listenerExecutor.execute(listener::onEnded);
logEvent(EVENT_VFP_SIGNAL_ENDED, C.TIME_END_OF_SOURCE); DebugTraceUtil.logEvent(COMPONENT_VFP, EVENT_VFP_SIGNAL_ENDED, C.TIME_END_OF_SOURCE);
} else { } else {
synchronized (lock) { synchronized (lock) {
if (pendingInputStreamInfo != null) { if (pendingInputStreamInfo != null) {
@ -535,7 +535,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
@InputType int inputType, List<Effect> effects, FrameInfo frameInfo) { @InputType int inputType, List<Effect> effects, FrameInfo frameInfo) {
// This method is only called after all samples in the current input stream are registered or // This method is only called after all samples in the current input stream are registered or
// queued. // queued.
logEvent( DebugTraceUtil.logEvent(
COMPONENT_VFP,
EVENT_VFP_REGISTER_NEW_INPUT_STREAM, EVENT_VFP_REGISTER_NEW_INPUT_STREAM,
/* presentationTimeUs= */ frameInfo.offsetToAddUs, /* presentationTimeUs= */ frameInfo.offsetToAddUs,
/* extraFormat= */ "InputType %s - %dx%d", /* extraFormat= */ "InputType %s - %dx%d",
@ -621,7 +622,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
@Override @Override
public void signalEndOfInput() { public void signalEndOfInput() {
logEvent(EVENT_VFP_RECEIVE_END_OF_INPUT, C.TIME_END_OF_SOURCE); DebugTraceUtil.logEvent(COMPONENT_VFP, EVENT_VFP_RECEIVE_END_OF_INPUT, C.TIME_END_OF_SOURCE);
checkState(!inputStreamEnded); checkState(!inputStreamEnded);
inputStreamEnded = true; inputStreamEnded = true;
inputSwitcher.signalEndOfInputStream(); inputSwitcher.signalEndOfInputStream();

View File

@ -19,6 +19,11 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.common.util.Util.isRunningOnEmulator; import static androidx.media3.common.util.Util.isRunningOnEmulator;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_EXTERNAL_TEXTURE_MANAGER;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VFP;
import static androidx.media3.effect.DebugTraceUtil.EVENT_EXTERNAL_TEXTURE_MANAGER_SIGNAL_EOS;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_QUEUE_FRAME;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_SURFACE_TEXTURE_INPUT;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
@ -126,7 +131,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
videoFrameProcessingTaskExecutor.submit( videoFrameProcessingTaskExecutor.submit(
() -> { () -> {
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_VFP_SURFACE_TEXTURE_INPUT, C.TIME_UNSET); COMPONENT_VFP, EVENT_VFP_SURFACE_TEXTURE_INPUT, C.TIME_UNSET);
if (shouldRejectIncomingFrames) { if (shouldRejectIncomingFrames) {
surfaceTexture.updateTexImage(); surfaceTexture.updateTexImage();
Log.w( Log.w(
@ -201,7 +206,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
currentInputStreamEnded = false; currentInputStreamEnded = false;
checkNotNull(externalShaderProgram).signalEndOfCurrentInputStream(); checkNotNull(externalShaderProgram).signalEndOfCurrentInputStream();
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_EXTERNAL_TEXTURE_MANAGER_SIGNAL_EOS, C.TIME_END_OF_SOURCE); COMPONENT_EXTERNAL_TEXTURE_MANAGER,
EVENT_EXTERNAL_TEXTURE_MANAGER_SIGNAL_EOS,
C.TIME_END_OF_SOURCE);
cancelForceSignalEndOfStreamTimer(); cancelForceSignalEndOfStreamTimer();
} else { } else {
maybeQueueFrameToExternalShaderProgram(); maybeQueueFrameToExternalShaderProgram();
@ -246,7 +253,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (pendingFrames.isEmpty() && currentFrame == null) { if (pendingFrames.isEmpty() && currentFrame == null) {
checkNotNull(externalShaderProgram).signalEndOfCurrentInputStream(); checkNotNull(externalShaderProgram).signalEndOfCurrentInputStream();
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_EXTERNAL_TEXTURE_MANAGER_SIGNAL_EOS, C.TIME_END_OF_SOURCE); COMPONENT_EXTERNAL_TEXTURE_MANAGER,
EVENT_EXTERNAL_TEXTURE_MANAGER_SIGNAL_EOS,
C.TIME_END_OF_SOURCE);
cancelForceSignalEndOfStreamTimer(); cancelForceSignalEndOfStreamTimer();
} else { } else {
currentInputStreamEnded = true; currentInputStreamEnded = true;
@ -376,7 +385,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (!repeatLastRegisteredFrame) { if (!repeatLastRegisteredFrame) {
checkStateNotNull(pendingFrames.remove()); checkStateNotNull(pendingFrames.remove());
} }
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_VFP_QUEUE_FRAME, presentationTimeUs); DebugTraceUtil.logEvent(COMPONENT_VFP, EVENT_VFP_QUEUE_FRAME, presentationTimeUs);
// If the queued frame is the last frame, end of stream will be signaled onInputFrameProcessed. // If the queued frame is the last frame, end of stream will be signaled onInputFrameProcessed.
} }
} }

View File

@ -17,6 +17,8 @@ package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VFP;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_RENDERED_TO_OUTPUT_SURFACE;
import static androidx.media3.effect.DefaultVideoFrameProcessor.WORKING_COLOR_SPACE_LINEAR; import static androidx.media3.effect.DefaultVideoFrameProcessor.WORKING_COLOR_SPACE_LINEAR;
import android.content.Context; import android.content.Context;
@ -390,7 +392,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
: renderTimeNs); : renderTimeNs);
EGL14.eglSwapBuffers(eglDisplay, outputEglSurface); EGL14.eglSwapBuffers(eglDisplay, outputEglSurface);
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_VFP_RENDERED_TO_OUTPUT_SURFACE, presentationTimeUs); COMPONENT_VFP, EVENT_VFP_RENDERED_TO_OUTPUT_SURFACE, presentationTimeUs);
} }
private void renderFrameToOutputTexture(GlTextureInfo inputTexture, long presentationTimeUs) private void renderFrameToOutputTexture(GlTextureInfo inputTexture, long presentationTimeUs)

View File

@ -22,9 +22,10 @@ import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.common.util.Util.contains; import static androidx.media3.common.util.Util.contains;
import static androidx.media3.common.util.Util.newSingleThreadScheduledExecutor; import static androidx.media3.common.util.Util.newSingleThreadScheduledExecutor;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_COMPOSITOR;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VFP;
import static androidx.media3.effect.DebugTraceUtil.EVENT_COMPOSITOR_OUTPUT_TEXTURE_RENDERED; import static androidx.media3.effect.DebugTraceUtil.EVENT_COMPOSITOR_OUTPUT_TEXTURE_RENDERED;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_OUTPUT_TEXTURE_RENDERED; import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_OUTPUT_TEXTURE_RENDERED;
import static androidx.media3.effect.DebugTraceUtil.logEvent;
import static androidx.media3.effect.DefaultVideoFrameProcessor.WORKING_COLOR_SPACE_LINEAR; import static androidx.media3.effect.DefaultVideoFrameProcessor.WORKING_COLOR_SPACE_LINEAR;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
@ -320,7 +321,7 @@ public abstract class MultipleInputVideoGraph implements VideoGraph {
GlTextureProducer textureProducer, GlTextureProducer textureProducer,
GlTextureInfo texture, GlTextureInfo texture,
long presentationTimeUs) { long presentationTimeUs) {
logEvent(EVENT_VFP_OUTPUT_TEXTURE_RENDERED, presentationTimeUs); DebugTraceUtil.logEvent(COMPONENT_VFP, EVENT_VFP_OUTPUT_TEXTURE_RENDERED, presentationTimeUs);
checkNotNull(videoCompositor) checkNotNull(videoCompositor)
.queueInputTexture( .queueInputTexture(
videoCompositorInputId, videoCompositorInputId,
@ -339,7 +340,8 @@ public abstract class MultipleInputVideoGraph implements VideoGraph {
long syncObject) { long syncObject) {
checkStateNotNull(compositionVideoFrameProcessor); checkStateNotNull(compositionVideoFrameProcessor);
checkState(!compositorEnded); checkState(!compositorEnded);
logEvent(EVENT_COMPOSITOR_OUTPUT_TEXTURE_RENDERED, presentationTimeUs); DebugTraceUtil.logEvent(
COMPONENT_COMPOSITOR, EVENT_COMPOSITOR_OUTPUT_TEXTURE_RENDERED, presentationTimeUs);
compositorOutputTextures.add( compositorOutputTextures.add(
new CompositorOutputTextureInfo(outputTexture, presentationTimeUs)); new CompositorOutputTextureInfo(outputTexture, presentationTimeUs));

View File

@ -16,6 +16,10 @@
package androidx.media3.effect; package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_TEX_ID_TEXTURE_MANAGER;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VFP;
import static androidx.media3.effect.DebugTraceUtil.EVENT_TEX_ID_TEXTURE_MANAGER_SIGNAL_EOS;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VFP_QUEUE_TEXTURE;
import android.opengl.GLES10; import android.opengl.GLES10;
import androidx.media3.common.C; import androidx.media3.common.C;
@ -86,7 +90,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
frameInfo.height); frameInfo.height);
checkNotNull(frameConsumptionManager).queueInputFrame(inputTexture, presentationTimeUs); checkNotNull(frameConsumptionManager).queueInputFrame(inputTexture, presentationTimeUs);
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_VFP_QUEUE_TEXTURE, COMPONENT_VFP,
EVENT_VFP_QUEUE_TEXTURE,
presentationTimeUs, presentationTimeUs,
/* extraFormat= */ "%dx%d", /* extraFormat= */ "%dx%d",
/* extraArgs...= */ frameInfo.width, /* extraArgs...= */ frameInfo.width,
@ -115,7 +120,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
() -> { () -> {
checkNotNull(frameConsumptionManager).signalEndOfCurrentStream(); checkNotNull(frameConsumptionManager).signalEndOfCurrentStream();
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_TEX_ID_TEXTURE_MANAGER_SIGNAL_EOS, C.TIME_END_OF_SOURCE); COMPONENT_TEX_ID_TEXTURE_MANAGER,
EVENT_TEX_ID_TEXTURE_MANAGER_SIGNAL_EOS,
C.TIME_END_OF_SOURCE);
}); });
} }

View File

@ -21,6 +21,10 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.common.util.Util.SDK_INT; import static androidx.media3.common.util.Util.SDK_INT;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_DECODER;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_ENCODER;
import static androidx.media3.effect.DebugTraceUtil.EVENT_DECODER_RECEIVE_EOS;
import static androidx.media3.effect.DebugTraceUtil.EVENT_ENCODER_RECEIVE_EOS;
import android.content.Context; import android.content.Context;
import android.media.MediaCodec; import android.media.MediaCodec;
@ -220,7 +224,8 @@ public final class DefaultCodec implements Codec {
if (isDecoder) { if (isDecoder) {
if (isVideo) { if (isVideo) {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_DECODER_RECEIVE_EOS, C.TIME_END_OF_SOURCE); DebugTraceUtil.logEvent(
COMPONENT_DECODER, EVENT_DECODER_RECEIVE_EOS, C.TIME_END_OF_SOURCE);
} }
// EOS buffer on the decoder input should never carry data. // EOS buffer on the decoder input should never carry data.
checkState(inputBuffer.data == null || !inputBuffer.data.hasRemaining()); checkState(inputBuffer.data == null || !inputBuffer.data.hasRemaining());
@ -241,7 +246,7 @@ public final class DefaultCodec implements Codec {
@Override @Override
public void signalEndOfInputStream() throws ExportException { public void signalEndOfInputStream() throws ExportException {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_ENCODER_RECEIVE_EOS, C.TIME_END_OF_SOURCE); DebugTraceUtil.logEvent(COMPONENT_ENCODER, EVENT_ENCODER_RECEIVE_EOS, C.TIME_END_OF_SOURCE);
try { try {
mediaCodec.signalEndOfInputStream(); mediaCodec.signalEndOfInputStream();
} catch (RuntimeException e) { } catch (RuntimeException e) {

View File

@ -17,6 +17,11 @@ package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkStateNotNull; import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_DECODER;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_VIDEO;
import static androidx.media3.effect.DebugTraceUtil.EVENT_DECODER_DECODED_FRAME;
import static androidx.media3.effect.DebugTraceUtil.EVENT_DECODER_SIGNAL_EOS;
import static androidx.media3.effect.DebugTraceUtil.EVENT_VIDEO_INPUT_FORMAT;
import static androidx.media3.transformer.TransformerUtil.getDecoderOutputColor; import static androidx.media3.transformer.TransformerUtil.getDecoderOutputColor;
import android.media.MediaCodec; import android.media.MediaCodec;
@ -86,7 +91,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@Override @Override
protected void onInputFormatRead(Format inputFormat) { protected void onInputFormatRead(Format inputFormat) {
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_VIDEO_INPUT_FORMAT, COMPONENT_VIDEO,
EVENT_VIDEO_INPUT_FORMAT,
C.TIME_UNSET, C.TIME_UNSET,
/* extraFormat= */ "%s", /* extraFormat= */ "%s",
/* extraArgs...= */ inputFormat); /* extraArgs...= */ inputFormat);
@ -151,7 +157,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@RequiresNonNull({"sampleConsumer", "decoder"}) @RequiresNonNull({"sampleConsumer", "decoder"})
protected boolean feedConsumerFromDecoder() throws ExportException { protected boolean feedConsumerFromDecoder() throws ExportException {
if (decoder.isEnded()) { if (decoder.isEnded()) {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_DECODER_SIGNAL_EOS, C.TIME_END_OF_SOURCE); DebugTraceUtil.logEvent(COMPONENT_DECODER, EVENT_DECODER_SIGNAL_EOS, C.TIME_END_OF_SOURCE);
sampleConsumer.signalEndOfVideoInput(); sampleConsumer.signalEndOfVideoInput();
isEnded = true; isEnded = true;
return false; return false;
@ -178,7 +184,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
decoder.releaseOutputBuffer(presentationTimeUs); decoder.releaseOutputBuffer(presentationTimeUs);
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_DECODER_DECODED_FRAME, presentationTimeUs); DebugTraceUtil.logEvent(COMPONENT_DECODER, EVENT_DECODER_DECODED_FRAME, presentationTimeUs);
return true; return true;
} }

View File

@ -24,6 +24,13 @@ import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.common.util.Util.areEqual; import static androidx.media3.common.util.Util.areEqual;
import static androidx.media3.common.util.Util.contains; import static androidx.media3.common.util.Util.contains;
import static androidx.media3.common.util.Util.usToMs; import static androidx.media3.common.util.Util.usToMs;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_MUXER;
import static androidx.media3.effect.DebugTraceUtil.EVENT_MUXER_CAN_WRITE_SAMPLE_AUDIO;
import static androidx.media3.effect.DebugTraceUtil.EVENT_MUXER_CAN_WRITE_SAMPLE_VIDEO;
import static androidx.media3.effect.DebugTraceUtil.EVENT_MUXER_TRACK_ENDED_AUDIO;
import static androidx.media3.effect.DebugTraceUtil.EVENT_MUXER_TRACK_ENDED_VIDEO;
import static androidx.media3.effect.DebugTraceUtil.EVENT_MUXER_WRITE_SAMPLE_AUDIO;
import static androidx.media3.effect.DebugTraceUtil.EVENT_MUXER_WRITE_SAMPLE_VIDEO;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
@ -524,7 +531,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
boolean canWriteSample = canWriteSample(trackType, presentationTimeUs); boolean canWriteSample = canWriteSample(trackType, presentationTimeUs);
if (trackType == C.TRACK_TYPE_VIDEO) { if (trackType == C.TRACK_TYPE_VIDEO) {
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_MUXER_CAN_WRITE_SAMPLE_VIDEO, COMPONENT_MUXER,
EVENT_MUXER_CAN_WRITE_SAMPLE_VIDEO,
presentationTimeUs, presentationTimeUs,
/* extraFormat= */ "%s", /* extraFormat= */ "%s",
/* extraArgs...= */ canWriteSample); /* extraArgs...= */ canWriteSample);
@ -533,7 +541,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
} else if (trackType == C.TRACK_TYPE_AUDIO) { } else if (trackType == C.TRACK_TYPE_AUDIO) {
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_MUXER_CAN_WRITE_SAMPLE_AUDIO, COMPONENT_MUXER,
EVENT_MUXER_CAN_WRITE_SAMPLE_AUDIO,
presentationTimeUs, presentationTimeUs,
/* extraFormat= */ "%s", /* extraFormat= */ "%s",
/* extraArgs...= */ canWriteSample); /* extraArgs...= */ canWriteSample);
@ -563,9 +572,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
TransformerUtil.getMediaCodecFlags(isKeyFrame ? C.BUFFER_FLAG_KEY_FRAME : 0)); TransformerUtil.getMediaCodecFlags(isKeyFrame ? C.BUFFER_FLAG_KEY_FRAME : 0));
muxer.writeSampleData(trackInfo.trackToken, data, bufferInfo); muxer.writeSampleData(trackInfo.trackToken, data, bufferInfo);
if (trackType == C.TRACK_TYPE_VIDEO) { if (trackType == C.TRACK_TYPE_VIDEO) {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_MUXER_WRITE_SAMPLE_VIDEO, presentationTimeUs); DebugTraceUtil.logEvent(COMPONENT_MUXER, EVENT_MUXER_WRITE_SAMPLE_VIDEO, presentationTimeUs);
} else if (trackType == C.TRACK_TYPE_AUDIO) { } else if (trackType == C.TRACK_TYPE_AUDIO) {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_MUXER_WRITE_SAMPLE_AUDIO, presentationTimeUs); DebugTraceUtil.logEvent(COMPONENT_MUXER, EVENT_MUXER_WRITE_SAMPLE_AUDIO, presentationTimeUs);
} }
previousTrackType = trackType; previousTrackType = trackType;
return true; return true;
@ -587,9 +596,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
listener.onTrackEnded( listener.onTrackEnded(
trackType, trackInfo.format, trackInfo.getAverageBitrate(), trackInfo.sampleCount); trackType, trackInfo.format, trackInfo.getAverageBitrate(), trackInfo.sampleCount);
if (trackType == C.TRACK_TYPE_VIDEO) { if (trackType == C.TRACK_TYPE_VIDEO) {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_MUXER_TRACK_ENDED_VIDEO, trackInfo.timeUs); DebugTraceUtil.logEvent(COMPONENT_MUXER, EVENT_MUXER_TRACK_ENDED_VIDEO, trackInfo.timeUs);
} else if (trackType == C.TRACK_TYPE_AUDIO) { } else if (trackType == C.TRACK_TYPE_AUDIO) {
DebugTraceUtil.logEvent(DebugTraceUtil.EVENT_MUXER_TRACK_ENDED_AUDIO, trackInfo.timeUs); DebugTraceUtil.logEvent(COMPONENT_MUXER, EVENT_MUXER_TRACK_ENDED_AUDIO, trackInfo.timeUs);
} }
if (muxerMode == MUXER_MODE_MUX_PARTIAL) { if (muxerMode == MUXER_MODE_MUX_PARTIAL) {

View File

@ -24,6 +24,8 @@ import static androidx.media3.common.ColorInfo.SRGB_BT709_FULL;
import static androidx.media3.common.ColorInfo.isTransferHdr; import static androidx.media3.common.ColorInfo.isTransferHdr;
import static androidx.media3.common.util.Assertions.checkArgument; import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.effect.DebugTraceUtil.COMPONENT_ENCODER;
import static androidx.media3.effect.DebugTraceUtil.EVENT_ENCODER_ENCODED_FRAME;
import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR; import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR;
import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL; import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL;
import static androidx.media3.transformer.TransformerUtil.getOutputMimeTypeAndHdrModeAfterFallback; import static androidx.media3.transformer.TransformerUtil.getOutputMimeTypeAndHdrModeAfterFallback;
@ -194,7 +196,7 @@ import org.checkerframework.dataflow.qual.Pure;
} }
} }
DebugTraceUtil.logEvent( DebugTraceUtil.logEvent(
DebugTraceUtil.EVENT_ENCODER_ENCODED_FRAME, bufferInfo.presentationTimeUs); COMPONENT_ENCODER, EVENT_ENCODER_ENCODED_FRAME, bufferInfo.presentationTimeUs);
encoderOutputBuffer.timeUs = bufferInfo.presentationTimeUs; encoderOutputBuffer.timeUs = bufferInfo.presentationTimeUs;
encoderOutputBuffer.setFlags(bufferInfo.flags); encoderOutputBuffer.setFlags(bufferInfo.flags);
return encoderOutputBuffer; return encoderOutputBuffer;