Loading media/jni/android_media_MediaPlayer.cpp +26 −14 Original line number Original line Diff line number Diff line Loading @@ -303,10 +303,10 @@ android_media_MediaPlayer_setDataSourceCallback(JNIEnv *env, jobject thiz, jobje process_media_player_call(env, thiz, mp->setDataSource(callbackDataSource), "java/lang/RuntimeException", "setDataSourceCallback failed." ); process_media_player_call(env, thiz, mp->setDataSource(callbackDataSource), "java/lang/RuntimeException", "setDataSourceCallback failed." ); } } static sp<IGraphicBufferProducer> static sp<MediaSurfaceType> getVideoSurfaceTexture(JNIEnv* env, jobject thiz) { getVideoSurfaceTexture(JNIEnv* env, jobject thiz) { IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture); MediaSurfaceType* const p = (MediaSurfaceType*)env->GetLongField(thiz, fields.surface_texture); return sp<IGraphicBufferProducer>(p); return sp<MediaSurfaceType>(p); } } static void static void Loading @@ -317,7 +317,7 @@ decVideoSurfaceRef(JNIEnv *env, jobject thiz) return; return; } } sp<IGraphicBufferProducer> old_st = getVideoSurfaceTexture(env, thiz); sp<MediaSurfaceType> old_st = getVideoSurfaceTexture(env, thiz); if (old_st != NULL) { if (old_st != NULL) { old_st->decStrong((void*)decVideoSurfaceRef); old_st->decStrong((void*)decVideoSurfaceRef); } } Loading @@ -336,31 +336,43 @@ setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlaye decVideoSurfaceRef(env, thiz); decVideoSurfaceRef(env, thiz); sp<IGraphicBufferProducer> new_st; #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION) sp<Surface> surface; if (jsurface) { if (jsurface) { sp<Surface> surface(android_view_Surface_getSurface(env, jsurface)); surface = android_view_Surface_getSurface(env, jsurface); if (surface != NULL) { if (surface == NULL) { new_st = surface->getIGraphicBufferProducer(); jniThrowException(env, "java/lang/IllegalArgumentException", if (new_st == NULL) { "The surface has been released"); return; } } #else sp<IGraphicBufferProducer> surface; if (jsurface) { sp<Surface> tempSurface(android_view_Surface_getSurface(env, jsurface)); if (tempSurface != NULL) { surface = tempSurface->getIGraphicBufferProducer(); if (surface == NULL) { jniThrowException(env, "java/lang/IllegalArgumentException", jniThrowException(env, "java/lang/IllegalArgumentException", "The surface does not have a binding SurfaceTexture!"); "The surface does not have a binding SurfaceTexture!"); return; return; } } new_st->incStrong((void*)decVideoSurfaceRef); surface->incStrong((void*)decVideoSurfaceRef); } else { } else { jniThrowException(env, "java/lang/IllegalArgumentException", jniThrowException(env, "java/lang/IllegalArgumentException", "The surface has been released"); "The surface has been released"); return; return; } } } } #endif env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get()); env->SetLongField(thiz, fields.surface_texture, (jlong)surface.get()); // This will fail if the media player has not been initialized yet. This // This will fail if the media player has not been initialized yet. This // can be the case if setDisplay() on MediaPlayer.java has been called // can be the case if setDisplay() on MediaPlayer.java has been called // before setDataSource(). The redundant call to setVideoSurfaceTexture() // before setDataSource(). The redundant call to setVideoSurfaceTexture() // in prepare/prepareAsync covers for this case. // in prepare/prepareAsync covers for this case. mp->setVideoSurfaceTexture(new_st); mp->setVideoSurfaceTexture(surface); } } static void static void Loading @@ -380,7 +392,7 @@ android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz, jobject piidParcel) // 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 // initialized. We try again to make it stick. // initialized. We try again to make it stick. sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); sp<MediaSurfaceType> st = getVideoSurfaceTexture(env, 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." ); Loading @@ -406,7 +418,7 @@ android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz, jobject piidPa // 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 // initialized. We try again to make it stick. // initialized. We try again to make it stick. sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); sp<MediaSurfaceType> st = getVideoSurfaceTexture(env, 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." ); Loading Loading
media/jni/android_media_MediaPlayer.cpp +26 −14 Original line number Original line Diff line number Diff line Loading @@ -303,10 +303,10 @@ android_media_MediaPlayer_setDataSourceCallback(JNIEnv *env, jobject thiz, jobje process_media_player_call(env, thiz, mp->setDataSource(callbackDataSource), "java/lang/RuntimeException", "setDataSourceCallback failed." ); process_media_player_call(env, thiz, mp->setDataSource(callbackDataSource), "java/lang/RuntimeException", "setDataSourceCallback failed." ); } } static sp<IGraphicBufferProducer> static sp<MediaSurfaceType> getVideoSurfaceTexture(JNIEnv* env, jobject thiz) { getVideoSurfaceTexture(JNIEnv* env, jobject thiz) { IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture); MediaSurfaceType* const p = (MediaSurfaceType*)env->GetLongField(thiz, fields.surface_texture); return sp<IGraphicBufferProducer>(p); return sp<MediaSurfaceType>(p); } } static void static void Loading @@ -317,7 +317,7 @@ decVideoSurfaceRef(JNIEnv *env, jobject thiz) return; return; } } sp<IGraphicBufferProducer> old_st = getVideoSurfaceTexture(env, thiz); sp<MediaSurfaceType> old_st = getVideoSurfaceTexture(env, thiz); if (old_st != NULL) { if (old_st != NULL) { old_st->decStrong((void*)decVideoSurfaceRef); old_st->decStrong((void*)decVideoSurfaceRef); } } Loading @@ -336,31 +336,43 @@ setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlaye decVideoSurfaceRef(env, thiz); decVideoSurfaceRef(env, thiz); sp<IGraphicBufferProducer> new_st; #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION) sp<Surface> surface; if (jsurface) { if (jsurface) { sp<Surface> surface(android_view_Surface_getSurface(env, jsurface)); surface = android_view_Surface_getSurface(env, jsurface); if (surface != NULL) { if (surface == NULL) { new_st = surface->getIGraphicBufferProducer(); jniThrowException(env, "java/lang/IllegalArgumentException", if (new_st == NULL) { "The surface has been released"); return; } } #else sp<IGraphicBufferProducer> surface; if (jsurface) { sp<Surface> tempSurface(android_view_Surface_getSurface(env, jsurface)); if (tempSurface != NULL) { surface = tempSurface->getIGraphicBufferProducer(); if (surface == NULL) { jniThrowException(env, "java/lang/IllegalArgumentException", jniThrowException(env, "java/lang/IllegalArgumentException", "The surface does not have a binding SurfaceTexture!"); "The surface does not have a binding SurfaceTexture!"); return; return; } } new_st->incStrong((void*)decVideoSurfaceRef); surface->incStrong((void*)decVideoSurfaceRef); } else { } else { jniThrowException(env, "java/lang/IllegalArgumentException", jniThrowException(env, "java/lang/IllegalArgumentException", "The surface has been released"); "The surface has been released"); return; return; } } } } #endif env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get()); env->SetLongField(thiz, fields.surface_texture, (jlong)surface.get()); // This will fail if the media player has not been initialized yet. This // This will fail if the media player has not been initialized yet. This // can be the case if setDisplay() on MediaPlayer.java has been called // can be the case if setDisplay() on MediaPlayer.java has been called // before setDataSource(). The redundant call to setVideoSurfaceTexture() // before setDataSource(). The redundant call to setVideoSurfaceTexture() // in prepare/prepareAsync covers for this case. // in prepare/prepareAsync covers for this case. mp->setVideoSurfaceTexture(new_st); mp->setVideoSurfaceTexture(surface); } } static void static void Loading @@ -380,7 +392,7 @@ android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz, jobject piidParcel) // 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 // initialized. We try again to make it stick. // initialized. We try again to make it stick. sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); sp<MediaSurfaceType> st = getVideoSurfaceTexture(env, 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." ); Loading @@ -406,7 +418,7 @@ android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz, jobject piidPa // 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 // initialized. We try again to make it stick. // initialized. We try again to make it stick. sp<IGraphicBufferProducer> st = getVideoSurfaceTexture(env, thiz); sp<MediaSurfaceType> st = getVideoSurfaceTexture(env, 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." ); Loading