diff --git a/ijkmediaplayer/jni/ffplay/ff_ffplay.c b/ijkmediaplayer/jni/ffplay/ff_ffplay.c index 87a44c9d11aea2f5829492c5394df1ecf3e21247..51ed7d80d24b49a22db0a9a0b801e2eb68122574 100644 --- a/ijkmediaplayer/jni/ffplay/ff_ffplay.c +++ b/ijkmediaplayer/jni/ffplay/ff_ffplay.c @@ -2047,7 +2047,7 @@ void ffp_global_uninit() g_ffmpeg_global_inited = false; } -FFPlayer *ffp_create_ffplayer() +FFPlayer *ffp_create() { FFPlayer* ffp = (FFPlayer*) malloc(sizeof(ffp)); if (!ffp) @@ -2060,12 +2060,11 @@ FFPlayer *ffp_create_ffplayer() return ffp; } -void ffp_destroy_ffplayer(FFPlayer **pffp) +void ffp_destroy(FFPlayer *ffp) { - if (!pffp || !*pffp) + if (!ffp) return; - FFPlayer *ffp = *pffp; if (ffp && ffp->is) { av_log(NULL, AV_LOG_WARNING, "ffp_destroy_ffplayer: force stream_close()"); stream_close(ffp); @@ -2075,13 +2074,20 @@ void ffp_destroy_ffplayer(FFPlayer **pffp) ffp_reset_internal(ffp); msg_queue_destroy(&ffp->msg_queue); + + SDL_VoutFreeP(&ffp->vout); + SDL_AoutFreeP(&ffp->aout); + free(ffp); - *pffp = NULL; } -void ffp_reset(FFPlayer *ffp) +void ffp_destroy_p(FFPlayer **pffp) { - ffp_reset_internal(ffp); + if (!pffp) + return; + + ffp_destroy(*pffp); + *pffp = NULL; } int ffp_prepare_async_l(FFPlayer *ffp, const char *file_name) diff --git a/ijkmediaplayer/jni/ffplay/ff_ffplay.h b/ijkmediaplayer/jni/ffplay/ff_ffplay.h index 2d6498a77f68caa114f9fc0f4ff9468fec9078ad..f5982c4c293b2b82aced55f35f9921a03c74713d 100644 --- a/ijkmediaplayer/jni/ffplay/ff_ffplay.h +++ b/ijkmediaplayer/jni/ffplay/ff_ffplay.h @@ -31,8 +31,9 @@ void ffp_global_init(); void ffp_global_uninit(); -FFPlayer *ffp_create_ffplayer(); -void ffp_destroy_ffplayer(FFPlayer **pffp); +FFPlayer *ffp_create(); +void ffp_destroy(FFPlayer *ffp); +void ffp_destroy_p(FFPlayer *ffp); void ffp_reset(FFPlayer *ffp); int ffp_prepare_async_l(FFPlayer *ffp, const char *file_name); diff --git a/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c b/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c index 0250e9acaa6140cbebd5ac367ab2e35c441d104d..2e5ed81ad522c5184566b75ec4ae7c2897599c4e 100644 --- a/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c +++ b/ijkmediaplayer/jni/ijkplayer/android/ijkplayer_android.c @@ -43,27 +43,26 @@ typedef struct IjkMediaPlayer { char *data_source; } IjkMediaPlayer; -inline static void destroy_mp(IjkMediaPlayer **pmp) +inline static void ijkmp_destroy(IjkMediaPlayer *mp) { - if (!pmp) - return; - - IjkMediaPlayer *mp = *pmp; if (!mp) return; - FFPlayer *ffp = mp->ffplayer; - if (ffp) { - SDL_AoutFree(ffp->aout); - SDL_VoutFree(ffp->vout); - ffp_destroy_ffplayer(&mp->ffplayer); - } + ffp_destroy_p(&mp->ffplayer); pthread_mutex_destroy(&mp->mutex); FFP_SAFE_FREE(mp->data_source); memset(mp, 0, sizeof(IjkMediaPlayer)); FFP_SAFE_FREE(mp); +} + +inline static void ijkmp_destroy_p(IjkMediaPlayer **pmp) +{ + if (!pmp) + return; + + ijkmp_destroy(*pmp); *pmp = NULL; } @@ -79,25 +78,31 @@ void ijkmp_global_uninit() IjkMediaPlayer *ijkmp_create() { + FFPlayer *ffp; IjkMediaPlayer *mp = (IjkMediaPlayer *) malloc(sizeof(IjkMediaPlayer)); - if (!mp) { - return NULL; - } + if (!mp) + goto fail; memset(mp, 0, sizeof(IjkMediaPlayer)); - FFPlayer *ffp = ffp_create_ffplayer(); - if (!mp) { - FFP_SAFE_FREE(mp); - return NULL; - } - - pthread_mutex_init(&mp->mutex, NULL); + mp->ffplayer = ffp_create(); + if (!mp) + goto fail; - ijkmp_inc_ref(mp); + mp->ffplayer->vout = SDL_VoutAndroid_CreateForAndroidSurface(); + if (!mp->ffplayer->vout) + goto fail; - mp->ffplayer = ffp; + mp->ffplayer->aout = SDL_AoutAndroid_CreateForAudioTrack(); + if (!mp->ffplayer->vout) + goto fail; + pthread_mutex_init(&mp->mutex, NULL); + ijkmp_inc_ref(mp); return mp; + + fail: + ijkmp_destroy_p(&mp); + return NULL; } void ijkmp_shutdown_l(IjkMediaPlayer *mp) diff --git a/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.c b/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.c index 05eecddc5573ffcfb5e8a66521c238d193082ebf..d6b302494a141ac6db0136dd51f356083b9a65ff 100644 --- a/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.c +++ b/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.c @@ -32,7 +32,7 @@ JavaVM *SDL_AndroidJni_GetJvm() return g_jvm; } -jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env, void *thr_args) +jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env) { JavaVM *jvm = g_jvm; if (!jvm) { @@ -40,7 +40,7 @@ jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env, void *thr_args) return -1; } - return (*jvm)->AttachCurrentThread(jvm, p_env, thr_args); + return (*jvm)->AttachCurrentThread(jvm, p_env, NULL); } jint SDL_AndroidJni_DetachCurrentThread() diff --git a/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.h b/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.h index c5b3cbb05b72629ab6e5ce930c97832fa5811069..827e05430cb2f721ccc8277d6d7c73821382e85b 100644 --- a/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.h +++ b/ijkmediaplayer/jni/ijksdl/android/ijksdl_android_jni.h @@ -28,6 +28,8 @@ JavaVM *SDL_AndroidJni_GetJvm(); -jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env, void *thr_args); +jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env); + +jint SDL_AndroidJni_DetachCurrentThread(); #endif diff --git a/ijkmediaplayer/jni/ijksdl/android/ijksdl_aout_android_audiotrack.c b/ijkmediaplayer/jni/ijksdl/android/ijksdl_aout_android_audiotrack.c index ff5b3531957681157492763f6e4e81f47f62e6f9..457ecb64130c60179534ba82ad3fafa190e16ad4 100644 --- a/ijkmediaplayer/jni/ijksdl/android/ijksdl_aout_android_audiotrack.c +++ b/ijkmediaplayer/jni/ijksdl/android/ijksdl_aout_android_audiotrack.c @@ -87,7 +87,7 @@ int aout_thread(void *arg) SDL_Aout_Opaque *opaque = aout->opaque; JNIEnv *env = NULL; - if (!SDL_AndroidJni_AttachCurrentThread(&env, NULL)) { + if (JNI_OK != SDL_AndroidJni_AttachCurrentThread(&env, NULL)) { ALOGE("aout_thread: AttachCurrentThread: failed"); return -1; } @@ -130,7 +130,7 @@ int aout_open_audio(SDL_Aout *aout, SDL_AudioSpec *desired, SDL_AudioSpec *obtai { SDL_Aout_Opaque *opaque = aout->opaque; JNIEnv *env = NULL; - if (!SDL_AndroidJni_AttachCurrentThread(&env, NULL)) { + if (JNI_OK != SDL_AndroidJni_AttachCurrentThread(&env, NULL)) { ALOGE("aout_open_audio: AttachCurrentThread: failed"); return -1; } diff --git a/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.c b/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.c index 8e0640f587811f9afd21cc23222a09af5912889c..08b3276aa1a1f8ddd5cc3a745fd37caa97954020 100644 --- a/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.c +++ b/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.c @@ -31,7 +31,7 @@ SDL_Vout *SDL_VoutAndroid_CreateForAndroidSurface() return SDL_VoutAndroid_CreateForANativeWindow(); } -void SDL_VoutAndroid_SetAndroidSurface(SDL_Vout *vout, JNIEnv *env, jobject android_surface) +static void SDL_VoutAndroid_SetAndroidSurface_n(JNIEnv *env, SDL_Vout *vout, jobject android_surface) { if (!android_surface) return; @@ -43,3 +43,19 @@ void SDL_VoutAndroid_SetAndroidSurface(SDL_Vout *vout, JNIEnv *env, jobject andr SDL_VoutAndroid_SetNativeWindow(vout, native_window); ANativeWindow_release(native_window); } + +void SDL_VoutAndroid_SetAndroidSurface(SDL_Vout *vout, jobject android_surface) +{ + if (!android_surface) + return; + + JNIEnv *env = NULL; + if (JNI_OK != SDL_AndroidJni_AttachCurrentThread(&env, NULL)) { + ALOGE("SDL_VoutAndroid_SetAndroidSurface: AttachCurrentThread: failed"); + return; + } + + SDL_VoutAndroid_SetAndroidSurface_n(env, vout, android_surface); + + SDL_AndroidJni_DetachCurrentThread(); +} diff --git a/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.h b/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.h index fb1aebb9055976aba4672bb0d0b6a7a073055df1..1510476766b6fed7f1a4d69404c2ebfe8772aac2 100644 --- a/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.h +++ b/ijkmediaplayer/jni/ijksdl/android/ijksdl_vout_android_surface.h @@ -29,6 +29,6 @@ #include "../ijksdl_vout.h" SDL_Vout *SDL_VoutAndroid_CreateForAndroidSurface(); -void SDL_VoutAndroid_SetAndroidSurface(SDL_Vout *vout, JNIEnv *env, jobject android_surface); +void SDL_VoutAndroid_SetAndroidSurface(SDL_Vout *vout, jobject android_surface); #endif diff --git a/ijkmediaplayer/jni/ijksdl/ijksdl_aout.c b/ijkmediaplayer/jni/ijksdl/ijksdl_aout.c index b2211743809a145d35734b593bf057ac9fc5de77..6641363528bf4bd4bbcbf3bba2e9a5f8cdc60ca0 100644 --- a/ijkmediaplayer/jni/ijksdl/ijksdl_aout.c +++ b/ijkmediaplayer/jni/ijksdl/ijksdl_aout.c @@ -53,3 +53,12 @@ void SDL_AoutFree(SDL_Aout *aout) else free(aout); } + +void SDL_AoutFreeP(SDL_Aout **paout) +{ + if (!paout) + return; + + SDL_AoutFree(*paout); + *paout = NULL; +} diff --git a/ijkmediaplayer/jni/ijksdl/ijksdl_aout.h b/ijkmediaplayer/jni/ijksdl/ijksdl_aout.h index 4125f2f0859c56ca0c3f6c9d8bfe534af5ac44b3..694e8d8c437bb1ffb8283f7938d814ee62ff7b56 100644 --- a/ijkmediaplayer/jni/ijksdl/ijksdl_aout.h +++ b/ijkmediaplayer/jni/ijksdl/ijksdl_aout.h @@ -43,5 +43,6 @@ int SDL_AoutOpenAudio(SDL_Aout *aout, SDL_AudioSpec *desired, SDL_AudioSpec *obt void SDL_AoutPauseAudio(SDL_Aout *aout, int pause_on); void SDL_AoutCloseAudio(SDL_Aout *aout); void SDL_AoutFree(SDL_Aout *aout); +void SDL_AoutFreeP(SDL_Aout **paout); #endif diff --git a/ijkmediaplayer/jni/ijksdl/ijksdl_vout.c b/ijkmediaplayer/jni/ijksdl/ijksdl_vout.c index a76dfe476ac2433f912cc73b9efd8db1b7d54740..fc887e8b204972431b8d58ec46a4f42c42bcf218 100644 --- a/ijkmediaplayer/jni/ijksdl/ijksdl_vout.c +++ b/ijkmediaplayer/jni/ijksdl/ijksdl_vout.c @@ -38,6 +38,15 @@ void SDL_VoutFree(SDL_Vout *vout) } } +void SDL_VoutFreeP(SDL_Vout **pvout) +{ + if (!pvout) + return; + + SDL_VoutFree(*pvout); + *pvout = NULL; +} + int SDL_VoutDisplayYUVOverlay(SDL_Vout *vout, SDL_VoutOverlay *overlay) { if (vout && overlay && vout->display_overlay) diff --git a/ijkmediaplayer/jni/ijksdl/ijksdl_vout.h b/ijkmediaplayer/jni/ijksdl/ijksdl_vout.h index 6b4b581d194b39ef127372c29f8c63c09b84e25a..ca58dd3280b0eddbaaea730736131f8bf49a81f7 100644 --- a/ijkmediaplayer/jni/ijksdl/ijksdl_vout.h +++ b/ijkmediaplayer/jni/ijksdl/ijksdl_vout.h @@ -55,6 +55,7 @@ typedef struct SDL_Vout { } SDL_Vout; void SDL_VoutFree(SDL_Vout *vout); +void SDL_VoutFreeP(SDL_Vout **pvout) int SDL_VoutDisplayYUVOverlay(SDL_Vout *vout, SDL_VoutOverlay *overlay); int SDL_VoutLockYUVOverlay(SDL_VoutOverlay *overlay);