]> git.sesse.net Git - ffmpeg/blob - libavcodec/jni.c
Merge commit 'e62ff72fc1052273deb708ba715f73e5187281d4'
[ffmpeg] / libavcodec / jni.c
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 <stdlib.h>
24
25 #include "config.h"
26 #include "jni.h"
27
28 #if CONFIG_JNI
29
30 #include <errno.h>
31 #include <jni.h>
32 #include <pthread.h>
33
34 #include "libavutil/log.h"
35 #include "libavutil/error.h"
36 #include "ffjni.h"
37
38 void *java_vm;
39 pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
40
41 int av_jni_set_java_vm(void *vm, void *log_ctx)
42 {
43     int ret = 0;
44
45     pthread_mutex_lock(&lock);
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     }
52     pthread_mutex_unlock(&lock);
53
54     return ret;
55 }
56
57 void *av_jni_get_java_vm(void *log_ctx)
58 {
59     void *vm;
60
61     pthread_mutex_lock(&lock);
62     vm = java_vm;
63     pthread_mutex_unlock(&lock);
64
65     return vm;
66 }
67
68 #else
69
70 int av_jni_set_java_vm(void *vm, void *log_ctx)
71 {
72     return 0;
73 }
74
75 void *av_jni_get_java_vm(void *log_ctx)
76 {
77     return NULL;
78 }
79
80 #endif