OSDN Git Service

avcodec/vorbisenc: Include bufqueue and afqueue
[android-x86/external-ffmpeg.git] / 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 "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 void *java_vm;
38 pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
39
40 int av_jni_set_java_vm(void *vm, void *log_ctx)
41 {
42     int ret = 0;
43
44     pthread_mutex_lock(&lock);
45     if (java_vm == NULL) {
46         java_vm = vm;
47     } else if (java_vm != vm) {
48         ret = AVERROR(EINVAL);
49         av_log(log_ctx, AV_LOG_ERROR, "A Java virtual machine has already been set");
50     }
51     pthread_mutex_unlock(&lock);
52
53     return ret;
54 }
55
56 void *av_jni_get_java_vm(void *log_ctx)
57 {
58     void *vm;
59
60     pthread_mutex_lock(&lock);
61     vm = java_vm;
62     pthread_mutex_unlock(&lock);
63
64     return vm;
65 }
66
67 #else
68
69 int av_jni_set_java_vm(void *vm, void *log_ctx)
70 {
71     return AVERROR(ENOSYS);
72 }
73
74 void *av_jni_get_java_vm(void *log_ctx)
75 {
76     return NULL;
77 }
78
79 #endif