Browse Source

modules: split android_env from android_utils

android_utils depends on GLES2_LIBS and EGL_LIBS, but it isn't forwarded
correctly from the convenience library. In particlar, it contains mostly
video-related code, and some helpers for the android environment state,
which is why the non-video code is using the utils library.

Move the code in a separate convenience library so that it can be
imported without constraints.
pull/144/head
Alexandre Janniaux 5 years ago
committed by Thomas Guillem
parent
commit
c65493d689
  1. 6
      modules/audio_output/Makefile.am
  2. 2
      modules/audio_output/android/audiotrack.c
  3. 2
      modules/audio_output/android/device.c
  4. 3
      modules/audio_output/android/opensles.c
  5. 3
      modules/codec/Makefile.am
  6. 1
      modules/codec/omxil/mediacodec_jni.c
  7. 2
      modules/keystore/Makefile.am
  8. 2
      modules/keystore/file_crypt_android.c
  9. 18
      modules/video_output/Makefile.am
  10. 103
      modules/video_output/android/env.c
  11. 33
      modules/video_output/android/env.h
  12. 80
      modules/video_output/android/utils.c
  13. 9
      modules/video_output/android/utils.h
  14. 3
      modules/video_output/opengl/Makefile.am

6
modules/audio_output/Makefile.am

@ -2,13 +2,13 @@ aoutdir = $(pluginsdir)/audio_output
aout_LTLIBRARIES =
libopensles_android_plugin_la_SOURCES = audio_output/android/opensles.c
libopensles_android_plugin_la_LIBADD = libandroid_utils.la $(LIBDL) $(LIBM)
libopensles_android_plugin_la_LIBADD = libandroid_env.la $(LIBDL) $(LIBM)
libandroid_audiotrack_plugin_la_SOURCES = audio_output/android/audiotrack.c audio_output/android/device.h
libandroid_audiotrack_plugin_la_LIBADD = libandroid_utils.la
libandroid_audiotrack_plugin_la_LIBADD = libandroid_env.la
libandroid_aaudio_plugin_la_SOURCES = audio_output/android/aaudio.c audio_output/android/device.h
libandroid_aaudio_plugin_la_LIBADD = libandroid_utils.la $(LIBDL)
libandroid_aaudio_plugin_la_LIBADD = libandroid_env.la $(LIBDL)
libandroid_audiodevice_plugin_la_SOURCES = audio_output/android/device.c audio_output/android/device.h

2
modules/audio_output/android/audiotrack.c

@ -33,7 +33,7 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>
#include "../video_output/android/utils.h"
#include "../video_output/android/env.h"
#include "device.h"
#define SMOOTHPOS_SAMPLE_COUNT 10

2
modules/audio_output/android/device.c

@ -29,7 +29,7 @@
#include <vlc_modules.h>
#include <vlc_aout.h>
#include "device.h"
#include "../video_output/android/utils.h"
#include "../video_output/android/env.h"
/* There is an undefined behavior when configuring AudioTrack with SPDIF or
* more than 2 channels when there is no HDMI out. It may succeed and the

3
modules/audio_output/android/opensles.c

@ -33,12 +33,13 @@
#include <dlfcn.h>
#include <math.h>
#include "../../video_output/android/env.h"
// For native audio
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#include <jni.h>
JNIEnv *android_getEnv(vlc_object_t *p_obj, const char *psz_thread_name);
#define OPENSLES_BUFFERS 255 /* maximum number of buffers */
#define OPENSLES_BUFLEN VLC_TICK_FROM_MS(10)

3
modules/codec/Makefile.am

@ -487,7 +487,8 @@ libmediacodec_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/codec/omxil
libmediacodec_plugin_la_SOURCES = codec/omxil/mediacodec.c codec/omxil/mediacodec.h \
codec/omxil/mediacodec_jni.c codec/omxil/mediacodec_ndk.c codec/omxil/utils.c \
codec/omxil/omxil_utils.h codec/omxil/qcom.c codec/omxil/qcom.h
libmediacodec_plugin_la_LIBADD = libchroma_copy.la libvlc_hxxxhelper.la libandroid_utils.la $(LIBDL)
libmediacodec_plugin_la_LIBADD = libchroma_copy.la libvlc_hxxxhelper.la \
libandroid_env.la libandroid_utils.la $(LIBDL) $(GLES2_LIBS) $(EGL_LIBS)
codec_LTLIBRARIES += $(LTLIBomxil)
EXTRA_LTLIBRARIES += libomxil_plugin.la
if HAVE_ANDROID

1
modules/codec/omxil/mediacodec_jni.c

@ -37,6 +37,7 @@
#include "../../packetizer/hevc_nal.h"
#include "mediacodec.h"
#include "../../video_output/android/env.h"
char* MediaCodec_GetName(vlc_object_t *p_obj, const char *psz_mime,
int profile, int *p_quirks);

2
modules/keystore/Makefile.am

