欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > [Android] NDK 里 ANativeWindow 和 Surface 之间的关系

[Android] NDK 里 ANativeWindow 和 Surface 之间的关系

2024/10/24 15:14:47 来源:https://blog.csdn.net/ykun089/article/details/140960415  浏览:    关键词:[Android] NDK 里 ANativeWindow 和 Surface 之间的关系

在MediaCodec里面可以看到 Configure 和 SetSurface 都是接收一个 sp<Surface> 入参的,而回归到 NDK 侧,则可以发现,传递给 AMediaCodec_Configure 和 AMediaCodec_SetSurface 的确是 ANativeWindow 指针,因此 ndk 里面必然进行了某种转换。

EXPORT
media_status_t AMediaCodec_configure(AMediaCodec *mData,const AMediaFormat* format,ANativeWindow* window,AMediaCrypto *crypto,uint32_t flags) {sp<AMessage> nativeFormat;AMediaFormat_getFormat(format, &nativeFormat);// create our shallow copy, so we aren't victim to any later changes.sp<AMessage> dupNativeFormat = nativeFormat->dup();ALOGV("configure with format: %s", dupNativeFormat->debugString(0).c_str());sp<Surface> surface = NULL;if (window != NULL) {surface = (Surface*) window;}status_t err = mData->mCodec->configure(dupNativeFormat, surface,crypto ? crypto->mCrypto : NULL, flags);if (err != OK) {ALOGE("configure: err(%d), failed with format: %s",err, dupNativeFormat->debugString(0).c_str());}return translate_error(err);
}
//prebuilts/vndk/v32/arm64/include/frameworks/native/libs/gui/include/gui/Surface.h/** An implementation of ANativeWindow that feeds graphics buffers into a* BufferQueue.** This is typically used by programs that want to render frames through* some means (maybe OpenGL, a software renderer, or a hardware decoder)* and have the frames they create forwarded to SurfaceFlinger for* compositing.  For example, a video decoder could render a frame and call* eglSwapBuffers(), which invokes ANativeWindow callbacks defined by* Surface.  Surface then forwards the buffers through Binder IPC* to the BufferQueue's producer interface, providing the new frame to a* consumer such as GLConsumer.*/
class Surface: public ANativeObjectBase<ANativeWindow, Surface, RefBase>

由此可见, Surface 类是 ANativeWindow 的子类。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com