1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * JNI utility functions
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * This file is part of FFmpeg.
7cabdff1aSopenharmony_ci *
8cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
9cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
10cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
11cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
12cabdff1aSopenharmony_ci *
13cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
14cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
15cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16cabdff1aSopenharmony_ci * Lesser General Public License for more details.
17cabdff1aSopenharmony_ci *
18cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
19cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
20cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21cabdff1aSopenharmony_ci */
22cabdff1aSopenharmony_ci
23cabdff1aSopenharmony_ci#ifndef AVCODEC_FFJNI_H
24cabdff1aSopenharmony_ci#define AVCODEC_FFJNI_H
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_ci#include <jni.h>
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_ci/*
29cabdff1aSopenharmony_ci * Attach permanently a JNI environment to the current thread and retrieve it.
30cabdff1aSopenharmony_ci *
31cabdff1aSopenharmony_ci * If successfully attached, the JNI environment will automatically be detached
32cabdff1aSopenharmony_ci * at thread destruction.
33cabdff1aSopenharmony_ci *
34cabdff1aSopenharmony_ci * @param attached pointer to an integer that will be set to 1 if the
35cabdff1aSopenharmony_ci * environment has been attached to the current thread or 0 if it is
36cabdff1aSopenharmony_ci * already attached.
37cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
38cabdff1aSopenharmony_ci * @return the JNI environment on success, NULL otherwise
39cabdff1aSopenharmony_ci */
40cabdff1aSopenharmony_ciJNIEnv *ff_jni_get_env(void *log_ctx);
41cabdff1aSopenharmony_ci
42cabdff1aSopenharmony_ci/*
43cabdff1aSopenharmony_ci * Convert a jstring to its utf characters equivalent.
44cabdff1aSopenharmony_ci *
45cabdff1aSopenharmony_ci * @param env JNI environment
46cabdff1aSopenharmony_ci * @param string Java string to convert
47cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
48cabdff1aSopenharmony_ci * @return a pointer to an array of unicode characters on success, NULL
49cabdff1aSopenharmony_ci * otherwise
50cabdff1aSopenharmony_ci */
51cabdff1aSopenharmony_cichar *ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx);
52cabdff1aSopenharmony_ci
53cabdff1aSopenharmony_ci/*
54cabdff1aSopenharmony_ci * Convert utf chars to its jstring equivalent.
55cabdff1aSopenharmony_ci *
56cabdff1aSopenharmony_ci * @param env JNI environment
57cabdff1aSopenharmony_ci * @param utf_chars a pointer to an array of unicode characters
58cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
59cabdff1aSopenharmony_ci * @return a Java string object on success, NULL otherwise
60cabdff1aSopenharmony_ci */
61cabdff1aSopenharmony_cijstring ff_jni_utf_chars_to_jstring(JNIEnv *env, const char *utf_chars, void *log_ctx);
62cabdff1aSopenharmony_ci
63cabdff1aSopenharmony_ci/*
64cabdff1aSopenharmony_ci * Extract the error summary from a jthrowable in the form of "className: errorMessage"
65cabdff1aSopenharmony_ci *
66cabdff1aSopenharmony_ci * @param env JNI environment
67cabdff1aSopenharmony_ci * @param exception exception to get the summary from
68cabdff1aSopenharmony_ci * @param error address pointing to the error, the value is updated if a
69cabdff1aSopenharmony_ci * summary can be extracted
70cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
71cabdff1aSopenharmony_ci * @return 0 on success, < 0 otherwise
72cabdff1aSopenharmony_ci */
73cabdff1aSopenharmony_ciint ff_jni_exception_get_summary(JNIEnv *env, jthrowable exception, char **error, void *log_ctx);
74cabdff1aSopenharmony_ci
75cabdff1aSopenharmony_ci/*
76cabdff1aSopenharmony_ci * Check if an exception has occurred,log it using av_log and clear it.
77cabdff1aSopenharmony_ci *
78cabdff1aSopenharmony_ci * @param env JNI environment
79cabdff1aSopenharmony_ci * @param log value used to enable logging if an exception has occurred,
80cabdff1aSopenharmony_ci * 0 disables logging, != 0 enables logging
81cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
82cabdff1aSopenharmony_ci */
83cabdff1aSopenharmony_ciint ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx);
84cabdff1aSopenharmony_ci
85cabdff1aSopenharmony_ci/*
86cabdff1aSopenharmony_ci * Jni field type.
87cabdff1aSopenharmony_ci */
88cabdff1aSopenharmony_cienum FFJniFieldType {
89cabdff1aSopenharmony_ci
90cabdff1aSopenharmony_ci    FF_JNI_CLASS,
91cabdff1aSopenharmony_ci    FF_JNI_FIELD,
92cabdff1aSopenharmony_ci    FF_JNI_STATIC_FIELD,
93cabdff1aSopenharmony_ci    FF_JNI_METHOD,
94cabdff1aSopenharmony_ci    FF_JNI_STATIC_METHOD
95cabdff1aSopenharmony_ci
96cabdff1aSopenharmony_ci};
97cabdff1aSopenharmony_ci
98cabdff1aSopenharmony_ci/*
99cabdff1aSopenharmony_ci * Jni field describing a class, a field or a method to be retrieved using
100cabdff1aSopenharmony_ci * the ff_jni_init_jfields method.
101cabdff1aSopenharmony_ci */
102cabdff1aSopenharmony_cistruct FFJniField {
103cabdff1aSopenharmony_ci
104cabdff1aSopenharmony_ci    const char *name;
105cabdff1aSopenharmony_ci    const char *method;
106cabdff1aSopenharmony_ci    const char *signature;
107cabdff1aSopenharmony_ci    enum FFJniFieldType type;
108cabdff1aSopenharmony_ci    int offset;
109cabdff1aSopenharmony_ci    int mandatory;
110cabdff1aSopenharmony_ci
111cabdff1aSopenharmony_ci};
112cabdff1aSopenharmony_ci
113cabdff1aSopenharmony_ci/*
114cabdff1aSopenharmony_ci * Retrieve class references, field ids and method ids to an arbitrary structure.
115cabdff1aSopenharmony_ci *
116cabdff1aSopenharmony_ci * @param env JNI environment
117cabdff1aSopenharmony_ci * @param jfields a pointer to an arbitrary structure where the different
118cabdff1aSopenharmony_ci * fields are declared and where the FFJNIField mapping table offsets are
119cabdff1aSopenharmony_ci * pointing to
120cabdff1aSopenharmony_ci * @param jfields_mapping null terminated array of FFJNIFields describing
121cabdff1aSopenharmony_ci * the class/field/method to be retrieved
122cabdff1aSopenharmony_ci * @param global make the classes references global. It is the caller
123cabdff1aSopenharmony_ci * responsibility to properly release global references.
124cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
125cabdff1aSopenharmony_ci * @return 0 on success, < 0 otherwise
126cabdff1aSopenharmony_ci */
127cabdff1aSopenharmony_ciint ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx);
128cabdff1aSopenharmony_ci
129cabdff1aSopenharmony_ci/*
130cabdff1aSopenharmony_ci * Delete class references, field ids and method ids of an arbitrary structure.
131cabdff1aSopenharmony_ci *
132cabdff1aSopenharmony_ci * @param env JNI environment
133cabdff1aSopenharmony_ci * @param jfields a pointer to an arbitrary structure where the different
134cabdff1aSopenharmony_ci * fields are declared and where the FFJNIField mapping table offsets are
135cabdff1aSopenharmony_ci * pointing to
136cabdff1aSopenharmony_ci * @param jfields_mapping null terminated array of FFJNIFields describing
137cabdff1aSopenharmony_ci * the class/field/method to be deleted
138cabdff1aSopenharmony_ci * @param global threat the classes references as global and delete them
139cabdff1aSopenharmony_ci * accordingly
140cabdff1aSopenharmony_ci * @param log_ctx context used for logging, can be NULL
141cabdff1aSopenharmony_ci * @return 0 on success, < 0 otherwise
142cabdff1aSopenharmony_ci */
143cabdff1aSopenharmony_ciint ff_jni_reset_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx);
144cabdff1aSopenharmony_ci
145cabdff1aSopenharmony_ci#endif /* AVCODEC_FFJNI_H */
146