diff --git a/core/api/current.txt b/core/api/current.txt index de8a10d467c1b..3af4394bab9da 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -20899,8 +20899,11 @@ package android.media { method public void onRoutingChanged(android.media.AudioRouting); } - public final class AudioTimestamp { + public final class AudioTimestamp implements android.os.Parcelable { ctor public AudioTimestamp(); + method public int describeContents(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; field public static final int TIMEBASE_BOOTTIME = 1; // 0x1 field public static final int TIMEBASE_MONOTONIC = 0; // 0x0 field public long framePosition; diff --git a/media/java/android/media/AudioTimestamp.aidl b/media/java/android/media/AudioTimestamp.aidl new file mode 100644 index 0000000000000..2c161b319de19 --- /dev/null +++ b/media/java/android/media/AudioTimestamp.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2022 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; + +parcelable AudioTimestamp; diff --git a/media/java/android/media/AudioTimestamp.java b/media/java/android/media/AudioTimestamp.java index be8ca151580db..a3277e53ea70d 100644 --- a/media/java/android/media/AudioTimestamp.java +++ b/media/java/android/media/AudioTimestamp.java @@ -16,11 +16,14 @@ package android.media; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.os.Parcel; +import android.os.Parcelable; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import android.annotation.IntDef; - /** * Structure that groups a position in frame units relative to an assumed audio stream, * together with the estimated time when that frame enters or leaves the audio @@ -33,8 +36,7 @@ import android.annotation.IntDef; * @see AudioTrack#getTimestamp AudioTrack.getTimestamp(AudioTimestamp) * @see AudioRecord#getTimestamp AudioRecord.getTimestamp(AudioTimestamp, int) */ -public final class AudioTimestamp -{ +public final class AudioTimestamp implements Parcelable { /** * Clock monotonic or its equivalent on the system, * in the same units and timebase as {@link java.lang.System#nanoTime}. @@ -86,4 +88,47 @@ public final class AudioTimestamp * with a timebase of {@link #TIMEBASE_MONOTONIC}. */ public long nanoTime; + + public AudioTimestamp() { + } + + private AudioTimestamp(@NonNull Parcel in) { + framePosition = in.readLong(); + nanoTime = in.readLong(); + } + + @Override + public String toString() { + return "AudioTimeStamp:" + + " framePos=" + framePosition + + " nanoTime=" + nanoTime; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeLong(framePosition); + dest.writeLong(nanoTime); + } + + @Override + public int describeContents() { + return 0; + } + + /** + * Creates an instance from a {@link Parcel}. + */ + @NonNull + public static final Creator CREATOR = new Creator<>() { + @Override + public AudioTimestamp createFromParcel(@NonNull Parcel in) { + return new AudioTimestamp(in); + } + + @Override + public AudioTimestamp[] newArray(int size) { + return new AudioTimestamp[size]; + } + }; } +