Browse Source

[android] Initial implementation for MediaCodec

lsfg-android
CamilleLaVey 4 weeks ago
parent
commit
a1b7cd51b4
  1. 5
      externals/ffmpeg/CMakeLists.txt
  2. 4
      src/common/android/id_cache.cpp
  3. 1
      src/common/android/id_cache.h
  4. 13
      src/video_core/host1x/ffmpeg.cpp

5
externals/ffmpeg/CMakeLists.txt

@ -59,6 +59,11 @@ endif()
if (PLATFORM_PS4 OR PLATFORM_MANAGARM) if (PLATFORM_PS4 OR PLATFORM_MANAGARM)
# Doesn't support VA-API, don't go thru the embarrassment of trying to enable it # Doesn't support VA-API, don't go thru the embarrassment of trying to enable it
list(APPEND FFmpeg_HWACCEL_FLAGS --disable-vaapi) list(APPEND FFmpeg_HWACCEL_FLAGS --disable-vaapi)
elseif (ANDROID)
list(APPEND FFmpeg_HWACCEL_FLAGS
--enable-mediacodec
--enable-jni
)
elseif (UNIX AND NOT DEFINED FFmpeg_IS_CROSS_COMPILING AND NOT ANDROID) elseif (UNIX AND NOT DEFINED FFmpeg_IS_CROSS_COMPILING AND NOT ANDROID)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBVA libva) pkg_check_modules(LIBVA libva)

4
src/common/android/id_cache.cpp

@ -123,6 +123,10 @@ namespace Common::Android {
return owned.env; return owned.env;
} }
JavaVM *GetJavaVM() {
return s_java_vm;
}
jclass GetNativeLibraryClass() { jclass GetNativeLibraryClass() {
return s_native_library_class; return s_native_library_class;
} }

1
src/common/android/id_cache.h

@ -12,6 +12,7 @@
namespace Common::Android { namespace Common::Android {
JNIEnv* GetEnvForThread(); JNIEnv* GetEnvForThread();
JavaVM* GetJavaVM();
/** /**
* Starts a new thread to run JNI. Intended to be used when you must run JNI from a fiber. * Starts a new thread to run JNI. Intended to be used when you must run JNI from a fiber.

13
src/video_core/host1x/ffmpeg.cpp

@ -19,8 +19,16 @@ extern "C" {
#endif #endif
#include <libavutil/hwcontext.h> #include <libavutil/hwcontext.h>
#if defined(__ANDROID__)
#include <libavcodec/jni.h>
#endif
} }
#if defined(__ANDROID__)
#include "common/android/id_cache.h"
#endif
namespace FFmpeg { namespace FFmpeg {
namespace { namespace {
@ -290,6 +298,11 @@ bool DecodeApi::Initialize(Tegra::Host1x::NvdecCommon::VideoCodec codec) {
// Enable GPU decoding if requested. // Enable GPU decoding if requested.
if (Settings::values.nvdec_emulation.GetValue() == Settings::NvdecEmulation::Gpu) { if (Settings::values.nvdec_emulation.GetValue() == Settings::NvdecEmulation::Gpu) {
#if defined(__ANDROID__)
static const int jni_vm_result =
av_jni_set_java_vm(Common::Android::GetJavaVM(), nullptr);
(void)jni_vm_result;
#endif
m_hardware_context.emplace(); m_hardware_context.emplace();
m_hardware_context->InitializeForDecoder(*m_decoder_context, *m_decoder); m_hardware_context->InitializeForDecoder(*m_decoder_context, *m_decoder);
} }

Loading…
Cancel
Save