74 {
"android/media/MediaCodecList",
"findDecoderForFormat",
"(Landroid/media/MediaFormat;)Ljava/lang/String;",
FF_JNI_METHOD, offsetof(
struct JNIAMediaCodecListFields, find_decoder_for_format_id), 0 },
81 {
"android/media/MediaCodecInfo",
"getCapabilitiesForType",
"(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;",
FF_JNI_METHOD, offsetof(
struct JNIAMediaCodecListFields, get_codec_capabilities_id), 1 },
88 {
"android/media/MediaCodecInfo$CodecCapabilities",
"profileLevels",
"[Landroid/media/MediaCodecInfo$CodecProfileLevel;",
FF_JNI_FIELD, offsetof(
struct JNIAMediaCodecListFields, profile_levels_id), 1 },
143 {
"android/media/MediaFormat",
"getByteBuffer",
"(Ljava/lang/String;)Ljava/nio/ByteBuffer;",
FF_JNI_METHOD, offsetof(
struct JNIAMediaFormatFields, get_bytebuffer_id), 1 },
149 {
"android/media/MediaFormat",
"setByteBuffer",
"(Ljava/lang/String;Ljava/nio/ByteBuffer;)V",
FF_JNI_METHOD, offsetof(
struct JNIAMediaFormatFields, set_bytebuffer_id), 1 },
239 {
"android/media/MediaCodec",
"configure",
"(Landroid/media/MediaFormat;Landroid/view/Surface;Landroid/media/MediaCrypto;I)V",
FF_JNI_METHOD, offsetof(
struct JNIAMediaCodecFields, configure_id), 1 },
245 {
"android/media/MediaCodec",
"getOutputFormat",
"()Landroid/media/MediaFormat;",
FF_JNI_METHOD, offsetof(
struct JNIAMediaCodecFields, get_output_format_id), 1 },
252 {
"android/media/MediaCodec",
"dequeueOutputBuffer",
"(Landroid/media/MediaCodec$BufferInfo;J)I",
FF_JNI_METHOD, offsetof(
struct JNIAMediaCodecFields, dequeue_output_buffer_id), 1 },
300 #define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret) do { \
301 (env) = ff_jni_get_env(log_ctx); \
307 #define JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx) do { \
308 (env) = ff_jni_get_env(log_ctx); \
320 jfieldID field_id = 0;
390 char *supported_type =
NULL;
396 jobject codec_name =
NULL;
400 jobjectArray types =
NULL;
402 jobject capabilities =
NULL;
403 jobject profile_level =
NULL;
404 jobjectArray profile_levels =
NULL;
421 for(
i = 0;
i < codec_count;
i++) {
441 if (is_encoder != encoder) {
451 if (is_software_only) {
467 (*env)->DeleteLocalRef(env, codec_name);
473 strstr(
name,
"OMX.google") ||
474 strstr(
name,
"OMX.ffmpeg") ||
475 (strstr(
name,
"OMX.SEC") && strstr(
name,
".sw.")) ||
476 !strcmp(
name,
"OMX.qcom.video.decoder.hevcswvdec")) {
480 type_count = (*env)->GetArrayLength(env, types);
481 for (j = 0; j < type_count; j++) {
485 type = (*env)->GetObjectArrayElement(env, types, j);
491 if (!supported_type) {
504 profile_levels = (*env)->GetObjectField(env, capabilities, jfields.
profile_levels_id);
509 profile_count = (*env)->GetArrayLength(env, profile_levels);
510 if (!profile_count) {
513 for (k = 0; k < profile_count; k++) {
514 int supported_profile = 0;
521 profile_level = (*env)->GetObjectArrayElement(env, profile_levels, k);
526 supported_profile = (*env)->GetIntField(env, profile_level, jfields.
profile_id);
531 found_codec =
profile == supported_profile;
534 (*env)->DeleteLocalRef(env, profile_level);
535 profile_level =
NULL;
544 if (profile_levels) {
545 (*env)->DeleteLocalRef(env, profile_levels);
546 profile_levels =
NULL;
550 (*env)->DeleteLocalRef(env, capabilities);
555 (*env)->DeleteLocalRef(env,
type);
568 (*env)->DeleteLocalRef(env,
info);
573 (*env)->DeleteLocalRef(env, types);
586 (*env)->DeleteLocalRef(env, codec_name);
590 (*env)->DeleteLocalRef(env,
info);
594 (*env)->DeleteLocalRef(env,
type);
598 (*env)->DeleteLocalRef(env, types);
602 (*env)->DeleteLocalRef(env, capabilities);
606 (*env)->DeleteLocalRef(env, profile_level);
609 if (profile_levels) {
610 (*env)->DeleteLocalRef(env, profile_levels);
629 jobject
object =
NULL;
647 object = (*env)->NewObject(env,
format->jfields.mediaformat_class,
format->jfields.init_id);
652 format->object = (*env)->NewGlobalRef(env,
object);
659 (*env)->DeleteLocalRef(env,
object);
691 format->object = (*env)->NewGlobalRef(env,
object);
717 (*env)->DeleteGlobalRef(env,
format->object);
758 jboolean contains_key;
770 contains_key = (*env)->CallBooleanMethod(env,
format->object,
format->jfields.contains_key_id,
key);
776 *
out = (*env)->CallIntMethod(env,
format->object,
format->jfields.get_integer_id,
key);
785 (*env)->DeleteLocalRef(env,
key);
797 jboolean contains_key;
809 contains_key = (*env)->CallBooleanMethod(env,
format->object,
format->jfields.contains_key_id,
key);
824 (*env)->DeleteLocalRef(env,
key);
836 jboolean contains_key;
848 contains_key = (*env)->CallBooleanMethod(env,
format->object,
format->jfields.contains_key_id,
key);
854 *
out = (*env)->CallFloatMethod(env,
format->object,
format->jfields.get_float_id,
key);
863 (*env)->DeleteLocalRef(env,
key);
875 jboolean contains_key;
888 contains_key = (*env)->CallBooleanMethod(env,
format->object,
format->jfields.contains_key_id,
key);
900 *
data = (*env)->GetDirectBufferAddress(env,
result);
901 *
size = (*env)->GetDirectBufferCapacity(env,
result);
917 (*env)->DeleteLocalRef(env,
key);
921 (*env)->DeleteLocalRef(env,
result);
933 jboolean contains_key;
946 contains_key = (*env)->CallBooleanMethod(env,
format->object,
format->jfields.contains_key_id,
key);
967 (*env)->DeleteLocalRef(env,
key);
971 (*env)->DeleteLocalRef(env,
result);
998 (*env)->DeleteLocalRef(env,
key);
1023 (*env)->DeleteLocalRef(env,
key);
1048 (*env)->DeleteLocalRef(env,
key);
1056 jstring
string =
NULL;
1072 (*env)->CallVoidMethod(env,
format->object,
format->jfields.set_string_id,
key,
string);
1079 (*env)->DeleteLocalRef(env,
key);
1083 (*env)->DeleteLocalRef(env,
string);
1126 (*env)->DeleteLocalRef(env,
key);
1130 (*env)->DeleteLocalRef(env,
buffer);
1188 #define CREATE_CODEC_BY_NAME 0
1189 #define CREATE_DECODER_BY_TYPE 1
1190 #define CREATE_ENCODER_BY_TYPE 2
1197 jstring jarg =
NULL;
1198 jobject
object =
NULL;
1199 jobject buffer_info =
NULL;
1200 jmethodID create_id =
NULL;
1231 object = (*env)->CallStaticObjectMethod(env,
1239 codec->
object = (*env)->NewGlobalRef(env,
object);
1257 codec->
buffer_info = (*env)->NewGlobalRef(env, buffer_info);
1265 (*env)->DeleteLocalRef(env, jarg);
1269 (*env)->DeleteLocalRef(env,
object);
1273 (*env)->DeleteLocalRef(env, buffer_info);
1278 (*env)->DeleteGlobalRef(env, codec->
object);
1292 #define DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method) \
1293 FFAMediaCodec *ff_AMediaCodec_##name(const char *arg) \
1295 return codec_create(method, arg); \
1314 (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_id);
1319 (*env)->DeleteGlobalRef(env, codec->input_buffers);
1320 codec->input_buffers =
NULL;
1322 (*env)->DeleteGlobalRef(env, codec->output_buffers);
1323 codec->output_buffers =
NULL;
1325 (*env)->DeleteGlobalRef(env, codec->object);
1326 codec->object =
NULL;
1328 (*env)->DeleteGlobalRef(env, codec->buffer_info);
1329 codec->buffer_info =
NULL;
1355 (*env)->DeleteLocalRef(env,
name);
1538 jobject input_buffers =
NULL;
1554 codec->
input_buffers = (*env)->NewGlobalRef(env, input_buffers);
1566 ret = (*env)->GetDirectBufferAddress(env,
buffer);
1570 (*env)->DeleteLocalRef(env,
buffer);
1573 if (input_buffers) {
1574 (*env)->DeleteLocalRef(env, input_buffers);
1586 jobject output_buffers =
NULL;
1602 codec->
output_buffers = (*env)->NewGlobalRef(env, output_buffers);
1614 ret = (*env)->GetDirectBufferAddress(env,
buffer);
1618 (*env)->DeleteLocalRef(env,
buffer);
1621 if (output_buffers) {
1622 (*env)->DeleteLocalRef(env, output_buffers);
1633 jobject mediaformat =
NULL;
1645 (*env)->DeleteLocalRef(env, mediaformat);
1713 jclass versionClass;
1714 jfieldID sdkIntFieldID;
1717 versionClass = (*env)->FindClass(env,
"android/os/Build$VERSION");
1718 sdkIntFieldID = (*env)->GetStaticFieldID(env, versionClass,
"SDK_INT",
"I");
1719 ret = (*env)->GetStaticIntField(env, versionClass, sdkIntFieldID);
1720 (*env)->DeleteLocalRef(env, versionClass);