summaryrefslogtreecommitdiff
path: root/media/java/android
diff options
context:
space:
mode:
authorshubang <shubang@google.com>2021-03-18 07:10:22 -0700
committershubang <shubang@google.com>2021-03-23 22:49:42 -0700
commitc56cc00ab8f98fb93e9039248fa252ace2c2465b (patch)
treec10964cc2206eb83600bd36d01ad919092998090 /media/java/android
parentdc2a0a63f908e263af28a03749cdb40e03f094ef (diff)
Change session ID string to ID object
Based on API review feedback from jmtrivi@ to reduce unexpected usage of the APIs. And add some stub APIs Reference CLs: MediaDrm ag/13835091 by robertshih@ MediaExtractor: ag/13607751 by aquilescanta@ MediaParser: ag/13714647 by aquilescanta@ MediaRecorder: ag/13545885 by dichenzhang@ AudioTrack & AudioRecord: ag/13712857 by hunga@ Bug: 183095725 Test: pending CTS CTS-Coverage-Bug: 183366721 Change-Id: I931edf021a5ec6b27a25bc6142a129b92da0fc9a Merged-In: I931edf021a5ec6b27a25bc6142a129b92da0fc9a
Diffstat (limited to 'media/java/android')
-rw-r--r--media/java/android/media/AudioRecord.java33
-rw-r--r--media/java/android/media/AudioTrack.java33
-rw-r--r--media/java/android/media/MediaCodec.java19
-rw-r--r--media/java/android/media/MediaDrm.java42
-rw-r--r--media/java/android/media/MediaExtractor.java21
-rw-r--r--media/java/android/media/MediaRecorder.java24
-rw-r--r--media/java/android/media/metrics/LogSessionId.java30
-rw-r--r--media/java/android/media/metrics/PlaybackComponent.java35
8 files changed, 142 insertions, 95 deletions
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index 0d613992f300..3399377be999 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -32,6 +32,7 @@ import android.content.Context;
import android.media.MediaRecorder.Source;
import android.media.audiopolicy.AudioMix;
import android.media.audiopolicy.AudioPolicy;
+import android.media.metrics.LogSessionId;
import android.media.permission.Identity;
import android.media.projection.MediaProjection;
import android.os.Binder;
@@ -282,9 +283,9 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
/**
* The log session id used for metrics.
- * A null or empty string here means it is not set.
+ * {@link LogSessionId#LOG_SESSION_ID_NONE} here means it is not set.
*/
- private String mLogSessionId;
+ @NonNull private LogSessionId mLogSessionId = LogSessionId.LOG_SESSION_ID_NONE;
//---------------------------------------------------------
// Constructor, Finalize
@@ -1963,24 +1964,34 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
}
/**
- * Sets a string handle to this AudioRecord for metrics collection.
+ * Sets a {@link LogSessionId} instance to this AudioRecord for metrics collection.
*
- * @param logSessionId a string which is used to identify this object
- * to the metrics service. Proper generated Ids must be obtained
- * from the Java metrics service and should be considered opaque.
- * Use null to remove the logSessionId association.
+ * @param logSessionId a {@link LogSessionId} instance which is used to
+ * identify this object to the metrics service. Proper generated
+ * Ids must be obtained from the Java metrics service and should
+ * be considered opaque. Use
+ * {@link LogSessionId#LOG_SESSION_ID_NONE} to remove the
+ * logSessionId association.
* @throws IllegalStateException if AudioRecord not initialized.
- *
- * @hide
*/
- public void setLogSessionId(@Nullable String logSessionId) {
+ public void setLogSessionId(@NonNull LogSessionId logSessionId) {
+ Objects.requireNonNull(logSessionId);
if (mState == STATE_UNINITIALIZED) {
throw new IllegalStateException("AudioRecord not initialized");
}
- native_setLogSessionId(logSessionId);
+ String stringId = logSessionId.getStringId();
+ native_setLogSessionId(stringId);
mLogSessionId = logSessionId;
}
+ /**
+ * Returns the {@link LogSessionId}.
+ */
+ @NonNull
+ public LogSessionId getLogSessionId() {
+ return mLogSessionId;
+ }
+
//---------------------------------------------------------
// Interface definitions
//--------------------
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index bccefdfd7b96..7a2b022b514a 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -26,6 +26,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
+import android.media.metrics.LogSessionId;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
@@ -45,6 +46,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.NioUtils;
import java.util.LinkedList;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -567,9 +569,9 @@ public class AudioTrack extends PlayerBase
/**
* The log session id used for metrics.
- * A null or empty string here means it is not set.
+ * {@link LogSessionId#LOG_SESSION_ID_NONE} here means it is not set.
*/
- private String mLogSessionId;
+ @NonNull private LogSessionId mLogSessionId = LogSessionId.LOG_SESSION_ID_NONE;
//--------------------------------
// Used exclusively by native code
@@ -4044,24 +4046,35 @@ public class AudioTrack extends PlayerBase
}
/**
- * Sets a string handle to this AudioTrack for metrics collection.
+ * Sets a {@link LogSessionId} instance to this AudioTrack for metrics collection.
*
- * @param logSessionId a string which is used to identify this object
- * to the metrics service. Proper generated Ids must be obtained
- * from the Java metrics service and should be considered opaque.
- * Use null to remove the logSessionId association.
+ * @param logSessionId a {@link LogSessionId} instance which is used to
+ * identify this object to the metrics service. Proper generated
+ * Ids must be obtained from the Java metrics service and should
+ * be considered opaque. Use
+ * {@link LogSessionId#LOG_SESSION_ID_NONE} to remove the
+ * logSessionId association.
* @throws IllegalStateException if AudioTrack not initialized.
*
- * @hide
*/
- public void setLogSessionId(@Nullable String logSessionId) {
+ public void setLogSessionId(@NonNull LogSessionId logSessionId) {
+ Objects.requireNonNull(logSessionId);
if (mState == STATE_UNINITIALIZED) {
throw new IllegalStateException("track not initialized");
}
- native_setLogSessionId(logSessionId);
+ String stringId = logSessionId.getStringId();
+ native_setLogSessionId(stringId);
mLogSessionId = logSessionId;
}
+ /**
+ * Returns the {@link LogSessionId}.
+ */
+ @NonNull
+ public LogSessionId getLogSessionId() {
+ return mLogSessionId;
+ }
+
//---------------------------------------------------------
// Inner classes
//--------------------
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java
index a7e2b65ebb8f..8db75d6ec2b1 100644
--- a/media/java/android/media/MediaCodec.java
+++ b/media/java/android/media/MediaCodec.java
@@ -25,7 +25,6 @@ import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.hardware.HardwareBuffer;
import android.media.MediaCodecInfo.CodecCapabilities;
-import android.media.metrics.PlaybackComponent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -1539,7 +1538,7 @@ import java.util.concurrent.locks.ReentrantLock;
</tbody>
</table>
*/
-final public class MediaCodec implements PlaybackComponent {
+final public class MediaCodec {
/**
* Per buffer metadata includes an offset and size specifying
@@ -1697,22 +1696,6 @@ final public class MediaCodec implements PlaybackComponent {
private static final int CB_OUTPUT_FORMAT_CHANGE = 4;
- /**
- * @hide
- */
- @Override
- public void setPlaybackId(@NonNull String playbackId) {
- // TODO: add a native method to pass the ID to the native code for logging.
- mPlaybackId = playbackId;
- }
- /**
- * @hide
- */
- @Override
- public String getPlaybackId() {
- return mPlaybackId;
- }
-
private class EventHandler extends Handler {
private MediaCodec mCodec;
diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java
index ae64c026fb51..10b99dce53b0 100644
--- a/media/java/android/media/MediaDrm.java
+++ b/media/java/android/media/MediaDrm.java
@@ -27,7 +27,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
-import android.media.metrics.PlaybackComponent;
+import android.media.metrics.LogSessionId;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
@@ -50,6 +50,7 @@ import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -1379,7 +1380,7 @@ public final class MediaDrm implements AutoCloseable {
public byte[] openSession(@SecurityLevel int level) throws
NotProvisionedException, ResourceBusyException {
byte[] sessionId = openSessionNative(level);
- mPlaybackComponentMap.put(ByteBuffer.wrap(sessionId), new PlaybackComponentImpl(sessionId));
+ mPlaybackComponentMap.put(ByteBuffer.wrap(sessionId), new PlaybackComponent(sessionId));
return sessionId;
}
@@ -2929,8 +2930,8 @@ public final class MediaDrm implements AutoCloseable {
/**
* Obtain a {@link PlaybackComponent} associated with a DRM session.
- * Call {@link PlaybackComponent#setPlaybackId(String)} on the returned object
- * to associate a playback session with the DRM session.
+ * Call {@link PlaybackComponent#setLogSessionId(LogSessionId)} on
+ * the returned object to associate a playback session with the DRM session.
*
* @param sessionId a DRM session ID obtained from {@link #openSession()}
* @return a {@link PlaybackComponent} associated with the session,
@@ -2945,28 +2946,37 @@ public final class MediaDrm implements AutoCloseable {
return mPlaybackComponentMap.get(ByteBuffer.wrap(sessionId));
}
- private native void setPlaybackId(byte[] sessionId, String playbackId);
+ private native void setPlaybackId(byte[] sessionId, String logSessionId);
- private final class PlaybackComponentImpl implements PlaybackComponent {
+ /** This class contains the Drm session ID and log session ID */
+ public final class PlaybackComponent {
private final byte[] mSessionId;
- private String mPlaybackId = "";
+ @NonNull private LogSessionId mLogSessionId = LogSessionId.LOG_SESSION_ID_NONE;
- public PlaybackComponentImpl(byte[] sessionId) {
+ /** @hide */
+ public PlaybackComponent(byte[] sessionId) {
mSessionId = sessionId;
}
- @Override
- public void setPlaybackId(@NonNull String playbackId) {
- if (playbackId == null) {
+
+ /**
+ * Gets the {@link LogSessionId}.
+ */
+ public void setLogSessionId(@NonNull LogSessionId logSessionId) {
+ Objects.requireNonNull(logSessionId);
+ if (logSessionId.getStringId() == null) {
throw new IllegalArgumentException("playbackId is null");
}
- MediaDrm.this.setPlaybackId(mSessionId, playbackId);
- mPlaybackId = playbackId;
+ MediaDrm.this.setPlaybackId(mSessionId, logSessionId.getStringId());
+ mLogSessionId = logSessionId;
}
- @Override
- @NonNull public String getPlaybackId() {
- return mPlaybackId;
+
+ /**
+ * Returns the {@link LogSessionId}.
+ */
+ @NonNull public LogSessionId getLogSessionId() {
+ return mLogSessionId;
}
}
diff --git a/media/java/android/media/MediaExtractor.java b/media/java/android/media/MediaExtractor.java
index 8f603300dc11..283f1f1d69a2 100644
--- a/media/java/android/media/MediaExtractor.java
+++ b/media/java/android/media/MediaExtractor.java
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
+import android.media.metrics.LogSessionId;
import android.net.Uri;
import android.os.IBinder;
import android.os.IHwBinder;
@@ -40,6 +41,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -73,7 +75,7 @@ import java.util.stream.Collectors;
* <p>This class requires the {@link android.Manifest.permission#INTERNET} permission
* when used with network-based content.
*/
-final public class MediaExtractor {
+public final class MediaExtractor {
public MediaExtractor() {
native_setup();
}
@@ -768,6 +770,22 @@ final public class MediaExtractor {
public native boolean hasCacheReachedEndOfStream();
/**
+ * Sets the {@link LogSessionId} for MediaExtractor.
+ */
+ public void setLogSessionId(@NonNull LogSessionId logSessionId) {
+ mLogSessionId = Objects.requireNonNull(logSessionId);
+ // TODO: implement native_setPlaybackId(playbackId);
+ }
+
+ /**
+ * Returns the {@link LogSessionId} for MediaExtractor.
+ */
+ @NonNull
+ public LogSessionId getLogSessionId() {
+ return mLogSessionId;
+ }
+
+ /**
* Return Metrics data about the current media container.
*
* @return a {@link PersistableBundle} containing the set of attributes and values
@@ -796,6 +814,7 @@ final public class MediaExtractor {
}
private MediaCas mMediaCas;
+ @NonNull private LogSessionId mLogSessionId = LogSessionId.LOG_SESSION_ID_NONE;
private long mNativeContext;
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index dd08d8adf20b..f960ff2b1a7e 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -29,6 +29,7 @@ import android.app.ActivityThread;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.hardware.Camera;
+import android.media.metrics.LogSessionId;
import android.media.permission.Identity;
import android.os.Build;
import android.os.Handler;
@@ -130,6 +131,8 @@ public class MediaRecorder implements AudioRouting,
private int mChannelCount;
+ @NonNull private LogSessionId mLogSessionId = LogSessionId.LOG_SESSION_ID_NONE;
+
/**
* Default constructor.
*
@@ -165,6 +168,27 @@ public class MediaRecorder implements AudioRouting,
}
/**
+ * Sets the {@link LogSessionId} for MediaRecorder.
+ *
+ * @param id the global ID for monitoring the MediaRecorder performance
+ */
+ public void setLogSessionId(@NonNull LogSessionId id) {
+ Objects.requireNonNull(id);
+ mLogSessionId = id;
+ setParameter("log-session-id=" + id.getStringId());
+ }
+
+ /**
+ * Returns the {@link LogSessionId} for MediaRecorder.
+ *
+ * @return the global ID for monitoring the MediaRecorder performance
+ */
+ @NonNull
+ public LogSessionId getLogSessionId() {
+ return mLogSessionId;
+ }
+
+ /**
* Sets a {@link android.hardware.Camera} to use for recording.
*
* <p>Use this function to switch quickly between preview and capture mode without a teardown of
diff --git a/media/java/android/media/metrics/LogSessionId.java b/media/java/android/media/metrics/LogSessionId.java
index f68ef4b68de1..41f30937489b 100644
--- a/media/java/android/media/metrics/LogSessionId.java
+++ b/media/java/android/media/metrics/LogSessionId.java
@@ -17,20 +17,29 @@
package android.media.metrics;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.TestApi;
+import java.util.Objects;
+
/**
* An instances of this class represents the ID of a log session.
*/
public final class LogSessionId {
- private final String mSessionId;
+ @NonNull private final String mSessionId;
- /* package */ LogSessionId(@NonNull String id) {
- mSessionId = id;
- }
+ /**
+ * A {@link LogSessionId} object which is used to clear any existing session ID.
+ */
+ @NonNull public static final LogSessionId LOG_SESSION_ID_NONE = new LogSessionId("");
/** @hide */
@TestApi
+ public LogSessionId(@NonNull String id) {
+ mSessionId = Objects.requireNonNull(id);
+ }
+
+ /** Returns the ID represented by a string. */
@NonNull
public String getStringId() {
return mSessionId;
@@ -40,4 +49,17 @@ public final class LogSessionId {
public String toString() {
return mSessionId;
}
+
+ @Override
+ public boolean equals(@Nullable Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ LogSessionId that = (LogSessionId) o;
+ return Objects.equals(mSessionId, that.mSessionId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mSessionId);
+ }
}
diff --git a/media/java/android/media/metrics/PlaybackComponent.java b/media/java/android/media/metrics/PlaybackComponent.java
deleted file mode 100644
index 1cadf3be38ee..000000000000
--- a/media/java/android/media/metrics/PlaybackComponent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.metrics;
-
-import android.annotation.NonNull;
-
-/**
- * Interface for playback related components used by playback metrics.
- */
-public interface PlaybackComponent {
-
- /**
- * Sets the playback ID of the component.
- */
- void setPlaybackId(@NonNull String playbackId);
-
- /**
- * Gets playback ID.
- */
- @NonNull String getPlaybackId();
-}