This will allow users to pass the Android ApplicationContext which is mandatory to retrieve the ContentResolver responsible to resolve/open Android content URIS.
Unified · Split
| @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | API changes, most recent first: | 3 | API changes, most recent first: |
| 4 | 4 | ||
| 5 | 2024-03-xx - xxxxxxxxxx - lavc 61.3.100 - jni.h | ||
| 6 | Add av_jni_set_android_app_ctx() and av_jni_get_android_app_ctx(). | ||
| 7 | |||
| 5 | 2024-03-22 - xxxxxxxxxx - lavu 59.4.100 - frame.h | 8 | 2024-03-22 - xxxxxxxxxx - lavu 59.4.100 - frame.h |
| 6 | Constified the first-level pointee of av_frame_side_data_get() | 9 | Constified the first-level pointee of av_frame_side_data_get() |
| 7 | and renamed it to av_frame_side_data_get_c(). From now on, | 10 | and renamed it to av_frame_side_data_get_c(). From now on, |
| @@ -35,6 +35,7 @@ · 34 unmodified lines | |||
| 35 | #include "ffjni.h" | 35 | #include "ffjni.h" |
| 36 | 36 | ||
| 37 | static void *java_vm; | 37 | static void *java_vm; |
| 38 | static void *android_app_ctx; | ||
| 38 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; | 39 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; |
| 39 | 40 | ||
| 40 | int av_jni_set_java_vm(void *vm, void *log_ctx) | 41 | int av_jni_set_java_vm(void *vm, void *log_ctx) |
| @@ -77,3 +78,45 @@ void *av_jni_get_java_vm(void *log_ctx) · 36 unmodified lines | |||
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | #endif | 80 | #endif |
| 81 | |||
| 82 | #if defined(__ANDROID__) | ||
| 83 | |||
| 84 | int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx) | ||
| 85 | { | ||
| 86 | #if CONFIG_JNI | ||
| 87 | JNIEnv *env = ff_jni_get_env(log_ctx); | ||
| 88 | if (!env) | ||
| 89 | return AVERROR(EINVAL); | ||
| 90 | |||
| 91 | jobjectRefType type = (*env)->GetObjectRefType(env, app_ctx); | ||
| 92 | if (type != JNIGlobalRefType) { | ||
| 93 | av_log(log_ctx, AV_LOG_ERROR, "Application context must be passed as a global reference"); | ||
| 94 | return AVERROR(EINVAL); | ||
| 95 | } | ||
| 96 | |||
| 97 | pthread_mutex_lock(&lock); | ||
| 98 | android_app_ctx = app_ctx; | ||
| 99 | pthread_mutex_unlock(&lock); | ||
| 100 | |||
| 101 | return 0; | ||
| 102 | #else | ||
| 103 | return AVERROR(ENOSYS); | ||
| 104 | #endif | ||
| 105 | } | ||
| 106 | |||
| 107 | void *av_jni_get_android_app_ctx(void) | ||
| 108 | { | ||
| 109 | #if CONFIG_JNI | ||
| 110 | void *ctx; | ||
| 111 | |||
| 112 | pthread_mutex_lock(&lock); | ||
| 113 | ctx = android_app_ctx; | ||
| 114 | pthread_mutex_unlock(&lock); | ||
| 115 | |||
| 116 | return ctx; | ||
| 117 | #else | ||
| 118 | return NULL; | ||
| 119 | #endif | ||
| 120 | } | ||
| 121 | |||
| 122 | #endif | ||
| @@ -43,4 +43,25 @@ int av_jni_set_java_vm(void *vm, void *log_ctx); · 42 unmodified lines | |||
| 43 | */ | 43 | */ |
| 44 | void *av_jni_get_java_vm(void *log_ctx); | 44 | void *av_jni_get_java_vm(void *log_ctx); |
| 45 | 45 | ||
| 46 | /* | ||
| 47 | * Set the Android application context which will be used to retrieve the Android | ||
| 48 | * content resolver to handle content uris. | ||
| 49 | * | ||
| 50 | * This function is only available on Android. | ||
| 51 | * | ||
| 52 | * @param app_ctx global JNI reference to the Android application context | ||
| 53 | * @return 0 on success, < 0 otherwise | ||
| 54 | */ | ||
| 55 | int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx); | ||
| 56 | |||
| 57 | /* | ||
| 58 | * Get the Android application context that has been set with | ||
| 59 | * av_jni_set_android_app_ctx. | ||
| 60 | * | ||
| 61 | * This function is only available on Android. | ||
| 62 | * | ||
| 63 | * @return a pointer the the Android application context | ||
| 64 | */ | ||
| 65 | void *av_jni_get_android_app_ctx(void); | ||
| 66 | |||
| 46 | #endif /* AVCODEC_JNI_H */ | 67 | #endif /* AVCODEC_JNI_H */ |