Report exporter and muxer names metrics to EditingEndedEvent

Added reporting 2 values from Transformer:

- `exporterName`: name of the package calling for export. Example: "androidx.media3.transformer".
- `muxerName`: name of the muxer used for the export operation. Example: "androidx.media3.muxer".

PiperOrigin-RevId: 714000672
This commit is contained in:
shahddaghash 2025-01-10 04:25:58 -08:00 committed by Copybara-Service
parent f6eb2e6dd5
commit 72a71e8b9c
4 changed files with 35 additions and 4 deletions

View File

@ -100,6 +100,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
private static final int SUCCESS_PROGRESS_PERCENTAGE = 100;
private final String exporterName;
@Nullable private final String muxerName;
private @MonotonicNonNull EditingSession editingSession;
private long startTimeMs;
@ -108,9 +110,16 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
*
* <p>A new instance must be created before starting a new export.
*
* <p>Both {@code exporterName} and {@code muxerName} should follow the format
* "<packageName>:<version>".
*
* @param context The {@link Context}.
* @param exporterName Java package name and version of the library or application implementing
* the editing operation.
* @param muxerName Java package name and version of the library or application that writes to the
* output file.
*/
public EditingMetricsCollector(Context context) {
public EditingMetricsCollector(Context context, String exporterName, @Nullable String muxerName) {
@Nullable
MediaMetricsManager mediaMetricsManager =
(MediaMetricsManager) context.getSystemService(Context.MEDIA_METRICS_SERVICE);
@ -118,6 +127,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
editingSession = checkNotNull(mediaMetricsManager.createEditingSession());
startTimeMs = SystemClock.DEFAULT.elapsedRealtime();
}
this.exporterName = exporterName;
this.muxerName = muxerName;
}
/** Called when export completes with success. */
@ -174,8 +185,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private EditingEndedEvent.Builder createEditingEndedEventBuilder(int finalState) {
long endTimeMs = SystemClock.DEFAULT.elapsedRealtime();
return new EditingEndedEvent.Builder(finalState)
.setTimeSinceCreatedMillis(endTimeMs - startTimeMs);
EditingEndedEvent.Builder editingEndedEventBuilder =
new EditingEndedEvent.Builder(finalState)
.setTimeSinceCreatedMillis(endTimeMs - startTimeMs)
.setExporterName(exporterName);
if (muxerName != null) {
editingEndedEventBuilder.setMuxerName(muxerName);
}
return editingEndedEventBuilder;
}
private static int getEditingEndedEventErrorCode(@ExportException.ErrorCode int errorCode) {

View File

@ -96,6 +96,8 @@ import java.util.Locale;
}
public static final String MUXER_STOPPING_FAILED_ERROR_MESSAGE = "Failed to stop the MediaMuxer";
public static final String MUXER_NAME =
checkNotNull(MediaMuxer.class.getPackage()).getName() + ":" + SDK_INT;
// MediaMuxer supported sample formats are documented in MediaMuxer.addTrack(MediaFormat).
private static final ImmutableList<String> SUPPORTED_VIDEO_SAMPLE_MIME_TYPES =

View File

@ -22,6 +22,7 @@ import android.media.MediaCodec.BufferInfo;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaLibraryInfo;
import androidx.media3.common.Metadata;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Log;
@ -205,6 +206,9 @@ public final class InAppMuxer implements Muxer {
}
}
public static final String MUXER_NAME =
"androidx.media3.media3-muxer:" + MediaLibraryInfo.VERSION;
private static final String TAG = "InAppMuxer";
private static final int TRACK_ID_UNSET = -1;

View File

@ -1580,7 +1580,15 @@ public final class Transformer {
}
DebugTraceUtil.reset();
if (canCollectEditingMetrics()) {
editingMetricsCollector = new EditingMetricsCollector(context);
String exporterName =
checkNotNull(this.getClass().getPackage()).getName() + ":" + MediaLibraryInfo.VERSION;
String muxerName = null;
if (muxerFactory instanceof InAppMuxer.Factory) {
muxerName = InAppMuxer.MUXER_NAME;
} else if (muxerFactory instanceof FrameworkMuxer.Factory) {
muxerName = FrameworkMuxer.MUXER_NAME;
}
editingMetricsCollector = new EditingMetricsCollector(context, exporterName, muxerName);
}
transformerInternal =
new TransformerInternal(