Surfaceview中的surface是用来渲染视频的,而编解码一般都是用C或C++来实现的。那么Native就要能够操作SurfaceView中的surface。而ANativeWindow正是android为我们提供的Surface。
先上流程图
ANativeWindow_fromSurface
/**
* Return the ANativeWindow associated with a Java Surface object,
* for interacting with it through native code. This acquires a reference
* on the ANativeWindow that is returned; be sure to use ANativeWindow_release()
* when done with it so that it doesn't leak.
*/
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
通过java层传过来的surface就可以获得ANativeWindow
ANativeWindow_setBuffersGeometry
int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
int32_t width, int32_t height, int32_t format);
设置渲染buffer的宽高格式
ANativeWindow_lock
/**
* Lock the window's next drawing surface for writing.
* inOutDirtyBounds is used as an in/out parameter, upon entering the
* function, it contains the dirty region, that is, the region the caller
* intends to redraw. When the function returns, inOutDirtyBounds is updated
* with the actual area the caller needs to redraw -- this region is often
* extended by {@link ANativeWindow_lock}.
*
* \return 0 for success, or a negative value on error.
*/
int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
ARect* inOutDirtyBounds);
锁定surface,以便于写数据
ANativeWindow_unlockAndPost
/**
* Unlock the window's drawing surface after previously locking it,
* posting the new buffer to the display.
*
* \return 0 for success, or a negative value on error.
*/
int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
解锁buffer并且显示图像
具体使用请参考