Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efb8cd13 authored by Wei Jia's avatar Wei Jia
Browse files

MediaTimestamp: add Builder

Test: cts
Bug: 112549021
Change-Id: I696fea67407c5a9b8fd4e2e17ac88c26be05a157
parent 1f7d4274
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -2919,6 +2919,13 @@ package android.media {
    field public static final int RADIO_TUNER = 1998; // 0x7ce
    field public static final int RADIO_TUNER = 1998; // 0x7ce
  }
  }


  public static class MediaTimestamp.Builder {
    ctor public MediaTimestamp.Builder();
    ctor public MediaTimestamp.Builder(android.media.MediaTimestamp);
    method public android.media.MediaTimestamp build();
    method public android.media.MediaTimestamp.Builder setMediaTimestamp(long, long, float);
  }

  public class PlayerProxy {
  public class PlayerProxy {
    method public void pause();
    method public void pause();
    method public void setPan(float);
    method public void setPan(float);
@@ -2939,7 +2946,7 @@ package android.media {
    ctor public TimedMetaData.Builder();
    ctor public TimedMetaData.Builder();
    ctor public TimedMetaData.Builder(android.media.TimedMetaData);
    ctor public TimedMetaData.Builder(android.media.TimedMetaData);
    method public android.media.TimedMetaData build();
    method public android.media.TimedMetaData build();
    method public android.media.TimedMetaData.Builder setTimedMetaData(int, byte[]);
    method public android.media.TimedMetaData.Builder setTimedMetaData(long, byte[]);
  }
  }


}
}
+18 −12
Original line number Original line Diff line number Diff line
@@ -1713,10 +1713,12 @@ public class MediaPlayer2 implements AutoCloseable
    public MediaTimestamp getTimestamp() {
    public MediaTimestamp getTimestamp() {
        try {
        try {
            // TODO: get the timestamp from native side
            // TODO: get the timestamp from native side
            return new MediaTimestamp(
            return new MediaTimestamp.Builder()
                    .setMediaTimestamp(
                        getCurrentPosition() * 1000L,
                        getCurrentPosition() * 1000L,
                        System.nanoTime(),
                        System.nanoTime(),
                    getState() == PLAYER_STATE_PLAYING ? getPlaybackParams().getSpeed() : 0.f);
                        getState() == PLAYER_STATE_PLAYING ? getPlaybackParams().getSpeed() : 0.f)
                    .build();
        } catch (IllegalStateException e) {
        } catch (IllegalStateException e) {
            return null;
            return null;
        }
        }
@@ -2400,11 +2402,13 @@ public class MediaPlayer2 implements AutoCloseable
                            return;
                            return;
                        }
                        }
                        Iterator<Value> in = playerMsg.getValuesList().iterator();
                        Iterator<Value> in = playerMsg.getValuesList().iterator();
                        SubtitleData data = new SubtitleData(
                        SubtitleData data = new SubtitleData.Builder()
                                .setSubtitleData(
                                    in.next().getInt32Value(),  // trackIndex
                                    in.next().getInt32Value(),  // trackIndex
                                    in.next().getInt64Value(),  // startTimeUs
                                    in.next().getInt64Value(),  // startTimeUs
                                    in.next().getInt64Value(),  // durationUs
                                    in.next().getInt64Value(),  // durationUs
                                in.next().getBytesValue().toByteArray());  // data
                                    in.next().getBytesValue().toByteArray())  // data
                                .build();
                        sendEvent(new EventNotifier() {
                        sendEvent(new EventNotifier() {
                            @Override
                            @Override
                            public void notify(EventCallback callback) {
                            public void notify(EventCallback callback) {
@@ -2428,9 +2432,11 @@ public class MediaPlayer2 implements AutoCloseable
                            return;
                            return;
                        }
                        }
                        Iterator<Value> in = playerMsg.getValuesList().iterator();
                        Iterator<Value> in = playerMsg.getValuesList().iterator();
                        data = new TimedMetaData(
                        data = new TimedMetaData.Builder()
                                .setTimedMetaData(
                                    in.next().getInt64Value(),  // timestampUs
                                    in.next().getInt64Value(),  // timestampUs
                                in.next().getBytesValue().toByteArray());  // metaData
                                    in.next().getBytesValue().toByteArray())  // metaData
                                .build();
                    } else {
                    } else {
                        data = null;
                        data = null;
                    }
                    }
+70 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,9 @@


package android.media;
package android.media;


import android.annotation.NonNull;
import android.annotation.SystemApi;

/**
/**
 * An immutable object that represents the linear correlation between the media time
 * An immutable object that represents the linear correlation between the media time
 * and the system time. It contains the media clock rate, together with the media timestamp
 * and the system time. It contains the media clock rate, together with the media timestamp
@@ -117,4 +120,71 @@ public final class MediaTimestamp
                + " clockRate=" + clockRate
                + " clockRate=" + clockRate
                + "}";
                + "}";
    }
    }

    /**
     * Builder class for {@link MediaTimestamp} objects.
     * <p> Here is an example where <code>Builder</code> is used to define the
     * {@link MediaTimestamp}:
     *
     * <pre class="prettyprint">
     * MediaTimestamp mts = new MediaTimestamp.Builder()
     *         .setMediaTimestamp(mediaTime, systemTime, rate)
     *         .build();
     * </pre>
     * @hide
     */
    @SystemApi
    public static class Builder {
        long mMediaTimeUs;
        long mNanoTime;
        float mClockRate = 1.0f;

        /**
         * Constructs a new Builder with the defaults.
         */
        public Builder() {
        }

        /**
         * Constructs a new Builder from a given {@link MediaTimestamp} instance
         * @param mts the {@link MediaTimestamp} object whose data will be reused
         * in the new Builder.
         */
        public Builder(@NonNull MediaTimestamp mts) {
            if (mts == null) {
                throw new IllegalArgumentException("null MediaTimestamp is not allowed");
            }
            mMediaTimeUs = mts.mediaTimeUs;
            mNanoTime = mts.nanoTime;
            mClockRate = mts.clockRate;
        }

        /**
         * Combines all of the fields that have been set and return a new
         * {@link MediaTimestamp} object.
         *
         * @return a new {@link MediaTimestamp} object
         */
        public @NonNull MediaTimestamp build() {
            return new MediaTimestamp(mMediaTimeUs, mNanoTime, mClockRate);
        }

        /**
         * Sets the info of media timestamp.
         *
         * @param mediaTimeUs the media time of the anchor in microseconds
         * @param nanoTime the {@link java.lang.System#nanoTime system time} corresponding to
         *     the media time in nanoseconds.
         * @param clockRate the rate of the media clock in relation to the system time.
         * @return the same Builder instance.
         */
        public @NonNull Builder setMediaTimestamp(
                long mediaTimeUs, long nanoTime, float clockRate) {
            mMediaTimeUs = mediaTimeUs;
            mNanoTime = nanoTime;
            mClockRate = clockRate;

            return this;
        }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -148,7 +148,7 @@ public final class TimedMetaData {
         *     It should not be null.
         *     It should not be null.
         * @return the same Builder instance.
         * @return the same Builder instance.
         */
         */
        public @NonNull Builder setTimedMetaData(int timestamp, @NonNull byte[] metaData) {
        public @NonNull Builder setTimedMetaData(long timestamp, @NonNull byte[] metaData) {
            if (metaData == null) {
            if (metaData == null) {
                throw new IllegalArgumentException("null metaData is not allowed");
                throw new IllegalArgumentException("null metaData is not allowed");
            }
            }