FFmpeg
jni.c
Go to the documentation of this file.
1 /*
2  * JNI public API functions
3  *
4  * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config.h"
24 
25 #include <stdlib.h>
26 
27 #include "libavutil/error.h"
28 #include "jni.h"
29 
30 #if CONFIG_JNI
31 #include <jni.h>
32 #include <pthread.h>
33 
34 #include "libavutil/log.h"
35 #include "ffjni.h"
36 
37 static void *java_vm;
38 static void *android_app_ctx;
40 
41 int av_jni_set_java_vm(void *vm, void *log_ctx)
42 {
43  int ret = 0;
44 
46  if (java_vm == NULL) {
47  java_vm = vm;
48  } else if (java_vm != vm) {
49  ret = AVERROR(EINVAL);
50  av_log(log_ctx, AV_LOG_ERROR, "A Java virtual machine has already been set");
51  }
53 
54  return ret;
55 }
56 
57 void *av_jni_get_java_vm(void *log_ctx)
58 {
59  void *vm;
60 
62  vm = java_vm;
64 
65  return vm;
66 }
67 
68 #else
69 
70 int av_jni_set_java_vm(void *vm, void *log_ctx)
71 {
72  return AVERROR(ENOSYS);
73 }
74 
75 void *av_jni_get_java_vm(void *log_ctx)
76 {
77  return NULL;
78 }
79 
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  jobjectRefType type;
88 
89  JNIEnv *env = ff_jni_get_env(log_ctx);
90  if (!env)
91  return AVERROR(EINVAL);
92 
93  type = (*env)->GetObjectRefType(env, app_ctx);
94  if (type != JNIGlobalRefType) {
95  av_log(log_ctx, AV_LOG_ERROR, "Application context must be passed as a global reference");
96  return AVERROR(EINVAL);
97  }
98 
100  android_app_ctx = app_ctx;
102 
103  return 0;
104 #else
105  return AVERROR(ENOSYS);
106 #endif
107 }
108 
109 void *av_jni_get_android_app_ctx(void)
110 {
111 #if CONFIG_JNI
112  void *ctx;
113 
115  ctx = android_app_ctx;
117 
118  return ctx;
119 #else
120  return NULL;
121 #endif
122 }
123 
124 #endif
pthread_mutex_t
_fmutex pthread_mutex_t
Definition: os2threads.h:53
av_jni_set_android_app_ctx
int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx)
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_jni_set_java_vm
int av_jni_set_java_vm(void *vm, void *log_ctx)
Definition: jni.c:70
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
ctx
AVFormatContext * ctx
Definition: movenc.c:49
java_vm
static JavaVM * java_vm
Definition: ffjni.c:36
NULL
#define NULL
Definition: coverity.c:32
pthread_mutex_unlock
#define pthread_mutex_unlock(a)
Definition: ffprobe.c:82
error.h
lock
static pthread_mutex_t lock
Definition: ffjni.c:39
log.h
ffjni.h
av_jni_get_android_app_ctx
void * av_jni_get_android_app_ctx(void)
av_jni_get_java_vm
void * av_jni_get_java_vm(void *log_ctx)
Definition: jni.c:75
ret
ret
Definition: filter_design.txt:187
ff_jni_get_env
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition: ffjni.c:53
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
jni.h
PTHREAD_MUTEX_INITIALIZER
#define PTHREAD_MUTEX_INITIALIZER
Definition: os2threads.h:56
pthread_mutex_lock
#define pthread_mutex_lock(a)
Definition: ffprobe.c:78