Merge "Send piid to the native MediaPlayer's AudioTrack"
This commit is contained in:
@@ -696,6 +696,13 @@ public class MediaPlayer extends PlayerBase
|
||||
baseRegisterPlayer(sessionId);
|
||||
}
|
||||
|
||||
private Parcel createPlayerIIdParcel() {
|
||||
Parcel parcel = newRequest();
|
||||
parcel.writeInt(INVOKE_ID_SET_PLAYER_IID);
|
||||
parcel.writeInt(mPlayerIId);
|
||||
return parcel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the MediaPlayer SurfaceTexture.
|
||||
* 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_SET_VIDEO_SCALE_MODE = 6;
|
||||
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
|
||||
@@ -1309,16 +1317,26 @@ public class MediaPlayer extends PlayerBase
|
||||
* @throws IllegalStateException if it is called in an invalid state
|
||||
*/
|
||||
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();
|
||||
|
||||
// DrmInfo, if any, has been resolved by now.
|
||||
synchronized (mDrmLock) {
|
||||
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.
|
||||
@@ -1330,7 +1348,20 @@ public class MediaPlayer extends PlayerBase
|
||||
*
|
||||
* @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,
|
||||
|
||||
@@ -369,13 +369,13 @@ android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsu
|
||||
setVideoSurface(env, thiz, jsurface, true /* mediaPlayerMustBeAlive */);
|
||||
}
|
||||
|
||||
static void
|
||||
android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz)
|
||||
static jint
|
||||
android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz, jobject piidParcel)
|
||||
{
|
||||
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
|
||||
if (mp == NULL ) {
|
||||
if (mp == nullptr) {
|
||||
jniThrowException(env, "java/lang/IllegalStateException", NULL);
|
||||
return;
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
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
|
||||
android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz)
|
||||
static jint
|
||||
android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz, jobject piidParcel)
|
||||
{
|
||||
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
|
||||
if (mp == NULL ) {
|
||||
if (mp == nullptr) {
|
||||
jniThrowException(env, "java/lang/IllegalStateException", NULL);
|
||||
return;
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
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
|
||||
@@ -1380,8 +1390,8 @@ static const JNINativeMethod gMethods[] = {
|
||||
{"_setDataSource", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaPlayer_setDataSourceFD},
|
||||
{"_setDataSource", "(Landroid/media/MediaDataSource;)V",(void *)android_media_MediaPlayer_setDataSourceCallback },
|
||||
{"_setVideoSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaPlayer_setVideoSurface},
|
||||
{"_prepare", "()V", (void *)android_media_MediaPlayer_prepare},
|
||||
{"prepareAsync", "()V", (void *)android_media_MediaPlayer_prepareAsync},
|
||||
{"_prepare", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_prepare},
|
||||
{"_prepareAsync", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_prepareAsync},
|
||||
{"_start", "()V", (void *)android_media_MediaPlayer_start},
|
||||
{"_stop", "()V", (void *)android_media_MediaPlayer_stop},
|
||||
{"getVideoWidth", "()I", (void *)android_media_MediaPlayer_getVideoWidth},
|
||||
|
||||
Reference in New Issue
Block a user