@ -9,7 +9,7 @@ libfile_keystore_plugin_la_SOURCES = keystore/file.c \
keystore/list_util.c keystore/list_util.h
if HAVE_ANDROID
libfile_keystore_plugin_la_SOURCES += keystore/file_crypt_android.c
libfile_keystore_plugin_la_LIBADD = libandroid_utils.la
libfile_keystore_plugin_la_LIBADD = libandroid_env.la
endif
if HAVE_WIN32
libfile_keystore_plugin_la_SOURCES += keystore/file_crypt_win32.c

2
modules/keystore/file_crypt_android.c

@ -32,7 +32,7 @@
#include <jni.h>
JNIEnv * android_getEnv(vlc_object_t *, const char *);
#include "../video_output/android/env.h"
#define GET_ENV() android_getEnv(VLC_OBJECT(p_keystore), "android keystore")
static struct

18
modules/video_output/Makefile.am

@ -291,26 +291,34 @@ endif
libandroid_utils_la_SOURCES = video_output/android/utils.c video_output/android/utils.h
libandroid_utils_la_CFLAGS = $(AM_CFLAGS) $(GLES2_CFLAGS) $(EGL_CFLAGS)
libandroid_utils_la_LIBADD = $(GLES2_LIBS) $(EGL_LIBS)
libandroid_env_la_SOURCES = \
video_output/android/env.c \
video_output/android/env.h
if HAVE_ANDROID
noinst_LTLIBRARIES += libandroid_utils.la
noinst_LTLIBRARIES += \
libandroid_utils.la \
libandroid_env.la
endif
libegl_android_plugin_la_SOURCES = video_output/opengl/egl.c
libegl_android_plugin_la_CFLAGS = $(AM_CFLAGS) $(EGL_CFLAGS) -DUSE_PLATFORM_ANDROID=1
libegl_android_plugin_la_LIBADD = $(EGL_LIBS) libandroid_utils.la
libegl_android_plugin_la_LIBADD = libandroid_env.la $(EGL_LIBS) libandroid_utils.la
libandroid_window_plugin_la_SOURCES = video_output/android/window.c \
video_output/wasync_resize_compressor.h
libandroid_window_plugin_la_LIBADD = libandroid_utils.la $(LIBDL)
libandroid_window_plugin_la_LIBADD = \
libandroid_env.la libandroid_utils.la $(LIBDL) $(EGL_LIBS) $(GLES2_LIBS)
libandroid_display_plugin_la_SOURCES = video_output/android/display.c
libandroid_display_plugin_la_CFLAGS = $(AM_CFLAGS) $(GLES2_CFLAGS) -DUSE_OPENGL_ES2
libandroid_display_plugin_la_LIBADD = libvlc_opengles.la
libandroid_display_plugin_la_LIBADD = libvlc_opengles.la $(EGL_LIBS) $(GLES2_LIBS)
libglinterop_android_plugin_la_SOURCES = video_output/opengl/interop_android.c \
video_output/opengl/interop.h
libglinterop_android_plugin_la_CFLAGS = $(AM_CFLAGS) -DUSE_OPENGL_ES2
libglinterop_android_plugin_la_LIBADD = libandroid_utils.la
libglinterop_android_plugin_la_LIBADD = libandroid_env.la libandroid_utils.la \
$(EGL_LIBS) $(GLES2_LIBS)
if HAVE_ANDROID
vout_LTLIBRARIES += libandroid_window_plugin.la libandroid_display_plugin.la

103
modules/video_output/android/env.c

@ -0,0 +1,103 @@
/*****************************************************************************
* env.c: shared code between Android modules.
*****************************************************************************
* Copyright (C) 2014-2015 VLC authors and VideoLAN
*
* Authors: Felix Abecassis <felix.abecassis@gmail.com>
* Thomas Guillem <thomas@gllm.fr>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "utils.h"
#include <dlfcn.h>
#include <jni.h>
#include <pthread.h>
#include <assert.h>
/*
* Android JNIEnv helper
*/
static pthread_key_t jni_env_key;
static pthread_once_t jni_env_key_once = PTHREAD_ONCE_INIT;
/* This function is called when a thread attached to the Java VM is canceled or
* exited */
static void
jni_detach_thread(void *data)
{
JNIEnv *env = data;
JavaVM *jvm;
(*env)->GetJavaVM(env, &jvm);
assert(jvm);
(*jvm)->DetachCurrentThread(jvm);
}
static void jni_env_key_create()
{
/* Create a TSD area and setup a destroy callback when a thread that
* previously set the jni_env_key is canceled or exited */
pthread_key_create(&jni_env_key, jni_detach_thread);
}
JNIEnv *
android_getEnvCommon(vlc_object_t *p_obj, JavaVM *jvm, const char *psz_name)
{
assert((p_obj && !jvm) || (!p_obj && jvm));
JNIEnv *env;
pthread_once(&jni_env_key_once, jni_env_key_create);
env = pthread_getspecific(jni_env_key);
if (env == NULL)
{
if (!jvm)
jvm = var_InheritAddress(p_obj, "android-jvm");
if (!jvm)
return NULL;
/* if GetEnv returns JNI_OK, the thread is already attached to the
* JavaVM, so we are already in a java thread, and we don't have to
* setup any destroy callbacks */
if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2) != JNI_OK)
{
/* attach the thread to the Java VM */
JavaVMAttachArgs args;
args.version = JNI_VERSION_1_2;
args.name = psz_name;
args.group = NULL;
if ((*jvm)->AttachCurrentThread(jvm, &env, &args) != JNI_OK)
return NULL;
/* Set the attached env to the thread-specific data area (TSD) */
if (pthread_setspecific(jni_env_key, env) != 0)
{
(*jvm)->DetachCurrentThread(jvm);
return NULL;
}
}
}
return env;
}

