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

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

Merge "MediaPlayer2: change getVideoWidth and getVideoHeight to getVideoSize"

parents 74514bcb 6e827f03
Loading
Loading
Loading
Loading
+20 −33
Original line number Diff line number Diff line
@@ -324,18 +324,6 @@ public abstract class MediaPlayer2 implements AutoCloseable
    // This is an asynchronous call.
    public abstract Object skipToNext();

    /**
     * Moves the media to specified time position.
     * Same as {@link #seekTo(long, int)} with {@code mode = SEEK_PREVIOUS_SYNC}.
     *
     * @param msec the offset in milliseconds from the start to seek to
     * @return a token which can be used to cancel the operation later with {@link #cancel}.
     */
    // This is an asynchronous call.
    public Object seekTo(long msec) {
        return seekTo(msec, SEEK_PREVIOUS_SYNC /* mode */);
    }

    /**
     * Gets the current playback position.
     *
@@ -661,28 +649,16 @@ public abstract class MediaPlayer2 implements AutoCloseable
            AudioRouting.OnRoutingChangedListener listener);

    /**
     * Returns the width of the video.
     * Returns the size of the video.
     *
     * @return the width of the video, or 0 if there is no video,
     * no display surface was set, or the width has not been determined
     * yet. The {@code EventCallback} can be registered via
     * @return the size of the video. The width and height of size could be 0 if there is no video,
     * no display surface was set, or the size has not been determined yet.
     * The {@code EventCallback} can be registered via
     * {@link #setEventCallback(Executor, EventCallback)} to provide a
     * notification {@code EventCallback.onVideoSizeChanged} when the width
     * notification {@code EventCallback.onVideoSizeChanged} when the size
     * is available.
     */
    public abstract int getVideoWidth();

    /**
     * Returns the height of the video.
     *
     * @return the height of the video, or 0 if there is no video,
     * no display surface was set, or the height has not been determined
     * yet. The {@code EventCallback} can be registered via
     * {@link #setEventCallback(Executor, EventCallback)} to provide a
     * notification {@code EventCallback.onVideoSizeChanged} when the height is
     * available.
     */
    public abstract int getVideoHeight();
    public abstract VideoSize getVideoSize();

    /**
     * Return Metrics data about the current player.
@@ -841,6 +817,18 @@ public abstract class MediaPlayer2 implements AutoCloseable
    @NonNull
    public abstract SyncParams getSyncParams();

    /**
     * Moves the media to specified time position.
     * Same as {@link #seekTo(long, int)} with {@code mode = SEEK_PREVIOUS_SYNC}.
     *
     * @param msec the offset in milliseconds from the start to seek to
     * @return a token which can be used to cancel the operation later with {@link #cancel}.
     */
    // This is an asynchronous call.
    public Object seekTo(long msec) {
        return seekTo(msec, SEEK_PREVIOUS_SYNC /* mode */);
    }

    /**
     * Seek modes used in method seekTo(long, int) to move media position
     * to a specified location.
@@ -1171,11 +1159,10 @@ public abstract class MediaPlayer2 implements AutoCloseable
         *
         * @param mp the MediaPlayer2 associated with this callback
         * @param dsd the DataSourceDesc of this data source
         * @param width the width of the video
         * @param height the height of the video
         * @param size the size of the video
         */
        public void onVideoSizeChanged(
                MediaPlayer2 mp, DataSourceDesc dsd, int width, int height) { }
                MediaPlayer2 mp, DataSourceDesc dsd, VideoSize size) { }

        /**
         * Called to indicate an avaliable timed text
+251 −248
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
    private AtomicInteger mBufferedPercentageCurrent = new AtomicInteger(0);
    private AtomicInteger mBufferedPercentageNext = new AtomicInteger(0);
    private volatile float mVolume = 1.0f;
    private VideoSize mVideoSize = new VideoSize(0, 0);

    // Modular DRM
    private final Object mDrmLock = new Object();
@@ -949,10 +950,9 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
    }

    @Override
    public native int getVideoWidth();

    @Override
    public native int getVideoHeight();
    public VideoSize getVideoSize() {
        return mVideoSize;
    }

    @Override
    public PersistableBundle getMetrics() {
@@ -1740,7 +1740,8 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
                            mNextSourcePlayPending = true;

                            Log.i(TAG, "MEDIA_PLAYBACK_COMPLETE: srcId=" + srcId
                                + ", currentSrcId=" + mCurrentSrcId + ", nextSrcId=" + mNextSrcId);
                                    + ", currentSrcId=" + mCurrentSrcId
                                    + ", nextSrcId=" + mNextSrcId);
                        }

                        playNextDataSource();
@@ -1799,11 +1800,13 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
                {
                    final int width = msg.arg1;
                    final int height = msg.arg2;

                    mVideoSize = new VideoSize(width, height);
                    sendEvent(new EventNotifier() {
                        @Override
                        public void notify(EventCallback callback) {
                            callback.onVideoSizeChanged(
                                mMediaPlayer, dsd, width, height);
                                    mMediaPlayer, dsd, mVideoSize);
                        }
                    });
                    return;
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 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;

/**
 * Immutable class for describing width and height dimensions.
 *
 * @hide
 */
