static void IjkMediaPlayer_setOption(JNIEnv *env, jobject thiz, jint category, jobject name, jobject value) { MPTRACE("%s\n", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); const char *c_name = NULL; const char *c_value = NULL; JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: setOption: null mp", LABEL_RETURN); c_name = (*env)->GetStringUTFChars(env, name, NULL ); JNI_CHECK_GOTO(c_name, env, "java/lang/OutOfMemoryError", "mpjni: setOption: name.string oom", LABEL_RETURN); if (value) { c_value = (*env)->GetStringUTFChars(env, value, NULL ); JNI_CHECK_GOTO(c_name, env, "java/lang/OutOfMemoryError", "mpjni: setOption: name.string oom", LABEL_RETURN); } ijkmp_set_option(mp, category, c_name, c_value); LABEL_RETURN: if (c_name) (*env)->ReleaseStringUTFChars(env, name, c_name); if (c_value) (*env)->ReleaseStringUTFChars(env, value, c_value); ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_pause(JNIEnv *env, jobject thiz) { IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: pause: null mp", LABEL_RETURN); ijkmp_pause(mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void ijkMediaPlayer_setPropertyLong(JNIEnv *env, jobject thiz, jint id, jlong value) { IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: setPropertyLong: null mp", LABEL_RETURN); ijkmp_set_property_int64(mp, id, value); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return; }
static void IjkMediaPlayer_setLoopCount(JNIEnv *env, jobject thiz, jint loop_count) { MPTRACE("%s\n", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: setLoopCount: null mp", LABEL_RETURN); ijkmp_set_loop(mp, loop_count); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_setVolume(JNIEnv *env, jobject thiz, jfloat leftVolume, jfloat rightVolume) { MPTRACE("IjkMediaPlayer_setVolume"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: setVolume: null mp", LABEL_RETURN); ijkmp_android_set_volume(env, mp, leftVolume, rightVolume); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_setFrameDrop(JNIEnv *env, jobject thiz, jint frameDrop) { MPTRACE("IjkMediaPlayer_setFrameDrop"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: setFrameDrop: null mp", LABEL_RETURN); ijkmp_set_framedrop(mp, frameDrop); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_setAutoPlayOnPrepared(JNIEnv *env, jobject thiz, jboolean enabled) { MPTRACE("%s", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: setAutoPlayOnPrepared: null mp", LABEL_RETURN); ijkmp_set_auto_play_on_prepared(mp, enabled); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_start(JNIEnv *env, jobject thiz) { MPTRACE("%s\n", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: start: null mp", LABEL_RETURN); ijkmp_start(mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_setOverlayFormat(JNIEnv *env, jobject thiz, jint chromaFourCC) { MPTRACE("IjkMediaPlayer_setOverlayFormat"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: setAvCodecOption: null mp", LABEL_RETURN); ijkmp_set_overlay_format(mp, chromaFourCC); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_seekTo(JNIEnv *env, jobject thiz, int msec) { MPTRACE("IjkMediaPlayer_seekTo"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: seekTo: null mp", LABEL_RETURN); ijkmp_seek_to(mp, msec); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_setOpenSLESEnabled(JNIEnv *env, jobject thiz, jboolean enabled) { MPTRACE("%s", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: setOpenSLESEnabled: null mp", LABEL_RETURN); ijkmp_android_set_opensles_enabled(mp, enabled); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface) { MPTRACE("IjkMediaPlayer_setVideoSurface"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: setVideoSurface: null mp", LABEL_RETURN); ijkmp_android_set_surface(env, mp, jsurface); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return; }
static void IjkMediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this) { MPTRACE("IjkMediaPlayer_native_setup"); IjkMediaPlayer *mp = ijkmp_android_create(message_loop); JNI_CHECK_GOTO(mp, env, "java/lang/OutOfMemoryError", "mpjni: native_setup: ijkmp_create() failed", LABEL_RETURN); jni_set_media_player(env, thiz, mp); ijkmp_set_weak_thiz(mp, (*env)->NewGlobalRef(env, weak_this)); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static jlong IjkMediaPlayer_getCurrentPosition(JNIEnv *env, jobject thiz) { jlong retval = 0; IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: getCurrentPosition: null mp", LABEL_RETURN); retval = ijkmp_get_current_position(mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return retval; }
static void IjkMediaPlayer_reset(JNIEnv *env, jobject thiz) { MPTRACE("IjkMediaPlayer_reset"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: reset: null mp", LABEL_RETURN); ijkmp_android_set_surface(env, mp, NULL); ijkmp_reset(mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static jboolean IjkMediaPlayer_isPlaying(JNIEnv *env, jobject thiz) { jboolean retval = JNI_FALSE; IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: isPlaying: null mp", LABEL_RETURN); retval = ijkmp_is_playing(mp) ? JNI_TRUE : JNI_FALSE; LABEL_RETURN: ijkmp_dec_ref_p(&mp); return retval; }
static jlong ijkMediaPlayer_getPropertyLong(JNIEnv *env, jobject thiz, jint id, jlong default_value) { jlong value = default_value; IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: getPropertyLong: null mp", LABEL_RETURN); value = ijkmp_get_property_int64(mp, id, default_value); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return value; }
static int IjkMediaPlayer_getDuration(JNIEnv *env, jobject thiz) { int retval = 0; IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: getDuration: null mp", LABEL_RETURN); retval = ijkmp_get_duration(mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return retval; }
static jint IjkMediaPlayer_getLoopCount(JNIEnv *env, jobject thiz) { jint loop_count = 1; MPTRACE("%s\n", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: getLoopCount: null mp", LABEL_RETURN); loop_count = ijkmp_get_loop(mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return loop_count; }
static void IjkMediaPlayer_prepareAsync(JNIEnv *env, jobject thiz) { MPTRACE("IjkMediaPlayer_prepareAsync"); int retval = 0; IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: prepareAsync: null mp", LABEL_RETURN); retval = ijkmp_prepare_async(mp); IJK_CHECK_MPRET_GOTO(retval, env, LABEL_RETURN); LABEL_RETURN: ijkmp_dec_ref_p(&mp); }
static jint IjkMediaPlayer_getAudioSessionId(JNIEnv *env, jobject thiz) { jint audio_session_id = 0; MPTRACE("%s\n", __func__); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, NULL, "mpjni: getAudioSessionId: null mp", LABEL_RETURN); audio_session_id = ijkmp_android_get_audio_session_id(env, mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); return audio_session_id; }
static void IjkMediaPlayer_reset(JNIEnv *env, jobject thiz) { MPTRACE("IjkMediaPlayer_reset"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); if (!mp) return; jobject weak_thiz = (jobject) ijkmp_set_weak_thiz(mp, NULL ); IjkMediaPlayer_release(env, thiz); IjkMediaPlayer_native_setup(env, thiz, weak_thiz); ijkmp_dec_ref_p(&mp); }
static void IjkMediaPlayer_release(JNIEnv *env, jobject thiz) { MPTRACE("IjkMediaPlayer_release"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); if (!mp) return; // explicit shutdown mp, in case it is not the last mp-ref here ijkmp_android_set_surface(env, mp, NULL); ijkmp_shutdown(mp); jni_set_media_player(env, thiz, NULL); ijkmp_dec_ref_p(&mp); }
static void ijkMediaPlayer_setStreamSelected(JNIEnv *env, jobject thiz, jint stream, jboolean selected) { IjkMediaPlayer *mp = jni_get_media_player(env, thiz); int ret = 0; JNI_CHECK_GOTO(mp, env, NULL, "mpjni: setStreamSelected: null mp", LABEL_RETURN); ret = ijkmp_set_stream_selected(mp, stream, selected); if (ret < 0) { ALOGE("failed to %s %d", selected ? "select" : "deselect", stream); goto LABEL_RETURN; } LABEL_RETURN: ijkmp_dec_ref_p(&mp); return; }
static void IjkMediaPlayer_release(JNIEnv *env, jobject thiz) { MPTRACE("IjkMediaPlayer_release"); IjkMediaPlayer *mp = jni_get_media_player(env, thiz); if (!mp) return; // explicit shutdown mp, in case it is not the last mp-ref here ijkmp_android_set_surface(env, mp, NULL ); ijkmp_shutdown(mp); //only delete weak_thiz at release jobject weak_thiz = (jobject) ijkmp_set_weak_thiz(mp, NULL ); (*env)->DeleteGlobalRef(env, weak_thiz); jni_set_media_player(env, thiz, NULL ); ijkmp_dec_ref_p(&mp); }
static IjkMediaPlayer *jni_set_media_player(JNIEnv* env, jobject thiz, IjkMediaPlayer *mp) { pthread_mutex_lock(&g_clazz.mutex); IjkMediaPlayer *old = (IjkMediaPlayer*) (intptr_t) J4AC_IjkMediaPlayer__mNativeMediaPlayer__get__catchAll(env, thiz); if (mp) { ijkmp_inc_ref(mp); } J4AC_IjkMediaPlayer__mNativeMediaPlayer__set__catchAll(env, thiz, (intptr_t) mp); pthread_mutex_unlock(&g_clazz.mutex); // NOTE: ijkmp_dec_ref may block thread if (old != NULL ) { ijkmp_dec_ref_p(&old); } return old; }
static IjkMediaPlayer *jni_set_media_player(JNIEnv* env, jobject thiz, IjkMediaPlayer *mp) { pthread_mutex_lock(&g_clazz.mutex); IjkMediaPlayer *old = (IjkMediaPlayer*) (intptr_t) (*env)->GetLongField(env, thiz, g_clazz.mNativeMediaPlayer); if (mp) { ijkmp_inc_ref(mp); } (*env)->SetLongField(env, thiz, g_clazz.mNativeMediaPlayer, (intptr_t) mp); pthread_mutex_unlock(&g_clazz.mutex); // NOTE: ijkmp_dec_ref may block thread if (old != NULL) { ijkmp_dec_ref_p(&old); } return old; }
static int message_loop(void *arg) { MPTRACE("message_loop"); JNIEnv *env = NULL; (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL); IjkMediaPlayer *mp = (IjkMediaPlayer*) arg; JNI_CHECK_GOTO(mp, env, NULL, "mpjni: native_message_loop: null mp", LABEL_RETURN); message_loop_n(env, mp); LABEL_RETURN: ijkmp_dec_ref_p(&mp); (*g_jvm)->DetachCurrentThread(g_jvm); MPTRACE("message_loop exit"); return 0; }
IjkMediaPlayer *ijkmp_android_create(int(*msg_loop)(void*)) { IjkMediaPlayer *mp = ijkmp_create(msg_loop); if (!mp) goto fail; mp->ffplayer->vout = SDL_VoutAndroid_CreateForAndroidSurface(); if (!mp->ffplayer->vout) goto fail; mp->ffplayer->aout = SDL_AoutAndroid_CreateForAudioTrack(); if (!mp->ffplayer->aout) goto fail; return mp; fail: ijkmp_dec_ref_p(&mp); return NULL; }
static jstring IjkMediaPlayer_getAudioCodecInfo(JNIEnv *env, jobject thiz) { MPTRACE("%s", __func__); jstring jcodec_info = NULL; int ret = 0; char *codec_info = NULL; IjkMediaPlayer *mp = jni_get_media_player(env, thiz); JNI_CHECK_GOTO(mp, env, "java/lang/IllegalStateException", "mpjni: getAudioCodecInfo: null mp", LABEL_RETURN); ret = ijkmp_get_audio_codec_info(mp, &codec_info); if (ret < 0 || !codec_info) goto LABEL_RETURN; jcodec_info = (*env)->NewStringUTF(env, codec_info); LABEL_RETURN: if (codec_info) free(codec_info); ijkmp_dec_ref_p(&mp); return jcodec_info; }