33
modules/video_output/android/env.h

@ -0,0 +1,33 @@
/*****************************************************************************
* env.h: shared code between Android modules
*****************************************************************************
* Copyright (C) 2014-2015 VLC authors and VideoLAN
*
* Authors: Felix Abecassis <felix.abecassis@gmail.com>
* Thomas Guillem <thomas@gllm.fr>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <jni.h>
JNIEnv *
android_getEnvCommon(vlc_object_t *p_obj, JavaVM *jvm, const char *psz_name);
static inline JNIEnv *
android_getEnv(vlc_object_t *p_obj, const char *psz_name)
{
return android_getEnvCommon(p_obj, NULL, psz_name);
}

80
modules/video_output/android/utils.c

@ -26,6 +26,8 @@
#endif
#include "utils.h"
#include "env.h"
#include <dlfcn.h>
#include <jni.h>
#include <pthread.h>
@ -150,84 +152,6 @@ struct AWindowHandler
#define JNI_STEXCALL(what, method, ...) \
(*p_env)->what(p_env, p_awh->jobj, p_awh->jfields.AWindow.method, ##__VA_ARGS__)
/*
* Android JNIEnv helper
*/
static pthread_key_t jni_env_key;
static pthread_once_t jni_env_key_once = PTHREAD_ONCE_INIT;
/* This function is called when a thread attached to the Java VM is canceled or
* exited */
static void
jni_detach_thread(void *data)
{
JNIEnv *env = data;
JavaVM *jvm;
(*env)->GetJavaVM(env, &jvm);
assert(jvm);
(*jvm)->DetachCurrentThread(jvm);
}
static void jni_env_key_create()
{
/* Create a TSD area and setup a destroy callback when a thread that
* previously set the jni_env_key is canceled or exited */
pthread_key_create(&jni_env_key, jni_detach_thread);
}
static JNIEnv *
android_getEnvCommon(vlc_object_t *p_obj, JavaVM *jvm, const char *psz_name)
{
assert((p_obj && !jvm) || (!p_obj && jvm));
JNIEnv *env;
pthread_once(&jni_env_key_once, jni_env_key_create);
env = pthread_getspecific(jni_env_key);
if (env == NULL)
{
if (!jvm)
jvm = var_InheritAddress(p_obj, "android-jvm");
if (!jvm)
return NULL;
/* if GetEnv returns JNI_OK, the thread is already attached to the
* JavaVM, so we are already in a java thread, and we don't have to
* setup any destroy callbacks */
if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2) != JNI_OK)
{
/* attach the thread to the Java VM */
JavaVMAttachArgs args;
args.version = JNI_VERSION_1_2;
args.name = psz_name;
args.group = NULL;
if ((*jvm)->AttachCurrentThread(jvm, &env, &args) != JNI_OK)
return NULL;
/* Set the attached env to the thread-specific data area (TSD) */
if (pthread_setspecific(jni_env_key, env) != 0)
{
(*jvm)->DetachCurrentThread(jvm);
return NULL;
}
}
}
return env;
}
JNIEnv *
android_getEnv(vlc_object_t *p_obj, const char *psz_name)
{
return android_getEnvCommon(p_obj, NULL, psz_name);
}
/*
* Android Surface (pre android 2.3)
*/

9
modules/video_output/android/utils.h

@ -114,15 +114,6 @@ struct vlc_asurfacetexture_operations
struct vlc_asurfacetexture *surface);
};
/**
* Attach or get a JNIEnv*
*
* The returned JNIEnv* is created from the android JavaVM attached to the VLC
* object var.
* \return a valid JNIEnv * or NULL. It doesn't need to be released.
*/
JNIEnv *android_getEnv(vlc_object_t *p_obj, const char *psz_thread_name);
/**
* Create new AWindowHandler
*

3
modules/video_output/opengl/Makefile.am

@ -223,7 +223,8 @@ endif
libegl_surfacetexture_plugin_la_SOURCES = video_filter/egl_surfacetexture.c
libegl_surfacetexture_plugin_la_CFLAGS = $(AM_CFLAGS) $(EGL_CFLAGS) -DUSE_OPENGL_ES2
libegl_surfacetexture_plugin_la_LIBADD = $(EGL_LIBS) libandroid_utils.la libvlc_opengles.la
libegl_surfacetexture_plugin_la_LIBADD = $(EGL_LIBS) \
libandroid_env.la libandroid_utils.la libvlc_opengles.la
if HAVE_ANDROID
if HAVE_EGL

Loading…
Cancel
Save