Commit 3ab17851 authored by Matthieu Bouron's avatar Matthieu Bouron

lavc: add JNI support

parent 6f5048f4
...@@ -196,6 +196,7 @@ Codecs: ...@@ -196,6 +196,7 @@ Codecs:
interplayvideo.c Mike Melanson interplayvideo.c Mike Melanson
ivi* Kostya Shishkov ivi* Kostya Shishkov
jacosub* Clément Bœsch jacosub* Clément Bœsch
jni*, ffjni* Matthieu Bouron
jpeg2000* Nicolas Bertrand jpeg2000* Nicolas Bertrand
jpeg_ls.c Kostya Shishkov jpeg_ls.c Kostya Shishkov
jvdec.c Peter Ross jvdec.c Peter Ross
......
...@@ -207,6 +207,7 @@ External library support: ...@@ -207,6 +207,7 @@ External library support:
--enable-gnutls enable gnutls, needed for https support --enable-gnutls enable gnutls, needed for https support
if openssl is not used [no] if openssl is not used [no]
--disable-iconv disable iconv [autodetect] --disable-iconv disable iconv [autodetect]
--enable-jni enable JNI support [no]
--enable-ladspa enable LADSPA audio filtering [no] --enable-ladspa enable LADSPA audio filtering [no]
--enable-libass enable libass subtitles rendering, --enable-libass enable libass subtitles rendering,
needed for subtitles and ass filter [no] needed for subtitles and ass filter [no]
...@@ -1436,6 +1437,7 @@ EXTERNAL_LIBRARY_LIST=" ...@@ -1436,6 +1437,7 @@ EXTERNAL_LIBRARY_LIST="
gmp gmp
gnutls gnutls
iconv iconv
jni
ladspa ladspa
libass libass
libbluray libbluray
...@@ -5556,6 +5558,8 @@ enabled decklink && { check_header DeckLinkAPI.h || die "ERROR: DeckLin ...@@ -5556,6 +5558,8 @@ enabled decklink && { check_header DeckLinkAPI.h || die "ERROR: DeckLin
enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; } enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
enabled gmp && require2 gmp gmp.h mpz_export -lgmp enabled gmp && require2 gmp gmp.h mpz_export -lgmp
enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
enabled jni && { [ $target_os = "android" ] && check_header jni.h && enabled pthreads &&
check_lib2 "dlfcn.h" dlopen -ldl; }
enabled ladspa && { check_header ladspa.h || die "ERROR: ladspa.h header not found"; } enabled ladspa && { check_header ladspa.h || die "ERROR: ladspa.h header not found"; }
enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883 enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
enabled libass && require_pkg_config libass ass/ass.h ass_library_init enabled libass && require_pkg_config libass ass/ass.h ass_library_init
...@@ -6324,6 +6328,7 @@ echo "threading support ${thread_type-no}" ...@@ -6324,6 +6328,7 @@ echo "threading support ${thread_type-no}"
echo "safe bitstream reader ${safe_bitstream_reader-no}" echo "safe bitstream reader ${safe_bitstream_reader-no}"
echo "SDL support ${sdl-no}" echo "SDL support ${sdl-no}"
echo "opencl enabled ${opencl-no}" echo "opencl enabled ${opencl-no}"
echo "JNI support ${jni-no}"
echo "texi2html enabled ${texi2html-no}" echo "texi2html enabled ${texi2html-no}"
echo "perl enabled ${perl-no}" echo "perl enabled ${perl-no}"
echo "pod2man enabled ${pod2man-no}" echo "pod2man enabled ${pod2man-no}"
......
...@@ -9,6 +9,7 @@ HEADERS = avcodec.h \ ...@@ -9,6 +9,7 @@ HEADERS = avcodec.h \
d3d11va.h \ d3d11va.h \
dirac.h \ dirac.h \
dxva2.h \ dxva2.h \
jni.h \
qsv.h \ qsv.h \
vaapi.h \ vaapi.h \
vda.h \ vda.h \
...@@ -30,6 +31,7 @@ OBJS = allcodecs.o \ ...@@ -30,6 +31,7 @@ OBJS = allcodecs.o \
dirac.o \ dirac.o \
dv_profile.o \ dv_profile.o \
imgconvert.o \ imgconvert.o \
jni.o \
mathtables.o \ mathtables.o \
options.o \ options.o \
parser.o \ parser.o \
...@@ -79,6 +81,7 @@ OBJS-$(CONFIG_IIRFILTER) += iirfilter.o ...@@ -79,6 +81,7 @@ OBJS-$(CONFIG_IIRFILTER) += iirfilter.o
OBJS-$(CONFIG_IMDCT15) += imdct15.o OBJS-$(CONFIG_IMDCT15) += imdct15.o
OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o
OBJS-$(CONFIG_IVIDSP) += ivi_dsp.o OBJS-$(CONFIG_IVIDSP) += ivi_dsp.o
OBJS-$(CONFIG_JNI) += ffjni.o jni.o
OBJS-$(CONFIG_JPEGTABLES) += jpegtables.o OBJS-$(CONFIG_JPEGTABLES) += jpegtables.o
OBJS-$(CONFIG_LIBXVID) += libxvid_rc.o OBJS-$(CONFIG_LIBXVID) += libxvid_rc.o
OBJS-$(CONFIG_LLAUDDSP) += lossless_audiodsp.o OBJS-$(CONFIG_LLAUDDSP) += lossless_audiodsp.o
...@@ -936,6 +939,7 @@ SKIPHEADERS += %_tablegen.h \ ...@@ -936,6 +939,7 @@ SKIPHEADERS += %_tablegen.h \
SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
SKIPHEADERS-$(CONFIG_JNI) += ffjni.h
SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
SKIPHEADERS-$(CONFIG_LIBUTVIDEO) += libutvideo.h SKIPHEADERS-$(CONFIG_LIBUTVIDEO) += libutvideo.h
SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h
......
This diff is collapsed.
/*
* JNI utility functions
*
* Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_FFJNI_H
#define AVCODEC_FFJNI_H
#include <jni.h>
/*
* Attach a JNI environment to the current thread.
*
* @param attached pointer to an integer that will be set to 1 if the
* environment has been attached to the current thread or 0 if it is
* already attached.
* @param log_ctx context used for logging, can be NULL
* @return the JNI environment on success, NULL otherwise
*/
JNIEnv *ff_jni_attach_env(int *attached, void *log_ctx);
/*
* Detach the JNI environment from the current thread.
*
* @param log_ctx context used for logging, can be NULL
* @return 0 on success, < 0 otherwise
*/
int ff_jni_detach_env(void *log_ctx);
/*
* Convert a jstring to its utf characters equivalent.
*
* @param env JNI environment
* @param string Java string to convert
* @param log_ctx context used for logging, can be NULL
* @return a pointer to an array of unicode characters on success, NULL
* otherwise
*/
char *ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx);
/*
* Convert utf chars to its jstring equivalent.
*
* @param env JNI environment
* @param utf_chars a pointer to an array of unicode characters
* @param log_ctx context used for logging, can be NULL
* @return a Java string object on success, NULL otherwise
*/
jstring ff_jni_utf_chars_to_jstring(JNIEnv *env, const char *utf_chars, void *log_ctx);
/*
* Extract the error summary from a jthrowable in the form of "className: errorMessage"
*
* @param env JNI environment
* @param exception exception to get the summary from
* @param error address pointing to the error, the value is updated if a
* summary can be extracted
* @param log_ctx context used for logging, can be NULL
* @return 0 on success, < 0 otherwise
*/
int ff_jni_exception_get_summary(JNIEnv *env, jthrowable exception, char **error, void *log_ctx);
/*
* Check if an exception has occurred,log it using av_log and clear it.
*
* @param env JNI environment
* @param log value used to enable logging if an exception has occurred,
* 0 disables logging, != 0 enables logging
* @param log_ctx context used for logging, can be NULL
*/
int ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx);
/*
* Jni field type.
*/
enum FFJniFieldType {
FF_JNI_CLASS,
FF_JNI_FIELD,
FF_JNI_STATIC_FIELD,
FF_JNI_METHOD,
FF_JNI_STATIC_METHOD
};
/*
* Jni field describing a class, a field or a method to be retrieved using
* the ff_jni_init_jfields method.
*/
struct FFJniField {
const char *name;
const char *method;
const char *signature;
enum FFJniFieldType type;
int offset;
int mandatory;
};
/*
* Retrieve class references, field ids and method ids to an arbitrary structure.
*
* @param env JNI environment
* @param jfields a pointer to an arbitrary structure where the different
* fields are declared and where the FFJNIField mapping table offsets are
* pointing to
* @param jfields_mapping null terminated array of FFJNIFields describing
* the class/field/method to be retrieved
* @param global make the classes references global. It is the caller
* responsibility to properly release global references.
* @param log_ctx context used for logging, can be NULL
* @return 0 on success, < 0 otherwise
*/
int ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx);
/*
* Delete class references, field ids and method ids of an arbitrary structure.
*
* @param env JNI environment
* @param jfields a pointer to an arbitrary structure where the different
* fields are declared and where the FFJNIField mapping table offsets are
* pointing to
* @param jfields_mapping null terminated array of FFJNIFields describing
* the class/field/method to be deleted
* @param global threat the classes references as global and delete them
* accordingly
* @param log_ctx context used for logging, can be NULL
* @return 0 on success, < 0 otherwise
*/
int ff_jni_reset_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx);
#endif /* AVCODEC_FFJNI_H */
/*
* JNI public API functions
*
* Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include "config.h"
#include "jni.h"
#if CONFIG_JNI
#include <errno.h>
#include <jni.h>
#include <pthread.h>
#include "libavutil/log.h"
#include "libavutil/error.h"
#include "ffjni.h"
void *java_vm;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
int av_jni_set_java_vm(void *vm, void *log_ctx)
{
int ret = 0;
pthread_mutex_lock(&lock);
if (java_vm == NULL) {
java_vm = vm;
} else if (java_vm != vm) {
ret = AVERROR(EINVAL);
av_log(log_ctx, AV_LOG_ERROR, "A Java virtual machine has already been set");
}
pthread_mutex_unlock(&lock);
return ret;
}
void *av_jni_get_java_vm(void *log_ctx)
{
void *vm;
pthread_mutex_lock(&lock);
vm = java_vm;
pthread_mutex_unlock(&lock);
return vm;
}
#else
int av_jni_set_java_vm(void *vm, void *log_ctx)
{
return 0;
}
void *av_jni_get_java_vm(void *log_ctx)
{
return NULL;
}
#endif
/*
* JNI public API functions
*
* Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_JNI_H
#define AVCODEC_JNI_H
/*
* Manually set a Java virtual machine which will be used to retrieve the JNI
* environment. Once a Java VM is set it cannot be changed afterwards, meaning
* you can call multiple times av_jni_set_java_vm with the same Java VM pointer
* however it will error out if you try to set a different Java VM.
*
* @param vm Java virtual machine
* @param log_ctx context used for logging, can be NULL
* @return 0 on success, < 0 otherwise
*/
int av_jni_set_java_vm(void *vm, void *log_ctx);
/*
* Get the Java virtual machine which has been set with av_jni_set_java_vm.
*
* @param vm Java virtual machine
* @return a pointer to the Java virtual machine
*/
void *av_jni_get_java_vm(void *log_ctx);
#endif /* AVCODEC_JNI_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment