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

Commit fc4fc2c9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MediaTimestamp: add Builder"

parents 70022d9c efb8cd13
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -2925,6 +2925,13 @@ package android.media {
    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 {
    method public void pause();
    method public void setPan(float);
@@ -2945,7 +2952,7 @@ package android.media {
    ctor public TimedMetaData.Builder();
    ctor public TimedMetaData.Builder(android.media.TimedMetaData);
    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 Diff line number Diff line
@@ -1711,10 +1711,12 @@ public class MediaPlayer2 implements AutoCloseable
    public MediaTimestamp getTimestamp() {
        try {
            // TODO: get the timestamp from native side
            return new MediaTimestamp(
            return new MediaTimestamp.Builder()
                    .setMediaTimestamp(
                        getCurrentPosition() * 1000L,
                        System.nanoTime(),
                    getState() == PLAYER_STATE_PLAYING ? getPlaybackParams().getSpeed() : 0.f);
                        getState() == PLAYER_STATE_PLAYING ? getPlaybackParams().getSpeed() : 0.f)
                    .build();
        } catch (IllegalStateException e) {
            return null;
        }
@@ -2398,11 +2400,13 @@ public class MediaPlayer2 implements AutoCloseable
                            return;
                        }
                        Iterator<Value> in = playerMsg.getValuesList().iterator();
                        SubtitleData data = new SubtitleData(
                        SubtitleData data = new SubtitleData.Builder()
                                .setSubtitleData(
                                    in.next().getInt32Value(),  // trackIndex
                                    in.next().getInt64Value(),  // startTimeUs
                                    in.next().getInt64Value(),  // durationUs
                                in.next().getBytesValue().toByteArray());  // data
                                    in.next().getBytesValue().toByteArray())  // data
                                .build();
                        sendEvent(new EventNotifier() {
                            @Override
                            public void notify(EventCallback callback) {
@@ -2426,9 +2430,11 @@ public class MediaPlayer2 implements AutoCloseable
                            return;
                        }
                        Iterator<Value> in = playerMsg.getValuesList().iterator();
                        data = new TimedMetaData(
                        data = new TimedMetaData.Builder()
                                .setTimedMetaData(
                                    in.next().getInt64Value(),  // timestampUs
                                in.next().getBytesValue().toByteArray());  // metaData
                                    in.next().getBytesValue().toByteArray())  // metaData
                                .build();
                    } else {
                        data = null;
                    }
+70 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.media;

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

/**
 * 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
@@ -117,4 +120,71 @@ public final class MediaTimestamp
                + " 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 Diff line number Diff line
@@ -148,7 +148,7 @@ public final class TimedMetaData {
         *     It should not be null.
         * @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) {
                throw new IllegalArgumentException("null metaData is not allowed");
            }