public final class VideoSize {
    /**
     * Create a new immutable VideoSize instance.
     *
     * @param width The width of the video size
     * @param height The height of the video size
     */
    public VideoSize(int width, int height) {
        mWidth = width;
        mHeight = height;
    }

    /**
     * Get the width of the video size
     * @return width
     */
    public int getWidth() {
        return mWidth;
    }

    /**
     * Get the height of the video size
     * @return height
     */
    public int getHeight() {
        return mHeight;
    }

    /**
     * Check if this video size is equal to another video size.
     * <p>
     * Two video sizes are equal if and only if both their widths and heights are
     * equal.
     * </p>
     * <p>
     * A video size object is never equal to any other type of object.
     * </p>
     *
     * @return {@code true} if the objects were equal, {@code false} otherwise
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof VideoSize) {
            VideoSize other = (VideoSize) obj;
            return mWidth == other.mWidth && mHeight == other.mHeight;
        }
        return false;
    }

    /**
     * Return the video size represented as a string with the format {@code "WxH"}
     *
     * @return string representation of the video size
     */
    @Override
    public String toString() {
        return mWidth + "x" + mHeight;
    }

    private final int mWidth;
    private final int mHeight;
}
+0 −36
Original line number Diff line number Diff line
@@ -790,40 +790,6 @@ android_media_MediaPlayer2_getState(JNIEnv *env, jobject thiz)
    return (jint)mp->getState();
}

static jint
android_media_MediaPlayer2_getVideoWidth(JNIEnv *env, jobject thiz)
{
    sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
    if (mp == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return 0;
    }
    int w;
    if (0 != mp->getVideoWidth(&w)) {
        ALOGE("getVideoWidth failed");
        w = 0;
    }
    ALOGV("getVideoWidth: %d", w);
    return (jint) w;
}

static jint
android_media_MediaPlayer2_getVideoHeight(JNIEnv *env, jobject thiz)
{
    sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
    if (mp == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return 0;
    }
    int h;
    if (0 != mp->getVideoHeight(&h)) {
        ALOGE("getVideoHeight failed");
        h = 0;
    }
    ALOGV("getVideoHeight: %d", h);
    return (jint) h;
}

static jobject
android_media_MediaPlayer2_native_getMetrics(JNIEnv *env, jobject thiz)
{
@@ -1459,8 +1425,6 @@ static const JNINativeMethod gMethods[] = {
    {"_prepare",            "()V",                              (void *)android_media_MediaPlayer2_prepare},
    {"_start",              "()V",                              (void *)android_media_MediaPlayer2_start},
    {"native_getState",     "()I",                              (void *)android_media_MediaPlayer2_getState},
    {"getVideoWidth",       "()I",                              (void *)android_media_MediaPlayer2_getVideoWidth},
    {"getVideoHeight",      "()I",                              (void *)android_media_MediaPlayer2_getVideoHeight},
    {"native_getMetrics",   "()Landroid/os/PersistableBundle;", (void *)android_media_MediaPlayer2_native_getMetrics},
    {"_setPlaybackParams", "(Landroid/media/PlaybackParams;)V", (void *)android_media_MediaPlayer2_setPlaybackParams},
    {"getPlaybackParams", "()Landroid/media/PlaybackParams;", (void *)android_media_MediaPlayer2_getPlaybackParams},