【camera 005】 Camera Surface 数据流获取流程深度解析

【camera 005】 Camera Surface 数据流获取流程深度解析 1 app 获取数据方式在 Android 相机架构中,mCameraDevice.createCaptureSession(…) 是应用层(App)发起创建一个相机捕获会话(Capture Session)的关键 API。你提到的代码:mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),mCaptureStateCallback,mBackgroundHandler);其中传入了两个 Surface 对象:一个是用于预览(如 TextureView 或 SurfaceView 的 Surface),另一个是用于图像捕获(如 ImageReader 的 Surface)。这些 Surface 本质上是 BufferQueue 的消费者端(Consumer),而 Camera HAL 是生产者端(Producer)。下面从 App → Framework → HAL 的完整数据流角度,详细说明数据是如何从 Camera 到达 App 的 Surface 的:demo/* * * Images drawn to the Surface will be made available to the {@link * SurfaceTexture}, which can attach them to an OpenGL ES texture via {@link * SurfaceTexture#updateTexImage}. * */SurfaceTexturetexture=mTextureView.getSurfaceTexture();asserttexture!=null;// We configure the size of default buffer to be the size of camera preview we want.texture.setDefaultBufferSize(mPreviewSize.getWidth(),mPreviewSize.getHeight());// This is the output Surface we need to start preview.Surfacesurface=newSurface(texture);Log.e(TAG,"new Surface");// We set up a CaptureRequest.Builder with the output Surface.