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

Commit 66824a3f authored by Vlad Popa's avatar Vlad Popa
Browse files

Send piid to the native MediaPlayer's AudioTrack

The piid is sent in the prepare and prepareAsync methods after the data source is being
set and the native variables are initialized.

Test: dumpsys audio & atest android.media.audio.cts.AudioPlaybackConfigurationTest
Bug: 235521198
Change-Id: Ie3cbdb69814ff014fafc1737462d4fa8a8f687ca
parent 1ec8c40e
Loading
Loading
Loading
Loading
+34 −3
Original line number Original line Diff line number Diff line
@@ -696,6 +696,13 @@ public class MediaPlayer extends PlayerBase
        baseRegisterPlayer(sessionId);
        baseRegisterPlayer(sessionId);
    }
    }


    private Parcel createPlayerIIdParcel() {
        Parcel parcel = newRequest();
        parcel.writeInt(INVOKE_ID_SET_PLAYER_IID);
        parcel.writeInt(mPlayerIId);
        return parcel;
    }

    /*
    /*
     * Update the MediaPlayer SurfaceTexture.
     * Update the MediaPlayer SurfaceTexture.
     * Call after setting a new display surface.
     * Call after setting a new display surface.
@@ -712,6 +719,7 @@ public class MediaPlayer extends PlayerBase
    private static final int INVOKE_ID_DESELECT_TRACK = 5;
    private static final int INVOKE_ID_DESELECT_TRACK = 5;
    private static final int INVOKE_ID_SET_VIDEO_SCALE_MODE = 6;
    private static final int INVOKE_ID_SET_VIDEO_SCALE_MODE = 6;
    private static final int INVOKE_ID_GET_SELECTED_TRACK = 7;
    private static final int INVOKE_ID_GET_SELECTED_TRACK = 7;
    private static final int INVOKE_ID_SET_PLAYER_IID = 8;


    /**
    /**
     * Create a request parcel which can be routed to the native media
     * Create a request parcel which can be routed to the native media
@@ -1309,16 +1317,26 @@ public class MediaPlayer extends PlayerBase
     * @throws IllegalStateException if it is called in an invalid state
     * @throws IllegalStateException if it is called in an invalid state
     */
     */
    public void prepare() throws IOException, IllegalStateException {
    public void prepare() throws IOException, IllegalStateException {
        _prepare();
        Parcel piidParcel = createPlayerIIdParcel();
        try {
            int retCode = _prepare(piidParcel);
            if (retCode != 0) {
                Log.w(TAG, "prepare(): could not set piid " + mPlayerIId);
            }
        } finally {
            piidParcel.recycle();
        }
        scanInternalSubtitleTracks();
        scanInternalSubtitleTracks();


        // DrmInfo, if any, has been resolved by now.
        // DrmInfo, if any, has been resolved by now.
        synchronized (mDrmLock) {
        synchronized (mDrmLock) {
            mDrmInfoResolved = true;
            mDrmInfoResolved = true;
        }
        }

    }
    }


    private native void _prepare() throws IOException, IllegalStateException;
    /** Returns the result of sending the {@code piidParcel} to the MediaPlayerService. */
    private native int _prepare(Parcel piidParcel) throws IOException, IllegalStateException;


    /**
    /**
     * Prepares the player for playback, asynchronously.
     * Prepares the player for playback, asynchronously.
@@ -1330,7 +1348,20 @@ public class MediaPlayer extends PlayerBase
     *
     *
     * @throws IllegalStateException if it is called in an invalid state
     * @throws IllegalStateException if it is called in an invalid state
     */
     */
    public native void prepareAsync() throws IllegalStateException;
    public void prepareAsync() throws IllegalStateException {
        Parcel piidParcel = createPlayerIIdParcel();
        try {
            int retCode = _prepareAsync(piidParcel);
            if (retCode != 0) {
                Log.w(TAG, "prepareAsync(): could not set piid " + mPlayerIId);
            }
        } finally {
            piidParcel.recycle();
        }
    }

    /** Returns the result of sending the {@code piidParcel} to the MediaPlayerService. */
    private native int _prepareAsync(Parcel piidParcel) throws IllegalStateException;


    /**
    /**
     * Starts or resumes playback. If playback had previously been paused,
     * Starts or resumes playback. If playback had previously been paused,
+20 −10
Original line number Original line Diff line number Diff line
@@ -369,13 +369,13 @@ android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsu
    setVideoSurface(env, thiz, jsurface, true /* mediaPlayerMustBeAlive */);
    setVideoSurface(env, thiz, jsurface, true /* mediaPlayerMustBeAlive */);
}
}


