问题
The only way to get profit from the fact, that mobile devices have shared memory for CPU and GPU was using GrphicBuffer
. But since Android 7 restrict access to private native libs (including gralloc) it is impossible to use it any more. The question - is there any alternative way to get direct memory access to texture's pixel data?
I know, that something simmilar can be done using PBO (pixel buffer object). But it still does additional memory copy, wich is undesirable. Especially if we know, that there was way to do it with zero copies.
There are many apps, wich used this feature, because it can heavily increase the performance. I think many developers are in stuck with this problem now.
回答1:
I think you can use SurfaceTexture, SurfaceTexture can create by MediaCore, SurfaceTexture can direct encode by MediaCore。This Plan can process 1080p video in 2ms-5ms per video frame。
回答2:
Since Android 8 / API 26 (sorry not for Android 7...)
Hardware Buffer APIs are alts for GrphicBuffer()
.
The native hardware buffer API lets you directly allocate buffers to create your own pipelines for cross-process buffer management. You can allocate an AHardwareBuffer and use it to obtain an EGLClientBuffer resource type via the eglGetNativeClientBufferANDROID extension.
NDK revision history
Minimum revision of NDK is 15c (July 2017)
Android NDK, Revision 15c (July 2017)
Added native APIs for Android 8.0.
* Hardware Buffer API
android/hardware_buffer_jni.h
is in the directory (NDK)/sysroot/usr/include/
Refs:
NDK - Native Hardware Buffer (android/hardware_buffer_jni.h)
Android/Java - HardwareBuffer
GrphicBuffer related article Using OpenGL ES to Accelerate Apps with Legacy 2D GUIs
NB: for Android 7 / API 24
Native API guide also says in Graphics/EGL section
API level 24 added support for the EGL_KHR_mutable_render_buffer, ANDROID_create_native_client_buffer, and ANDROID_front_buffer_auto_refresh extensions.
and EGL_ANDROID_create_native_client_buffer is an EGL extension which contains eglCreateNativeClientBufferANDROID()
, which returns EGLClientBuffer
. (EGL/eglext.h)
来源:https://stackoverflow.com/questions/40527332/android-7-graphicbuffer-alternative-for-direct-access-to-opengl-texture-memory