android jni中使用native Window渲染ffmpeg frame中的rgba数据
初始化:
jobject surface=NULL;
ANativeWindow* nativeWindow=NULL;
ANativeWindow_Buffer outBuffer;
nativeWindow=ANativeWindow_fromSurface(env, surface);
使用:
ANativeWindow_setBuffersGeometry(nativeWindow, filt_frame->width, filt_frame->height,
WINDOW_FORMAT_RGBA_8888);
ANativeWindow_lock(nativeWindow, &outBuffer, NULL);
uint8_t *dst = (uint8_t *) outBuffer.bits;
int destStride = outBuffer.stride * 4;
uint8_t *src = filt_frame->data[0];
int srcStride = filt_frame->linesize[0];
for (int i = 0; i < filt_frame->height; ++i) {
memcpy(dst + i * destStride, src + i * srcStride,
static_cast<size_t>(srcStride));
}
ANativeWindow_unlockAndPost(nativeWindow);
关闭:
if (nativeWindow!=NULL)
ANativeWindow_release(nativeWindow);
最重要在cmake中添加库
find_library( # Sets the name of the path variable.
lnative_window_jni-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
android )
网友评论