From 8281ed6f8295e87a9affca17808947a78c346f0b Mon Sep 17 00:00:00 2001 From: shubang Date: Wed, 9 Dec 2020 17:44:28 -0800 Subject: [PATCH] Add PlaybackComponent interface And use it for MediaCodec as an example. Test: mmm Bug: 167036690 Change-Id: Idfea3876d413c3d8d3d6e153e716687e79815d95 --- media/java/android/media/MediaCodec.java | 22 +++++++++++- .../media/metrics/PlaybackComponent.java | 36 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 media/java/android/media/metrics/PlaybackComponent.java diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index ae97a71bd93a3..607c8f11e01a1 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -25,6 +25,7 @@ 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; @@ -1538,7 +1539,8 @@ import java.util.concurrent.locks.ReentrantLock; */ -final public class MediaCodec { +final public class MediaCodec implements PlaybackComponent { + /** * Per buffer metadata includes an offset and size specifying * the range of valid data in the associated codec (output) buffer. @@ -1680,6 +1682,7 @@ final public class MediaCodec { private MediaCodecInfo mCodecInfo; private final Object mCodecInfoLock = new Object(); private MediaCrypto mCrypto; + private String mPlaybackId; private static final int EVENT_CALLBACK = 1; private static final int EVENT_SET_CALLBACK = 2; @@ -1690,6 +1693,23 @@ final public class MediaCodec { private static final int CB_ERROR = 3; 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/metrics/PlaybackComponent.java b/media/java/android/media/metrics/PlaybackComponent.java new file mode 100644 index 0000000000000..625dd0a1870d2 --- /dev/null +++ b/media/java/android/media/metrics/PlaybackComponent.java @@ -0,0 +1,36 @@ +/* + * 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. + * @hide + */ +public interface PlaybackComponent { + + /** + * Sets the playback ID of the component. + */ + void setPlaybackId(@NonNull String playbackId); + + /** + * Gets playback ID. + */ + @NonNull String getPlaybackId(); +}