static void
static jint
android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz)
android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz, jobject piidParcel)
{
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL ) {
    if (mp == nullptr) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return;
        return UNKNOWN_ERROR;
    }
    }


    // Handle the case where the display surface was set before the mp was
    // Handle the case where the display surface was set before the mp was
@@ -384,15 +384,20 @@ android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz)
    mp->setVideoSurfaceTexture(st);
    mp->setVideoSurfaceTexture(st);


    process_media_player_call( env, thiz, mp->prepare(), "java/io/IOException", "Prepare failed." );
    process_media_player_call( env, thiz, mp->prepare(), "java/io/IOException", "Prepare failed." );

    // update the piid
    Parcel *request = parcelForJavaObject(env, piidParcel);
    auto reply = std::make_unique<Parcel>();
    return static_cast<jint>(mp->invoke(*request, reply.get()));
}
}


static void
static jint
android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz)
android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz, jobject piidParcel)
{
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL ) {
    if (mp == nullptr) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return;
        return UNKNOWN_ERROR;
    }
    }


    // Handle the case where the display surface was set before the mp was
    // Handle the case where the display surface was set before the mp was
@@ -401,6 +406,11 @@ android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz)
    mp->setVideoSurfaceTexture(st);
    mp->setVideoSurfaceTexture(st);


    process_media_player_call( env, thiz, mp->prepareAsync(), "java/io/IOException", "Prepare Async failed." );
    process_media_player_call( env, thiz, mp->prepareAsync(), "java/io/IOException", "Prepare Async failed." );

    // update the piid
    Parcel *request = parcelForJavaObject(env, piidParcel);
    auto reply = std::make_unique<Parcel>();
    return static_cast<jint>(mp->invoke(*request, reply.get()));
}
}


static void
static void
@@ -1380,8 +1390,8 @@ static const JNINativeMethod gMethods[] = {
    {"_setDataSource",      "(Ljava/io/FileDescriptor;JJ)V",    (void *)android_media_MediaPlayer_setDataSourceFD},
    {"_setDataSource",      "(Ljava/io/FileDescriptor;JJ)V",    (void *)android_media_MediaPlayer_setDataSourceFD},
    {"_setDataSource",      "(Landroid/media/MediaDataSource;)V",(void *)android_media_MediaPlayer_setDataSourceCallback },
    {"_setDataSource",      "(Landroid/media/MediaDataSource;)V",(void *)android_media_MediaPlayer_setDataSourceCallback },
    {"_setVideoSurface",    "(Landroid/view/Surface;)V",        (void *)android_media_MediaPlayer_setVideoSurface},
    {"_setVideoSurface",    "(Landroid/view/Surface;)V",        (void *)android_media_MediaPlayer_setVideoSurface},
    {"_prepare",            "()V",                              (void *)android_media_MediaPlayer_prepare},
    {"_prepare",            "(Landroid/os/Parcel;)I",           (void *)android_media_MediaPlayer_prepare},
    {"prepareAsync",        "()V",                              (void *)android_media_MediaPlayer_prepareAsync},
    {"_prepareAsync",       "(Landroid/os/Parcel;)I",           (void *)android_media_MediaPlayer_prepareAsync},
    {"_start",              "()V",                              (void *)android_media_MediaPlayer_start},
    {"_start",              "()V",                              (void *)android_media_MediaPlayer_start},
    {"_stop",               "()V",                              (void *)android_media_MediaPlayer_stop},
    {"_stop",               "()V",                              (void *)android_media_MediaPlayer_stop},
    {"getVideoWidth",       "()I",                              (void *)android_media_MediaPlayer_getVideoWidth},
    {"getVideoWidth",       "()I",                              (void *)android_media_MediaPlayer_getVideoWidth},